X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/73c04bcfe1096173b00431f0cdc742894b15eef0..ba6d6ed23dec08b1cd5700a128c0752491c10ac9:/icuSources/test/cintltst/trietest.c diff --git a/icuSources/test/cintltst/trietest.c b/icuSources/test/cintltst/trietest.c index 37a98c85..ac595b67 100644 --- a/icuSources/test/cintltst/trietest.c +++ b/icuSources/test/cintltst/trietest.c @@ -1,7 +1,7 @@ /* ****************************************************************************** * -* Copyright (C) 2001-2005, International Business Machines +* Copyright (C) 2001-2011, International Business Machines * Corporation and others. All Rights Reserved. * ****************************************************************************** @@ -16,6 +16,7 @@ #include #include "unicode/utypes.h" +#include "unicode/utf16.h" #include "utrie.h" #include "cstring.h" #include "cmemory.h" @@ -49,10 +50,6 @@ typedef struct CheckRange { UChar32 limit; uint32_t value; } CheckRange; -struct{ - double bogus; /* needed for aligining the storage */ - uint8_t storage[10000000]; -} storageHolder; static uint32_t U_CALLCONV @@ -160,7 +157,7 @@ testTrieIteration(const char *testName, c=checkRanges[i].limit; if(c!=0) { --c; - UTF_APPEND_CHAR_UNSAFE(s, length, c); + U16_APPEND_UNSAFE(s, length, c); values[countValues++]=checkRanges[i].value; } } @@ -183,7 +180,7 @@ testTrieIteration(const char *testName, if( c2==0 ? c!=*(p-1) : - !UTF_IS_LEAD(c) || !UTF_IS_TRAIL(c2) || c!=*(p-2) || c2!=*(p-1) + !U16_IS_LEAD(c) || !U16_IS_TRAIL(c2) || c!=*(p-2) || c2!=*(p-1) ) { log_err("error: wrong (c, c2) from UTRIE_NEXT(%s): (U+%04lx, U+%04lx)\n", testName, c, c2); @@ -247,7 +244,7 @@ testTrieIteration(const char *testName, if( c2==0 ? c!=*p: - !UTF_IS_LEAD(c) || !UTF_IS_TRAIL(c2) || c!=*p || c2!=*(p+1) + !U16_IS_LEAD(c) || !U16_IS_TRAIL(c2) || c!=*p || c2!=*(p+1) ) { log_err("error: wrong (c, c2) from UTRIE_PREVIOUS(%s): (U+%04lx, U+%04lx)\n", testName, c, c2); @@ -270,7 +267,8 @@ testTrieRangesWithMalloc(const char *testName, UErrorCode errorCode; UBool overwrite, ok; uint8_t* storage =NULL; - storage = (uint8_t*) uprv_malloc(sizeof(uint8_t)*100000); + static const int32_t DEFAULT_STORAGE_SIZE = 32768; + storage = (uint8_t*) uprv_malloc(sizeof(uint8_t)*DEFAULT_STORAGE_SIZE); log_verbose("\ntesting Trie '%s'\n", testName); newTrie=utrie_open(NULL, NULL, 2000, @@ -317,7 +315,7 @@ testTrieRangesWithMalloc(const char *testName, } errorCode=U_ZERO_ERROR; - length=utrie_serialize(newTrie, storage, 1000000, + length=utrie_serialize(newTrie, storage, DEFAULT_STORAGE_SIZE, dataIs32 ? _testFoldedValue32 : _testFoldedValue16, (UBool)!dataIs32, &errorCode); @@ -387,7 +385,7 @@ testTrieRangesWithMalloc(const char *testName, log_err("error: unserialized trie(%s).fromBMP(U+%04lx)==0x%lx instead of 0x%lx\n", testName, start, value2, value); } - if(!UTF_IS_LEAD(start)) { + if(!U16_IS_LEAD(start)) { if(dataIs32) { value2=UTRIE_GET32_FROM_LEAD(&trie, start); } else { @@ -448,6 +446,10 @@ testTrieRanges(const char *testName, const SetRange setRanges[], int32_t countSetRanges, const CheckRange checkRanges[], int32_t countCheckRanges, UBool dataIs32, UBool latin1Linear) { + union{ + double bogus; /* needed for aligining the storage */ + uint8_t storage[32768]; + } storageHolder; UTrieGetFoldingOffset *getFoldingOffset; UNewTrieGetFoldedValue *getFoldedValue; const CheckRange *enumRanges; @@ -524,6 +526,11 @@ testTrieRanges(const char *testName, utrie_close(newTrie); return; } + if (length >= (int32_t)sizeof(storageHolder.storage)) { + log_err("error: utrie_serialize(%s) needs more memory\n", testName); + utrie_close(newTrie); + return; + } /* test linear Latin-1 range from utrie_getData() */ if(latin1Linear) { @@ -587,7 +594,7 @@ testTrieRanges(const char *testName, log_err("error: unserialized trie(%s).fromBMP(U+%04lx)==0x%lx instead of 0x%lx\n", testName, start, value2, value); } - if(!UTF_IS_LEAD(start)) { + if(!U16_IS_LEAD(start)) { if(dataIs32) { value2=UTRIE_GET32_FROM_LEAD(&trie, start); } else { @@ -739,6 +746,9 @@ setRanges2[]={ {0x2f800,0x2fedc, 0x7a, TRUE}, {0x72, 0xdd, 3, TRUE}, {0xdd, 0xde, 4, FALSE}, + {0x201, 0x220, 6, TRUE}, /* 3 consecutive blocks with the same pattern but discontiguous value ranges */ + {0x221, 0x240, 6, TRUE}, + {0x241, 0x260, 6, TRUE}, {0x2f987,0x2fa98, 5, TRUE}, {0x2f777,0x2f833, 0, TRUE}, {0x2f900,0x2ffee, 1, FALSE}, @@ -752,6 +762,12 @@ checkRanges2[]={ {0x72, 0x5555}, {0xdd, 3}, {0xde, 4}, + {0x201, 0}, + {0x220, 6}, + {0x221, 0}, + {0x240, 6}, + {0x241, 0}, + {0x260, 6}, {0x2f833,0}, {0x2f987,0x7a}, {0x2fa98,5}, @@ -804,7 +820,7 @@ dummyGetFoldingOffset(uint32_t data) { static void dummyTest(UBool make16BitTrie) { - static int32_t mem[UTRIE_DUMMY_SIZE/4]; + int32_t mem[UTRIE_DUMMY_SIZE/4]; UTrie trie; UErrorCode errorCode;