diff options
author | Mike Frysinger <vapier@gentoo.org> | 2008-01-05 09:22:58 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2008-01-05 09:22:58 +0000 |
commit | c616287f88aeefcf81125f89978de57aaa52408d (patch) | |
tree | 8b541dc6f821bb42ba1c34ade3a4eb1d36d77b8a /test/string/tester.c | |
parent | d08085316bb279f35f41e80a8faa0a964be50b48 (diff) |
patch from Mats Erik Andersson for better catching edge cases in optimized string functions
Diffstat (limited to 'test/string/tester.c')
-rw-r--r-- | test/string/tester.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/test/string/tester.c b/test/string/tester.c index 71fee0c9b..647b8c174 100644 --- a/test/string/tester.c +++ b/test/string/tester.c @@ -1087,15 +1087,31 @@ test_strsep (void) static void test_memcmp (void) { + int i, cnt = 1; + char one[21], two[21]; + it = "memcmp"; - check(memcmp("a", "a", 1) == 0, 1); /* Identity. */ - check(memcmp("abc", "abc", 3) == 0, 2); /* Multicharacter. */ - check(memcmp("abcd", "abce", 4) < 0, 3); /* Honestly unequal. */ - check(memcmp("abce", "abcd", 4) > 0, 4); - check(memcmp("alph", "beta", 4) < 0, 5); - check(memcmp("a\203", "a\003", 2) > 0, 6); - check(memcmp("abce", "abcd", 3) == 0, 7); /* Count limited. */ - check(memcmp("abc", "def", 0) == 0, 8); /* Zero count. */ + check(memcmp("a", "a", 1) == 0, cnt++); /* Identity. */ + check(memcmp("abc", "abc", 3) == 0, cnt++); /* Multicharacter. */ + check(memcmp("abcd", "abcf", 4) < 0, cnt++); /* Honestly unequal. */ + check(memcmp("abcf", "abcd", 4) > 0, cnt++); + check(memcmp("alph", "cold", 4) < 0, cnt++); + check(memcmp("a\203", "a\003", 2) > 0, cnt++); + check(memcmp("a\003", "a\203", 2) < 0, cnt++); + check(memcmp("a\003bc", "a\203bc", 2) < 0, cnt++); + check(memcmp("abc\203", "abc\003", 4) > 0, cnt++); + check(memcmp("abc\003", "abc\203", 4) < 0, cnt++); + check(memcmp("abcf", "abcd", 3) == 0, cnt++); /* Count limited. */ + check(memcmp("abc", "def", 0) == 0, cnt++); /* Zero count. */ + /* Comparisons with shifting 4-byte boundaries. */ + for (i=0; i<4; i++) + { + char *a = one + i, *b = two + i; + strncpy( a, "--------11112222", 16); + strncpy( b, "--------33334444", 16); + check( memcmp(b, a, 16) > 0, cnt++); + check( memcmp(a, b, 16) < 0, cnt++); + } } static void |