X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/46f4442e9a5a4f3b98b7c1083586332f6a8a99a4..249c4c5ea9376c24572daf9c2effa7484a282f14:/icuSources/test/intltest/testidn.cpp diff --git a/icuSources/test/intltest/testidn.cpp b/icuSources/test/intltest/testidn.cpp index e1f62773..29ac0b2a 100644 --- a/icuSources/test/intltest/testidn.cpp +++ b/icuSources/test/intltest/testidn.cpp @@ -1,12 +1,14 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /* ******************************************************************************* * -* Copyright (C) 2003-2006, International Business Machines +* Copyright (C) 2003-2013, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* * file name: testidn.cpp -* encoding: US-ASCII +* encoding: UTF-8 * tab size: 8 (not used) * indentation:4 * @@ -30,6 +32,7 @@ #include "cmemory.h" #include "cstring.h" #include "unicode/udata.h" +#include "unicode/utf16.h" #include "unewdata.h" #include "uoptions.h" #include "uparse.h" @@ -61,19 +64,17 @@ testAllCodepoints(TestIDNA& test); static TestIDNA* pTestIDNA =NULL; static const char* fileNames[] = { - "NamePrepProfile.txt" + "rfc3491.txt" }; -static UStringPrepProfile *profile = NULL; static const UTrie *idnTrie = NULL; static const int32_t *indexes = NULL; static const uint16_t *mappingData = NULL; /* -------------------------------------------------------------------------- */ /* file definitions */ -#define DATA_NAME "uidna" #define DATA_TYPE "icu" -#define MISC_DIR "misc" +#define SPREP_DIR "sprep" extern int testData(TestIDNA& test) { @@ -81,9 +82,9 @@ testData(TestIDNA& test) { UErrorCode errorCode=U_ZERO_ERROR; char *saveBasename =NULL; - profile = usprep_open(NULL, DATA_NAME, &errorCode); + LocalUStringPrepProfilePointer profile(usprep_openByType(USPREP_RFC3491_NAMEPREP, &errorCode)); if(U_FAILURE(errorCode)){ - test.errln("Failed to load IDNA data file. " + UnicodeString(u_errorName(errorCode))); + test.errcheckln(errorCode, "Failed to load IDNA data file. " + UnicodeString(u_errorName(errorCode))); return errorCode; } @@ -119,8 +120,9 @@ testData(TestIDNA& test) { /* first copy misc directory */ saveBasename = basename; - uprv_strcpy(basename,MISC_DIR); - basename = basename + uprv_strlen(MISC_DIR); + (void)saveBasename; // Suppress set but not used warning. + uprv_strcpy(basename,SPREP_DIR); + basename = basename + uprv_strlen(SPREP_DIR); *basename++=U_FILE_SEP_CHAR; /* process unassigned */ @@ -133,7 +135,6 @@ testData(TestIDNA& test) { testAllCodepoints(test); - usprep_close(profile); pTestIDNA = NULL; free(filename); return errorCode; @@ -151,7 +152,14 @@ strprepProfileLineFn(void * /*context*/, /*UBool* mapWithNorm = (UBool*) context;*/ const char* typeName; uint32_t rangeStart=0,rangeEnd =0; - + const char *s; + + s = u_skipWhitespace(fields[0][0]); + if (*s == '@') { + /* a special directive introduced in 4.2 */ + return; + } + if(fieldCount != 3){ *pErrorCode = U_INVALID_FORMAT_ERROR; return; @@ -162,21 +170,21 @@ strprepProfileLineFn(void * /*context*/, if(uprv_strstr(typeName, usprepTypeNames[USPREP_UNASSIGNED])!=NULL){ - u_parseCodePointRange(fields[0][0], &rangeStart,&rangeEnd, pErrorCode); + u_parseCodePointRange(s, &rangeStart,&rangeEnd, pErrorCode); /* store the range */ compareFlagsForRange(rangeStart,rangeEnd,USPREP_UNASSIGNED); }else if(uprv_strstr(typeName, usprepTypeNames[USPREP_PROHIBITED])!=NULL){ - u_parseCodePointRange(fields[0][0], &rangeStart,&rangeEnd, pErrorCode); + u_parseCodePointRange(s, &rangeStart,&rangeEnd, pErrorCode); /* store the range */ compareFlagsForRange(rangeStart,rangeEnd,USPREP_PROHIBITED); }else if(uprv_strstr(typeName, usprepTypeNames[USPREP_MAP])!=NULL){ /* get the character code, field 0 */ - code=(uint32_t)uprv_strtoul(fields[0][0], &end, 16); + code=(uint32_t)uprv_strtoul(s, &end, 16); /* parse the mapping string */ length=u_parseCodePoints(map, mapping, sizeof(mapping)/4, pErrorCode); @@ -377,8 +385,8 @@ compareMapping(uint32_t codepoint, uint32_t* mapping,int32_t mapLength, pTestIDNA->errln("Did not get the expected result. Expected: 0x%04X Got: 0x%04X \n", mapping[i], mappingData[index+i]); } }else{ - UChar lead = UTF16_LEAD(mapping[i]); - UChar trail = UTF16_TRAIL(mapping[i]); + UChar lead = U16_LEAD(mapping[i]); + UChar trail = U16_TRAIL(mapping[i]); if(mappingData[index+i] != lead || mappingData[index+i+1] != trail){ pTestIDNA->errln( "Did not get the expected result. Expected: 0x%04X 0x%04X Got: 0x%04X 0x%04X", lead, trail, mappingData[index+i], mappingData[index+i+1]); @@ -401,9 +409,9 @@ compareFlagsForRange(uint32_t start, uint32_t end, UStringPrepType retType; UBool isIndex=FALSE; int32_t value=0; -/* +/* // supplementary code point - UChar __lead16=UTF16_LEAD(0x2323E); + UChar __lead16=U16_LEAD(0x2323E); int32_t __offset; // get data for lead surrogate