summaryrefslogtreecommitdiff
path: root/tests/unistr
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2010-07-31 21:26:01 +0200
committerBruno Haible <bruno@clisp.org>2010-07-31 21:26:01 +0200
commitc8068b3df116650efbf0fbf2d790c706577ae972 (patch)
tree6c2486b7570140bcfecd4e2d6b4d1544b8d8dcad /tests/unistr
parent870daa58035b4bb39549f15d20ad1422dd649d63 (diff)
downloadgnulib-c8068b3df116650efbf0fbf2d790c706577ae972.tar.gz
More tests for unistr/u8-strchr.
Diffstat (limited to 'tests/unistr')
-rw-r--r--tests/unistr/test-strchr.h40
-rw-r--r--tests/unistr/test-u16-strchr.c8
-rw-r--r--tests/unistr/test-u32-strchr.c8
-rw-r--r--tests/unistr/test-u8-strchr.c115
4 files changed, 164 insertions, 7 deletions
diff --git a/tests/unistr/test-strchr.h b/tests/unistr/test-strchr.h
index f280406eb1..9a22fb7412 100644
--- a/tests/unistr/test-strchr.h
+++ b/tests/unistr/test-strchr.h
@@ -1,4 +1,4 @@
-/* Test of uN_chr() functions.
+/* Test of uN_strchr() functions.
Copyright (C) 2008-2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
@@ -17,8 +17,8 @@
/* Written by Paolo Bonzini <bonzini@gnu.org>, 2010.
Based on test-chr.h, by Eric Blake and Bruno Haible. */
-int
-main (void)
+static void
+test_strchr (void)
{
size_t size = 0x100000;
size_t length;
@@ -101,8 +101,7 @@ main (void)
}
}
- /* Check that uN_chr() does not read past the first occurrence of the
- byte being searched. */
+ /* Check that uN_strchr() does not read past the end of the string. */
{
char *page_boundary = (char *) zerosize_ptr ();
size_t n;
@@ -122,7 +121,34 @@ main (void)
}
}
- free (input);
+ /* Check that uN_strchr() does not read past the first occurrence of the
+ byte being searched. */
+ {
+ char *page_boundary = (char *) zerosize_ptr ();
+ size_t n;
+
+ if (page_boundary != NULL)
+ {
+ for (n = 2; n <= 500 / sizeof (UNIT); n++)
+ {
+ UNIT *mem = (UNIT *) (page_boundary - n * sizeof (UNIT));
+ U_SET (mem, 'X', n - 1);
+ mem[n - 1] = 0;
+ ASSERT (U_STRCHR (mem, 'U') == NULL);
+
+ {
+ size_t i;
- return 0;
+ for (i = 0; i < n; i++)
+ {
+ mem[i] = 'U';
+ ASSERT (U_STRCHR (mem, 'U') == mem + i);
+ mem[i] = 'X';
+ }
+ }
+ }
+ }
+ }
+
+ free (input);
}
diff --git a/tests/unistr/test-u16-strchr.c b/tests/unistr/test-u16-strchr.c
index 24cab3a060..7de8c6405a 100644
--- a/tests/unistr/test-u16-strchr.c
+++ b/tests/unistr/test-u16-strchr.c
@@ -32,3 +32,11 @@
#define U_STRCHR u16_strchr
#define U_SET u16_set
#include "test-strchr.h"
+
+int
+main (void)
+{
+ test_strchr ();
+
+ return 0;
+}
diff --git a/tests/unistr/test-u32-strchr.c b/tests/unistr/test-u32-strchr.c
index fdbdc0dbca..74903d9b95 100644
--- a/tests/unistr/test-u32-strchr.c
+++ b/tests/unistr/test-u32-strchr.c
@@ -32,3 +32,11 @@
#define U_STRCHR u32_strchr
#define U_SET u32_set
#include "test-strchr.h"
+
+int
+main (void)
+{
+ test_strchr ();
+
+ return 0;
+}
diff --git a/tests/unistr/test-u8-strchr.c b/tests/unistr/test-u8-strchr.c
index ee8b9f2b32..2a289fb381 100644
--- a/tests/unistr/test-u8-strchr.c
+++ b/tests/unistr/test-u8-strchr.c
@@ -32,3 +32,118 @@
#define U_STRCHR u8_strchr
#define U_SET u8_set
#include "test-strchr.h"
+
+int
+main (void)
+{
+ test_strchr ();
+
+ /* Check that u8_strchr() does not read past the end of the string. */
+ {
+ char *page_boundary = (char *) zerosize_ptr ();
+
+ if (page_boundary != NULL)
+ {
+ UNIT *mem;
+
+ mem = (UNIT *) (page_boundary - 1 * sizeof (UNIT));
+ mem[0] = 0;
+ ASSERT (u8_strchr (mem, 0x55) == NULL);
+ ASSERT (u8_strchr (mem, 0x123) == NULL);
+ ASSERT (u8_strchr (mem, 0x3456) == NULL);
+ ASSERT (u8_strchr (mem, 0x23456) == NULL);
+
+ mem = (UNIT *) (page_boundary - 2 * sizeof (UNIT));
+ mem[0] = 0x50;
+ mem[1] = 0;
+ ASSERT (u8_strchr (mem, 0x55) == NULL);
+ ASSERT (u8_strchr (mem, 0x123) == NULL);
+ ASSERT (u8_strchr (mem, 0x3456) == NULL);
+ ASSERT (u8_strchr (mem, 0x23456) == NULL);
+
+ mem = (UNIT *) (page_boundary - 3 * sizeof (UNIT));
+ mem[0] = 0x50;
+ mem[1] = 0x50;
+ mem[2] = 0;
+ ASSERT (u8_strchr (mem, 0x55) == NULL);
+ ASSERT (u8_strchr (mem, 0x123) == NULL);
+ ASSERT (u8_strchr (mem, 0x3456) == NULL);
+ ASSERT (u8_strchr (mem, 0x23456) == NULL);
+
+ mem = (UNIT *) (page_boundary - 3 * sizeof (UNIT));
+ mem[0] = 0xC4; mem[1] = 0xA0; /* U+0120 */
+ mem[2] = 0;
+ ASSERT (u8_strchr (mem, 0x55) == NULL);
+ ASSERT (u8_strchr (mem, 0x123) == NULL);
+ ASSERT (u8_strchr (mem, 0x3456) == NULL);
+ ASSERT (u8_strchr (mem, 0x23456) == NULL);
+
+ mem = (UNIT *) (page_boundary - 3 * sizeof (UNIT));
+ mem[0] = 0xC5; mem[1] = 0xA3; /* U+0163 */
+ mem[2] = 0;
+ ASSERT (u8_strchr (mem, 0x55) == NULL);
+ ASSERT (u8_strchr (mem, 0x123) == NULL);
+ ASSERT (u8_strchr (mem, 0x3456) == NULL);
+ ASSERT (u8_strchr (mem, 0x23456) == NULL);
+
+ mem = (UNIT *) (page_boundary - 4 * sizeof (UNIT));
+ mem[0] = 0x50;
+ mem[1] = 0x50;
+ mem[2] = 0x50;
+ mem[3] = 0;
+ ASSERT (u8_strchr (mem, 0x55) == NULL);
+ ASSERT (u8_strchr (mem, 0x123) == NULL);
+ ASSERT (u8_strchr (mem, 0x3456) == NULL);
+ ASSERT (u8_strchr (mem, 0x23456) == NULL);
+
+ mem = (UNIT *) (page_boundary - 4 * sizeof (UNIT));
+ mem[0] = 0x50;
+ mem[1] = 0xC5; mem[2] = 0xA3; /* U+0163 */
+ mem[3] = 0;
+ ASSERT (u8_strchr (mem, 0x55) == NULL);
+ ASSERT (u8_strchr (mem, 0x123) == NULL);
+ ASSERT (u8_strchr (mem, 0x3456) == NULL);
+ ASSERT (u8_strchr (mem, 0x23456) == NULL);
+ ASSERT (u8_strchr (mem, 0x163) == mem + 1);
+
+ mem = (UNIT *) (page_boundary - 4 * sizeof (UNIT));
+ mem[0] = 0xE3; mem[1] = 0x91; mem[2] = 0x00; /* U+3450 */
+ mem[3] = 0;
+ ASSERT (u8_strchr (mem, 0x55) == NULL);
+ ASSERT (u8_strchr (mem, 0x123) == NULL);
+ ASSERT (u8_strchr (mem, 0x3456) == NULL);
+ ASSERT (u8_strchr (mem, 0x23456) == NULL);
+
+ mem = (UNIT *) (page_boundary - 4 * sizeof (UNIT));
+ mem[0] = 0xE3; mem[1] = 0x92; mem[2] = 0x96; /* U+3496 */
+ mem[3] = 0;
+ ASSERT (u8_strchr (mem, 0x55) == NULL);
+ ASSERT (u8_strchr (mem, 0x123) == NULL);
+ ASSERT (u8_strchr (mem, 0x3456) == NULL);
+ ASSERT (u8_strchr (mem, 0x23456) == NULL);
+
+ mem = (UNIT *) (page_boundary - 5 * sizeof (UNIT));
+ mem[0] = 0x50;
+ mem[1] = 0x50;
+ mem[2] = 0x50;
+ mem[3] = 0x50;
+ mem[4] = 0;
+ ASSERT (u8_strchr (mem, 0x55) == NULL);
+ ASSERT (u8_strchr (mem, 0x123) == NULL);
+ ASSERT (u8_strchr (mem, 0x3456) == NULL);
+ ASSERT (u8_strchr (mem, 0x23456) == NULL);
+
+ mem = (UNIT *) (page_boundary - 5 * sizeof (UNIT));
+ mem[0] = 0x50;
+ mem[1] = 0xE3; mem[2] = 0x92; mem[3] = 0x96; /* U+3496 */
+ mem[4] = 0;
+ ASSERT (u8_strchr (mem, 0x55) == NULL);
+ ASSERT (u8_strchr (mem, 0x123) == NULL);
+ ASSERT (u8_strchr (mem, 0x3456) == NULL);
+ ASSERT (u8_strchr (mem, 0x23456) == NULL);
+ ASSERT (u8_strchr (mem, 0x3496) == mem + 1);
+ }
+ }
+
+ return 0;
+}