bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/5] unistr/u*-chr, unistr/u*-strchr: prepare for multibyte tests


From: bonzini
Subject: [PATCH 2/5] unistr/u*-chr, unistr/u*-strchr: prepare for multibyte tests
Date: Tue, 20 Jul 2010 17:26:26 +0200

From: Paolo Bonzini <address@hidden>

* modules/unistr/u16-chr-test,  modules/unistr/u16-strchr-test:
Depend on u32-to-u16.
* modules/unistr/u8-chr-test,  modules/unistr/u8-strchr-test:
Depend on u32-to-u8.
* tests/unistr/test-chr.h, tests/unistr/test-strchr.h: Build initial
version as UCS4 then convert.
* tests/unistr/test-u16-chr.c, tests/unistr/test-u16-strchr.c,
 tests/unistr/test-u32-chr.c, tests/unistr/test-u32-strchr.c,
 tests/unistr/test-u8-chr.c, tests/unistr/test-u8-strchr.c:
Define U32_TO_U.
---
 modules/unistr/u16-chr-tests    |    1 +
 modules/unistr/u16-strchr-tests |    1 +
 modules/unistr/u8-chr-tests     |    1 +
 modules/unistr/u8-strchr-tests  |    1 +
 tests/unistr/test-chr.h         |   21 +++++++++++++--------
 tests/unistr/test-strchr.h      |   29 +++++++++++++++++------------
 tests/unistr/test-u16-chr.c     |    1 +
 tests/unistr/test-u16-strchr.c  |    1 +
 tests/unistr/test-u32-chr.c     |    1 +
 tests/unistr/test-u32-strchr.c  |    1 +
 tests/unistr/test-u8-chr.c      |    1 +
 tests/unistr/test-u8-strchr.c   |    1 +
 12 files changed, 40 insertions(+), 20 deletions(-)

diff --git a/modules/unistr/u16-chr-tests b/modules/unistr/u16-chr-tests
index 86dfddf..41692e2 100644
--- a/modules/unistr/u16-chr-tests
+++ b/modules/unistr/u16-chr-tests
@@ -9,6 +9,7 @@ Depends-on:
 extensions
 getpagesize
 unistr/u16-set
+unistr/u32-to-u16
 
 configure.ac:
 gl_FUNC_MMAP_ANON
diff --git a/modules/unistr/u16-strchr-tests b/modules/unistr/u16-strchr-tests
index 8ac0078..c7beb98 100644
--- a/modules/unistr/u16-strchr-tests
+++ b/modules/unistr/u16-strchr-tests
@@ -9,6 +9,7 @@ Depends-on:
 extensions
 getpagesize
 unistr/u16-set
+unistr/u32-to-u16
 
 configure.ac:
 gl_FUNC_MMAP_ANON
diff --git a/modules/unistr/u8-chr-tests b/modules/unistr/u8-chr-tests
index 3ee6af9..8bbba24 100644
--- a/modules/unistr/u8-chr-tests
+++ b/modules/unistr/u8-chr-tests
@@ -9,6 +9,7 @@ Depends-on:
 extensions
 getpagesize
 unistr/u8-set
+unistr/u32-to-u8
 
 configure.ac:
 gl_FUNC_MMAP_ANON
diff --git a/modules/unistr/u8-strchr-tests b/modules/unistr/u8-strchr-tests
index 103671f..e202519 100644
--- a/modules/unistr/u8-strchr-tests
+++ b/modules/unistr/u8-strchr-tests
@@ -9,6 +9,7 @@ Depends-on:
 extensions
 getpagesize
 unistr/u8-set
+unistr/u32-to-u8
 
 configure.ac:
 gl_FUNC_MMAP_ANON
