Mercurial > hg > octave-kai > gnulib-hg
changeset 13520:1d091087ce86
More tests for unistr/u8-strchr.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sat, 31 Jul 2010 21:26:01 +0200 |
parents | da9dc9b63c04 |
children | 2d6b353bde02 |
files | ChangeLog tests/unistr/test-strchr.h tests/unistr/test-u16-strchr.c tests/unistr/test-u32-strchr.c tests/unistr/test-u8-strchr.c |
diffstat | 5 files changed, 174 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2010-07-31 Bruno Haible <bruno@clisp.org> + + 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 <bruno@clisp.org> posix-modules: Ignore backup files of documentation files.
--- 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 @@ } } - /* 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 @@ } } - 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); - return 0; + { + size_t i; + + for (i = 0; i < n; i++) + { + mem[i] = 'U'; + ASSERT (U_STRCHR (mem, 'U') == mem + i); + mem[i] = 'X'; + } + } + } + } + } + + free (input); }
--- 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; +}
--- 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; +}
--- 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; +}