/*
*******************************************************************************
*
-* Copyright (C) 2003, International Business Machines
+* Copyright (C) 2003-2013, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
* in various IDNA conversion processes.
*/
-#include <stdio.h>
-#include <stdlib.h>
#include "unicode/utypes.h"
#if !UCONFIG_NO_IDNA && !UCONFIG_NO_TRANSLITERATION
#include "cmemory.h"
#include "cstring.h"
#include "unicode/udata.h"
+#include "unicode/utf16.h"
#include "unewdata.h"
#include "uoptions.h"
#include "uparse.h"
#include "sprpimpl.h"
#include "testidna.h"
#include "punyref.h"
+#include <stdlib.h>
UBool beVerbose=FALSE, haveCopyright=TRUE;
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;
/* 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 */
testAllCodepoints(test);
- usprep_close(profile);
pTestIDNA = NULL;
free(filename);
return errorCode;
/*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;
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);
* the source codepoint is copied to the destination
*/
type = USPREP_TYPE_LIMIT;
+ isIndex =FALSE;
+ value = 0;
}else if(result >= _SPREP_TYPE_THRESHOLD){
type = (UStringPrepType) (result - _SPREP_TYPE_THRESHOLD);
+ isIndex =FALSE;
+ value = 0;
}else{
/* get the state */
type = USPREP_MAP;
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]);
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