summaryrefslogtreecommitdiff
path: root/test/string/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/string/string.c')
-rw-r--r--test/string/string.c70
1 files changed, 64 insertions, 6 deletions
diff --git a/test/string/string.c b/test/string/string.c
index 60caddf99..cccef3ad9 100644
--- a/test/string/string.c
+++ b/test/string/string.c
@@ -1,5 +1,5 @@
/* Tester for string functions.
- Copyright (C) 1995-2000, 2001 Free Software Foundation, Inc.
+ Copyright (C) 1995-2001, 2003, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -34,6 +34,7 @@
#include <strings.h>
#include <fcntl.h>
+
#define STREQ(a, b) (strcmp((a), (b)) == 0)
const char *it = "<UNSET>"; /* Routine name for message routines. */
@@ -84,8 +85,8 @@ test_strcmp (void)
int k;
for (k = 0; k < 0x3f; k++)
{
- buf1[j] = '0' ^ (k & 4);
- buf2[j] = '4' ^ (k & 4);
+ buf1[k] = '0' ^ (k & 4);
+ buf2[k] = '4' ^ (k & 4);
}
buf1[i] = buf1[0x3f] = 0;
buf2[j] = buf2[0x3f] = 0;
@@ -168,6 +169,12 @@ test_strcpy (void)
SIMPLE_COPY(strcpy, 14, "44444444444444", 55);
SIMPLE_COPY(strcpy, 15, "555555555555555", 56);
SIMPLE_COPY(strcpy, 16, "6666666666666666", 57);
+
+ /* Simple test using implicitly coerced `void *' arguments. */
+ const void *src = "frobozz";
+ void *dst = one;
+ check (strcpy (dst, src) == dst, 1);
+ equal (dst, "frobozz", 2);
}
static void
@@ -360,7 +367,7 @@ test_strncmp (void)
check (strncmp ("abce", "abc", 3) == 0, 11); /* Count == length. */
check (strncmp ("abcd", "abce", 4) < 0, 12); /* Nudging limit. */
check (strncmp ("abc", "def", 0) == 0, 13); /* Zero count. */
- check (strncmp ("abc", "", (size_t)-1) > 0, 14); /* set sign bit in count */
+ check (strncmp ("abc", "", (size_t)-1) > 0, 14); /* set sign bit in count */
check (strncmp ("abc", "abc", (size_t)-2) == 0, 15);
}
@@ -433,7 +440,7 @@ test_strnlen (void)
it = "strnlen";
check (strnlen ("", 10) == 0, 1); /* Empty. */
check (strnlen ("a", 10) == 1, 2); /* Single char. */
- check (strnlen ("abcd", 10) == 4, 3); /* Multiple chars. */
+ check (strnlen ("abcd", 10) == 4, 3); /* Multiple chars. */
check (strnlen ("foo", (size_t)-1) == 3, 4); /* limits of n. */
{
@@ -1325,6 +1332,52 @@ test_strerror (void)
check(strerror(ENOENT) != 0, 3);
}
+static void
+test_strcasecmp (void)
+{
+ it = "strcasecmp";
+ /* Note that the locale is "C". */
+ check(strcasecmp("a", "a") == 0, 1);
+ check(strcasecmp("a", "A") == 0, 2);
+ check(strcasecmp("A", "a") == 0, 3);
+ check(strcasecmp("a", "b") < 0, 4);
+ check(strcasecmp("c", "b") > 0, 5);
+ check(strcasecmp("abc", "AbC") == 0, 6);
+ check(strcasecmp("0123456789", "0123456789") == 0, 7);
+ check(strcasecmp("", "0123456789") < 0, 8);
+ check(strcasecmp("AbC", "") > 0, 9);
+ check(strcasecmp("AbC", "A") > 0, 10);
+ check(strcasecmp("AbC", "Ab") > 0, 11);
+ check(strcasecmp("AbC", "ab") > 0, 12);
+}
+
+static void
+test_strncasecmp (void)
+{
+ it = "strncasecmp";
+ /* Note that the locale is "C". */
+ check(strncasecmp("a", "a", 5) == 0, 1);
+ check(strncasecmp("a", "A", 5) == 0, 2);
+ check(strncasecmp("A", "a", 5) == 0, 3);
+ check(strncasecmp("a", "b", 5) < 0, 4);
+ check(strncasecmp("c", "b", 5) > 0, 5);
+ check(strncasecmp("abc", "AbC", 5) == 0, 6);
+ check(strncasecmp("0123456789", "0123456789", 10) == 0, 7);
+ check(strncasecmp("", "0123456789", 10) < 0, 8);
+ check(strncasecmp("AbC", "", 5) > 0, 9);
+ check(strncasecmp("AbC", "A", 5) > 0, 10);
+ check(strncasecmp("AbC", "Ab", 5) > 0, 11);
+ check(strncasecmp("AbC", "ab", 5) > 0, 12);
+ check(strncasecmp("0123456789", "AbC", 0) == 0, 13);
+ check(strncasecmp("AbC", "abc", 1) == 0, 14);
+ check(strncasecmp("AbC", "abc", 2) == 0, 15);
+ check(strncasecmp("AbC", "abc", 3) == 0, 16);
+ check(strncasecmp("AbC", "abcd", 3) == 0, 17);
+ check(strncasecmp("AbC", "abcd", 4) < 0, 18);
+ check(strncasecmp("ADC", "abcd", 1) == 0, 19);
+ check(strncasecmp("ADC", "abcd", 2) > 0, 20);
+}
+
int
main (void)
{
@@ -1438,6 +1491,11 @@ main (void)
/* strerror - VERY system-dependent. */
test_strerror ();
+ /* strcasecmp. Without locale dependencies. */
+ test_strcasecmp ();
+
+ /* strncasecmp. Without locale dependencies. */
+ test_strncasecmp ();
if (errors == 0)
{
@@ -1447,7 +1505,7 @@ main (void)
else
{
status = EXIT_FAILURE;
- printf("%lu errors.\n", (unsigned long)errors);
+ printf("%Zd errors.\n", errors);
}
return status;