/* * Test that our strcspn() matches the results of the * system strcspn(). * * Dan Cross */ #include #include #include #include #include "myunit.h" int myu_ntests = 0; /* Be explicit about initialization. */ int myu_nfailed = 0; #define strcspn mystrcspn extern size_t mystrcspn(const char *, const char *); #include "strcspn.c" #undef strcspn int testcase(const char *tname, const char *aa, const char *bb) { size_t a, b; /* The system version can't handle the first argument being NULL */ if (aa == NULL || bb == NULL) return 0; b = strcspn(aa, bb); a = mystrcspn(aa, bb); myuassert(a == b, "%s mismatch: a = %d, b = %d", tname, a, b); return(0); } #define test(a, b) myuruntest(testcase, #a ", " #b, a, b) int main(int argc, char *argv[]) { myuinit(); test(NULL, NULL); test("", NULL); test(NULL, ""); test("", ""); test("This", "is"); test("This", "not"); test("This", ""); test("This", NULL); test("no", "longer"); test("Yes", "especially"); test("abcd", "efghijkl"); myureport("strcspn"); return(EXIT_SUCCESS); }