From: Paolo Bonzini <[email protected]> * modules/unistr/u16-strchr-tests, modules/unistr/u32-strchr-tests, modules/unistr/u8-strchr-tests, tests/unistr/test-strchr.h, tests/unistr/test-u16-strchr.c, tests/unistr/test-u32-strchr.c, tests/unistr/test-u8-strchr.c: New files. --- modules/unistr/u16-strchr-tests | 22 +++++++++ modules/unistr/u32-strchr-tests | 22 +++++++++ modules/unistr/u8-strchr-tests | 22 +++++++++ tests/unistr/test-strchr.h | 95 +++++++++++++++++++++++++++++++++++++++ tests/unistr/test-u16-strchr.c | 31 +++++++++++++ tests/unistr/test-u32-strchr.c | 31 +++++++++++++ tests/unistr/test-u8-strchr.c | 31 +++++++++++++ 7 files changed, 254 insertions(+), 0 deletions(-) create mode 100644 modules/unistr/u16-strchr-tests create mode 100644 modules/unistr/u32-strchr-tests create mode 100644 modules/unistr/u8-strchr-tests create mode 100644 tests/unistr/test-strchr.h create mode 100644 tests/unistr/test-u16-strchr.c create mode 100644 tests/unistr/test-u32-strchr.c create mode 100644 tests/unistr/test-u8-strchr.c
diff --git a/modules/unistr/u16-strchr-tests b/modules/unistr/u16-strchr-tests new file mode 100644 index 0000000..8ac0078 --- /dev/null +++ b/modules/unistr/u16-strchr-tests @@ -0,0 +1,22 @@ +Files: +tests/unistr/test-u16-strchr.c +tests/unistr/test-strchr.h +tests/zerosize-ptr.h +tests/macros.h +m4/mmap-anon.m4 + +Depends-on: +extensions +getpagesize +unistr/u16-set + +configure.ac: +gl_FUNC_MMAP_ANON +AC_CHECK_HEADERS_ONCE([sys/mman.h]) +AC_CHECK_FUNCS_ONCE([mprotect]) + +Makefile.am: +TESTS += test-u16-strchr +check_PROGRAMS += test-u16-strchr +test_u16_strchr_SOURCES = unistr/test-u16-strchr.c +test_u16_strchr_LDADD = $(LDADD) $(LIBUNISTRING) diff --git a/modules/unistr/u32-strchr-tests b/modules/unistr/u32-strchr-tests new file mode 100644 index 0000000..f8278e9 --- /dev/null +++ b/modules/unistr/u32-strchr-tests @@ -0,0 +1,22 @@ +Files: +tests/unistr/test-u32-strchr.c +tests/unistr/test-strchr.h +tests/zerosize-ptr.h +tests/macros.h +m4/mmap-anon.m4 + +Depends-on: +extensions +getpagesize +unistr/u32-set + +configure.ac: +gl_FUNC_MMAP_ANON +AC_CHECK_HEADERS_ONCE([sys/mman.h]) +AC_CHECK_FUNCS_ONCE([mprotect]) + +Makefile.am: +TESTS += test-u32-strchr +check_PROGRAMS += test-u32-strchr +test_u32_strchr_SOURCES = unistr/test-u32-strchr.c +test_u32_strchr_LDADD = $(LDADD) $(LIBUNISTRING) diff --git a/modules/unistr/u8-strchr-tests b/modules/unistr/u8-strchr-tests new file mode 100644 index 0000000..103671f --- /dev/null +++ b/modules/unistr/u8-strchr-tests @@ -0,0 +1,22 @@ +Files: +tests/unistr/test-u8-strchr.c +tests/unistr/test-strchr.h +tests/zerosize-ptr.h +tests/macros.h +m4/mmap-anon.m4 + +Depends-on: +extensions +getpagesize +unistr/u8-set + +configure.ac: +gl_FUNC_MMAP_ANON +AC_CHECK_HEADERS_ONCE([sys/mman.h]) +AC_CHECK_FUNCS_ONCE([mprotect]) + +Makefile.am: +TESTS += test-u8-strchr +check_PROGRAMS += test-u8-strchr +test_u8_strchr_SOURCES = unistr/test-u8-strchr.c +test_u8_strchr_LDADD = $(LDADD) $(LIBUNISTRING) diff --git a/tests/unistr/test-strchr.h b/tests/unistr/test-strchr.h new file mode 100644 index 0000000..69bbcda --- /dev/null +++ b/tests/unistr/test-strchr.h @@ -0,0 +1,95 @@ +/* Test of uN_chr() functions. + Copyright (C) 2008-2010 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* Written by Paolo Bonzini <[email protected]>, 2010. + Based on test-chr.h, by Eric Blake and Bruno Haible. */ + +int +main (void) +{ + size_t n = 0x100000; + UNIT *input = (UNIT *) malloc ((n + 1) * sizeof (UNIT)); + ASSERT (input); + + input[0] = 'a'; + input[1] = 'b'; + U_SET (input + 2, 'c', 1024); + U_SET (input + 1026, 'd', n - 1028); + input[n - 2] = 'e'; + input[n - 1] = 'a'; + input[n] = 0; + + /* Basic behavior tests. */ + ASSERT (U_CHR (input, 'a') == input); + ASSERT (U_CHR (input, 'b') == input + 1); + ASSERT (U_CHR (input, 'c') == input + 2); + ASSERT (U_CHR (input, 'd') == input + 1026); + + ASSERT (U_CHR (input + 1, 'a') == input + n - 1); + ASSERT (U_CHR (input + 1, 'e') == input + n - 2); + + ASSERT (U_CHR (input, 'f') == NULL); + ASSERT (U_CHR (input, '\0') == input + n); + + /* Check that a very long haystack is handled quickly if the byte is + found near the beginning. */ + { + size_t repeat = 10000; + for (; repeat > 0; repeat--) + { + ASSERT (U_CHR (input, 'c') == input + 2); + } + } + + /* Alignment tests. */ + { + int i, j; + for (i = 0; i < 32; i++) + { + for (j = 0; j < 127; j++) + input[i + j] = j + 1; + input[i + 128] = 0; + for (j = 0; j < 127; j++) + { + ASSERT (U_CHR (input + i, j + 1) == input + i + j); + } + } + } + + /* Check that uN_chr() does not read past the first occurrence of the + byte being searched. */ + { + char *page_boundary = (char *) zerosize_ptr (); + + 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 - 2); + mem[n - 2] = 0; + ASSERT (U_CHR (mem, 'U') == NULL); + mem[n - 2] = 'X'; + mem[n - 1] = 0; + ASSERT (U_CHR (mem, 'U') == NULL); + } + } + } + + free (input); + + return 0; +} diff --git a/tests/unistr/test-u16-strchr.c b/tests/unistr/test-u16-strchr.c new file mode 100644 index 0000000..fc4bd62 --- /dev/null +++ b/tests/unistr/test-u16-strchr.c @@ -0,0 +1,31 @@ +/* Test of u16_chr() function. + Copyright (C) 2010 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* Written by Paolo Bonzini <[email protected]>, 2010. */ + +#include <config.h> + +#include "unistr.h" + +#include <stdlib.h> + +#include "zerosize-ptr.h" +#include "macros.h" + +#define UNIT uint16_t +#define U_CHR u16_strchr +#define U_SET u16_set +#include "test-strchr.h" diff --git a/tests/unistr/test-u32-strchr.c b/tests/unistr/test-u32-strchr.c new file mode 100644 index 0000000..214bc66 --- /dev/null +++ b/tests/unistr/test-u32-strchr.c @@ -0,0 +1,31 @@ +/* Test of u32_chr() function. + Copyright (C) 2010 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* Written by Paolo Bonzini <[email protected]>, 2010. */ + +#include <config.h> + +#include "unistr.h" + +#include <stdlib.h> + +#include "zerosize-ptr.h" +#include "macros.h" + +#define UNIT uint32_t +#define U_CHR u32_strchr +#define U_SET u32_set +#include "test-strchr.h" diff --git a/tests/unistr/test-u8-strchr.c b/tests/unistr/test-u8-strchr.c new file mode 100644 index 0000000..edcd32e --- /dev/null +++ b/tests/unistr/test-u8-strchr.c @@ -0,0 +1,31 @@ +/* Test of u8_chr() function. + Copyright (C) 2010 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* Written by Paolo Bonzini <[email protected]>, 2010. */ + +#include <config.h> + +#include "unistr.h" + +#include <stdlib.h> + +#include "zerosize-ptr.h" +#include "macros.h" + +#define UNIT uint8_t +#define U_CHR u8_strchr +#define U_SET u8_set +#include "test-strchr.h" -- 1.7.1
