/*
*******************************************************************************
*
- * Copyright (C) 2003-2008, International Business Machines
+ * Copyright (C) 2003-2012, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
#include <limits.h>
#include <stdlib.h>
#include <string.h>
+#include "unicode/localpointer.h"
#include "unicode/ustring.h"
#include "unicode/usprep.h"
#include "unicode/uniset.h"
UErrorCode prepStatus = U_ZERO_ERROR;
NamePrepTransform* trans = NamePrepTransform::createInstance(parseError,transStatus);
int32_t prepOptions = (((options & UIDNA_ALLOW_UNASSIGNED) != 0) ? USPREP_ALLOW_UNASSIGNED: 0);
- UStringPrepProfile* prep = usprep_open(NULL,"uidna",&prepStatus);
+ LocalUStringPrepProfilePointer prep(usprep_openByType(USPREP_RFC3491_NAMEPREP,&prepStatus));
UChar *transOut=NULL, *prepOut=NULL;
int32_t transOutLength=0, prepOutLength=0;
transOutLength = trans->process(src,srcLength,transOut, transOutLength, prepOptions>0, &parseError, transStatus);
}
- prepOutLength = usprep_prepare(prep, src, srcLength, prepOut, 0, prepOptions, &parseError, &prepStatus);
+ prepOutLength = usprep_prepare(prep.getAlias(), src, srcLength, prepOut, 0, prepOptions, &parseError, &prepStatus);
if( prepStatus == U_BUFFER_OVERFLOW_ERROR){
prepStatus = U_ZERO_ERROR;
prepOut = (UChar*) malloc(U_SIZEOF_UCHAR * prepOutLength);
- prepOutLength = usprep_prepare(prep, src, srcLength, prepOut, prepOutLength, prepOptions, &parseError, &prepStatus);
+ prepOutLength = usprep_prepare(prep.getAlias(), src, srcLength, prepOut, prepOutLength, prepOptions, &parseError, &prepStatus);
}
if(UnicodeString(transOut,transOutLength)!= UnicodeString(prepOut, prepOutLength)){
free(transOut);
free(prepOut);
delete trans;
-
}
void TestIDNA::testAPI(const UChar* src, const UChar* expected, const char* testName,
}
if(status != expectedStatus){
- errln( "Did not get the expected error for "+
+ errcheckln(status, "Did not get the expected error for "+
UnicodeString(testName)+
" null terminated source. Expected: " +UnicodeString(u_errorName(expectedStatus))
+ " Got: "+ UnicodeString(u_errorName(status))
errln("Did not get the expected result for %s with null termniated strings.\n",testName);
}
if(U_FAILURE(status)){
- errln( "%s null terminated source failed. Error: %s\n", testName,u_errorName(status));
+ errcheckln(status, "%s null terminated source failed. Error: %s", testName,u_errorName(status));
}
status = U_ZERO_ERROR;
errln("Did not get the expected result for %s with null termniated strings with options set.\n", testName);
}
if(U_FAILURE(status)){
- errln( "%s null terminated source and options set failed. Error: %s\n",testName, u_errorName(status));
+ errcheckln(status, "%s null terminated source and options set failed. Error: %s",testName, u_errorName(status));
}
status = U_ZERO_ERROR;
errln("Did not get the expected result for %s with string length.\n",testName);
}
if(U_FAILURE(status)){
- errln( "%s with string length. Error: %s\n",testName, u_errorName(status));
+ errcheckln(status, "%s with string length. Error: %s",testName, u_errorName(status));
}
status = U_ZERO_ERROR;
errln("Did not get the expected result for %s with string length and options set.\n",testName);
}
if(U_FAILURE(status)){
- errln( "%s with string length and options set. Error: %s\n", u_errorName(status), testName);
+ errcheckln(status, "%s with string length and options set. Error: %s", u_errorName(status), testName);
}
}
bufLen = u_unescape(domainNames[i],buf, bufLen+1);
func(buf,bufLen,expected,MAX_DEST_SIZE, UIDNA_ALLOW_UNASSIGNED, &parseError,&status);
if(U_FAILURE(status)){
- errln( "%s failed to convert domainNames[%i].Error: %s \n",testName, i, u_errorName(status));
+ errcheckln(status, "%s failed to convert domainNames[%i].Error: %s",testName, i, u_errorName(status));
break;
}
testAPI(buf,expected,testName,FALSE,U_ZERO_ERROR, TRUE, TRUE, func);
bufLen = u_unescape(domainNames[i],buf, bufLen+1);
func(buf,bufLen,expected,MAX_DEST_SIZE, UIDNA_ALLOW_UNASSIGNED, &parseError,&status);
if(U_FAILURE(status)){
- errln( "%s failed to convert domainNames[%i].Error: %s \n",testName,i, u_errorName(status));
+ errcheckln(status, "%s failed to convert domainNames[%i].Error: %s",testName,i, u_errorName(status));
break;
}
testAPI(buf,expected,testName, FALSE,U_ZERO_ERROR, TRUE, TRUE, func);
// test null-terminated source
expectedLen = func(src,-1,expected,MAX_DEST_SIZE, options, &parseError, &status);
if(U_FAILURE(status)){
- errln("%s null terminated source failed. Error: %s\n",testName, u_errorName(status));
+ errcheckln(status, "%s null terminated source failed. Error: %s",testName, u_errorName(status));
}
memcpy(odd,expected,(expectedLen+1) * U_SIZEOF_UCHAR);
memcpy(even,expected,(expectedLen+1) * U_SIZEOF_UCHAR);
if((i%2) ==0){
evenLen = func(odd,-1,even,MAX_DEST_SIZE,options, &parseError, &status);
if(U_FAILURE(status)){
- errln("%s null terminated source failed\n",testName);
+ errcheckln(status, "%s null terminated source failed - %s",testName, u_errorName(status));
break;
}
}else{
status = U_ZERO_ERROR;
expectedLen = func(src,-1,expected,MAX_DEST_SIZE,options|UIDNA_ALLOW_UNASSIGNED, &parseError, &status);
if(U_FAILURE(status)){
- errln("%s null terminated source with options set failed. Error: %s\n",testName, u_errorName(status));
+ errcheckln(status, "%s null terminated source with options set failed. Error: %s",testName, u_errorName(status));
}
memcpy(odd,expected,(expectedLen+1) * U_SIZEOF_UCHAR);
memcpy(even,expected,(expectedLen+1) * U_SIZEOF_UCHAR);
if((i%2) ==0){
evenLen = func(odd,-1,even,MAX_DEST_SIZE,options|UIDNA_ALLOW_UNASSIGNED, &parseError, &status);
if(U_FAILURE(status)){
- errln("%s null terminated source with options set failed\n",testName);
+ errcheckln(status, "%s null terminated source with options set failed - %s",testName, u_errorName(status));
break;
}
}else{
status = U_ZERO_ERROR;
expectedLen = func(src,srcLen,expected,MAX_DEST_SIZE,options, &parseError, &status);
if(U_FAILURE(status)){
- errln("%s null terminated source failed. Error: %s\n",testName, u_errorName(status));
+ errcheckln(status, "%s null terminated source failed. Error: %s",testName, u_errorName(status));
}
memcpy(odd,expected,(expectedLen+1) * U_SIZEOF_UCHAR);
memcpy(even,expected,(expectedLen+1) * U_SIZEOF_UCHAR);
if((i%2) ==0){
evenLen = func(odd,oddLen,even,MAX_DEST_SIZE,options, &parseError, &status);
if(U_FAILURE(status)){
- errln("%s source with source length failed\n",testName);
+ errcheckln(status, "%s source with source length failed - %s",testName, u_errorName(status));
break;
}
}else{
oddLen = func(even,evenLen,odd,MAX_DEST_SIZE,options, &parseError, &status);
if(U_FAILURE(status)){
- errln("%s source with source length failed\n",testName);
+ errcheckln(status, "%s source with source length failed - %s",testName, u_errorName(status));
break;
}
}
status = U_ZERO_ERROR;
expectedLen = func(src,srcLen,expected,MAX_DEST_SIZE,options|UIDNA_ALLOW_UNASSIGNED, &parseError, &status);
if(U_FAILURE(status)){
- errln("%s null terminated source with options set failed. Error: %s\n",testName, u_errorName(status));
+ errcheckln(status, "%s null terminated source with options set failed. Error: %s",testName, u_errorName(status));
}
memcpy(odd,expected,(expectedLen+1) * U_SIZEOF_UCHAR);
memcpy(even,expected,(expectedLen+1) * U_SIZEOF_UCHAR);
if((i%2) ==0){
evenLen = func(odd,oddLen,even,MAX_DEST_SIZE,options|UIDNA_ALLOW_UNASSIGNED, &parseError, &status);
if(U_FAILURE(status)){
- errln("%s source with source length and options set failed\n",testName);
+ errcheckln(status, "%s source with source length and options set failed - %s",testName, u_errorName(status));
break;
}
}else{
oddLen = func(even,evenLen,odd,MAX_DEST_SIZE,options|UIDNA_ALLOW_UNASSIGNED, &parseError, &status);
if(U_FAILURE(status)){
- errln("%s source with source length and options set failed\n",testName);
+ errcheckln(status, "%s source with source length and options set failed - %s",testName, u_errorName(status));
break;
}
}
// runIndexedTest
//---------------------------------------------
+extern IntlTest *createUTS46Test();
+
void TestIDNA::runIndexedTest( int32_t index, UBool exec, const char* &name, char* par)
{
if (exec) logln((UnicodeString)"TestSuite IDNA API ");
case 7: name = "TestRootLabelSeparator"; if(exec) TestRootLabelSeparator(); break;
case 8: name = "TestCompareReferenceImpl"; if(exec) TestCompareReferenceImpl(); break;
case 9: name = "TestDataFile"; if(exec) TestDataFile(); break;
+#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
case 10: name = "TestRefIDNA"; if(exec) TestRefIDNA(); break;
case 11: name = "TestIDNAMonkeyTest"; if(exec) TestIDNAMonkeyTest(); break;
+#else
+ case 10: case 11: name = "skip"; break;
+#endif
case 12:
{
name = "TestConformanceTestVectors";
}
break;
}
+ case 13:
+ name = "UTS46Test";
+ if (exec) {
+ logln("TestSuite UTS46Test---"); logln();
+ LocalPointer<IntlTest> test(createUTS46Test());
+ callTest(*test, par);
+ }
+ break;
default: name = ""; break; /*needed to end loop*/
}
}
getInstance(status); // Init prep
if (U_FAILURE(status)) {
- if (status == U_FILE_ACCESS_ERROR) {
- dataerrln("[DATA] Test could not initialize.");
- } else {
- errln("Test could not initialize. Got %s", u_errorName(status));
- }
+ dataerrln("Test could not initialize. Got %s", u_errorName(status));
return;
}
}
void TestIDNA::TestCompareReferenceImpl(){
-
+
UChar src [2] = {0,0};
int32_t srcLen = 0;
-
- for(int32_t i = 0x40000 ; i< 0x10ffff; i++){
- if(quick==TRUE && i> 0x1FFFF){
+ // data even OK?
+ {
+ UErrorCode dataStatus = U_ZERO_ERROR;
+ loadTestData(dataStatus);
+ if(U_FAILURE(dataStatus)) {
+ dataerrln("Couldn't load test data: %s\n", u_errorName(dataStatus)); // save us from thousands and thousands of errors
+ return;
+ }
+ }
+
+ for (int32_t i = 0; i <= 0x10FFFF; i++){
+ if (quick == TRUE && i > 0x0FFF){
return;
}
- if(i >= 0x30000 && i <= 0xF0000){
- i+=0xB0000;
+ if(i == 0x30000){
+ // jump to E0000, no characters assigned in plain 3 to plain 13 as of Unicode 6.0
+ i = 0xE0000;
}
- if(i>0xFFFF){
- src[0] = U16_LEAD(i);
- src[1] = U16_TRAIL(i);
- srcLen =2;
- }else{
+ if (i > 0xFFFF){
+ src[0] = U16_LEAD(i);
+ src[1] = U16_TRAIL(i);
+ srcLen =2;
+ } else {
src[0] = (UChar)i;
src[1] = 0;
srcLen = 1;
getInstance(status); // Init prep
if (U_FAILURE(status)) {
if (status == U_FILE_ACCESS_ERROR) {
- dataerrln("[DATA] Test could not initialize.");
- } else {
- errln("Test could not initialize. Got %s", u_errorName(status));
+ dataerrln("Test could not initialize. Got %s", u_errorName(status));
}
return;
}