bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH v2 1/5] unistr/u*-chr: prepare for multibyte tests


From: bonzini
Subject: [PATCH v2 1/5] unistr/u*-chr: prepare for multibyte tests
Date: Fri, 23 Jul 2010 08:53:48 +0200

From: Paolo Bonzini <address@hidden>

* modules/unistr/u16-chr-tests: Depend on u32-to-u16.
* modules/unistr/u8-chr-tests: Depend on u32-to-u8.
* tests/unistr/test-chr.h: Build initial version as UCS-4 then convert.
* tests/unistr/test-u16-chr.c, tests/unistr/test-u32-chr.c,
tests/unistr/test-u8-chr.c: Define U32_TO_U.
---
 modules/unistr/u16-chr-tests |    1 +
 modules/unistr/u8-chr-tests  |    1 +
 tests/unistr/test-chr.h      |   21 +++++++++++++--------
 tests/unistr/test-u16-chr.c  |    1 +
 tests/unistr/test-u32-chr.c  |    1 +
 tests/unistr/test-u8-chr.c   |    1 +
 6 files changed, 18 insertions(+), 8 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/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/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-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-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-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"
-- 
1.7.1





reply via email to

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