Index: source/test/intltest/itspoof.cpp |
diff --git a/source/test/intltest/itspoof.cpp b/source/test/intltest/itspoof.cpp |
index 68f4dfd680682be9e130e5d803468969bfc5556d..b5b90e27e4e31cea47b4bc0d038e9e608afab6f0 100644 |
--- a/source/test/intltest/itspoof.cpp |
+++ b/source/test/intltest/itspoof.cpp |
@@ -1,6 +1,6 @@ |
/* |
********************************************************************** |
-* Copyright (C) 2011-2013, International Business Machines Corporation |
+* Copyright (C) 2011-2014, International Business Machines Corporation |
* and others. All Rights Reserved. |
********************************************************************** |
*/ |
@@ -45,8 +45,6 @@ |
errln("Test Failure at file %s, line %d: \"%s\" (%d) == \"%s\" (%d)", \ |
__FILE__, __LINE__, #a, (a), #b, (b)); }} |
-#define LENGTHOF(array) ((int32_t)(sizeof(array)/sizeof((array)[0]))) |
- |
/* |
* TEST_SETUP and TEST_TEARDOWN |
* macros to handle the boilerplate around setting up test case. |
@@ -369,12 +367,11 @@ U_DEFINE_LOCAL_OPEN_POINTER(LocalStdioFilePointer, FILE, fclose); |
// verify that it transforms correctly in a skeleton. |
// |
void IntlTestSpoof::testConfData() { |
- UErrorCode status = U_ZERO_ERROR; |
- |
- const char *testDataDir = IntlTest::getSourceTestData(status); |
- TEST_ASSERT_SUCCESS(status); |
char buffer[2000]; |
- uprv_strcpy(buffer, testDataDir); |
+ if (getUnidataPath(buffer) == NULL) { |
+ errln("Skipping test spoof/testConfData. Unable to find path to source/data/unidata/."); |
+ return; |
+ } |
uprv_strcat(buffer, "confusables.txt"); |
LocalStdioFilePointer f(fopen(buffer, "rb")); |
@@ -394,6 +391,7 @@ void IntlTestSpoof::testConfData() { |
} |
UnicodeString confusablesTxt = UnicodeString::fromUTF8(StringPiece(fileBuf.getAlias(), fileSize)); |
+ UErrorCode status = U_ZERO_ERROR; |
LocalUSpoofCheckerPointer sc(uspoof_open(&status)); |
TEST_ASSERT_SUCCESS(status); |
@@ -505,13 +503,13 @@ void IntlTestSpoof::testIdentifierInfo() { |
{"\\u0061\\u0031\\u0661", USPOOF_UNRESTRICTIVE, "[\\u0030\\u0660]", "Latn", "Arab Thaa", "Arab Thaa"}, |
{"\\u0061\\u0031\\u0661\\u06F1", USPOOF_UNRESTRICTIVE, "[\\u0030\\u0660\\u06F0]", "Latn Arab", "", ""}, |
{"\\u0661\\u30FC\\u3006\\u0061\\u30A2\\u0031\\u0967\\u06F1", USPOOF_UNRESTRICTIVE, |
- "[\\u0030\\u0660\\u06F0\\u0966]", "Latn Kana Arab", "Deva Kthi", "Deva Kthi"}, |
+ "[\\u0030\\u0660\\u06F0\\u0966]", "Latn Kana Arab", "Deva Kthi Mahj", "Deva Kthi Mahj"}, |
{"\\u0061\\u30A2\\u30FC\\u3006\\u0031\\u0967\\u0661\\u06F1", USPOOF_UNRESTRICTIVE, |
- "[\\u0030\\u0660\\u06F0\\u0966]", "Latn Kana Arab", "Deva Kthi", "Deva Kthi"} |
+ "[\\u0030\\u0660\\u06F0\\u0966]", "Latn Kana Arab", "Deva Kthi Mahj", "Deva Kthi Mahj"} |
}; |
int testNum; |
- for (testNum = 0; testNum < LENGTHOF(tests); testNum++) { |
+ for (testNum = 0; testNum < UPRV_LENGTHOF(tests); testNum++) { |
char testNumStr[40]; |
sprintf(testNumStr, "testNum = %d", testNum); |
Test &test = tests[testNum]; |
@@ -575,7 +573,7 @@ void IntlTestSpoof::testIdentifierInfo() { |
status = U_ZERO_ERROR; |
IdentifierInfo identifierInfo(status); |
- for (testNum=0; testNum<LENGTHOF(scriptTests); testNum++) { |
+ for (testNum=0; testNum<UPRV_LENGTHOF(scriptTests); testNum++) { |
ScriptTest &test = scriptTests[testNum]; |
char msgBuf[100]; |
sprintf(msgBuf, "testNum = %d ", testNum); |
@@ -675,22 +673,23 @@ void IntlTestSpoof::testRestrictionLevel() { |
} tests[] = { |
{"\\u0061\\u03B3\\u2665", USPOOF_UNRESTRICTIVE}, |
{"a", USPOOF_ASCII}, |
- {"\\u03B3", USPOOF_HIGHLY_RESTRICTIVE}, |
+ {"\\u03B3", USPOOF_SINGLE_SCRIPT_RESTRICTIVE}, |
{"\\u0061\\u30A2\\u30FC", USPOOF_HIGHLY_RESTRICTIVE}, |
{"\\u0061\\u0904", USPOOF_MODERATELY_RESTRICTIVE}, |
{"\\u0061\\u03B3", USPOOF_MINIMALLY_RESTRICTIVE} |
}; |
char msgBuffer[100]; |
- URestrictionLevel restrictionLevels[] = { USPOOF_ASCII, USPOOF_HIGHLY_RESTRICTIVE, |
- USPOOF_MODERATELY_RESTRICTIVE, USPOOF_MINIMALLY_RESTRICTIVE, USPOOF_UNRESTRICTIVE}; |
+ URestrictionLevel restrictionLevels[] = { USPOOF_ASCII, USPOOF_SINGLE_SCRIPT_RESTRICTIVE, |
+ USPOOF_HIGHLY_RESTRICTIVE, USPOOF_MODERATELY_RESTRICTIVE, USPOOF_MINIMALLY_RESTRICTIVE, |
+ USPOOF_UNRESTRICTIVE}; |
UErrorCode status = U_ZERO_ERROR; |
IdentifierInfo idInfo(status); |
TEST_ASSERT_SUCCESS(status); |
idInfo.setIdentifierProfile(*uspoof_getRecommendedUnicodeSet(&status)); |
TEST_ASSERT_SUCCESS(status); |
- for (int32_t testNum=0; testNum < LENGTHOF(tests); testNum++) { |
+ for (int32_t testNum=0; testNum < UPRV_LENGTHOF(tests); testNum++) { |
status = U_ZERO_ERROR; |
const Test &test = tests[testNum]; |
UnicodeString testString = UnicodeString(test.fId).unescape(); |
@@ -699,21 +698,39 @@ void IntlTestSpoof::testRestrictionLevel() { |
sprintf(msgBuffer, "testNum = %d ", testNum); |
TEST_ASSERT_SUCCESS(status); |
TEST_ASSERT_MSG(expectedLevel == idInfo.getRestrictionLevel(status), msgBuffer); |
- for (int levelIndex=0; levelIndex<LENGTHOF(restrictionLevels); levelIndex++) { |
+ for (int levelIndex=0; levelIndex<UPRV_LENGTHOF(restrictionLevels); levelIndex++) { |
status = U_ZERO_ERROR; |
URestrictionLevel levelSetInSpoofChecker = restrictionLevels[levelIndex]; |
USpoofChecker *sc = uspoof_open(&status); |
uspoof_setChecks(sc, USPOOF_RESTRICTION_LEVEL, &status); |
uspoof_setAllowedChars(sc, uspoof_getRecommendedSet(&status), &status); |
uspoof_setRestrictionLevel(sc, levelSetInSpoofChecker); |
- UBool actualValue = uspoof_checkUnicodeString(sc, testString, NULL, &status) != 0; |
- |
+ int32_t actualValue = uspoof_checkUnicodeString(sc, testString, NULL, &status); |
+ |
// we want to fail if the text is (say) MODERATE and the testLevel is ASCII |
- UBool expectedFailure = expectedLevel > levelSetInSpoofChecker || |
- !uspoof_getRecommendedUnicodeSet(&status)->containsAll(testString); |
- sprintf(msgBuffer, "testNum = %d, levelIndex = %d", testNum, levelIndex); |
- TEST_ASSERT_MSG(expectedFailure == actualValue, msgBuffer); |
+ int32_t expectedValue = 0; |
+ if (expectedLevel > levelSetInSpoofChecker) { |
+ expectedValue |= USPOOF_RESTRICTION_LEVEL; |
+ } |
+ if (!uspoof_getRecommendedUnicodeSet(&status)->containsAll(testString)) { |
+ expectedValue |= USPOOF_CHAR_LIMIT; |
+ } |
+ sprintf(msgBuffer, "testNum = %d, levelIndex = %d, expected = %#x, actual = %#x", |
+ testNum, levelIndex, expectedValue, actualValue); |
+ TEST_ASSERT_MSG(expectedValue == actualValue, msgBuffer); |
TEST_ASSERT_SUCCESS(status); |
+ |
+ // Run the same check again, with the Spoof Checker configured to return |
+ // the actual restriction level. |
+ uspoof_setChecks(sc, USPOOF_AUX_INFO | USPOOF_RESTRICTION_LEVEL, &status); |
+ uspoof_setAllowedChars(sc, uspoof_getRecommendedSet(&status), &status); |
+ uspoof_setRestrictionLevel(sc, levelSetInSpoofChecker); |
+ int32_t result = uspoof_checkUnicodeString(sc, testString, NULL, &status); |
+ TEST_ASSERT_SUCCESS(status); |
+ if (U_SUCCESS(status)) { |
+ TEST_ASSERT_EQ(expectedLevel, result & USPOOF_RESTRICTION_LEVEL_MASK); |
+ TEST_ASSERT_EQ(expectedValue, result & USPOOF_ALL_CHECKS); |
+ } |
uspoof_close(sc); |
} |
} |
@@ -732,7 +749,7 @@ void IntlTestSpoof::testMixedNumbers() { |
}; |
UErrorCode status = U_ZERO_ERROR; |
IdentifierInfo idInfo(status); |
- for (int32_t testNum=0; testNum < LENGTHOF(tests); testNum++) { |
+ for (int32_t testNum=0; testNum < UPRV_LENGTHOF(tests); testNum++) { |
char msgBuf[100]; |
sprintf(msgBuf, "testNum = %d ", testNum); |
Test &test = tests[testNum]; |