1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ******************************************************************************* 3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius * Copyright (C) 2003-2012, International Business Machines 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Corporation and others. All Rights Reserved. 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ******************************************************************************* 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * file name: spreptst.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: 2003jul11 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * created by: Ram Viswanadha 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define USPREP_TYPE_NAMES_ARRAY 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h" 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_IDNA 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ustring.h" 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/putil.h" 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cintltst.h" 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/usprep.h" 26103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius#include "unicode/utf16.h" 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "sprpimpl.h" 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "uparse.h" 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cmemory.h" 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "ustr_imp.h" 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cstring.h" 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruparseMappings(const char *filename, UStringPrepProfile* data, UBool reportError, UErrorCode *pErrorCode); 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerucompareMapping(UStringPrepProfile* data, uint32_t codepoint, uint32_t* mapping, int32_t mapLength, 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UStringPrepType option); 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerucompareFlagsForRange(UStringPrepProfile* data, uint32_t start, uint32_t end,UStringPrepType option); 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoStringPrepTest(const char* binFileName, const char* txtFileName, int32_t options, UErrorCode* errorCode); 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void U_CALLCONV 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerustrprepProfileLineFn(void *context, 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *fields[][2], int32_t fieldCount, 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode *pErrorCode) { 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t mapping[40]; 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *end, *map; 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t code; 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t length; 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UStringPrepProfile* data = (UStringPrepProfile*) context; 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* typeName; 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t rangeStart=0,rangeEnd =0; 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru typeName = fields[2][0]; 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru map = fields[1][0]; 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strstr(typeName, usprepTypeNames[USPREP_UNASSIGNED])!=NULL){ 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_parseCodePointRange(fields[0][0], &rangeStart,&rangeEnd, pErrorCode); 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* store the range */ 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru compareFlagsForRange(data, rangeStart,rangeEnd,USPREP_UNASSIGNED); 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else if(strstr(typeName, usprepTypeNames[USPREP_PROHIBITED])!=NULL){ 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_parseCodePointRange(fields[0][0], &rangeStart,&rangeEnd, pErrorCode); 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* store the range */ 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru compareFlagsForRange(data, rangeStart,rangeEnd,USPREP_PROHIBITED); 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else if(strstr(typeName, usprepTypeNames[USPREP_MAP])!=NULL){ 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* get the character code, field 0 */ 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru code=(uint32_t)uprv_strtoul(fields[0][0], &end, 16); 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* parse the mapping string */ 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru length=u_parseCodePoints(map, mapping, sizeof(mapping)/4, pErrorCode); 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* compare the mapping */ 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru compareMapping(data, code,mapping, length,USPREP_MAP); 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *pErrorCode = U_INVALID_FORMAT_ERROR; 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruparseMappings(const char *filename, UStringPrepProfile* data, UBool reportError, UErrorCode *pErrorCode) { 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *fields[3][2]; 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_parseDelimitedFile(filename, ';', fields, 3, strprepProfileLineFn, (void*)data, pErrorCode); 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*fprintf(stdout,"Number of code points that have mappings with length >1 : %i\n",len);*/ 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(*pErrorCode) && (reportError || *pErrorCode!=U_FILE_ACCESS_ERROR)) { 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err( "testidn error: u_parseDelimitedFile(\"%s\") failed - %s\n", filename, u_errorName(*pErrorCode)); 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UStringPrepType 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerugetValues(uint32_t result, int32_t* value, UBool* isIndex){ 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UStringPrepType type; 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(result == 0){ 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Initial value stored in the mapping table 117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * just return USPREP_TYPE_LIMIT .. so that 118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the source codepoint is copied to the destination 119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru type = USPREP_TYPE_LIMIT; 121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else if(result >= _SPREP_TYPE_THRESHOLD){ 122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru type = (UStringPrepType) (result - _SPREP_TYPE_THRESHOLD); 123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* get the type */ 125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru type = USPREP_MAP; 126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* ascertain if the value is index or delta */ 127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(result & 0x02){ 128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *isIndex = TRUE; 129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *value = result >> 2; 130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *isIndex = FALSE; 133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *value = (int16_t)result; 134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *value = (*value >> 2); 135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if((result>>2) == _SPREP_MAX_INDEX_VALUE){ 138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru type = USPREP_DELETE; 139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru isIndex =FALSE; 140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru value = 0; 141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return type; 144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void 147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerucompareMapping(UStringPrepProfile* data, uint32_t codepoint, uint32_t* mapping,int32_t mapLength, 148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UStringPrepType type){ 149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t result = 0; 150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t length=0; 151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool isIndex = FALSE; 152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UStringPrepType retType; 15354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius int32_t value=0, idx=0, delta=0; 154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t* indexes = data->indexes; 155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UTrie trie = data->sprepTrie; 156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const uint16_t* mappingData = data->mappingData; 157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t realLength =0; 158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t j=0; 159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int8_t i=0; 160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UTRIE_GET16(&trie, codepoint, result); 162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru retType = getValues(result,&value,&isIndex); 163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(type != retType && retType != USPREP_DELETE){ 166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err( "Did not get the assigned type for codepoint 0x%08X. Expected: %i Got: %i\n",codepoint, USPREP_MAP, type); 168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(isIndex){ 17254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius idx = value; 17354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if(idx >= indexes[_SPREP_ONE_UCHAR_MAPPING_INDEX_START] && 17454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius idx < indexes[_SPREP_TWO_UCHARS_MAPPING_INDEX_START]){ 175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru length = 1; 17654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius }else if(idx >= indexes[_SPREP_TWO_UCHARS_MAPPING_INDEX_START] && 17754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius idx < indexes[_SPREP_THREE_UCHARS_MAPPING_INDEX_START]){ 178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru length = 2; 17954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius }else if(idx >= indexes[_SPREP_THREE_UCHARS_MAPPING_INDEX_START] && 18054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius idx < indexes[_SPREP_FOUR_UCHARS_MAPPING_INDEX_START]){ 181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru length = 3; 182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 18354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius length = mappingData[idx++]; 184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delta = value; 187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru length = (retType == USPREP_DELETE)? 0 : 1; 188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* figure out the real length */ 191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(j=0; j<mapLength; j++){ 192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(mapping[j] > 0xFFFF){ 193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru realLength +=2; 194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru realLength++; 196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(realLength != length){ 200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err( "Did not get the expected length. Expected: %i Got: %i\n", mapLength, length); 201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(isIndex){ 204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i =0; i< mapLength; i++){ 205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(mapping[i] <= 0xFFFF){ 20654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if(mappingData[idx+i] != (uint16_t)mapping[i]){ 20754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius log_err("Did not get the expected result. Expected: 0x%04X Got: 0x%04X \n", mapping[i], mappingData[idx+i]); 208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 210103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius UChar lead = U16_LEAD(mapping[i]); 211103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius UChar trail = U16_TRAIL(mapping[i]); 21254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if(mappingData[idx+i] != lead || 21354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius mappingData[idx+i+1] != trail){ 21454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius log_err( "Did not get the expected result. Expected: 0x%04X 0x%04X Got: 0x%04X 0x%04X\n", lead, trail, mappingData[idx+i], mappingData[idx+i+1]); 215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(retType!=USPREP_DELETE && (codepoint-delta) != (uint16_t)mapping[0]){ 220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Did not get the expected result. Expected: 0x%04X Got: 0x%04X \n", mapping[0],(codepoint-delta)); 221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void 227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerucompareFlagsForRange(UStringPrepProfile* data, 228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t start, uint32_t end, 229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UStringPrepType type){ 230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t result =0 ; 232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UStringPrepType retType; 233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool isIndex=FALSE; 234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t value=0; 235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UTrie trie = data->sprepTrie; 236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // supplementary code point 238103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius UChar __lead16=U16_LEAD(0x2323E); 239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t __offset; 240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // get data for lead surrogate 242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (result)=_UTRIE_GET_RAW((&idnTrie), index, 0, (__lead16)); 243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru __offset=(&idnTrie)->getFoldingOffset(result); 244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // get the real data from the folded lead/trail units 246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(__offset>0) { 247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (result)=_UTRIE_GET_RAW((&idnTrie), index, __offset, (0x2323E)&0x3ff); 248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (result)=(uint32_t)((&idnTrie)->initialValue); 250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UTRIE_GET16(&idnTrie,0x2323E, result); 253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while(start < end+1){ 255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UTRIE_GET16(&trie,start, result); 256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru retType = getValues(result, &value, &isIndex); 257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(result > _SPREP_TYPE_THRESHOLD){ 258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(retType != type){ 259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err( "FAIL: Did not get the expected type for 0x%06X. Expected: %s Got: %s\n",start,usprepTypeNames[type], usprepTypeNames[retType]); 260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(type == USPREP_PROHIBITED && ((result & 0x01) != 0x01)){ 263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err( "FAIL: Did not get the expected type for 0x%06X. Expected: %s Got: %s\n",start,usprepTypeNames[type], usprepTypeNames[retType]); 264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru start++; 268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid 273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoStringPrepTest(const char* binFileName, const char* txtFileName, int32_t options, UErrorCode* errorCode){ 274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *testdatapath = loadTestData(errorCode); 276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *srcdatapath = NULL; 277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *relativepath = NULL; 278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *filename = NULL; 279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UStringPrepProfile* profile = NULL; 280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifdef U_TOPSRCDIR 282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru srcdatapath = U_TOPSRCDIR; 283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru relativepath = U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING; 284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#else 285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru srcdatapath = ctest_dataOutDir(); 286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru relativepath = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING; 287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru profile = usprep_open(testdatapath, binFileName, errorCode); 290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 29185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(*errorCode == U_FILE_ACCESS_ERROR) { 29285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Failed to load %s data file. Error: %s \n", binFileName, u_errorName(*errorCode)); 29385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return; 29485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else if(U_FAILURE(*errorCode)){ 295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Failed to load %s data file. Error: %s \n", binFileName, u_errorName(*errorCode)); 296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 298b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho filename = (char*) malloc(strlen(srcdatapath)+strlen(relativepath)+strlen(txtFileName)+10 ); 299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* open and load the txt file */ 300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(filename,srcdatapath); 301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(filename,relativepath); 302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(filename,txtFileName); 303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru parseMappings(filename,profile, TRUE,errorCode); 305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(filename); 307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Hey, Emacs, please set the following: 311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Local Variables: 313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * indent-tabs-mode: nil 314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * End: 315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 317