diff --git a/tests/unistr/test-chr.h b/tests/unistr/test-chr.h
index 5a021c2..fbed0e1 100644
--- a/tests/unistr/test-chr.h
+++ b/tests/unistr/test-chr.h
@@ -20,16 +20,21 @@ int
 main (void)
 {
   size_t n = 0x100000;
-  UNIT *input = (UNIT *) malloc (n * sizeof (UNIT));
+  size_t length;
+  UNIT *input;
+  uint32_t *input32 = (uint32_t *) malloc (n * sizeof (uint32_t));
+  ASSERT (input32);
+
+  input32[0] = 'a';
+  input32[1] = 'b';
+  u32_set (input32 + 2, 'c', 1024);
+  u32_set (input32 + 1026, 'd', n - 1028);
+  input32[n - 2] = 'e';
+  input32[n - 1] = 'a';
+
+  input = U32_TO_U (input32, n, NULL, &length);
   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';
-
   /* Basic behavior tests.  */
   ASSERT (U_CHR (input, n, 'a') == input);
 
diff --git a/tests/unistr/test-strchr.h b/tests/unistr/test-strchr.h
index 69bbcda..8cb5b91 100644
--- a/tests/unistr/test-strchr.h
+++ b/tests/unistr/test-strchr.h
@@ -21,16 +21,21 @@ int
 main (void)
 {
   size_t n = 0x100000;
-  UNIT *input = (UNIT *) malloc ((n + 1) * sizeof (UNIT));
-  ASSERT (input);
+  size_t length;
+  UNIT *input;
+  uint32_t *input32 = (uint32_t *) malloc ((n + 1) * sizeof (uint32_t));
+  ASSERT (input32);
+
+  input32[0] = 'a';
+  input32[1] = 'b';
+  u32_set (input32 + 2, 'c', 1024);
+  u32_set (input32 + 1026, 'd', n - 1028);
+  input32[n - 2] = 'e';
+  input32[n - 1] = 'a';
+  input32[n] = 0;
 
-  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;
+  input = U32_TO_U (input32, n + 1, NULL, &length);
+  ASSERT (input);
 
   /* Basic behavior tests.  */
   ASSERT (U_CHR (input, 'a') == input);
@@ -38,11 +43,11 @@ main (void)
   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 + 1, 'a') == input + length - 2);
+  ASSERT (U_CHR (input + 1, 'e') == input + length - 3);
 
   ASSERT (U_CHR (input, 'f') == NULL);
-  ASSERT (U_CHR (input, '\0') == input + n);
+  ASSERT (U_CHR (input, '\0') == input + length - 1);
 
   /* Check that a very long haystack is handled quickly if the byte is
      found near the beginning.  */
diff --git a/tests/unistr/test-u16-chr.c b/tests/unistr/test-u16-chr.c
index d71755c..b9792df 100644
--- a/tests/unistr/test-u16-chr.c
+++ b/tests/unistr/test-u16-chr.c
@@ -26,6 +26,7 @@
 #include "macros.h"
 
 #define UNIT uint16_t
+#define U32_TO_U u32_to_u16
 #define U_CHR u16_chr
 #define U_SET u16_set
 #include "test-chr.h"
diff --git a/tests/unistr/test-u16-strchr.c b/tests/unistr/test-u16-strchr.c
index fc4bd62..add31c7 100644
--- a/tests/unistr/test-u16-strchr.c
+++ b/tests/unistr/test-u16-strchr.c
@@ -26,6 +26,7 @@
 #include "macros.h"
 
 #define UNIT uint16_t
+#define U32_TO_U u32_to_u16
 #define U_CHR u16_strchr
 #define U_SET u16_set
 #include "test-strchr.h"
diff --git a/tests/unistr/test-u32-chr.c b/tests/unistr/test-u32-chr.c
index f23aa08..5b74baf 100644
--- a/tests/unistr/test-u32-chr.c
+++ b/tests/unistr/test-u32-chr.c
@@ -26,6 +26,7 @@
 #include "macros.h"
 
 #define UNIT uint32_t
+#define U32_TO_U(s, n, result, length) (*(length) = (n), (s))
 #define U_CHR u32_chr
 #define U_SET u32_set
 #include "test-chr.h"
diff --git a/tests/unistr/test-u32-strchr.c b/tests/unistr/test-u32-strchr.c
index 214bc66..30ed401 100644
--- a/tests/unistr/test-u32-strchr.c
+++ b/tests/unistr/test-u32-strchr.c
@@ -26,6 +26,7 @@
 #include "macros.h"
 
 #define UNIT uint32_t
+#define U32_TO_U(s, n, result, length) (*(length) = (n), (s))
 #define U_CHR u32_strchr
 #define U_SET u32_set
 #include "test-strchr.h"
diff --git a/tests/unistr/test-u8-chr.c b/tests/unistr/test-u8-chr.c
index 7c4b999..aefc6ba 100644
--- a/tests/unistr/test-u8-chr.c
+++ b/tests/unistr/test-u8-chr.c
@@ -26,6 +26,7 @@
 #include "macros.h"
 
 #define UNIT uint8_t
+#define U32_TO_U u32_to_u8
 #define U_CHR u8_chr
 #define U_SET u8_set
 #include "test-chr.h"
diff --git a/tests/unistr/test-u8-strchr.c b/tests/unistr/test-u8-strchr.c
index edcd32e..648a020 100644
--- a/tests/unistr/test-u8-strchr.c
+++ b/tests/unistr/test-u8-strchr.c
@@ -26,6 +26,7 @@
 #include "macros.h"
 
 #define UNIT uint8_t
+#define U32_TO_U u32_to_u8
 #define U_CHR u8_strchr
 #define U_SET u8_set
 #include "test-strchr.h"
-- 
1.7.1





reply via email to

[Prev in Thread] Current Thread [Next in Thread]