[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/5] unistr/u*-chr, unistr/u*-strchr: test multibyte sequences
From: |
bonzini |
Subject: |
[PATCH 3/5] unistr/u*-chr, unistr/u*-strchr: test multibyte sequences |
Date: |
Tue, 20 Jul 2010 17:26:27 +0200 |
From: Paolo Bonzini <address@hidden>
* tests/unistr/test-chr.h, tests/unistr/test-strchr.h: put
characters above 0-127 in the test input.
---
tests/unistr/test-chr.h | 29 +++++++++++++++++++----------
tests/unistr/test-strchr.h | 10 +++++++++-
2 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/tests/unistr/test-chr.h b/tests/unistr/test-chr.h
index fbed0e1..266cda0 100644
--- a/tests/unistr/test-chr.h
+++ b/tests/unistr/test-chr.h
@@ -20,6 +20,7 @@ int
main (void)
{
size_t n = 0x100000;
+ size_t i;
size_t length;
UNIT *input;
uint32_t *input32 = (uint32_t *) malloc (n * sizeof (uint32_t));
@@ -28,7 +29,15 @@ main (void)
input32[0] = 'a';
input32[1] = 'b';
u32_set (input32 + 2, 'c', 1024);
- u32_set (input32 + 1026, 'd', n - 1028);
+ for (i = 1026; i < n - 2; i += 63)
+ {
+ size_t last = i + 63 < n - 2 ? i + 63 : n - 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';
@@ -36,20 +45,20 @@ main (void)
ASSERT (input);
/* Basic behavior tests. */
- ASSERT (U_CHR (input, n, 'a') == input);
+ ASSERT (U_CHR (input, length, 'a') == input);
ASSERT (U_CHR (input, 0, 'a') == NULL);
ASSERT (U_CHR (zerosize_ptr (), 0, 'a') == NULL);
- ASSERT (U_CHR (input, n, 'b') == input + 1);
- ASSERT (U_CHR (input, n, 'c') == input + 2);
- ASSERT (U_CHR (input, n, 'd') == input + 1026);
+ ASSERT (U_CHR (input, length, 'b') == input + 1);
+ ASSERT (U_CHR (input, length, 'c') == input + 2);
+ ASSERT (U_CHR (input, length, 'd') == input + 1026);
- ASSERT (U_CHR (input + 1, n - 1, 'a') == input + n - 1);
- ASSERT (U_CHR (input + 1, n - 1, 'e') == input + n - 2);
+ ASSERT (U_CHR (input + 1, length - 1, 'a') == input + length - 1);
+ ASSERT (U_CHR (input + 1, length - 1, 'e') == input + length - 2);
- ASSERT (U_CHR (input, n, 'f') == NULL);
- ASSERT (U_CHR (input, n, '\0') == NULL);
+ ASSERT (U_CHR (input, length, 'f') == NULL);
+ ASSERT (U_CHR (input, length, '\0') == NULL);
/* Check that a very long haystack is handled quickly if the byte is
found near the beginning. */
@@ -57,7 +66,7 @@ main (void)
size_t repeat = 10000;
for (; repeat > 0; repeat--)
{
- ASSERT (U_CHR (input, n, 'c') == input + 2);
+ ASSERT (U_CHR (input, length, 'c') == input + 2);
}
}
diff --git a/tests/unistr/test-strchr.h b/tests/unistr/test-strchr.h
index 8cb5b91..f7a7da9 100644
--- a/tests/unistr/test-strchr.h
+++ b/tests/unistr/test-strchr.h
@@ -22,6 +22,7 @@ main (void)
{
size_t n = 0x100000;
size_t length;
+ size_t i;
UNIT *input;
uint32_t *input32 = (uint32_t *) malloc ((n + 1) * sizeof (uint32_t));
ASSERT (input32);
@@ -29,7 +30,14 @@ main (void)
input32[0] = 'a';
input32[1] = 'b';
u32_set (input32 + 2, 'c', 1024);
- u32_set (input32 + 1026, 'd', n - 1028);
+ for (i = 1026; i < n - 2; i += 63)
+ {
+ size_t last = i + 63 < n - 2 ? i + 63 : n - 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[n] = 0;
--
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, 2010/07/20
- [PATCH 3/5] unistr/u*-chr, unistr/u*-strchr: test multibyte sequences,
bonzini <=
- [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