]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/intltest/testidn.cpp
ICU-62141.0.1.tar.gz
[apple/icu.git] / icuSources / test / intltest / testidn.cpp
index 8cc9b1687faaabdee86fc4063d6af36207fa9d67..29ac0b2aae3df7f71a8bd313db82e95e5d62e898 100644 (file)
@@ -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,35 +64,34 @@ 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) {
-    char* filename = (char*) malloc(strlen(IntlTest::pathToDataDirectory())*5555);
-    //TODO get the srcDir dynamically 
-    const char *srcDir=IntlTest::pathToDataDirectory();
     char *basename=NULL;
     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;
     }
     
+    char* filename = (char*) malloc(strlen(IntlTest::pathToDataDirectory())*1024);
+    //TODO get the srcDir dynamically 
+    const char *srcDir=IntlTest::pathToDataDirectory();
+
     idnTrie     = &profile->sprepTrie;
     indexes     = profile->indexes;
     mappingData = profile->mappingData;
@@ -118,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 */
@@ -132,7 +135,6 @@ testData(TestIDNA& test) {
 
     testAllCodepoints(test);
 
-    usprep_close(profile);
     pTestIDNA = NULL;
     free(filename);
     return errorCode;
@@ -150,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;
@@ -161,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);
@@ -376,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]);
@@ -400,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