]> Savannah Git Hosting - gnulib.git/commitdiff
unistr/u*strstr tests: Add more tests.
authorBruno Haible <bruno@clisp.org>
Sun, 2 Apr 2023 10:52:44 +0000 (12:52 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 2 Apr 2023 10:52:44 +0000 (12:52 +0200)
* 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.

ChangeLog
modules/unistr/u16-strstr-tests
modules/unistr/u32-strstr-tests
modules/unistr/u8-strstr-tests
tests/unistr/test-u-strstr.h
tests/unistr/test-u16-strstr.c
tests/unistr/test-u32-strstr.c
tests/unistr/test-u8-strstr.c

index ca6f2d54f40a17c64978279db06681a18b295eb3..ddc568db032c77e9e515c44faf0dbe2bd88c5a17 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2023-04-02  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        vasnwprintf-posix: Fix behaviour in the C locale.
index 5c3cfbff8d6991596c69f97bb3f20df0b082497e..3e77e8af4a0d44077af7098a08d55f834d7023e0 100644 (file)
@@ -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])
index 8ec3124225abcca0b63f0dbe42f870f026c8f1d7..bccd5e602fec0ad4dbef0a5195da9f1ba2422dc3 100644 (file)
@@ -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])
index fdc7b76e12b3762e462b18383f42c0c8602c493c..23336d21849340ba5b4c66a3f43bc5108e923c02 100644 (file)
@@ -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])
index b97badc0054a1c0c04cbd4c9bec5c4c67c8a9b3a..639b3d911250461cee871f6645942cb7dd79f213 100644 (file)
@@ -207,4 +207,42 @@ test_u_strstr (void)
     free (needle);
     free (haystack);
   }
+
+  /* Test case from Yves Bastide.
+     <https://www.openwall.com/lists/musl/2014/04/18/2>  */
+  {
+    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);
+  }
 }
index b5cd028ff61810d5b741e6fd5798f217857af0c6..9c49aa0496a0baca587c8afdb77bff419c4de5c1 100644 (file)
@@ -29,6 +29,7 @@
 
 #define UNIT uint16_t
 #define U_STRSTR u16_strstr
+#define U_SET u16_set
 #include "test-u-strstr.h"
 
 int
index 9f388127a58707788c923feddee46e3d2d6b46c7..134a3c5366528d952a85bfcc99881bbc9bd50e2b 100644 (file)
@@ -29,6 +29,7 @@
 
 #define UNIT uint32_t
 #define U_STRSTR u32_strstr
+#define U_SET u32_set
 #include "test-u-strstr.h"
 
 int
index f11d9408c27ad50fa5bd8a670a0a81cd0d83c9f9..39f831b2ea0d19f6f3b72e33bd5c9e57022b5e5b 100644 (file)
@@ -29,6 +29,7 @@
 
 #define UNIT uint8_t
 #define U_STRSTR u8_strstr
+#define U_SET u8_set
 #include "test-u-strstr.h"
 
 int