From: Bruno Haible Date: Sun, 2 Apr 2023 10:52:44 +0000 (+0200) Subject: unistr/u*strstr tests: Add more tests. X-Git-Tag: v1.0~1533 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=768593d575328a4b7c0fae0958f3d3af0a2ac3f9;p=gnulib.git unistr/u*strstr tests: Add more tests. * tests/unistr/test-u-strstr.h (test_u_strstr): Add the two latest tests from tests/test-strstr.c. * tests/unistr/test-u8-strstr.c (U_SET): New macro. * tests/unistr/test-u16-strstr.c (U_SET): New macro. * tests/unistr/test-u32-strstr.c (U_SET): New macro. * modules/unistr/u8-strstr-tests (Depends-on): Add unistr/u8-set. * modules/unistr/u16-strstr-tests (Depends-on): Add unistr/u16-set. * modules/unistr/u32-strstr-tests (Depends-on): Add unistr/u32-set. --- diff --git a/ChangeLog b/ChangeLog index ca6f2d54f4..ddc568db03 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2023-04-02 Bruno Haible + + unistr/u*strstr tests: Add more tests. + * tests/unistr/test-u-strstr.h (test_u_strstr): Add the two latest tests + from tests/test-strstr.c. + * tests/unistr/test-u8-strstr.c (U_SET): New macro. + * tests/unistr/test-u16-strstr.c (U_SET): New macro. + * tests/unistr/test-u32-strstr.c (U_SET): New macro. + * modules/unistr/u8-strstr-tests (Depends-on): Add unistr/u8-set. + * modules/unistr/u16-strstr-tests (Depends-on): Add unistr/u16-set. + * modules/unistr/u32-strstr-tests (Depends-on): Add unistr/u32-set. + 2023-04-01 Bruno Haible vasnwprintf-posix: Fix behaviour in the C locale. diff --git a/modules/unistr/u16-strstr-tests b/modules/unistr/u16-strstr-tests index 5c3cfbff8d..3e77e8af4a 100644 --- a/modules/unistr/u16-strstr-tests +++ b/modules/unistr/u16-strstr-tests @@ -4,6 +4,7 @@ tests/unistr/test-u-strstr.h tests/macros.h Depends-on: +unistr/u16-set configure.ac: AC_CHECK_DECLS_ONCE([alarm]) diff --git a/modules/unistr/u32-strstr-tests b/modules/unistr/u32-strstr-tests index 8ec3124225..bccd5e602f 100644 --- a/modules/unistr/u32-strstr-tests +++ b/modules/unistr/u32-strstr-tests @@ -4,6 +4,7 @@ tests/unistr/test-u-strstr.h tests/macros.h Depends-on: +unistr/u32-set configure.ac: AC_CHECK_DECLS_ONCE([alarm]) diff --git a/modules/unistr/u8-strstr-tests b/modules/unistr/u8-strstr-tests index fdc7b76e12..23336d2184 100644 --- a/modules/unistr/u8-strstr-tests +++ b/modules/unistr/u8-strstr-tests @@ -4,6 +4,7 @@ tests/unistr/test-u-strstr.h tests/macros.h Depends-on: +unistr/u8-set configure.ac: AC_CHECK_DECLS_ONCE([alarm]) diff --git a/tests/unistr/test-u-strstr.h b/tests/unistr/test-u-strstr.h index b97badc005..639b3d9112 100644 --- a/tests/unistr/test-u-strstr.h +++ b/tests/unistr/test-u-strstr.h @@ -207,4 +207,42 @@ test_u_strstr (void) free (needle); free (haystack); } + + /* Test case from Yves Bastide. + */ + { + const UNIT input[] = + { 'p', 'l', 'a', 'y', 'i', 'n', 'g', ' ', 'p', 'l', 'a', 'y', ' ', 'p', + 'l', 'a', 'y', ' ', 'p', 'l', 'a', 'y', ' ', 'a', 'l', 'w', 'a', 'y', + 's', 0 + }; + const UNIT needle[] = + { 'p', 'l', 'a', 'y', ' ', 'p', 'l', 'a', 'y', ' ', 'p', 'l', 'a', 'y', + 0 + }; + const UNIT *result = U_STRSTR (input, needle); + ASSERT (result == input + 8); + } + + /* Test long needles. */ + { + size_t m = 1024; + UNIT *haystack = (UNIT *) malloc ((2 * m + 1) * sizeof (UNIT)); + UNIT *needle = (UNIT *) malloc ((m + 1) * sizeof (UNIT)); + if (haystack != NULL && needle != NULL) + { + const UNIT *p; + haystack[0] = 'x'; + U_SET (haystack + 1, ' ', m - 1); + U_SET (haystack + m, 'x', m); + haystack[2 * m] = '\0'; + U_SET (needle, 'x', m); + needle[m] = '\0'; + p = U_STRSTR (haystack, needle); + ASSERT (p); + ASSERT (p - haystack == m); + } + free (needle); + free (haystack); + } } diff --git a/tests/unistr/test-u16-strstr.c b/tests/unistr/test-u16-strstr.c index b5cd028ff6..9c49aa0496 100644 --- a/tests/unistr/test-u16-strstr.c +++ b/tests/unistr/test-u16-strstr.c @@ -29,6 +29,7 @@ #define UNIT uint16_t #define U_STRSTR u16_strstr +#define U_SET u16_set #include "test-u-strstr.h" int diff --git a/tests/unistr/test-u32-strstr.c b/tests/unistr/test-u32-strstr.c index 9f388127a5..134a3c5366 100644 --- a/tests/unistr/test-u32-strstr.c +++ b/tests/unistr/test-u32-strstr.c @@ -29,6 +29,7 @@ #define UNIT uint32_t #define U_STRSTR u32_strstr +#define U_SET u32_set #include "test-u-strstr.h" int diff --git a/tests/unistr/test-u8-strstr.c b/tests/unistr/test-u8-strstr.c index f11d9408c2..39f831b2ea 100644 --- a/tests/unistr/test-u8-strstr.c +++ b/tests/unistr/test-u8-strstr.c @@ -29,6 +29,7 @@ #define UNIT uint8_t #define U_STRSTR u8_strstr +#define U_SET u8_set #include "test-u-strstr.h" int