/* * Test our strnlen() function. * * Dan Cross */ #include #include #include #include #include "myunit.h" int myu_ntests = 0; /* Be explicit about initialization. */ int myu_nfailed = 0; extern size_t strnlen(const char *, size_t); #include "strnlen.c" int testcase(const char *str, size_t max, size_t expected) { myuassert(strnlen(str, max) == expected, "mismatch: str = %s, max = %z, expected = %z", str, max, expected); return(0); } #define test(a, b, c) myuruntest(testcase, a, b, c) int main(int argc, char *argv[]) { myuinit(); test("", 0, 0); test("", 10, 0); test("a", 3, 1); test("ab", 1, 1); test("abc", 3, 3); test("abc", 4, 3); test("abcd", 3, 3); test("abcde", 10, 5); myureport("strnlen"); return(EXIT_SUCCESS); }