unistr/u*-chr: prepare for multibyte tests
authorPaolo Bonzini <pbonzini@redhat.com>
Tue, 20 Jul 2010 14:06:33 +0000 (16:06 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 23 Jul 2010 06:33:01 +0000 (08:33 +0200)
* 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
modules/unistr/u8-chr-tests
tests/unistr/test-chr.h
tests/unistr/test-u16-chr.c
tests/unistr/test-u32-chr.c
tests/unistr/test-u8-chr.c

index 86dfddf..41692e2 100644 (file)
@@ -9,6 +9,7 @@ Depends-on:
 extensions
 getpagesize
 unistr/u16-set
+unistr/u32-to-u16
 
 configure.ac:
 gl_FUNC_MMAP_ANON
index 3ee6af9..8bbba24 100644 (file)
@@ -9,6 +9,7 @@ Depends-on:
 extensions
 getpagesize
 unistr/u8-set
+unistr/u32-to-u8
 
 configure.ac:
 gl_FUNC_MMAP_ANON
index 5a021c2..fbed0e1 100644 (file)
@@ -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);
 
index d71755c..b9792df 100644 (file)
@@ -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"
index f23aa08..5b74baf 100644 (file)
@@ -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"
index 7c4b999..aefc6ba 100644 (file)
@@ -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"