[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 3/5] unistr/u*-chr: test multibyte sequences more
From: |
bonzini |
Subject: |
[PATCH v2 3/5] unistr/u*-chr: test multibyte sequences more |
Date: |
Fri, 23 Jul 2010 08:53:50 +0200 |
From: Paolo Bonzini <address@hidden>
* tests/unistr/test-chr.h: Do complete testing of the characters in the
test vector.
* tests/unistr/test-u8-chr.c, tests/unistr/test-u32-chr.c,
tests/unistr/test-u16-chr.c (U_UCTOMB): Define.
---
tests/unistr/test-chr.h | 34 +++++++++++++++++++++++++++-------
tests/unistr/test-u16-chr.c | 1 +
tests/unistr/test-u32-chr.c | 1 +
tests/unistr/test-u8-chr.c | 1 +
4 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/tests/unistr/test-chr.h b/tests/unistr/test-chr.h
index 266cda0..fc4f5c5 100644
--- a/tests/unistr/test-chr.h
+++ b/tests/unistr/test-chr.h
@@ -19,29 +19,29 @@
int
main (void)
{
- size_t n = 0x100000;
+ size_t size = 0x100000;
size_t i;
size_t length;
UNIT *input;
- uint32_t *input32 = (uint32_t *) malloc (n * sizeof (uint32_t));
+ uint32_t *input32 = (uint32_t *) malloc (size * sizeof (uint32_t));
ASSERT (input32);
input32[0] = 'a';
input32[1] = 'b';
u32_set (input32 + 2, 'c', 1024);
- for (i = 1026; i < n - 2; i += 63)
+ for (i = 1026; i < size - 2; i += 63)
{
- size_t last = i + 63 < n - 2 ? i + 63 : n - 2;
+ size_t last = i + 63 < size - 2 ? i + 63 : size - 2;
ucs4_t uc = 'd' | (i - 1026);
if (uc >= 0xd800 && uc <= 0xdfff)
uc |= 0x100000;
u32_set (input32 + i, uc, last - i);
}
- input32[n - 2] = 'e';
- input32[n - 1] = 'a';
+ input32[size - 2] = 'e';
+ input32[size - 1] = 'a';
- input = U32_TO_U (input32, n, NULL, &length);
+ input = U32_TO_U (input32, size, NULL, &length);
ASSERT (input);
/* Basic behavior tests. */
@@ -54,6 +54,25 @@ main (void)
ASSERT (U_CHR (input, length, 'c') == input + 2);
ASSERT (U_CHR (input, length, 'd') == input + 1026);
+ {
+ UNIT *exp = input + 1026;
+ UNIT *prev = input + 1;
+ for (i = 1026; i < size - 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);
@@ -88,6 +107,7 @@ main (void)
byte being searched. */
{
char *page_boundary = (char *) zerosize_ptr ();
+ size_t n;
if (page_boundary != NULL)
{
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-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-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
--
1.7.1
- [PATCH v2 0/5] Speed up uNN_chr and uNN_strchr with Boyer-Moore algorithm, bonzini, 2010/07/23
- [PATCH v2 1/5] unistr/u*-chr: prepare for multibyte tests, bonzini, 2010/07/23
- [PATCH v2 2/5] unistr/u*-chr: test multibyte sequences, bonzini, 2010/07/23
- [PATCH v2 3/5] unistr/u*-chr: test multibyte sequences more,
bonzini <=
- [PATCH v2 4/5] unistr/u*-strchr: add tests, bonzini, 2010/07/23
- [PATCH v2 5/5] unistr/u8-chr, unistr/u8-strchr: use Boyer-Moore like algorithm., bonzini, 2010/07/23
- Re: [PATCH v2 0/5] Speed up uNN_chr and uNN_strchr with Boyer-Moore algorithm, Bruno Haible, 2010/07/23
- Re: [PATCH v2 0/5] Speed up uNN_chr and uNN_strchr with Boyer-Moore algorithm, Paolo Bonzini, 2010/07/23
- Re: [PATCH v2 0/5] Speed up uNN_chr and uNN_strchr with Boyer-Moore algorithm, Pádraig Brady, 2010/07/27
- Re: [PATCH v2 0/5] Speed up uNN_chr and uNN_strchr with Boyer-Moore algorithm, Paolo Bonzini, 2010/07/27
- Re: [PATCH v2 0/5] Speed up uNN_chr and uNN_strchr with Boyer-Moore algorithm, Pádraig Brady, 2010/07/27
- Re: [PATCH v2 0/5] Speed up uNN_chr and uNN_strchr with Boyer-Moore algorithm, Paolo Bonzini, 2010/07/27
- Re: ucs4_t type, Bruno Haible, 2010/07/28
- Re: [PATCH v2 0/5] Speed up uNN_chr and uNN_strchr with Boyer-Moore algorithm, Bruno Haible, 2010/07/28