[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/5] unistr/u*-chr, unistr/u*-strchr: test multibyte sequences mo
From: |
bonzini |
Subject: |
[PATCH 4/5] unistr/u*-chr, unistr/u*-strchr: test multibyte sequences more |
Date: |
Tue, 20 Jul 2010 17:26:28 +0200 |
From: Paolo Bonzini <address@hidden>
* tests/unistr/test-chr.h, tests/unistr/test-strchr.h: do complete
testing of the characters in the test vector.
---
tests/unistr/test-chr.h | 19 +++++++++++++++++++
tests/unistr/test-strchr.h | 21 ++++++++++++++++++++-
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 +
8 files changed, 45 insertions(+), 1 deletions(-)
diff --git a/tests/unistr/test-chr.h b/tests/unistr/test-chr.h
index 266cda0..d4de7bf 100644
--- a/tests/unistr/test-chr.h
+++ b/tests/unistr/test-chr.h
@@ -23,6 +23,8 @@ main (void)
size_t i;
size_t length;
UNIT *input;
+ UNIT *exp;
+ UNIT *prev;
uint32_t *input32 = (uint32_t *) malloc (n * sizeof (uint32_t));
ASSERT (input32);
@@ -54,6 +56,23 @@ main (void)
ASSERT (U_CHR (input, length, 'c') == input + 2);
ASSERT (U_CHR (input, length, 'd') == input + 1026);
+ exp = input + 1026;
+ prev = input + 1;
+ for (i = 1026; i < n - 2; i += 63)
+ {
+ UNIT c[6];
+ size_t n;
+ ucs4_t uc = 'd' | (i - 1026);
+ if (uc >= 0xd800 && uc <= 0xdfff)
+ uc |= 0x100000;
+ n = U_UCTOMB(c, uc, 6);
+ ASSERT (exp < input + length - 1);
+ ASSERT (U_CHR (prev, (length - 1) - (prev - input), uc) == exp);
+ ASSERT (memcmp (exp, c, n * sizeof (UNIT)) == 0);
+ prev = exp;
+ exp += n * 63;
+ }
+
ASSERT (U_CHR (input + 1, length - 1, 'a') == input + length - 1);
ASSERT (U_CHR (input + 1, length - 1, 'e') == input + length - 2);
diff --git a/tests/unistr/test-strchr.h b/tests/unistr/test-strchr.h
index f7a7da9..2a62a5c 100644
--- a/tests/unistr/test-strchr.h
+++ b/tests/unistr/test-strchr.h
@@ -24,6 +24,8 @@ main (void)
size_t length;
size_t i;
UNIT *input;
+ UNIT *exp;
+ UNIT *prev;
uint32_t *input32 = (uint32_t *) malloc ((n + 1) * sizeof (uint32_t));
ASSERT (input32);
@@ -49,7 +51,24 @@ main (void)
ASSERT (U_CHR (input, 'a') == input);
ASSERT (U_CHR (input, 'b') == input + 1);
ASSERT (U_CHR (input, 'c') == input + 2);
- ASSERT (U_CHR (input, 'd') == input + 1026);
+
+ exp = input + 1026;
+ prev = input + 2;
+
+ for (i = 1026; i < n - 2; i += 63)
+ {
+ UNIT c[6];
+ size_t n;
+ ucs4_t uc = 'd' | (i - 1026);
+ if (uc >= 0xd800 && uc <= 0xdfff)
+ uc |= 0x100000;
+ n = U_UCTOMB(c, uc, 6);
+ ASSERT (exp < input + length - 2);
+ ASSERT (U_CHR (prev, uc) == exp);
+ ASSERT (memcmp (exp, c, n * sizeof (UNIT)) == 0);
+ prev = exp;
+ exp += n * 63;
+ }
ASSERT (U_CHR (input + 1, 'a') == input + length - 2);
ASSERT (U_CHR (input + 1, 'e') == input + length - 3);
diff --git a/tests/unistr/test-u16-chr.c b/tests/unistr/test-u16-chr.c
index b9792df..10a0ccb 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 U_UCTOMB u16_uctomb
#define U32_TO_U u32_to_u16
#define U_CHR u16_chr
#define U_SET u16_set
diff --git a/tests/unistr/test-u16-strchr.c b/tests/unistr/test-u16-strchr.c
index add31c7..16392d4 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 U_UCTOMB u16_uctomb
#define U32_TO_U u32_to_u16
#define U_CHR u16_strchr
#define U_SET u16_set
diff --git a/tests/unistr/test-u32-chr.c b/tests/unistr/test-u32-chr.c
index 5b74baf..da58e95 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 U_UCTOMB(s, uc, n) (*(s) = (uc), 1)
#define U32_TO_U(s, n, result, length) (*(length) = (n), (s))
#define U_CHR u32_chr
#define U_SET u32_set
diff --git a/tests/unistr/test-u32-strchr.c b/tests/unistr/test-u32-strchr.c
index 30ed401..7b2161e 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 U_UCTOMB(s, uc, n) (*(s) = (uc), 1)
#define U32_TO_U(s, n, result, length) (*(length) = (n), (s))
#define U_CHR u32_strchr
#define U_SET u32_set
diff --git a/tests/unistr/test-u8-chr.c b/tests/unistr/test-u8-chr.c
index aefc6ba..6162c90 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 U_UCTOMB u8_uctomb
#define U32_TO_U u32_to_u8
#define U_CHR u8_chr
#define U_SET u8_set
diff --git a/tests/unistr/test-u8-strchr.c b/tests/unistr/test-u8-strchr.c
index 648a020..aad50c6 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 U_UCTOMB u8_uctomb
#define U32_TO_U u32_to_u8
#define U_CHR u8_strchr
#define U_SET u8_set
--
1.7.1
- [PATCH 0/5] unistr/u*-chr, unistr/u*-strchr: improve test coverage, optimize, bonzini, 2010/07/20
- [PATCH 1/5] unistr/u*-strchr: add tests, bonzini, 2010/07/20
- [PATCH 2/5] unistr/u*-chr, unistr/u*-strchr: prepare for multibyte tests, bonzini, 2010/07/20
- [PATCH 4/5] unistr/u*-chr, unistr/u*-strchr: test multibyte sequences more,
bonzini <=
- [PATCH 3/5] unistr/u*-chr, unistr/u*-strchr: test multibyte sequences, bonzini, 2010/07/20
- [PATCH 5/5] unistr/u8-chr: use Boyer-Moore like algorithm., bonzini, 2010/07/20
- Re: [PATCH 0/5] unistr/u*-chr, unistr/u*-strchr: improve test coverage, optimize, Bruno Haible, 2010/07/20