]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/cintltst/trietest.c
ICU-6.2.8.tar.gz
[apple/icu.git] / icuSources / test / cintltst / trietest.c
1 /*
2 ******************************************************************************
3 *
4 * Copyright (C) 2001-2003, International Business Machines
5 * Corporation and others. All Rights Reserved.
6 *
7 ******************************************************************************
8 * file name: trietest.c
9 * encoding: US-ASCII
10 * tab size: 8 (not used)
11 * indentation:4
12 *
13 * created on: 2001nov20
14 * created by: Markus W. Scherer
15 */
16
17 #include <stdio.h>
18 #include "unicode/utypes.h"
19 #include "utrie.h"
20 #include "cstring.h"
21 #include "cmemory.h"
22
23 #if 1
24 #include "cintltst.h"
25 #else
26 /* definitions from standalone utrie development */
27 #define log_err printf
28 #define log_verbose printf
29
30 #undef u_errorName
31 #define u_errorName(errorCode) "some error code"
32 #endif
33
34 #define ARRAY_LENGTH(array) (sizeof(array)/sizeof(array[0]))
35
36 /* Values for setting possibly overlapping, out-of-order ranges of values */
37 typedef struct SetRange {
38 UChar32 start, limit;
39 uint32_t value;
40 UBool overwrite;
41 } SetRange;
42
43 /*
44 * Values for testing:
45 * value is set from the previous boundary's limit to before
46 * this boundary's limit
47 */
48 typedef struct CheckRange {
49 UChar32 limit;
50 uint32_t value;
51 } CheckRange;
52 struct{
53 double bogus; /* needed for aligining the storage */
54 uint8_t storage[10000000];
55 } storageHolder;
56
57
58 static uint32_t U_CALLCONV
59 _testFoldedValue32(UNewTrie *trie, UChar32 start, int32_t offset) {
60 uint32_t foldedValue, value;
61 UChar32 limit;
62 UBool inBlockZero;
63
64 foldedValue=0;
65
66 limit=start+0x400;
67 while(start<limit) {
68 value=utrie_get32(trie, start, &inBlockZero);
69 if(inBlockZero) {
70 start+=UTRIE_DATA_BLOCK_LENGTH;
71 } else {
72 foldedValue|=value;
73 ++start;
74 }
75 }
76
77 if(foldedValue!=0) {
78 return ((uint32_t)offset<<16)|foldedValue;
79 } else {
80 return 0;
81 }
82 }
83
84 static int32_t U_CALLCONV
85 _testFoldingOffset32(uint32_t data) {
86 return (int32_t)(data>>16);
87 }
88
89 static uint32_t U_CALLCONV
90 _testFoldedValue16(UNewTrie *trie, UChar32 start, int32_t offset) {
91 uint32_t foldedValue, value;
92 UChar32 limit;
93 UBool inBlockZero;
94
95 foldedValue=0;
96
97 limit=start+0x400;
98 while(start<limit) {
99 value=utrie_get32(trie, start, &inBlockZero);
100 if(inBlockZero) {
101 start+=UTRIE_DATA_BLOCK_LENGTH;
102 } else {
103 foldedValue|=value;
104 ++start;
105 }
106 }
107
108 if(foldedValue!=0) {
109 return (uint32_t)(offset|0x8000);
110 } else {
111 return 0;
112 }
113 }
114
115 static int32_t U_CALLCONV
116 _testFoldingOffset16(uint32_t data) {
117 if(data&0x8000) {
118 return (int32_t)(data&0x7fff);
119 } else {
120 return 0;
121 }
122 }
123
124 static uint32_t U_CALLCONV
125 _testEnumValue(const void *context, uint32_t value) {
126 return value^0x5555;
127 }
128
129 static UBool U_CALLCONV
130 _testEnumRange(const void *context, UChar32 start, UChar32 limit, uint32_t value) {
131 const CheckRange **pb=(const CheckRange **)context;
132 const CheckRange *b=(*pb)++;
133
134 value^=0x5555;
135 if(start!=(b-1)->limit || limit!=b->limit || value!=b->value) {
136 log_err("error: utrie_enum() delivers wrong range [U+%04lx..U+%04lx[.0x%lx instead of [U+%04lx..U+%04lx[.0x%lx\n",
137 start, limit, value,
138 (b-1)->limit, b->limit, b->value);
139 }
140 return TRUE;
141 }
142
143 static void
144 testTrieIteration(const char *testName,
145 const UTrie *trie,
146 const CheckRange checkRanges[], int32_t countCheckRanges) {
147 UChar s[100];
148 uint32_t values[30];
149
150 const UChar *p, *limit;
151
152 uint32_t value;
153 UChar32 c;
154 int32_t i, length, countValues;
155 UChar c2;
156
157 /* write a string */
158 length=countValues=0;
159 for(i=0; i<countCheckRanges; ++i) {
160 c=checkRanges[i].limit;
161 if(c!=0) {
162 --c;
163 UTF_APPEND_CHAR_UNSAFE(s, length, c);
164 values[countValues++]=checkRanges[i].value;
165 }
166 }
167 limit=s+length;
168
169 /* try forward */
170 p=s;
171 i=0;
172 while(p<limit) {
173 c=c2=0x33;
174 if(trie->data32!=NULL) {
175 UTRIE_NEXT32(trie, p, limit, c, c2, value);
176 } else {
177 UTRIE_NEXT16(trie, p, limit, c, c2, value);
178 }
179 if(value!=values[i]) {
180 log_err("error: wrong value from UTRIE_NEXT(%s)(U+%04lx, U+%04lx): 0x%lx instead of 0x%lx\n",
181 testName, c, c2, value, values[i]);
182 }
183 if(
184 c2==0 ?
185 c!=*(p-1) :
186 !UTF_IS_LEAD(c) || !UTF_IS_TRAIL(c2) || c!=*(p-2) || c2!=*(p-1)
187 ) {
188 log_err("error: wrong (c, c2) from UTRIE_NEXT(%s): (U+%04lx, U+%04lx)\n",
189 testName, c, c2);
190 continue;
191 }
192 if(c2!=0) {
193 int32_t offset;
194
195 if(trie->data32==NULL) {
196 value=UTRIE_GET16_FROM_LEAD(trie, c);
197 offset=trie->getFoldingOffset(value);
198 if(offset>0) {
199 value=UTRIE_GET16_FROM_OFFSET_TRAIL(trie, offset, c2);
200 } else {
201 value=trie->initialValue;
202 }
203 } else {
204 value=UTRIE_GET32_FROM_LEAD(trie, c);
205 offset=trie->getFoldingOffset(value);
206 if(offset>0) {
207 value=UTRIE_GET32_FROM_OFFSET_TRAIL(trie, offset, c2);
208 } else {
209 value=trie->initialValue;
210 }
211 }
212 if(value!=values[i]) {
213 log_err("error: wrong value from UTRIE_GETXX_FROM_OFFSET_TRAIL(%s)(U+%04lx, U+%04lx): 0x%lx instead of 0x%lx\n",
214 testName, c, c2, value, values[i]);
215 }
216 }
217 if(c2!=0) {
218 value=0x44;
219 if(trie->data32==NULL) {
220 UTRIE_GET16_FROM_PAIR(trie, c, c2, value);
221 } else {
222 UTRIE_GET32_FROM_PAIR(trie, c, c2, value);
223 }
224 if(value!=values[i]) {
225 log_err("error: wrong value from UTRIE_GETXX_FROM_PAIR(%s)(U+%04lx, U+%04lx): 0x%lx instead of 0x%lx\n",
226 testName, c, c2, value, values[i]);
227 }
228 }
229 ++i;
230 }
231
232 /* try backward */
233 p=limit;
234 i=countValues;
235 while(s<p) {
236 --i;
237 c=c2=0x33;
238 if(trie->data32!=NULL) {
239 UTRIE_PREVIOUS32(trie, s, p, c, c2, value);
240 } else {
241 UTRIE_PREVIOUS16(trie, s, p, c, c2, value);
242 }
243 if(value!=values[i]) {
244 log_err("error: wrong value from UTRIE_PREVIOUS(%s)(U+%04lx, U+%04lx): 0x%lx instead of 0x%lx\n",
245 testName, c, c2, value, values[i]);
246 }
247 if(
248 c2==0 ?
249 c!=*p:
250 !UTF_IS_LEAD(c) || !UTF_IS_TRAIL(c2) || c!=*p || c2!=*(p+1)
251 ) {
252 log_err("error: wrong (c, c2) from UTRIE_PREVIOUS(%s): (U+%04lx, U+%04lx)\n",
253 testName, c, c2);
254 }
255 }
256 }
257
258 static void
259 testTrieRangesWithMalloc(const char *testName,
260 const SetRange setRanges[], int32_t countSetRanges,
261 const CheckRange checkRanges[], int32_t countCheckRanges,
262 UBool dataIs32, UBool latin1Linear) {
263 UTrieGetFoldingOffset *getFoldingOffset;
264 const CheckRange *enumRanges;
265 UNewTrie *newTrie;
266 UTrie trie={ 0 };
267 uint32_t value, value2;
268 UChar32 start, limit;
269 int32_t i, length;
270 UErrorCode errorCode;
271 UBool overwrite, ok;
272 uint8_t* storage =NULL;
273 storage = (uint8_t*) uprv_malloc(sizeof(uint8_t)*100000);
274
275 log_verbose("\ntesting Trie '%s'\n", testName);
276 newTrie=utrie_open(NULL, NULL, 2000,
277 checkRanges[0].value, checkRanges[0].value,
278 latin1Linear);
279
280 /* set values from setRanges[] */
281 ok=TRUE;
282 for(i=0; i<countSetRanges; ++i) {
283 start=setRanges[i].start;
284 limit=setRanges[i].limit;
285 value=setRanges[i].value;
286 overwrite=setRanges[i].overwrite;
287 if((limit-start)==1 && overwrite) {
288 ok&=utrie_set32(newTrie, start, value);
289 } else {
290 ok&=utrie_setRange32(newTrie, start, limit, value, overwrite);
291 }
292 }
293 if(!ok) {
294 log_err("error: setting values into a trie failed (%s)\n", testName);
295 return;
296 }
297
298 /* verify that all these values are in the new Trie */
299 start=0;
300 for(i=0; i<countCheckRanges; ++i) {
301 limit=checkRanges[i].limit;
302 value=checkRanges[i].value;
303
304 while(start<limit) {
305 if(value!=utrie_get32(newTrie, start, NULL)) {
306 log_err("error: newTrie(%s)[U+%04lx]==0x%lx instead of 0x%lx\n",
307 testName, start, utrie_get32(newTrie, start, NULL), value);
308 }
309 ++start;
310 }
311 }
312
313 if(dataIs32) {
314 getFoldingOffset=_testFoldingOffset32;
315 } else {
316 getFoldingOffset=_testFoldingOffset16;
317 }
318
319 errorCode=U_ZERO_ERROR;
320 length=utrie_serialize(newTrie, storage, 1000000,
321 dataIs32 ? _testFoldedValue32 : _testFoldedValue16,
322 (UBool)!dataIs32,
323 &errorCode);
324 if(U_FAILURE(errorCode)) {
325 log_err("error: utrie_serialize(%s) failed: %s\n", testName, u_errorName(errorCode));
326 utrie_close(newTrie);
327 return;
328 }
329
330 /* test linear Latin-1 range from utrie_getData() */
331 if(latin1Linear) {
332 uint32_t *data;
333 int32_t dataLength;
334
335 data=utrie_getData(newTrie, &dataLength);
336 start=0;
337 for(i=0; i<countCheckRanges && start<=0xff; ++i) {
338 limit=checkRanges[i].limit;
339 value=checkRanges[i].value;
340
341 while(start<limit && start<=0xff) {
342 if(value!=data[UTRIE_DATA_BLOCK_LENGTH+start]) {
343 log_err("error: newTrie(%s).latin1Data[U+%04lx]==0x%lx instead of 0x%lx\n",
344 testName, start, data[UTRIE_DATA_BLOCK_LENGTH+start], value);
345 }
346 ++start;
347 }
348 }
349 }
350
351 utrie_close(newTrie);
352
353 errorCode=U_ZERO_ERROR;
354 if(!utrie_unserialize(&trie, storage, length, &errorCode)) {
355 log_err("error: utrie_unserialize() failed, %s\n", u_errorName(errorCode));
356 return;
357 }
358 trie.getFoldingOffset=getFoldingOffset;
359
360 if(dataIs32!=(trie.data32!=NULL)) {
361 log_err("error: trie serialization (%s) did not preserve 32-bitness\n", testName);
362 }
363 if(latin1Linear!=trie.isLatin1Linear) {
364 log_err("error: trie serialization (%s) did not preserve Latin-1-linearity\n", testName);
365 }
366
367 /* verify that all these values are in the unserialized Trie */
368 start=0;
369 for(i=0; i<countCheckRanges; ++i) {
370 limit=checkRanges[i].limit;
371 value=checkRanges[i].value;
372
373 if(start==0xd800) {
374 /* skip surrogates */
375 start=limit;
376 continue;
377 }
378
379 while(start<limit) {
380 if(start<=0xffff) {
381 if(dataIs32) {
382 value2=UTRIE_GET32_FROM_BMP(&trie, start);
383 } else {
384 value2=UTRIE_GET16_FROM_BMP(&trie, start);
385 }
386 if(value!=value2) {
387 log_err("error: unserialized trie(%s).fromBMP(U+%04lx)==0x%lx instead of 0x%lx\n",
388 testName, start, value2, value);
389 }
390 if(!UTF_IS_LEAD(start)) {
391 if(dataIs32) {
392 value2=UTRIE_GET32_FROM_LEAD(&trie, start);
393 } else {
394 value2=UTRIE_GET16_FROM_LEAD(&trie, start);
395 }
396 if(value!=value2) {
397 log_err("error: unserialized trie(%s).fromLead(U+%04lx)==0x%lx instead of 0x%lx\n",
398 testName, start, value2, value);
399 }
400 }
401 }
402 if(dataIs32) {
403 UTRIE_GET32(&trie, start, value2);
404 } else {
405 UTRIE_GET16(&trie, start, value2);
406 }
407 if(value!=value2) {
408 log_err("error: unserialized trie(%s).get(U+%04lx)==0x%lx instead of 0x%lx\n",
409 testName, start, value2, value);
410 }
411 ++start;
412 }
413 }
414
415 /* enumerate and verify all ranges */
416 enumRanges=checkRanges+1;
417 utrie_enum(&trie, _testEnumValue, _testEnumRange, &enumRanges);
418
419 /* test linear Latin-1 range */
420 if(trie.isLatin1Linear) {
421 if(trie.data32!=NULL) {
422 const uint32_t *latin1=UTRIE_GET32_LATIN1(&trie);
423
424 for(start=0; start<0x100; ++start) {
425 if(latin1[start]!=UTRIE_GET32_FROM_LEAD(&trie, start)) {
426 log_err("error: (%s) trie.latin1[U+%04lx]=0x%lx!=0x%lx=trie.get32(U+%04lx)\n",
427 testName, start, latin1[start], UTRIE_GET32_FROM_LEAD(&trie, start), start);
428 }
429 }
430 } else {
431 const uint16_t *latin1=UTRIE_GET16_LATIN1(&trie);
432
433 for(start=0; start<0x100; ++start) {
434 if(latin1[start]!=UTRIE_GET16_FROM_LEAD(&trie, start)) {
435 log_err("error: (%s) trie.latin1[U+%04lx]=0x%lx!=0x%lx=trie.get16(U+%04lx)\n",
436 testName, start, latin1[start], UTRIE_GET16_FROM_LEAD(&trie, start), start);
437 }
438 }
439 }
440 }
441
442 testTrieIteration(testName, &trie, checkRanges, countCheckRanges);
443 uprv_free(storage);
444 }
445
446 static void
447 testTrieRanges(const char *testName,
448 const SetRange setRanges[], int32_t countSetRanges,
449 const CheckRange checkRanges[], int32_t countCheckRanges,
450 UBool dataIs32, UBool latin1Linear) {
451 UTrieGetFoldingOffset *getFoldingOffset;
452 const CheckRange *enumRanges;
453 UNewTrie *newTrie;
454 UTrie trie={ 0 };
455 uint32_t value, value2;
456 UChar32 start, limit;
457 int32_t i, length;
458 UErrorCode errorCode;
459 UBool overwrite, ok;
460
461 log_verbose("\ntesting Trie '%s'\n", testName);
462 newTrie=utrie_open(NULL, NULL, 2000,
463 checkRanges[0].value, checkRanges[0].value,
464 latin1Linear);
465
466 /* set values from setRanges[] */
467 ok=TRUE;
468 for(i=0; i<countSetRanges; ++i) {
469 start=setRanges[i].start;
470 limit=setRanges[i].limit;
471 value=setRanges[i].value;
472 overwrite=setRanges[i].overwrite;
473 if((limit-start)==1 && overwrite) {
474 ok&=utrie_set32(newTrie, start, value);
475 } else {
476 ok&=utrie_setRange32(newTrie, start, limit, value, overwrite);
477 }
478 }
479 if(!ok) {
480 log_err("error: setting values into a trie failed (%s)\n", testName);
481 return;
482 }
483
484 /* verify that all these values are in the new Trie */
485 start=0;
486 for(i=0; i<countCheckRanges; ++i) {
487 limit=checkRanges[i].limit;
488 value=checkRanges[i].value;
489
490 while(start<limit) {
491 if(value!=utrie_get32(newTrie, start, NULL)) {
492 log_err("error: newTrie(%s)[U+%04lx]==0x%lx instead of 0x%lx\n",
493 testName, start, utrie_get32(newTrie, start, NULL), value);
494 }
495 ++start;
496 }
497 }
498
499 if(dataIs32) {
500 getFoldingOffset=_testFoldingOffset32;
501 } else {
502 getFoldingOffset=_testFoldingOffset16;
503 }
504
505 errorCode=U_ZERO_ERROR;
506 length=utrie_serialize(newTrie, storageHolder.storage, sizeof(storageHolder.storage),
507 dataIs32 ? _testFoldedValue32 : _testFoldedValue16,
508 (UBool)!dataIs32,
509 &errorCode);
510 if(U_FAILURE(errorCode)) {
511 log_err("error: utrie_serialize(%s) failed: %s\n", testName, u_errorName(errorCode));
512 utrie_close(newTrie);
513 return;
514 }
515
516 /* test linear Latin-1 range from utrie_getData() */
517 if(latin1Linear) {
518 uint32_t *data;
519 int32_t dataLength;
520
521 data=utrie_getData(newTrie, &dataLength);
522 start=0;
523 for(i=0; i<countCheckRanges && start<=0xff; ++i) {
524 limit=checkRanges[i].limit;
525 value=checkRanges[i].value;
526
527 while(start<limit && start<=0xff) {
528 if(value!=data[UTRIE_DATA_BLOCK_LENGTH+start]) {
529 log_err("error: newTrie(%s).latin1Data[U+%04lx]==0x%lx instead of 0x%lx\n",
530 testName, start, data[UTRIE_DATA_BLOCK_LENGTH+start], value);
531 }
532 ++start;
533 }
534 }
535 }
536
537 utrie_close(newTrie);
538
539 errorCode=U_ZERO_ERROR;
540 if(!utrie_unserialize(&trie, storageHolder.storage, length, &errorCode)) {
541 log_err("error: utrie_unserialize() failed, %s\n", u_errorName(errorCode));
542 return;
543 }
544 trie.getFoldingOffset=getFoldingOffset;
545
546 if(dataIs32!=(trie.data32!=NULL)) {
547 log_err("error: trie serialization (%s) did not preserve 32-bitness\n", testName);
548 }
549 if(latin1Linear!=trie.isLatin1Linear) {
550 log_err("error: trie serialization (%s) did not preserve Latin-1-linearity\n", testName);
551 }
552
553 /* verify that all these values are in the unserialized Trie */
554 start=0;
555 for(i=0; i<countCheckRanges; ++i) {
556 limit=checkRanges[i].limit;
557 value=checkRanges[i].value;
558
559 if(start==0xd800) {
560 /* skip surrogates */
561 start=limit;
562 continue;
563 }
564
565 while(start<limit) {
566 if(start<=0xffff) {
567 if(dataIs32) {
568 value2=UTRIE_GET32_FROM_BMP(&trie, start);
569 } else {
570 value2=UTRIE_GET16_FROM_BMP(&trie, start);
571 }
572 if(value!=value2) {
573 log_err("error: unserialized trie(%s).fromBMP(U+%04lx)==0x%lx instead of 0x%lx\n",
574 testName, start, value2, value);
575 }
576 if(!UTF_IS_LEAD(start)) {
577 if(dataIs32) {
578 value2=UTRIE_GET32_FROM_LEAD(&trie, start);
579 } else {
580 value2=UTRIE_GET16_FROM_LEAD(&trie, start);
581 }
582 if(value!=value2) {
583 log_err("error: unserialized trie(%s).fromLead(U+%04lx)==0x%lx instead of 0x%lx\n",
584 testName, start, value2, value);
585 }
586 }
587 }
588 if(dataIs32) {
589 UTRIE_GET32(&trie, start, value2);
590 } else {
591 UTRIE_GET16(&trie, start, value2);
592 }
593 if(value!=value2) {
594 log_err("error: unserialized trie(%s).get(U+%04lx)==0x%lx instead of 0x%lx\n",
595 testName, start, value2, value);
596 }
597 ++start;
598 }
599 }
600
601 /* enumerate and verify all ranges */
602 enumRanges=checkRanges+1;
603 utrie_enum(&trie, _testEnumValue, _testEnumRange, &enumRanges);
604
605 /* test linear Latin-1 range */
606 if(trie.isLatin1Linear) {
607 if(trie.data32!=NULL) {
608 const uint32_t *latin1=UTRIE_GET32_LATIN1(&trie);
609
610 for(start=0; start<0x100; ++start) {
611 if(latin1[start]!=UTRIE_GET32_FROM_LEAD(&trie, start)) {
612 log_err("error: (%s) trie.latin1[U+%04lx]=0x%lx!=0x%lx=trie.get32(U+%04lx)\n",
613 testName, start, latin1[start], UTRIE_GET32_FROM_LEAD(&trie, start), start);
614 }
615 }
616 } else {
617 const uint16_t *latin1=UTRIE_GET16_LATIN1(&trie);
618
619 for(start=0; start<0x100; ++start) {
620 if(latin1[start]!=UTRIE_GET16_FROM_LEAD(&trie, start)) {
621 log_err("error: (%s) trie.latin1[U+%04lx]=0x%lx!=0x%lx=trie.get16(U+%04lx)\n",
622 testName, start, latin1[start], UTRIE_GET16_FROM_LEAD(&trie, start), start);
623 }
624 }
625 }
626 }
627
628 testTrieIteration(testName, &trie, checkRanges, countCheckRanges);
629 }
630
631 static void
632 testTrieRanges2(const char *testName,
633 const SetRange setRanges[], int32_t countSetRanges,
634 const CheckRange checkRanges[], int32_t countCheckRanges,
635 UBool dataIs32) {
636 char name[40];
637
638 testTrieRanges(testName,
639 setRanges, countSetRanges,
640 checkRanges, countCheckRanges,
641 dataIs32, FALSE);
642 testTrieRangesWithMalloc(testName,
643 setRanges, countSetRanges,
644 checkRanges, countCheckRanges,
645 dataIs32, FALSE);
646
647 uprv_strcpy(name, testName);
648 uprv_strcat(name, "-latin1Linear");
649 testTrieRanges(name,
650 setRanges, countSetRanges,
651 checkRanges, countCheckRanges,
652 dataIs32, TRUE);
653 testTrieRangesWithMalloc(name,
654 setRanges, countSetRanges,
655 checkRanges, countCheckRanges,
656 dataIs32, TRUE);
657 }
658
659 static void
660 testTrieRanges4(const char *testName,
661 const SetRange setRanges[], int32_t countSetRanges,
662 const CheckRange checkRanges[], int32_t countCheckRanges) {
663 char name[40];
664
665 uprv_strcpy(name, testName);
666 uprv_strcat(name, ".32");
667 testTrieRanges2(name,
668 setRanges, countSetRanges,
669 checkRanges, countCheckRanges,
670 TRUE);
671
672 uprv_strcpy(name, testName);
673 uprv_strcat(name, ".16");
674 testTrieRanges2(name,
675 setRanges, countSetRanges,
676 checkRanges, countCheckRanges,
677 FALSE);
678 }
679
680 /* test data ----------------------------------------------------------------*/
681
682 /* set consecutive ranges, even with value 0 */
683 static const SetRange
684 setRanges1[]={
685 {0, 0x20, 0, FALSE},
686 {0x20, 0xa7, 0x1234, FALSE},
687 {0xa7, 0x3400, 0, FALSE},
688 {0x3400, 0x9fa6, 0x6162, FALSE},
689 {0x9fa6, 0xda9e, 0x3132, FALSE},
690 {0xdada, 0xeeee, 0x87ff, FALSE}, /* try to disrupt _testFoldingOffset16() */
691 {0xeeee, 0x11111, 1, FALSE},
692 {0x11111, 0x44444, 0x6162, FALSE},
693 {0x44444, 0x60003, 0, FALSE},
694 {0xf0003, 0xf0004, 0xf, FALSE},
695 {0xf0004, 0xf0006, 0x10, FALSE},
696 {0xf0006, 0xf0007, 0x11, FALSE},
697 {0xf0007, 0xf0020, 0x12, FALSE},
698 {0xf0020, 0x110000, 0, FALSE}
699 };
700
701 static const CheckRange
702 checkRanges1[]={
703 {0, 0}, /* dummy start range to make _testEnumRange() simpler */
704 {0x20, 0},
705 {0xa7, 0x1234},
706 {0x3400, 0},
707 {0x9fa6, 0x6162},
708 {0xda9e, 0x3132},
709 {0xdada, 0},
710 {0xeeee, 0x87ff},
711 {0x11111,1},
712 {0x44444,0x6162},
713 {0xf0003,0},
714 {0xf0004,0xf},
715 {0xf0006,0x10},
716 {0xf0007,0x11},
717 {0xf0020,0x12},
718 {0x110000, 0}
719 };
720
721 /* set some interesting overlapping ranges */
722 static const SetRange
723 setRanges2[]={
724 {0x21, 0x7f, 0x5555, TRUE},
725 {0x2f800,0x2fedc, 0x7a, TRUE},
726 {0x72, 0xdd, 3, TRUE},
727 {0xdd, 0xde, 4, FALSE},
728 {0x2f987,0x2fa98, 5, TRUE},
729 {0x2f777,0x2f833, 0, TRUE},
730 {0x2f900,0x2ffee, 1, FALSE},
731 {0x2ffee,0x2ffef, 2, TRUE}
732 };
733
734 static const CheckRange
735 checkRanges2[]={
736 {0, 0}, /* dummy start range to make _testEnumRange() simpler */
737 {0x21, 0},
738 {0x72, 0x5555},
739 {0xdd, 3},
740 {0xde, 4},
741 {0x2f833,0},
742 {0x2f987,0x7a},
743 {0x2fa98,5},
744 {0x2fedc,0x7a},
745 {0x2ffee,1},
746 {0x2ffef,2},
747 {0x110000, 0}
748 };
749
750 /* use a non-zero initial value */
751 static const SetRange
752 setRanges3[]={
753 {0x31, 0xa4, 1, FALSE},
754 {0x3400, 0x6789, 2, FALSE},
755 {0x30000,0x34567,9, TRUE},
756 {0x45678,0x56789,3, TRUE}
757 };
758
759 static const CheckRange
760 checkRanges3[]={
761 {0, 9}, /* dummy start range, also carries the initial value */
762 {0x31, 9},
763 {0xa4, 1},
764 {0x3400, 9},
765 {0x6789, 2},
766 {0x45678,9},
767 {0x56789,3},
768 {0x110000,9}
769 };
770
771 static void
772 TrieTest(void) {
773 testTrieRanges4("set1",
774 setRanges1, ARRAY_LENGTH(setRanges1),
775 checkRanges1, ARRAY_LENGTH(checkRanges1));
776 testTrieRanges4("set2-overlap",
777 setRanges2, ARRAY_LENGTH(setRanges2),
778 checkRanges2, ARRAY_LENGTH(checkRanges2));
779 testTrieRanges4("set3-initial-9",
780 setRanges3, ARRAY_LENGTH(setRanges3),
781 checkRanges3, ARRAY_LENGTH(checkRanges3));
782 }
783
784 #if 1
785 void
786 addTrieTest(TestNode** root);
787
788 void
789 addTrieTest(TestNode** root) {
790 addTest(root, &TrieTest, "tsutil/trietest/TrieTest");
791 }
792 #else
793 /* standalone utrie development */
794 int main(int argc, const char *argv[]) {
795 TrieTest();
796 return 0;
797 }
798 #endif