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