From: Bruno Haible Date: Sat, 31 Jul 2010 19:26:01 +0000 (+0200) Subject: More tests for unistr/u8-strchr. X-Git-Tag: v0.1~3967 X-Git-Url: http://erislabs.net/gitweb/?p=gnulib.git;a=commitdiff_plain;h=c8068b3df116650efbf0fbf2d790c706577ae972 More tests for unistr/u8-strchr. --- diff --git a/ChangeLog b/ChangeLog index b0d710415..264945825 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2010-07-31 Bruno Haible + More tests for unistr/u8-strchr. + * tests/unistr/test-strchr.h (test_strchr): Renamed from main. Check + that the function does not read past the first occurrence of the byte + being searched. + * tests/unistr/test-u8-strchr.c (main): New function, with more tests. + * tests/unistr/test-u16-strchr.c (main): New function. + * tests/unistr/test-u32-strchr.c (main): New function. + +2010-07-31 Bruno Haible + posix-modules: Ignore backup files of documentation files. * posix-modules: grep only through files named *.texi. diff --git a/tests/unistr/test-strchr.h b/tests/unistr/test-strchr.h index f280406eb..9a22fb741 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 , 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 24cab3a06..7de8c6405 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 fdbdc0dbc..74903d9b9 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 ee8b9f2b3..2a289fb38 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; +}