1
/* $Id: strncasecmp.c,v 1.1 2007/02/24 14:20:17 dmix Exp $ */
10
void Check (int line, const char *s1, const char *s2, size_t len, int expect)
15
if ( strlen_P(s1) > sizeof(t1) - 1
16
|| strlen_P(s2) > sizeof(t2) - 1)
20
i = strncasecmp (t1, t2, len);
24
printf ("\nLine %d: expect: %d, result: %d\n",
26
if (line > 255) line = 255;
33
#define CHECK(s1, s2, len,expect) do { \
34
Check (__LINE__, PSTR(s1), PSTR(s2), len, expect); \
39
/* One or both strings are empty. */
40
CHECK ("", "", 10, 0);
41
CHECK ("", "\001", 10, -1);
42
CHECK ("", "\377", 10, -255);
43
CHECK ("\001", "", 10, 1);
44
CHECK ("\377", "", 10, 255);
47
CHECK ("a", "[", 10, 'a' - '[');
48
CHECK ("[", "a", 10, '[' - 'a');
51
CHECK ("\001", "\001", 10, 0);
52
CHECK ("1234\377", "1234\377", 10, 0);
53
CHECK ("ABC", "abc", 10, 0);
54
CHECK ("FoO", "fOO", 10, 0);
56
/* Args are not equal. */
57
CHECK ("@", "`", 10, '@' - '`'); /* '@'=='A'-1, '`'=='a'-1 */
58
CHECK ("{", "[", 10, '{' - '['); /* '{'=='z'+1, '['=='A'+1 */
60
/* Alpha is always converted to lower */
61
CHECK ("1", "A", 10, '1'-'a');
62
CHECK ("Z", "2", 10, 'z'-'2');
64
/* Chars are unsigned */
65
CHECK ("\200", "\177", 10, 1);
66
CHECK ("\177", "\200", 10, -1);
67
CHECK ("\001", "\377", 10, -254);
68
CHECK ("\377", "\001", 10, 254);
70
/* Length too small */
72
CHECK ("ab", "ac", 1, 0);
73
CHECK ("FOO", "foo123", 3, 0);
74
CHECK ("ABCDEF", "AbcD", 4, 0);
77
CHECK ("", "", ~0, 0);
78
CHECK ("foo", "Foo", ~0, 0);
80
/* Length is equal to string length */
81
CHECK ("12345678", "12345678", 8, 0);
82
CHECK ("12345679", "12345678", 8, 1);
83
CHECK ("12345678", "12345679", 8, -1);