static void testAPI(const UChar* src, const UChar* expected, const char* testName, UBool useSTD3ASCIIRules,UErrorCode expectedStatus, UBool doCompare, UBool testUnassigned, TestFunc func){ UErrorCode status = U_ZERO_ERROR; UChar destStack[MAX_DEST_SIZE]; int32_t destLen = 0; UChar* dest = NULL; int32_t expectedLen = (expected != NULL) ? u_strlen(expected) : 0; int32_t options = (useSTD3ASCIIRules == TRUE) ? UIDNA_USE_STD3_RULES : UIDNA_DEFAULT; UParseError parseError; int32_t tSrcLen = 0; UChar* tSrc = NULL; if(src != NULL){ tSrcLen = u_strlen(src); tSrc =(UChar*) malloc( U_SIZEOF_UCHAR * tSrcLen ); memcpy(tSrc,src,tSrcLen * U_SIZEOF_UCHAR); } /* test null-terminated source and return value of number of UChars required */ destLen = func(src,-1,NULL,0,options, &parseError , &status); if(status == U_BUFFER_OVERFLOW_ERROR){ status = U_ZERO_ERROR; /* reset error code */ if(destLen+1 < MAX_DEST_SIZE){ dest = destStack; destLen = func(src,-1,dest,destLen+1,options, &parseError, &status); /* TODO : compare output with expected */ if(U_SUCCESS(status) && expectedStatus != U_IDNA_STD3_ASCII_RULES_ERROR&& (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){ log_err("Did not get the expected result for null terminated source.\n" ); } }else{ log_err( "%s null terminated source failed. Requires destCapacity > 300\n",testName); } } if(status != expectedStatus){ log_err_status(status, "Did not get the expected error for %s null terminated source failed. Expected: %s Got: %s\n",testName, u_errorName(expectedStatus), u_errorName(status)); free(tSrc); return; } if(testUnassigned ){ status = U_ZERO_ERROR; destLen = func(src,-1,NULL,0,options | UIDNA_ALLOW_UNASSIGNED, &parseError, &status); if(status == U_BUFFER_OVERFLOW_ERROR){ status = U_ZERO_ERROR; /* reset error code */ if(destLen+1 < MAX_DEST_SIZE){ dest = destStack; destLen = func(src,-1,dest,destLen+1,options | UIDNA_ALLOW_UNASSIGNED, &parseError, &status); /* TODO : compare output with expected */ if(U_SUCCESS(status) && (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){ log_err("Did not get the expected result for %s null terminated source with both options set.\n",testName); } }else{ log_err( "%s null terminated source failed. Requires destCapacity > 300\n",testName); } } /*testing query string*/ if(status != expectedStatus && expectedStatus != U_IDNA_UNASSIGNED_ERROR){ log_err( "Did not get the expected error for %s null terminated source with options set. Expected: %s Got: %s\n",testName, u_errorName(expectedStatus), u_errorName(status)); } } status = U_ZERO_ERROR; /* test source with lengthand return value of number of UChars required*/ destLen = func(tSrc, tSrcLen, NULL,0,options, &parseError, &status); if(status == U_BUFFER_OVERFLOW_ERROR){ status = U_ZERO_ERROR; /* reset error code */ if(destLen+1 < MAX_DEST_SIZE){ dest = destStack; destLen = func(src,u_strlen(src),dest,destLen+1,options, &parseError, &status); /* TODO : compare output with expected */ if(U_SUCCESS(status) && (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){ log_err("Did not get the expected result for %s with source length.\n",testName); } }else{ log_err( "%s with source length failed. Requires destCapacity > 300\n",testName); } } if(status != expectedStatus){ log_err( "Did not get the expected error for %s with source length. Expected: %s Got: %s\n",testName, u_errorName(expectedStatus), u_errorName(status)); } if(testUnassigned){ status = U_ZERO_ERROR; destLen = func(tSrc,tSrcLen,NULL,0,options | UIDNA_ALLOW_UNASSIGNED, &parseError, &status); if(status == U_BUFFER_OVERFLOW_ERROR){ status = U_ZERO_ERROR; /* reset error code */ if(destLen+1 < MAX_DEST_SIZE){ dest = destStack; destLen = func(src,u_strlen(src),dest,destLen+1,options | UIDNA_ALLOW_UNASSIGNED, &parseError, &status); /* TODO : compare output with expected */ if(U_SUCCESS(status) && (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){ log_err("Did not get the expected result for %s with source length and both options set.\n",testName); } }else{ log_err( "%s with source length failed. Requires destCapacity > 300\n",testName); } } /*testing query string*/ if(status != expectedStatus && expectedStatus != U_IDNA_UNASSIGNED_ERROR){ log_err( "Did not get the expected error for %s with source length and options set. Expected: %s Got: %s\n",testName, u_errorName(expectedStatus), u_errorName(status)); } } status = U_ZERO_ERROR; destLen = func(src,-1,NULL,0,options | UIDNA_USE_STD3_RULES, &parseError, &status); if(status == U_BUFFER_OVERFLOW_ERROR){ status = U_ZERO_ERROR; /* reset error code*/ if(destLen+1 < MAX_DEST_SIZE){ dest = destStack; destLen = func(src,-1,dest,destLen+1,options | UIDNA_USE_STD3_RULES, &parseError, &status); /* TODO : compare output with expected*/ if(U_SUCCESS(status) && (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){ log_err("Did not get the expected result for %s null terminated source with both options set.\n",testName); } }else{ log_err( "%s null terminated source failed. Requires destCapacity > 300\n",testName); } } /*testing query string*/ if(status != expectedStatus){ log_err( "Did not get the expected error for %s null terminated source with options set. Expected: %s Got: %s\n",testName, u_errorName(expectedStatus), u_errorName(status)); } status = U_ZERO_ERROR; destLen = func(tSrc,tSrcLen,NULL,0,options | UIDNA_USE_STD3_RULES, &parseError, &status); if(status == U_BUFFER_OVERFLOW_ERROR){ status = U_ZERO_ERROR; /* reset error code*/ if(destLen+1 < MAX_DEST_SIZE){ dest = destStack; destLen = func(src,u_strlen(src),dest,destLen+1,options | UIDNA_USE_STD3_RULES, &parseError, &status); /* TODO : compare output with expected*/ if(U_SUCCESS(status) && (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){ log_err("Did not get the expected result for %s with source length and both options set.\n",testName); } }else{ log_err( "%s with source length failed. Requires destCapacity > 300\n",testName); } } /*testing query string*/ if(status != expectedStatus && expectedStatus != U_IDNA_UNASSIGNED_ERROR){ log_err( "Did not get the expected error for %s with source length and options set. Expected: %s Got: %s\n",testName, u_errorName(expectedStatus), u_errorName(status)); } free(tSrc); }
static void TestCaseCompare(void) { static const UChar mixed[]= { 0x61, 0x42, 0x131, 0x3a3, 0xdf, 0xfb03, 0xd93f, 0xdfff, 0 }, otherDefault[]= { 0x41, 0x62, 0x131, 0x3c3, 0x73, 0x53, 0x46, 0x66, 0x49, 0xd93f, 0xdfff, 0 }, otherExcludeSpecialI[]={ 0x41, 0x62, 0x131, 0x3c3, 0x53, 0x73, 0x66, 0x46, 0x69, 0xd93f, 0xdfff, 0 }, different[]= { 0x41, 0x62, 0x131, 0x3c3, 0x73, 0x53, 0x46, 0x66, 0x49, 0xd93f, 0xdffd, 0 }; UVersionInfo unicodeVersion={ 0, 0, 17, 89 }, unicode_3_1={ 3, 1, 0, 0 }; int32_t result, lenMixed, lenOtherDefault, lenOtherExcludeSpecialI, lenDifferent; UErrorCode errorCode; UBool isUnicode_3_1; errorCode=U_ZERO_ERROR; lenMixed=u_strlen(mixed); lenOtherDefault=u_strlen(otherDefault); (void)lenOtherDefault; /* Suppress set but not used warning. */ lenOtherExcludeSpecialI=u_strlen(otherExcludeSpecialI); lenDifferent=u_strlen(different); /* if unicodeVersion()>=3.1 then test exclude-special-i cases as well */ u_getUnicodeVersion(unicodeVersion); isUnicode_3_1= uprv_memcmp(unicodeVersion, unicode_3_1, 4)>=0; (void)isUnicode_3_1; /* Suppress set but not used warning. */ /* test u_strcasecmp() */ result=u_strcasecmp(mixed, otherDefault, U_FOLD_CASE_DEFAULT); if(result!=0) { log_err("error: u_strcasecmp(mixed, other, default)=%ld instead of 0\n", result); } result=u_strCaseCompare(mixed, -1, otherDefault, -1, U_FOLD_CASE_DEFAULT, &errorCode); if(result!=0) { log_err("error: u_strCaseCompare(mixed, other, default)=%ld instead of 0\n", result); } /* test u_strcasecmp() - exclude special i */ result=u_strcasecmp(mixed, otherExcludeSpecialI, U_FOLD_CASE_EXCLUDE_SPECIAL_I); if(result!=0) { log_err("error: u_strcasecmp(mixed, other, exclude special i)=%ld instead of 0\n", result); } result=u_strCaseCompare(mixed, lenMixed, otherExcludeSpecialI, lenOtherExcludeSpecialI, U_FOLD_CASE_EXCLUDE_SPECIAL_I, &errorCode); if(result!=0) { log_err("error: u_strCaseCompare(mixed, other, exclude special i)=%ld instead of 0\n", result); } /* test u_strcasecmp() */ result=u_strcasecmp(mixed, different, U_FOLD_CASE_DEFAULT); if(result<=0) { log_err("error: u_strcasecmp(mixed, different, default)=%ld instead of positive\n", result); } result=u_strCaseCompare(mixed, -1, different, lenDifferent, U_FOLD_CASE_DEFAULT, &errorCode); if(result<=0) { log_err("error: u_strCaseCompare(mixed, different, default)=%ld instead of positive\n", result); } /* test u_strncasecmp() - stop before the sharp s (U+00df) */ result=u_strncasecmp(mixed, different, 4, U_FOLD_CASE_DEFAULT); if(result!=0) { log_err("error: u_strncasecmp(mixed, different, 4, default)=%ld instead of 0\n", result); } result=u_strCaseCompare(mixed, 4, different, 4, U_FOLD_CASE_DEFAULT, &errorCode); if(result!=0) { log_err("error: u_strCaseCompare(mixed, 4, different, 4, default)=%ld instead of 0\n", result); } /* test u_strncasecmp() - stop in the middle of the sharp s (U+00df) */ result=u_strncasecmp(mixed, different, 5, U_FOLD_CASE_DEFAULT); if(result<=0) { log_err("error: u_strncasecmp(mixed, different, 5, default)=%ld instead of positive\n", result); } result=u_strCaseCompare(mixed, 5, different, 5, U_FOLD_CASE_DEFAULT, &errorCode); if(result<=0) { log_err("error: u_strCaseCompare(mixed, 5, different, 5, default)=%ld instead of positive\n", result); } /* test u_memcasecmp() - stop before the sharp s (U+00df) */ result=u_memcasecmp(mixed, different, 4, U_FOLD_CASE_DEFAULT); if(result!=0) { log_err("error: u_memcasecmp(mixed, different, 4, default)=%ld instead of 0\n", result); } /* test u_memcasecmp() - stop in the middle of the sharp s (U+00df) */ result=u_memcasecmp(mixed, different, 5, U_FOLD_CASE_DEFAULT); if(result<=0) { log_err("error: u_memcasecmp(mixed, different, 5, default)=%ld instead of positive\n", result); } }