6 #define ASSERT(cnd) printf("ASSERT: "#cnd" == %s\n", ((cnd) ? "pass" : "FAIL"))
10 ASSERT(strcmp("hello", "world") < 0);
11 ASSERT(strcmp("hello", "hello") == 0);
12 ASSERT(strcmp("wello", "hello") > 0);
13 ASSERT(strcmp("\xff", "\1") > 0);
14 ASSERT(strcmp("\1", "\xff") < 0);
15 ASSERT(strcmp("Hello", "hello") < 0);
17 ASSERT(strncmp("hello world", "hello", 5) == 0);
19 ASSERT(strcasecmp("hello", "world") < 0);
20 ASSERT(strcasecmp("hello", "hello") == 0);
21 ASSERT(strcasecmp("wello", "hello") > 0);
22 ASSERT(strcasecmp("\xff", "\1") > 0);
23 ASSERT(strcasecmp("\1", "\xff") < 0);
24 ASSERT(strcasecmp("Hello", "hello") == 0);
25 ASSERT(strcasecmp("Hello", "Hello") == 0);
26 ASSERT(strcasecmp("hellO", "Hello") == 0);
29 memset(buf, 127, sizeof(buf));
30 ASSERT(buf[0] == 127); ASSERT(buf[4] == 127);
31 strncpy(buf, "hello", 4);
32 ASSERT(buf[3] == 'l'); ASSERT(buf[4] == 127);
33 strncpy(buf, "hello", 8);
34 ASSERT(buf[4] == 'o'); ASSERT(buf[5] == '\0'); ASSERT(buf[7] == '\0'); ASSERT(buf[8] == 127);
37 ASSERT(buf[0] == 0); ASSERT(buf[12] == 0);
39 ASSERT(memchr("\xffhello", 'x', 6) == NULL);
41 const char *teststr_foo = "foo";
42 ASSERT(strchr(teststr_foo, 'f') == teststr_foo+0);
43 ASSERT(strchr(teststr_foo, 'o') == teststr_foo+1);
44 ASSERT(strchr(teststr_foo, '\0') == teststr_foo+3);
45 ASSERT(strchr(teststr_foo, 'X') == NULL);
46 ASSERT(strrchr(teststr_foo, 'f') == teststr_foo+0);
47 ASSERT(strrchr(teststr_foo, 'o') == teststr_foo+2);
48 ASSERT(strrchr(teststr_foo, '\0') == teststr_foo+3);
49 ASSERT(strrchr(teststr_foo, 'X') == NULL);