X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/57a6839dcb3bba09e8228b822b290604668416fe..a0b4f637ba1a6c3c5651b61a69303b029bacf7d3:/icuSources/test/intltest/itspoof.cpp diff --git a/icuSources/test/intltest/itspoof.cpp b/icuSources/test/intltest/itspoof.cpp index ef951206..42869a73 100644 --- a/icuSources/test/intltest/itspoof.cpp +++ b/icuSources/test/intltest/itspoof.cpp @@ -1,6 +1,6 @@ /* ********************************************************************** -* Copyright (C) 2011-2014, International Business Machines Corporation +* Copyright (C) 2011-2015, 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. @@ -179,6 +177,9 @@ void IntlTestSpoof::testSpoofAPI() { // Unicode data file confusables.txt // Test cases chosen for substitutions of various lengths, and // membership in different mapping tables. +// Note: for ICU 55, all tables collapsed to the MA table data. +// TODO: for ICU 56 with Unicode 8, revisit this test. +// void IntlTestSpoof::testSkeleton() { const uint32_t ML = 0; const uint32_t SL = USPOOF_SINGLE_SCRIPT_CONFUSABLE; @@ -186,49 +187,42 @@ void IntlTestSpoof::testSkeleton() { const uint32_t SA = USPOOF_SINGLE_SCRIPT_CONFUSABLE | USPOOF_ANY_CASE; TEST_SETUP - // A long "identifier" that will overflow implementation stack buffers, forcing heap allocations. - CHECK_SKELETON(SL, " A 1ong \\u02b9identifier' that will overflow implementation stack buffers, forcing heap allocations." - " A 1ong 'identifier' that will overflow implementation stack buffers, forcing heap allocations." - " A 1ong 'identifier' that will overflow implementation stack buffers, forcing heap allocations." - " A 1ong 'identifier' that will overflow implementation stack buffers, forcing heap allocations.", - - " A long 'identifier' that vvill overflovv irnplernentation stack buffers, forcing heap allocations." - " A long 'identifier' that vvill overflovv irnplernentation stack buffers, forcing heap allocations." - " A long 'identifier' that vvill overflovv irnplernentation stack buffers, forcing heap allocations." - " A long 'identifier' that vvill overflovv irnplernentation stack buffers, forcing heap allocations.") - CHECK_SKELETON(SL, "nochange", "nochange"); + CHECK_SKELETON(SA, "nochange", "nochange"); + CHECK_SKELETON(ML, "nochange", "nochange"); + CHECK_SKELETON(MA, "nochange", "nochange"); CHECK_SKELETON(MA, "love", "love"); CHECK_SKELETON(MA, "1ove", "love"); // Digit 1 to letter l CHECK_SKELETON(ML, "OOPS", "OOPS"); - CHECK_SKELETON(ML, "00PS", "00PS"); // Digit 0 unchanged in lower case mode. + CHECK_SKELETON(ML, "00PS", "OOPS"); CHECK_SKELETON(MA, "OOPS", "OOPS"); CHECK_SKELETON(MA, "00PS", "OOPS"); // Digit 0 to letter O in any case mode only CHECK_SKELETON(SL, "\\u059c", "\\u0301"); CHECK_SKELETON(SL, "\\u2A74", "\\u003A\\u003A\\u003D"); CHECK_SKELETON(SL, "\\u247E", "\\u0028\\u006C\\u006C\\u0029"); // "(ll)" - CHECK_SKELETON(SL, "\\uFDFB", "\\u062C\\u0644\\u0020\\u062C\\u0644\\u0627\\u0644\\u0647"); + CHECK_SKELETON(SL, "\\uFDFB", "\\u062C\\u0644\\u0020\\u062C\\u0644\\u006c\\u0644\\u006f"); // This mapping exists in the ML and MA tables, does not exist in SL, SA - //0C83 ; 0C03 ; - CHECK_SKELETON(SL, "\\u0C83", "\\u0C83"); - CHECK_SKELETON(SA, "\\u0C83", "\\u0C83"); + // 0C83 ; 0983 ; ML + // 0C83 ; 0983 ; MA + // + + CHECK_SKELETON(SL, "\\u0C83", "\\u0983"); + CHECK_SKELETON(SA, "\\u0C83", "\\u0983"); CHECK_SKELETON(ML, "\\u0C83", "\\u0983"); CHECK_SKELETON(MA, "\\u0C83", "\\u0983"); - // 0391 ; 0041 ; - // This mapping exists only in the MA table. + // 0391 mappings exist only in MA and SA tables. CHECK_SKELETON(MA, "\\u0391", "A"); - CHECK_SKELETON(SA, "\\u0391", "\\u0391"); - CHECK_SKELETON(ML, "\\u0391", "\\u0391"); - CHECK_SKELETON(SL, "\\u0391", "\\u0391"); + CHECK_SKELETON(SA, "\\u0391", "A"); + CHECK_SKELETON(ML, "\\u0391", "A"); + CHECK_SKELETON(SL, "\\u0391", "A"); - // 13CF ; 0062 ; - // This mapping exists in the ML and MA tables + // 13CF Mappings in all four tables, different in MA. CHECK_SKELETON(ML, "\\u13CF", "b"); CHECK_SKELETON(MA, "\\u13CF", "b"); - CHECK_SKELETON(SL, "\\u13CF", "\\u13CF"); - CHECK_SKELETON(SA, "\\u13CF", "\\u13CF"); + CHECK_SKELETON(SL, "\\u13CF", "b"); + CHECK_SKELETON(SA, "\\u13CF", "b"); // 0022 ; 0027 0027 ; // all tables. @@ -237,10 +231,11 @@ void IntlTestSpoof::testSkeleton() { CHECK_SKELETON(ML, "\\u0022", "\\u0027\\u0027"); CHECK_SKELETON(MA, "\\u0022", "\\u0027\\u0027"); - // 017F ; 0066 ; - // This mapping exists in the SA and MA tables + // 017F mappings exist only in MA and SA tables. CHECK_SKELETON(MA, "\\u017F", "f"); CHECK_SKELETON(SA, "\\u017F", "f"); + CHECK_SKELETON(ML, "\\u017F", "f"); + CHECK_SKELETON(SL, "\\u017F", "f"); TEST_TEARDOWN; } @@ -369,12 +364,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 +388,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 +500,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 +570,7 @@ void IntlTestSpoof::testIdentifierInfo() { status = U_ZERO_ERROR; IdentifierInfo identifierInfo(status); - for (testNum=0; testNum