2 ******************************************************************************
4 * Copyright (C) 2001-2014, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 ******************************************************************************
8 * file name: trietest.c
10 * tab size: 8 (not used)
13 * created on: 2008sep01 (starting from a copy of trietest.c)
14 * created by: Markus W. Scherer
18 #include "unicode/utypes.h"
26 void addTrie2Test(TestNode
** root
);
28 /* Values for setting possibly overlapping, out-of-order ranges of values */
29 typedef struct SetRange
{
37 * value is set from the previous boundary's limit to before
38 * this boundary's limit
40 * There must be an entry with limit 0 and the intialValue.
41 * It may be preceded by an entry with negative limit and the errorValue.
43 typedef struct CheckRange
{
49 skipSpecialValues(const CheckRange checkRanges
[], int32_t countCheckRanges
) {
51 for(i
=0; i
<countCheckRanges
&& checkRanges
[i
].limit
<=0; ++i
) {}
56 getSpecialValues(const CheckRange checkRanges
[], int32_t countCheckRanges
,
57 uint32_t *pInitialValue
, uint32_t *pErrorValue
) {
59 if(i
<countCheckRanges
&& checkRanges
[i
].limit
<0) {
60 *pErrorValue
=checkRanges
[i
++].value
;
64 if(i
<countCheckRanges
&& checkRanges
[i
].limit
==0) {
65 *pInitialValue
=checkRanges
[i
++].value
;
72 /* utrie2_enum() callback, modifies a value */
73 static uint32_t U_CALLCONV
74 testEnumValue(const void *context
, uint32_t value
) {
78 /* utrie2_enum() callback, verifies a range */
79 static UBool U_CALLCONV
80 testEnumRange(const void *context
, UChar32 start
, UChar32 end
, uint32_t value
) {
81 const CheckRange
**pb
=(const CheckRange
**)context
;
82 const CheckRange
*b
=(*pb
)++;
86 if(start
!=(b
-1)->limit
|| limit
!=b
->limit
|| value
!=b
->value
) {
87 log_err("error: utrie2_enum() delivers wrong range [U+%04lx..U+%04lx].0x%lx instead of [U+%04lx..U+%04lx].0x%lx\n",
88 (long)start
, (long)end
, (long)value
,
89 (long)(b
-1)->limit
, (long)b
->limit
-1, (long)b
->value
);
95 testTrieEnum(const char *testName
,
97 const CheckRange checkRanges
[], int32_t countCheckRanges
) {
98 /* skip over special values */
99 while(countCheckRanges
>0 && checkRanges
[0].limit
<=0) {
103 utrie2_enum(trie
, testEnumValue
, testEnumRange
, &checkRanges
);
106 /* verify all expected values via UTRIE2_GETxx() */
108 testTrieGetters(const char *testName
,
109 const UTrie2
*trie
, UTrie2ValueBits valueBits
,
110 const CheckRange checkRanges
[], int32_t countCheckRanges
) {
111 uint32_t initialValue
, errorValue
;
112 uint32_t value
, value2
;
113 UChar32 start
, limit
;
114 int32_t i
, countSpecials
;
116 UBool isFrozen
=utrie2_isFrozen(trie
);
117 const char *const typeName
= isFrozen
? "frozen trie" : "newTrie";
119 countSpecials
=getSpecialValues(checkRanges
, countCheckRanges
, &initialValue
, &errorValue
);
122 for(i
=countSpecials
; i
<countCheckRanges
; ++i
) {
123 limit
=checkRanges
[i
].limit
;
124 value
=checkRanges
[i
].value
;
129 if(!U_IS_LEAD(start
)) {
130 if(valueBits
==UTRIE2_16_VALUE_BITS
) {
131 value2
=UTRIE2_GET16_FROM_U16_SINGLE_LEAD(trie
, start
);
133 value2
=UTRIE2_GET32_FROM_U16_SINGLE_LEAD(trie
, start
);
136 log_err("error: %s(%s).fromBMP(U+%04lx)==0x%lx instead of 0x%lx\n",
137 typeName
, testName
, (long)start
, (long)value2
, (long)value
);
141 if(valueBits
==UTRIE2_16_VALUE_BITS
) {
142 value2
=UTRIE2_GET16_FROM_SUPP(trie
, start
);
144 value2
=UTRIE2_GET32_FROM_SUPP(trie
, start
);
147 log_err("error: %s(%s).fromSupp(U+%04lx)==0x%lx instead of 0x%lx\n",
148 typeName
, testName
, (long)start
, (long)value2
, (long)value
);
151 if(valueBits
==UTRIE2_16_VALUE_BITS
) {
152 value2
=UTRIE2_GET16(trie
, start
);
154 value2
=UTRIE2_GET32(trie
, start
);
157 log_err("error: %s(%s).get(U+%04lx)==0x%lx instead of 0x%lx\n",
158 typeName
, testName
, (long)start
, (long)value2
, (long)value
);
161 value2
=utrie2_get32(trie
, start
);
163 log_err("error: %s(%s).get32(U+%04lx)==0x%lx instead of 0x%lx\n",
164 typeName
, testName
, (long)start
, (long)value2
, (long)value
);
171 /* test linear ASCII range from the data array pointer (access to "internal" field) */
173 for(i
=countSpecials
; i
<countCheckRanges
&& start
<=0x7f; ++i
) {
174 limit
=checkRanges
[i
].limit
;
175 value
=checkRanges
[i
].value
;
177 while(start
<limit
&& start
<=0x7f) {
178 if(valueBits
==UTRIE2_16_VALUE_BITS
) {
179 value2
=trie
->data16
[start
];
181 value2
=trie
->data32
[start
];
184 log_err("error: %s(%s).asciiData[U+%04lx]==0x%lx instead of 0x%lx\n",
185 typeName
, testName
, (long)start
, (long)value2
, (long)value
);
191 if(valueBits
==UTRIE2_16_VALUE_BITS
) {
192 value2
=trie
->data16
[start
];
194 value2
=trie
->data32
[start
];
196 if(errorValue
!=value2
) {
197 log_err("error: %s(%s).badData[U+%04lx]==0x%lx instead of 0x%lx\n",
198 typeName
, testName
, (long)start
, (long)value2
, (long)errorValue
);
204 if(0!=strncmp(testName
, "dummy", 5) && 0!=strncmp(testName
, "trie1", 5)) {
205 /* test values for lead surrogate code units */
206 for(start
=0xd7ff; start
<0xdc01; ++start
) {
225 if(isFrozen
&& U_IS_LEAD(start
)) {
226 if(valueBits
==UTRIE2_16_VALUE_BITS
) {
227 value2
=UTRIE2_GET16_FROM_U16_SINGLE_LEAD(trie
, start
);
229 value2
=UTRIE2_GET32_FROM_U16_SINGLE_LEAD(trie
, start
);
232 log_err("error: %s(%s).LSCU(U+%04lx)==0x%lx instead of 0x%lx\n",
233 typeName
, testName
, (long)start
, (long)value2
, (long)value
);
236 value2
=utrie2_get32FromLeadSurrogateCodeUnit(trie
, start
);
238 log_err("error: %s(%s).lscu(U+%04lx)==0x%lx instead of 0x%lx\n",
239 typeName
, testName
, (long)start
, (long)value2
, (long)value
);
244 /* test errorValue */
246 if(valueBits
==UTRIE2_16_VALUE_BITS
) {
247 value
=UTRIE2_GET16(trie
, -1);
248 value2
=UTRIE2_GET16(trie
, 0x110000);
250 value
=UTRIE2_GET32(trie
, -1);
251 value2
=UTRIE2_GET32(trie
, 0x110000);
253 if(value
!=errorValue
|| value2
!=errorValue
) {
254 log_err("error: %s(%s).get(out of range) != errorValue\n",
258 value
=utrie2_get32(trie
, -1);
259 value2
=utrie2_get32(trie
, 0x110000);
260 if(value
!=errorValue
|| value2
!=errorValue
) {
261 log_err("error: %s(%s).get32(out of range) != errorValue\n",
267 testTrieUTF16(const char *testName
,
268 const UTrie2
*trie
, UTrie2ValueBits valueBits
,
269 const CheckRange checkRanges
[], int32_t countCheckRanges
) {
271 uint32_t values
[100];
273 const UChar
*p
, *limit
;
276 UChar32 prevCP
, c
, c2
;
277 int32_t i
, length
, sIndex
, countValues
;
281 length
=countValues
=0;
282 for(i
=skipSpecialValues(checkRanges
, countCheckRanges
); i
<countCheckRanges
; ++i
) {
283 value
=checkRanges
[i
].value
;
284 /* write three code points */
285 U16_APPEND_UNSAFE(s
, length
, prevCP
); /* start of the range */
286 values
[countValues
++]=value
;
287 c
=checkRanges
[i
].limit
;
288 prevCP
=(prevCP
+c
)/2; /* middle of the range */
289 U16_APPEND_UNSAFE(s
, length
, prevCP
);
290 values
[countValues
++]=value
;
292 --c
; /* end of the range */
293 U16_APPEND_UNSAFE(s
, length
, c
);
294 values
[countValues
++]=value
;
302 sIndex
=(int32_t)(p
-s
);
303 U16_NEXT(s
, sIndex
, length
, c2
);
305 if(valueBits
==UTRIE2_16_VALUE_BITS
) {
306 UTRIE2_U16_NEXT16(trie
, p
, limit
, c
, value
);
308 UTRIE2_U16_NEXT32(trie
, p
, limit
, c
, value
);
310 if(value
!=values
[i
]) {
311 log_err("error: wrong value from UTRIE2_NEXT(%s)(U+%04lx): 0x%lx instead of 0x%lx\n",
312 testName
, (long)c
, (long)value
, (long)values
[i
]);
315 log_err("error: wrong code point from UTRIE2_NEXT(%s): U+%04lx != U+%04lx\n",
316 testName
, (long)c
, (long)c2
);
327 sIndex
=(int32_t)(p
-s
);
328 U16_PREV(s
, 0, sIndex
, c2
);
330 if(valueBits
==UTRIE2_16_VALUE_BITS
) {
331 UTRIE2_U16_PREV16(trie
, s
, p
, c
, value
);
333 UTRIE2_U16_PREV32(trie
, s
, p
, c
, value
);
335 if(value
!=values
[i
]) {
336 log_err("error: wrong value from UTRIE2_PREV(%s)(U+%04lx): 0x%lx instead of 0x%lx\n",
337 testName
, (long)c
, (long)value
, (long)values
[i
]);
340 log_err("error: wrong code point from UTRIE2_PREV(%s): U+%04lx != U+%04lx\n",
347 testTrieUTF8(const char *testName
,
348 const UTrie2
*trie
, UTrie2ValueBits valueBits
,
349 const CheckRange checkRanges
[], int32_t countCheckRanges
) {
350 static const uint8_t illegal
[]={
351 0xc0, 0x80, /* non-shortest U+0000 */
352 0xc1, 0xbf, /* non-shortest U+007f */
353 0xc2, /* truncated */
354 0xe0, 0x90, 0x80, /* non-shortest U+0400 */
355 0xe0, 0xa0, /* truncated */
356 0xed, 0xa0, 0x80, /* lead surrogate U+d800 */
357 0xed, 0xbf, 0xbf, /* trail surrogate U+dfff */
358 0xf0, 0x8f, 0xbf, 0xbf, /* non-shortest U+ffff */
359 0xf0, 0x90, 0x80, /* truncated */
360 0xf4, 0x90, 0x80, 0x80, /* beyond-Unicode U+110000 */
361 0xf8, 0x80, 0x80, 0x80, /* truncated */
362 0xf8, 0x80, 0x80, 0x80, 0x80, /* 5-byte UTF-8 */
363 0xfd, 0xbf, 0xbf, 0xbf, 0xbf, /* truncated */
364 0xfd, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, /* 6-byte UTF-8 */
369 uint32_t values
[200];
371 const uint8_t *p
, *limit
;
373 uint32_t initialValue
, errorValue
;
374 uint32_t value
, bytes
;
376 int32_t i
, countSpecials
, length
, countValues
;
379 countSpecials
=getSpecialValues(checkRanges
, countCheckRanges
, &initialValue
, &errorValue
);
383 length
=countValues
=0;
384 /* first a couple of trail bytes in lead position */
386 values
[countValues
++]=errorValue
;
388 values
[countValues
++]=errorValue
;
390 for(i
=countSpecials
; i
<countCheckRanges
; ++i
) {
391 value
=checkRanges
[i
].value
;
392 /* write three legal (or surrogate) code points */
393 U8_APPEND_UNSAFE(s
, length
, prevCP
); /* start of the range */
394 values
[countValues
++]=U_IS_SURROGATE(prevCP
) ? errorValue
: value
;
395 c
=checkRanges
[i
].limit
;
396 prevCP
=(prevCP
+c
)/2; /* middle of the range */
397 U8_APPEND_UNSAFE(s
, length
, prevCP
);
398 values
[countValues
++]=U_IS_SURROGATE(prevCP
) ? errorValue
: value
;
400 --c
; /* end of the range */
401 U8_APPEND_UNSAFE(s
, length
, c
);
402 values
[countValues
++]=U_IS_SURROGATE(c
) ? errorValue
: value
;
403 /* write an illegal byte sequence */
404 if(i8
<sizeof(illegal
)) {
405 U8_FWD_1(illegal
, i8
, sizeof(illegal
));
407 s
[length
++]=illegal
[prev8
++];
409 values
[countValues
++]=errorValue
;
412 /* write the remaining illegal byte sequences */
413 while(i8
<sizeof(illegal
)) {
414 U8_FWD_1(illegal
, i8
, sizeof(illegal
));
416 s
[length
++]=illegal
[prev8
++];
418 values
[countValues
++]=errorValue
;
426 prev8
=i8
=(int32_t)(p
-s
);
427 U8_NEXT(s
, i8
, length
, c
);
428 if(valueBits
==UTRIE2_16_VALUE_BITS
) {
429 UTRIE2_U8_NEXT16(trie
, p
, limit
, value
);
431 UTRIE2_U8_NEXT32(trie
, p
, limit
, value
);
434 if(value
!=values
[i
] || i8
!=(p
-s
)) {
436 bytes
=(bytes
<<8)|s
[prev8
++];
439 if(value
!=values
[i
]) {
440 log_err("error: wrong value from UTRIE2_U8_NEXT(%s)(%lx->U+%04lx): 0x%lx instead of 0x%lx\n",
441 testName
, (unsigned long)bytes
, (long)c
, (long)value
, (long)values
[i
]);
444 log_err("error: wrong end index from UTRIE2_U8_NEXT(%s)(%lx->U+%04lx): %ld != %ld\n",
445 testName
, (unsigned long)bytes
, (long)c
, (long)(p
-s
), (long)i8
);
456 prev8
=i8
=(int32_t)(p
-s
);
457 U8_PREV(s
, 0, i8
, c
);
458 if(valueBits
==UTRIE2_16_VALUE_BITS
) {
459 UTRIE2_U8_PREV16(trie
, s
, p
, value
);
461 UTRIE2_U8_PREV32(trie
, s
, p
, value
);
464 if(value
!=values
[i
] || i8
!=(p
-s
)) {
467 bytes
=(bytes
<<8)|s
[k
++];
470 if(value
!=values
[i
]) {
471 log_err("error: wrong value from UTRIE2_U8_PREV(%s)(%lx->U+%04lx): 0x%lx instead of 0x%lx\n",
472 testName
, (unsigned long)bytes
, (long)c
, (long)value
, (long)values
[i
]);
475 log_err("error: wrong end index from UTRIE2_U8_PREV(%s)(%lx->U+%04lx): %ld != %ld\n",
476 testName
, (unsigned long)bytes
, (long)c
, (long)(p
-s
), (long)i8
);
483 testFrozenTrie(const char *testName
,
484 UTrie2
*trie
, UTrie2ValueBits valueBits
,
485 const CheckRange checkRanges
[], int32_t countCheckRanges
) {
486 UErrorCode errorCode
;
487 uint32_t value
, value2
;
489 if(!utrie2_isFrozen(trie
)) {
490 log_err("error: utrie2_isFrozen(frozen %s) returned FALSE (not frozen)\n",
495 testTrieGetters(testName
, trie
, valueBits
, checkRanges
, countCheckRanges
);
496 testTrieEnum(testName
, trie
, checkRanges
, countCheckRanges
);
497 testTrieUTF16(testName
, trie
, valueBits
, checkRanges
, countCheckRanges
);
498 testTrieUTF8(testName
, trie
, valueBits
, checkRanges
, countCheckRanges
);
500 errorCode
=U_ZERO_ERROR
;
501 value
=utrie2_get32(trie
, 1);
502 utrie2_set32(trie
, 1, 234, &errorCode
);
503 value2
=utrie2_get32(trie
, 1);
504 if(errorCode
!=U_NO_WRITE_PERMISSION
|| value2
!=value
) {
505 log_err("error: utrie2_set32(frozen %s) failed: it set %s != U_NO_WRITE_PERMISSION\n",
506 testName
, u_errorName(errorCode
));
510 errorCode
=U_ZERO_ERROR
;
511 utrie2_setRange32(trie
, 1, 5, 234, TRUE
, &errorCode
);
512 value2
=utrie2_get32(trie
, 1);
513 if(errorCode
!=U_NO_WRITE_PERMISSION
|| value2
!=value
) {
514 log_err("error: utrie2_setRange32(frozen %s) failed: it set %s != U_NO_WRITE_PERMISSION\n",
515 testName
, u_errorName(errorCode
));
519 errorCode
=U_ZERO_ERROR
;
520 value
=utrie2_get32FromLeadSurrogateCodeUnit(trie
, 0xd801);
521 utrie2_set32ForLeadSurrogateCodeUnit(trie
, 0xd801, 234, &errorCode
);
522 value2
=utrie2_get32FromLeadSurrogateCodeUnit(trie
, 0xd801);
523 if(errorCode
!=U_NO_WRITE_PERMISSION
|| value2
!=value
) {
524 log_err("error: utrie2_set32ForLeadSurrogateCodeUnit(frozen %s) failed: "
525 "it set %s != U_NO_WRITE_PERMISSION\n",
526 testName
, u_errorName(errorCode
));
532 testNewTrie(const char *testName
, const UTrie2
*trie
,
533 const CheckRange checkRanges
[], int32_t countCheckRanges
) {
534 /* The valueBits are ignored for an unfrozen trie. */
535 testTrieGetters(testName
, trie
, UTRIE2_COUNT_VALUE_BITS
, checkRanges
, countCheckRanges
);
536 testTrieEnum(testName
, trie
, checkRanges
, countCheckRanges
);
540 testTrieSerialize(const char *testName
,
541 UTrie2
*trie
, UTrie2ValueBits valueBits
,
543 const CheckRange checkRanges
[], int32_t countCheckRanges
) {
544 uint32_t storage
[10000];
545 int32_t length1
, length2
, length3
;
546 UTrie2ValueBits otherValueBits
;
547 UErrorCode errorCode
;
549 /* clone the trie so that the caller can reuse the original */
550 errorCode
=U_ZERO_ERROR
;
551 trie
=utrie2_clone(trie
, &errorCode
);
552 if(U_FAILURE(errorCode
)) {
553 log_err("error: utrie2_clone(unfrozen %s) failed - %s\n",
554 testName
, u_errorName(errorCode
));
559 * This is not a loop, but simply a block that we can exit with "break"
560 * when something goes wrong.
563 errorCode
=U_ZERO_ERROR
;
564 utrie2_serialize(trie
, storage
, sizeof(storage
), &errorCode
);
565 if(errorCode
!=U_ILLEGAL_ARGUMENT_ERROR
) {
566 log_err("error: utrie2_serialize(unfrozen %s) set %s != U_ILLEGAL_ARGUMENT_ERROR\n",
567 testName
, u_errorName(errorCode
));
570 errorCode
=U_ZERO_ERROR
;
571 utrie2_freeze(trie
, valueBits
, &errorCode
);
572 if(U_FAILURE(errorCode
) || !utrie2_isFrozen(trie
)) {
573 log_err("error: utrie2_freeze(%s) failed: %s isFrozen: %d\n",
574 testName
, u_errorName(errorCode
), utrie2_isFrozen(trie
));
577 otherValueBits
= valueBits
==UTRIE2_16_VALUE_BITS
? UTRIE2_32_VALUE_BITS
: UTRIE2_16_VALUE_BITS
;
578 utrie2_freeze(trie
, otherValueBits
, &errorCode
);
579 if(errorCode
!=U_ILLEGAL_ARGUMENT_ERROR
) {
580 log_err("error: utrie2_freeze(already-frozen with other valueBits %s) "
581 "set %s != U_ILLEGAL_ARGUMENT_ERROR\n",
582 testName
, u_errorName(errorCode
));
585 errorCode
=U_ZERO_ERROR
;
587 /* clone a frozen trie */
588 UTrie2
*clone
=utrie2_clone(trie
, &errorCode
);
589 if(U_FAILURE(errorCode
)) {
590 log_err("error: cloning a frozen UTrie2 failed (%s) - %s\n",
591 testName
, u_errorName(errorCode
));
592 errorCode
=U_ZERO_ERROR
; /* continue with the original */
598 length1
=utrie2_serialize(trie
, NULL
, 0, &errorCode
);
599 if(errorCode
!=U_BUFFER_OVERFLOW_ERROR
) {
600 log_err("error: utrie2_serialize(%s) preflighting set %s != U_BUFFER_OVERFLOW_ERROR\n",
601 testName
, u_errorName(errorCode
));
604 errorCode
=U_ZERO_ERROR
;
605 length2
=utrie2_serialize(trie
, storage
, sizeof(storage
), &errorCode
);
606 if(errorCode
==U_BUFFER_OVERFLOW_ERROR
) {
607 log_err("error: utrie2_serialize(%s) needs more memory\n", testName
);
610 if(U_FAILURE(errorCode
)) {
611 log_err("error: utrie2_serialize(%s) failed: %s\n", testName
, u_errorName(errorCode
));
614 if(length1
!=length2
) {
615 log_err("error: trie serialization (%s) lengths different: "
616 "preflight vs. serialize\n", testName
);
620 testFrozenTrie(testName
, trie
, valueBits
, checkRanges
, countCheckRanges
);
625 uint32_t swapped
[10000];
626 int32_t swappedLength
;
630 /* swap to opposite-endian */
631 uprv_memset(swapped
, 0x55, length2
);
632 ds
=udata_openSwapper(U_IS_BIG_ENDIAN
, U_CHARSET_FAMILY
,
633 !U_IS_BIG_ENDIAN
, U_CHARSET_FAMILY
, &errorCode
);
634 swappedLength
=utrie2_swap(ds
, storage
, -1, NULL
, &errorCode
);
635 if(U_FAILURE(errorCode
) || swappedLength
!=length2
) {
636 log_err("error: utrie2_swap(%s to OE preflighting) failed (%s) "
637 "or before/after lengths different\n",
638 testName
, u_errorName(errorCode
));
639 udata_closeSwapper(ds
);
642 swappedLength
=utrie2_swap(ds
, storage
, length2
, swapped
, &errorCode
);
643 udata_closeSwapper(ds
);
644 if(U_FAILURE(errorCode
) || swappedLength
!=length2
) {
645 log_err("error: utrie2_swap(%s to OE) failed (%s) or before/after lengths different\n",
646 testName
, u_errorName(errorCode
));
650 /* swap back to platform-endian */
651 uprv_memset(storage
, 0xaa, length2
);
652 ds
=udata_openSwapper(!U_IS_BIG_ENDIAN
, U_CHARSET_FAMILY
,
653 U_IS_BIG_ENDIAN
, U_CHARSET_FAMILY
, &errorCode
);
654 swappedLength
=utrie2_swap(ds
, swapped
, -1, NULL
, &errorCode
);
655 if(U_FAILURE(errorCode
) || swappedLength
!=length2
) {
656 log_err("error: utrie2_swap(%s to PE preflighting) failed (%s) "
657 "or before/after lengths different\n",
658 testName
, u_errorName(errorCode
));
659 udata_closeSwapper(ds
);
662 swappedLength
=utrie2_swap(ds
, swapped
, length2
, storage
, &errorCode
);
663 udata_closeSwapper(ds
);
664 if(U_FAILURE(errorCode
) || swappedLength
!=length2
) {
665 log_err("error: utrie2_swap(%s to PE) failed (%s) or before/after lengths different\n",
666 testName
, u_errorName(errorCode
));
671 trie
=utrie2_openFromSerialized(valueBits
, storage
, length2
, &length3
, &errorCode
);
672 if(U_FAILURE(errorCode
)) {
673 log_err("error: utrie2_openFromSerialized(%s) failed, %s\n", testName
, u_errorName(errorCode
));
676 if((valueBits
==UTRIE2_16_VALUE_BITS
)!=(trie
->data32
==NULL
)) {
677 log_err("error: trie serialization (%s) did not preserve 32-bitness\n", testName
);
680 if(length2
!=length3
) {
681 log_err("error: trie serialization (%s) lengths different: "
682 "serialize vs. unserialize\n", testName
);
685 /* overwrite the storage that is not supposed to be needed */
686 uprv_memset((char *)storage
+length3
, 0xfa, (int32_t)(sizeof(storage
)-length3
));
688 utrie2_freeze(trie
, valueBits
, &errorCode
);
689 if(U_FAILURE(errorCode
) || !utrie2_isFrozen(trie
)) {
690 log_err("error: utrie2_freeze(unserialized %s) failed: %s isFrozen: %d\n",
691 testName
, u_errorName(errorCode
), utrie2_isFrozen(trie
));
694 utrie2_freeze(trie
, otherValueBits
, &errorCode
);
695 if(errorCode
!=U_ILLEGAL_ARGUMENT_ERROR
) {
696 log_err("error: utrie2_freeze(unserialized with other valueBits %s) "
697 "set %s != U_ILLEGAL_ARGUMENT_ERROR\n",
698 testName
, u_errorName(errorCode
));
701 errorCode
=U_ZERO_ERROR
;
703 /* clone an unserialized trie */
704 UTrie2
*clone
=utrie2_clone(trie
, &errorCode
);
705 if(U_FAILURE(errorCode
)) {
706 log_err("error: utrie2_clone(unserialized %s) failed - %s\n",
707 testName
, u_errorName(errorCode
));
708 errorCode
=U_ZERO_ERROR
;
709 /* no need to break: just test the original trie */
713 uprv_memset(storage
, 0, sizeof(storage
));
716 testFrozenTrie(testName
, trie
, valueBits
, checkRanges
, countCheckRanges
);
718 /* clone-as-thawed an unserialized trie */
719 UTrie2
*clone
=utrie2_cloneAsThawed(trie
, &errorCode
);
720 if(U_FAILURE(errorCode
) || utrie2_isFrozen(clone
)) {
721 log_err("error: utrie2_cloneAsThawed(unserialized %s) failed - "
722 "%s (isFrozen: %d)\n",
723 testName
, u_errorName(errorCode
), clone
!=NULL
&& utrie2_isFrozen(trie
));
731 uint32_t value
, value2
;
733 value
=utrie2_get32(trie
, 0xa1);
734 utrie2_set32(trie
, 0xa1, 789, &errorCode
);
735 value2
=utrie2_get32(trie
, 0xa1);
736 utrie2_set32(trie
, 0xa1, value
, &errorCode
);
737 if(U_FAILURE(errorCode
) || value2
!=789) {
738 log_err("error: modifying a cloneAsThawed UTrie2 (%s) failed - %s\n",
739 testName
, u_errorName(errorCode
));
742 testNewTrie(testName
, trie
, checkRanges
, countCheckRanges
);
749 testTrieSerializeAllValueBits(const char *testName
,
750 UTrie2
*trie
, UBool withClone
,
751 const CheckRange checkRanges
[], int32_t countCheckRanges
) {
754 /* verify that all the expected values are in the unfrozen trie */
755 testNewTrie(testName
, trie
, checkRanges
, countCheckRanges
);
758 * Test with both valueBits serializations,
759 * and that utrie2_serialize() can be called multiple times.
761 uprv_strcpy(name
, testName
);
762 uprv_strcat(name
, ".16");
763 testTrieSerialize(name
, trie
,
764 UTRIE2_16_VALUE_BITS
, withClone
,
765 checkRanges
, countCheckRanges
);
769 * try cloning after the first serialization;
770 * clone-as-thawed just to sometimes try it on an unfrozen trie
772 UErrorCode errorCode
=U_ZERO_ERROR
;
773 UTrie2
*clone
=utrie2_cloneAsThawed(trie
, &errorCode
);
774 if(U_FAILURE(errorCode
)) {
775 log_err("error: utrie2_cloneAsThawed(%s) after serialization failed - %s\n",
776 testName
, u_errorName(errorCode
));
781 testNewTrie(testName
, trie
, checkRanges
, countCheckRanges
);
785 uprv_strcpy(name
, testName
);
786 uprv_strcat(name
, ".32");
787 testTrieSerialize(name
, trie
,
788 UTRIE2_32_VALUE_BITS
, withClone
,
789 checkRanges
, countCheckRanges
);
791 return trie
; /* could be the clone */
795 makeTrieWithRanges(const char *testName
, UBool withClone
,
796 const SetRange setRanges
[], int32_t countSetRanges
,
797 const CheckRange checkRanges
[], int32_t countCheckRanges
) {
799 uint32_t initialValue
, errorValue
;
801 UChar32 start
, limit
;
803 UErrorCode errorCode
;
806 log_verbose("\ntesting Trie '%s'\n", testName
);
807 errorCode
=U_ZERO_ERROR
;
808 getSpecialValues(checkRanges
, countCheckRanges
, &initialValue
, &errorValue
);
809 trie
=utrie2_open(initialValue
, errorValue
, &errorCode
);
810 if(U_FAILURE(errorCode
)) {
811 log_err("error: utrie2_open(%s) failed: %s\n", testName
, u_errorName(errorCode
));
815 /* set values from setRanges[] */
816 for(i
=0; i
<countSetRanges
; ++i
) {
817 if(withClone
&& i
==countSetRanges
/2) {
818 /* switch to a clone in the middle of setting values */
819 UTrie2
*clone
=utrie2_clone(trie
, &errorCode
);
820 if(U_FAILURE(errorCode
)) {
821 log_err("error: utrie2_clone(%s) failed - %s\n",
822 testName
, u_errorName(errorCode
));
823 errorCode
=U_ZERO_ERROR
; /* continue with the original */
829 start
=setRanges
[i
].start
;
830 limit
=setRanges
[i
].limit
;
831 value
=setRanges
[i
].value
;
832 overwrite
=setRanges
[i
].overwrite
;
833 if((limit
-start
)==1 && overwrite
) {
834 utrie2_set32(trie
, start
, value
, &errorCode
);
836 utrie2_setRange32(trie
, start
, limit
-1, value
, overwrite
, &errorCode
);
840 /* set some values for lead surrogate code units */
841 utrie2_set32ForLeadSurrogateCodeUnit(trie
, 0xd800, 90, &errorCode
);
842 utrie2_set32ForLeadSurrogateCodeUnit(trie
, 0xd999, 94, &errorCode
);
843 utrie2_set32ForLeadSurrogateCodeUnit(trie
, 0xdbff, 99, &errorCode
);
844 if(U_SUCCESS(errorCode
)) {
847 log_err("error: setting values into a trie (%s) failed - %s\n",
848 testName
, u_errorName(errorCode
));
855 testTrieRanges(const char *testName
, UBool withClone
,
856 const SetRange setRanges
[], int32_t countSetRanges
,
857 const CheckRange checkRanges
[], int32_t countCheckRanges
) {
858 UTrie2
*trie
=makeTrieWithRanges(testName
, withClone
,
859 setRanges
, countSetRanges
,
860 checkRanges
, countCheckRanges
);
862 trie
=testTrieSerializeAllValueBits(testName
, trie
, withClone
,
863 checkRanges
, countCheckRanges
);
868 /* test data ----------------------------------------------------------------*/
870 /* set consecutive ranges, even with value 0 */
871 static const SetRange
873 { 0, 0x40, 0, FALSE
},
874 { 0x40, 0xe7, 0x1234, FALSE
},
875 { 0xe7, 0x3400, 0, FALSE
},
876 { 0x3400, 0x9fa6, 0x6162, FALSE
},
877 { 0x9fa6, 0xda9e, 0x3132, FALSE
},
878 { 0xdada, 0xeeee, 0x87ff, FALSE
},
879 { 0xeeee, 0x11111, 1, FALSE
},
880 { 0x11111, 0x44444, 0x6162, FALSE
},
881 { 0x44444, 0x60003, 0, FALSE
},
882 { 0xf0003, 0xf0004, 0xf, FALSE
},
883 { 0xf0004, 0xf0006, 0x10, FALSE
},
884 { 0xf0006, 0xf0007, 0x11, FALSE
},
885 { 0xf0007, 0xf0040, 0x12, FALSE
},
886 { 0xf0040, 0x110000, 0, FALSE
}
889 static const CheckRange
909 /* set some interesting overlapping ranges */
910 static const SetRange
912 { 0x21, 0x7f, 0x5555, TRUE
},
913 { 0x2f800, 0x2fedc, 0x7a, TRUE
},
914 { 0x72, 0xdd, 3, TRUE
},
915 { 0xdd, 0xde, 4, FALSE
},
916 { 0x201, 0x240, 6, TRUE
}, /* 3 consecutive blocks with the same pattern but */
917 { 0x241, 0x280, 6, TRUE
}, /* discontiguous value ranges, testing utrie2_enum() */
918 { 0x281, 0x2c0, 6, TRUE
},
919 { 0x2f987, 0x2fa98, 5, TRUE
},
920 { 0x2f777, 0x2f883, 0, TRUE
},
921 { 0x2f900, 0x2ffaa, 1, FALSE
},
922 { 0x2ffaa, 0x2ffab, 2, TRUE
},
923 { 0x2ffbb, 0x2ffc0, 7, TRUE
}
926 static const CheckRange
950 static const CheckRange
951 checkRanges2_d800
[]={
956 static const CheckRange
957 checkRanges2_d87e
[]={
965 static const CheckRange
966 checkRanges2_d87f
[]={
976 static const CheckRange
977 checkRanges2_dbff
[]={
982 /* use a non-zero initial value */
983 static const SetRange
985 { 0x31, 0xa4, 1, FALSE
},
986 { 0x3400, 0x6789, 2, FALSE
},
987 { 0x8000, 0x89ab, 9, TRUE
},
988 { 0x9000, 0xa000, 4, TRUE
},
989 { 0xabcd, 0xbcde, 3, TRUE
},
990 { 0x55555, 0x110000, 6, TRUE
}, /* highStart<U+ffff with non-initialValue */
991 { 0xcccc, 0x55555, 6, TRUE
}
994 static const CheckRange
996 { 0, 9 }, /* non-zero initialValue */
1009 /* empty or single-value tries, testing highStart==0 */
1010 static const SetRange
1012 { 0, 0, 0, FALSE
}, /* need some values for it to compile */
1015 static const CheckRange
1016 checkRangesEmpty
[]={
1021 static const SetRange
1022 setRangesSingleValue
[]={
1023 { 0, 0x110000, 5, TRUE
},
1026 static const CheckRange
1027 checkRangesSingleValue
[]={
1034 testTrieRanges("set1", FALSE
,
1035 setRanges1
, UPRV_LENGTHOF(setRanges1
),
1036 checkRanges1
, UPRV_LENGTHOF(checkRanges1
));
1037 testTrieRanges("set2-overlap", FALSE
,
1038 setRanges2
, UPRV_LENGTHOF(setRanges2
),
1039 checkRanges2
, UPRV_LENGTHOF(checkRanges2
));
1040 testTrieRanges("set3-initial-9", FALSE
,
1041 setRanges3
, UPRV_LENGTHOF(setRanges3
),
1042 checkRanges3
, UPRV_LENGTHOF(checkRanges3
));
1043 testTrieRanges("set-empty", FALSE
,
1045 checkRangesEmpty
, UPRV_LENGTHOF(checkRangesEmpty
));
1046 testTrieRanges("set-single-value", FALSE
,
1047 setRangesSingleValue
, UPRV_LENGTHOF(setRangesSingleValue
),
1048 checkRangesSingleValue
, UPRV_LENGTHOF(checkRangesSingleValue
));
1050 testTrieRanges("set2-overlap.withClone", TRUE
,
1051 setRanges2
, UPRV_LENGTHOF(setRanges2
),
1052 checkRanges2
, UPRV_LENGTHOF(checkRanges2
));
1056 EnumNewTrieForLeadSurrogateTest(void) {
1057 static const char *const testName
="enum-for-lead";
1058 UTrie2
*trie
=makeTrieWithRanges(testName
, FALSE
,
1059 setRanges2
, UPRV_LENGTHOF(setRanges2
),
1060 checkRanges2
, UPRV_LENGTHOF(checkRanges2
));
1062 const CheckRange
*checkRanges
;
1064 checkRanges
=checkRanges2_d800
+1;
1065 utrie2_enumForLeadSurrogate(trie
, 0xd800,
1066 testEnumValue
, testEnumRange
,
1068 checkRanges
=checkRanges2_d87e
+1
;
1069 utrie2_enumForLeadSurrogate(trie
, 0xd87e,
1070 testEnumValue
, testEnumRange
,
1072 checkRanges
=checkRanges2_d87f
+1;
1073 utrie2_enumForLeadSurrogate(trie
, 0xd87f,
1074 testEnumValue
, testEnumRange
,
1076 checkRanges
=checkRanges2_dbff
+1;
1077 utrie2_enumForLeadSurrogate(trie
, 0xdbff,
1078 testEnumValue
, testEnumRange
,
1080 if(!utrie2_isFrozen(trie
)) {
1081 UErrorCode errorCode
=U_ZERO_ERROR
;
1082 utrie2_freeze(trie
, UTRIE2_16_VALUE_BITS
, &errorCode
);
1083 if(U_FAILURE(errorCode
)) {
1084 log_err("error: utrie2_freeze(%s) failed\n", testName
);
1095 /* test utrie2_openDummy() -------------------------------------------------- */
1098 dummyTest(UTrie2ValueBits valueBits
) {
1107 UErrorCode errorCode
;
1109 const char *testName
;
1110 uint32_t initialValue
, errorValue
;
1112 if(valueBits
==UTRIE2_16_VALUE_BITS
) {
1113 testName
="dummy.16";
1117 testName
="dummy.32";
1118 initialValue
=0x01234567;
1119 errorValue
=0x89abcdef;
1121 checkRanges
[0].value
=errorValue
;
1122 checkRanges
[1].value
=checkRanges
[2].value
=initialValue
;
1124 errorCode
=U_ZERO_ERROR
;
1125 trie
=utrie2_openDummy(valueBits
, initialValue
, errorValue
, &errorCode
);
1126 if(U_FAILURE(errorCode
)) {
1127 log_err("utrie2_openDummy(valueBits=%d) failed - %s\n", valueBits
, u_errorName(errorCode
));
1131 testFrozenTrie(testName
, trie
, valueBits
, checkRanges
, UPRV_LENGTHOF(checkRanges
));
1136 DummyTrieTest(void) {
1137 dummyTest(UTRIE2_16_VALUE_BITS
);
1138 dummyTest(UTRIE2_32_VALUE_BITS
);
1141 /* test builder memory management ------------------------------------------- */
1144 FreeBlocksTest(void) {
1145 static const CheckRange
1153 static const char *const testName
="free-blocks";
1157 UErrorCode errorCode
;
1159 errorCode
=U_ZERO_ERROR
;
1160 trie
=utrie2_open(1, 0xbad, &errorCode
);
1161 if(U_FAILURE(errorCode
)) {
1162 log_err("error: utrie2_open(%s) failed: %s\n", testName
, u_errorName(errorCode
));
1167 * Repeatedly set overlapping same-value ranges to stress the free-data-block management.
1168 * If it fails, it will overflow the data array.
1170 for(i
=0; i
<(0x120000>>UTRIE2_SHIFT_2
)/2; ++i
) {
1171 utrie2_setRange32(trie
, 0x740, 0x840-1, 1, TRUE
, &errorCode
);
1172 utrie2_setRange32(trie
, 0x780, 0x880-1, 1, TRUE
, &errorCode
);
1173 utrie2_setRange32(trie
, 0x740, 0x840-1, 2, TRUE
, &errorCode
);
1174 utrie2_setRange32(trie
, 0x780, 0x880-1, 3, TRUE
, &errorCode
);
1176 /* make blocks that will be free during compaction */
1177 utrie2_setRange32(trie
, 0x1000, 0x3000-1, 2, TRUE
, &errorCode
);
1178 utrie2_setRange32(trie
, 0x2000, 0x4000-1, 3, TRUE
, &errorCode
);
1179 utrie2_setRange32(trie
, 0x1000, 0x4000-1, 1, TRUE
, &errorCode
);
1180 /* set some values for lead surrogate code units */
1181 utrie2_set32ForLeadSurrogateCodeUnit(trie
, 0xd800, 90, &errorCode
);
1182 utrie2_set32ForLeadSurrogateCodeUnit(trie
, 0xd999, 94, &errorCode
);
1183 utrie2_set32ForLeadSurrogateCodeUnit(trie
, 0xdbff, 99, &errorCode
);
1184 if(U_FAILURE(errorCode
)) {
1185 log_err("error: setting lots of ranges into a trie (%s) failed - %s\n",
1186 testName
, u_errorName(errorCode
));
1191 trie
=testTrieSerializeAllValueBits(testName
, trie
, FALSE
,
1192 checkRanges
, UPRV_LENGTHOF(checkRanges
));
1197 GrowDataArrayTest(void) {
1198 static const CheckRange
1206 static const char *const testName
="grow-data";
1210 UErrorCode errorCode
;
1212 errorCode
=U_ZERO_ERROR
;
1213 trie
=utrie2_open(1, 0xbad, &errorCode
);
1214 if(U_FAILURE(errorCode
)) {
1215 log_err("error: utrie2_open(%s) failed: %s\n", testName
, u_errorName(errorCode
));
1220 * Use utrie2_set32() not utrie2_setRange32() to write non-initialValue-data.
1221 * Should grow/reallocate the data array to a sufficient length.
1223 for(i
=0; i
<0x1000; ++i
) {
1224 utrie2_set32(trie
, i
, 2, &errorCode
);
1226 for(i
=0x720; i
<0x1100; ++i
) { /* some overlap */
1227 utrie2_set32(trie
, i
, 3, &errorCode
);
1229 for(i
=0x7a0; i
<0x900; ++i
) {
1230 utrie2_set32(trie
, i
, 4, &errorCode
);
1232 for(i
=0x8a0; i
<0x110000; ++i
) {
1233 utrie2_set32(trie
, i
, 5, &errorCode
);
1235 for(i
=0xd800; i
<0xdc00; ++i
) {
1236 utrie2_set32ForLeadSurrogateCodeUnit(trie
, i
, 1, &errorCode
);
1238 /* set some values for lead surrogate code units */
1239 utrie2_set32ForLeadSurrogateCodeUnit(trie
, 0xd800, 90, &errorCode
);
1240 utrie2_set32ForLeadSurrogateCodeUnit(trie
, 0xd999, 94, &errorCode
);
1241 utrie2_set32ForLeadSurrogateCodeUnit(trie
, 0xdbff, 99, &errorCode
);
1242 if(U_FAILURE(errorCode
)) {
1243 log_err("error: setting lots of values into a trie (%s) failed - %s\n",
1244 testName
, u_errorName(errorCode
));
1249 trie
=testTrieSerializeAllValueBits(testName
, trie
, FALSE
,
1250 checkRanges
, UPRV_LENGTHOF(checkRanges
));
1254 /* versions 1 and 2 --------------------------------------------------------- */
1257 GetVersionTest(void) {
1260 (data
[0]=0x54726965, 1!=utrie2_getVersion(data
, sizeof(data
), FALSE
)) ||
1261 (data
[0]=0x54726965, 1!=utrie2_getVersion(data
, sizeof(data
), TRUE
)) ||
1262 (data
[0]=0x65697254, 0!=utrie2_getVersion(data
, sizeof(data
), FALSE
)) ||
1263 (data
[0]=0x65697254, 1!=utrie2_getVersion(data
, sizeof(data
), TRUE
)) ||
1265 (data
[0]=0x54726932, 2!=utrie2_getVersion(data
, sizeof(data
), FALSE
)) ||
1266 (data
[0]=0x54726932, 2!=utrie2_getVersion(data
, sizeof(data
), TRUE
)) ||
1267 (data
[0]=0x32697254, 0!=utrie2_getVersion(data
, sizeof(data
), FALSE
)) ||
1268 (data
[0]=0x32697254, 2!=utrie2_getVersion(data
, sizeof(data
), TRUE
)) ||
1269 /* illegal arguments */
1270 (data
[0]=0x54726932, 0!=utrie2_getVersion(NULL
, sizeof(data
), FALSE
)) ||
1271 (data
[0]=0x54726932, 0!=utrie2_getVersion(data
, 3, FALSE
)) ||
1272 (data
[0]=0x54726932, 0!=utrie2_getVersion((char *)data
+1, sizeof(data
), FALSE
)) ||
1273 /* unknown signature values */
1274 (data
[0]=0x11223344, 0!=utrie2_getVersion(data
, sizeof(data
), FALSE
)) ||
1275 (data
[0]=0x54726933, 0!=utrie2_getVersion(data
, sizeof(data
), FALSE
))
1277 log_err("error: utrie2_getVersion() is not working as expected\n");
1282 makeNewTrie1WithRanges(const char *testName
,
1283 const SetRange setRanges
[], int32_t countSetRanges
,
1284 const CheckRange checkRanges
[], int32_t countCheckRanges
) {
1286 uint32_t initialValue
, errorValue
;
1288 UChar32 start
, limit
;
1290 UErrorCode errorCode
;
1291 UBool overwrite
, ok
;
1293 log_verbose("\ntesting Trie '%s'\n", testName
);
1294 errorCode
=U_ZERO_ERROR
;
1295 getSpecialValues(checkRanges
, countCheckRanges
, &initialValue
, &errorValue
);
1296 newTrie
=utrie_open(NULL
, NULL
, 2000,
1297 initialValue
, initialValue
,
1299 if(U_FAILURE(errorCode
)) {
1300 log_err("error: utrie_open(%s) failed: %s\n", testName
, u_errorName(errorCode
));
1304 /* set values from setRanges[] */
1306 for(i
=0; i
<countSetRanges
; ++i
) {
1307 start
=setRanges
[i
].start
;
1308 limit
=setRanges
[i
].limit
;
1309 value
=setRanges
[i
].value
;
1310 overwrite
=setRanges
[i
].overwrite
;
1311 if((limit
-start
)==1 && overwrite
) {
1312 ok
&=utrie_set32(newTrie
, start
, value
);
1314 ok
&=utrie_setRange32(newTrie
, start
, limit
, value
, overwrite
);
1320 log_err("error: setting values into a trie1 (%s) failed\n", testName
);
1321 utrie_close(newTrie
);
1327 testTrie2FromTrie1(const char *testName
,
1328 const SetRange setRanges
[], int32_t countSetRanges
,
1329 const CheckRange checkRanges
[], int32_t countCheckRanges
) {
1330 uint32_t memory1_16
[3000], memory1_32
[3000];
1331 int32_t length16
, length32
;
1336 UNewTrie
*newTrie1_16
, *newTrie1_32
;
1337 UTrie trie1_16
, trie1_32
;
1339 uint32_t initialValue
, errorValue
;
1340 UErrorCode errorCode
;
1342 newTrie1_16
=makeNewTrie1WithRanges(testName
,
1343 setRanges
, countSetRanges
,
1344 checkRanges
, countCheckRanges
);
1345 if(newTrie1_16
==NULL
) {
1348 newTrie1_32
=utrie_clone(NULL
, newTrie1_16
, NULL
, 0);
1349 if(newTrie1_32
==NULL
) {
1350 utrie_close(newTrie1_16
);
1353 errorCode
=U_ZERO_ERROR
;
1354 length16
=utrie_serialize(newTrie1_16
, memory1_16
, sizeof(memory1_16
),
1355 NULL
, TRUE
, &errorCode
);
1356 length32
=utrie_serialize(newTrie1_32
, memory1_32
, sizeof(memory1_32
),
1357 NULL
, FALSE
, &errorCode
);
1358 utrie_unserialize(&trie1_16
, memory1_16
, length16
, &errorCode
);
1359 utrie_unserialize(&trie1_32
, memory1_32
, length32
, &errorCode
);
1360 utrie_close(newTrie1_16
);
1361 utrie_close(newTrie1_32
);
1362 if(U_FAILURE(errorCode
)) {
1363 log_err("error: utrie_serialize or unserialize(%s) failed: %s\n",
1364 testName
, u_errorName(errorCode
));
1368 getSpecialValues(checkRanges
, countCheckRanges
, &initialValue
, &errorValue
);
1370 uprv_strcpy(name
, testName
);
1371 uprv_strcat(name
, ".16");
1372 trie2
=utrie2_fromUTrie(&trie1_16
, errorValue
, &errorCode
);
1373 if(U_SUCCESS(errorCode
)) {
1374 testFrozenTrie(name
, trie2
, UTRIE2_16_VALUE_BITS
, checkRanges
, countCheckRanges
);
1375 for(lead
=0xd800; lead
<0xdc00; ++lead
) {
1376 uint32_t value1
, value2
;
1377 value1
=UTRIE_GET16_FROM_LEAD(&trie1_16
, lead
);
1378 value2
=UTRIE2_GET16_FROM_U16_SINGLE_LEAD(trie2
, lead
);
1379 if(value1
!=value2
) {
1380 log_err("error: utrie2_fromUTrie(%s) wrong value %ld!=%ld "
1381 "from lead surrogate code unit U+%04lx\n",
1382 name
, (long)value2
, (long)value1
, (long)lead
);
1387 utrie2_close(trie2
);
1389 uprv_strcpy(name
, testName
);
1390 uprv_strcat(name
, ".32");
1391 trie2
=utrie2_fromUTrie(&trie1_32
, errorValue
, &errorCode
);
1392 if(U_SUCCESS(errorCode
)) {
1393 testFrozenTrie(name
, trie2
, UTRIE2_32_VALUE_BITS
, checkRanges
, countCheckRanges
);
1394 for(lead
=0xd800; lead
<0xdc00; ++lead
) {
1395 uint32_t value1
, value2
;
1396 value1
=UTRIE_GET32_FROM_LEAD(&trie1_32
, lead
);
1397 value2
=UTRIE2_GET32_FROM_U16_SINGLE_LEAD(trie2
, lead
);
1398 if(value1
!=value2
) {
1399 log_err("error: utrie2_fromUTrie(%s) wrong value %ld!=%ld "
1400 "from lead surrogate code unit U+%04lx\n",
1401 name
, (long)value2
, (long)value1
, (long)lead
);
1406 utrie2_close(trie2
);
1410 Trie12ConversionTest(void) {
1411 testTrie2FromTrie1("trie1->trie2",
1412 setRanges2
, UPRV_LENGTHOF(setRanges2
),
1413 checkRanges2
, UPRV_LENGTHOF(checkRanges2
));
1417 addTrie2Test(TestNode
** root
) {
1418 addTest(root
, &TrieTest
, "tsutil/trie2test/TrieTest");
1419 addTest(root
, &EnumNewTrieForLeadSurrogateTest
,
1420 "tsutil/trie2test/EnumNewTrieForLeadSurrogateTest");
1421 addTest(root
, &DummyTrieTest
, "tsutil/trie2test/DummyTrieTest");
1422 addTest(root
, &FreeBlocksTest
, "tsutil/trie2test/FreeBlocksTest");
1423 addTest(root
, &GrowDataArrayTest
, "tsutil/trie2test/GrowDataArrayTest");
1424 addTest(root
, &GetVersionTest
, "tsutil/trie2test/GetVersionTest");
1425 addTest(root
, &Trie12ConversionTest
, "tsutil/trie2test/Trie12ConversionTest");