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