OLD | NEW |
1 /* | 1 /* |
2 ********************************************************************** | 2 ********************************************************************** |
3 * Copyright (C) 2011-2013, International Business Machines Corporation | 3 * Copyright (C) 2011-2014, International Business Machines Corporation |
4 * and others. All Rights Reserved. | 4 * and others. All Rights Reserved. |
5 ********************************************************************** | 5 ********************************************************************** |
6 */ | 6 */ |
7 /** | 7 /** |
8 * IntlTestSpoof tests for USpoofDetector | 8 * IntlTestSpoof tests for USpoofDetector |
9 */ | 9 */ |
10 | 10 |
11 #include "unicode/utypes.h" | 11 #include "unicode/utypes.h" |
12 | 12 |
13 #if !UCONFIG_NO_REGULAR_EXPRESSIONS && !UCONFIG_NO_NORMALIZATION && !UCONFIG_NO_
FILE_IO | 13 #if !UCONFIG_NO_REGULAR_EXPRESSIONS && !UCONFIG_NO_NORMALIZATION && !UCONFIG_NO_
FILE_IO |
(...skipping 24 matching lines...) Expand all Loading... |
38 dataerrln("Test Failure at file %s, line %d, %s: \"%s\" is false.", __FILE__
, __LINE__, msg, #expr);};} | 38 dataerrln("Test Failure at file %s, line %d, %s: \"%s\" is false.", __FILE__
, __LINE__, msg, #expr);};} |
39 | 39 |
40 #define TEST_ASSERT_EQ(a, b) { if ((a) != (b)) { \ | 40 #define TEST_ASSERT_EQ(a, b) { if ((a) != (b)) { \ |
41 errln("Test Failure at file %s, line %d: \"%s\" (%d) != \"%s\" (%d)", \ | 41 errln("Test Failure at file %s, line %d: \"%s\" (%d) != \"%s\" (%d)", \ |
42 __FILE__, __LINE__, #a, (a), #b, (b)); }} | 42 __FILE__, __LINE__, #a, (a), #b, (b)); }} |
43 | 43 |
44 #define TEST_ASSERT_NE(a, b) { if ((a) == (b)) { \ | 44 #define TEST_ASSERT_NE(a, b) { if ((a) == (b)) { \ |
45 errln("Test Failure at file %s, line %d: \"%s\" (%d) == \"%s\" (%d)", \ | 45 errln("Test Failure at file %s, line %d: \"%s\" (%d) == \"%s\" (%d)", \ |
46 __FILE__, __LINE__, #a, (a), #b, (b)); }} | 46 __FILE__, __LINE__, #a, (a), #b, (b)); }} |
47 | 47 |
48 #define LENGTHOF(array) ((int32_t)(sizeof(array)/sizeof((array)[0]))) | |
49 | |
50 /* | 48 /* |
51 * TEST_SETUP and TEST_TEARDOWN | 49 * TEST_SETUP and TEST_TEARDOWN |
52 * macros to handle the boilerplate around setting up test case. | 50 * macros to handle the boilerplate around setting up test case. |
53 * Put arbitrary test code between SETUP and TEARDOWN. | 51 * Put arbitrary test code between SETUP and TEARDOWN. |
54 * "sc" is the ready-to-go SpoofChecker for use in the tests. | 52 * "sc" is the ready-to-go SpoofChecker for use in the tests. |
55 */ | 53 */ |
56 #define TEST_SETUP { \ | 54 #define TEST_SETUP { \ |
57 UErrorCode status = U_ZERO_ERROR; \ | 55 UErrorCode status = U_ZERO_ERROR; \ |
58 USpoofChecker *sc; \ | 56 USpoofChecker *sc; \ |
59 sc = uspoof_open(&status); \ | 57 sc = uspoof_open(&status); \ |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 } | 360 } |
363 dest.append((UChar)0x20); | 361 dest.append((UChar)0x20); |
364 } | 362 } |
365 | 363 |
366 U_DEFINE_LOCAL_OPEN_POINTER(LocalStdioFilePointer, FILE, fclose); | 364 U_DEFINE_LOCAL_OPEN_POINTER(LocalStdioFilePointer, FILE, fclose); |
367 | 365 |
368 // testConfData - Check each data item from the Unicode confusables.txt file, | 366 // testConfData - Check each data item from the Unicode confusables.txt file, |
369 // verify that it transforms correctly in a skeleton. | 367 // verify that it transforms correctly in a skeleton. |
370 // | 368 // |
371 void IntlTestSpoof::testConfData() { | 369 void IntlTestSpoof::testConfData() { |
372 UErrorCode status = U_ZERO_ERROR; | |
373 | |
374 const char *testDataDir = IntlTest::getSourceTestData(status); | |
375 TEST_ASSERT_SUCCESS(status); | |
376 char buffer[2000]; | 370 char buffer[2000]; |
377 uprv_strcpy(buffer, testDataDir); | 371 if (getUnidataPath(buffer) == NULL) { |
| 372 errln("Skipping test spoof/testConfData. Unable to find path to source/d
ata/unidata/."); |
| 373 return; |
| 374 } |
378 uprv_strcat(buffer, "confusables.txt"); | 375 uprv_strcat(buffer, "confusables.txt"); |
379 | 376 |
380 LocalStdioFilePointer f(fopen(buffer, "rb")); | 377 LocalStdioFilePointer f(fopen(buffer, "rb")); |
381 if (f.isNull()) { | 378 if (f.isNull()) { |
382 errln("Skipping test spoof/testConfData. File confusables.txt not acces
sible."); | 379 errln("Skipping test spoof/testConfData. File confusables.txt not acces
sible."); |
383 return; | 380 return; |
384 } | 381 } |
385 fseek(f.getAlias(), 0, SEEK_END); | 382 fseek(f.getAlias(), 0, SEEK_END); |
386 int32_t fileSize = ftell(f.getAlias()); | 383 int32_t fileSize = ftell(f.getAlias()); |
387 LocalArray<char> fileBuf(new char[fileSize]); | 384 LocalArray<char> fileBuf(new char[fileSize]); |
388 fseek(f.getAlias(), 0, SEEK_SET); | 385 fseek(f.getAlias(), 0, SEEK_SET); |
389 int32_t amt_read = fread(fileBuf.getAlias(), 1, fileSize, f.getAlias()); | 386 int32_t amt_read = fread(fileBuf.getAlias(), 1, fileSize, f.getAlias()); |
390 TEST_ASSERT_EQ(amt_read, fileSize); | 387 TEST_ASSERT_EQ(amt_read, fileSize); |
391 TEST_ASSERT(fileSize>0); | 388 TEST_ASSERT(fileSize>0); |
392 if (amt_read != fileSize || fileSize <=0) { | 389 if (amt_read != fileSize || fileSize <=0) { |
393 return; | 390 return; |
394 } | 391 } |
395 UnicodeString confusablesTxt = UnicodeString::fromUTF8(StringPiece(fileBuf.g
etAlias(), fileSize)); | 392 UnicodeString confusablesTxt = UnicodeString::fromUTF8(StringPiece(fileBuf.g
etAlias(), fileSize)); |
396 | 393 |
| 394 UErrorCode status = U_ZERO_ERROR; |
397 LocalUSpoofCheckerPointer sc(uspoof_open(&status)); | 395 LocalUSpoofCheckerPointer sc(uspoof_open(&status)); |
398 TEST_ASSERT_SUCCESS(status); | 396 TEST_ASSERT_SUCCESS(status); |
399 | 397 |
400 // Parse lines from the confusables.txt file. Example Line: | 398 // Parse lines from the confusables.txt file. Example Line: |
401 // FF44 ; 0064 ; SL # ( d -> d ) FULLWIDTH .... | 399 // FF44 ; 0064 ; SL # ( d -> d ) FULLWIDTH .... |
402 // Three fields. The hex fields can contain more than one character, | 400 // Three fields. The hex fields can contain more than one character, |
403 // and each character may be more than 4 digits (for supplemn
tals) | 401 // and each character may be more than 4 digits (for supplemn
tals) |
404 // This regular expression matches lines and splits the fields into capture
groups. | 402 // This regular expression matches lines and splits the fields into capture
groups. |
405 RegexMatcher parseLine("(?m)^([0-9A-F]{4}[^#;]*?);([^#;]*?);([^#]*)", confus
ablesTxt, 0, status); | 403 RegexMatcher parseLine("(?m)^([0-9A-F]{4}[^#;]*?);([^#;]*?);([^#]*)", confus
ablesTxt, 0, status); |
406 TEST_ASSERT_SUCCESS(status); | 404 TEST_ASSERT_SUCCESS(status); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 const char *fCommonAlternates; | 496 const char *fCommonAlternates; |
499 } tests[] = { | 497 } tests[] = { |
500 {"\\u0061\\u2665", USPOOF_UNRESTRICTIVE, "[]", "
Latn", "", ""}, | 498 {"\\u0061\\u2665", USPOOF_UNRESTRICTIVE, "[]", "
Latn", "", ""}, |
501 {"\\u0061\\u3006", USPOOF_HIGHLY_RESTRICTIVE, "[]", "
Latn", "Hani Hira Kana", "Hani Hira Kana"}, | 499 {"\\u0061\\u3006", USPOOF_HIGHLY_RESTRICTIVE, "[]", "
Latn", "Hani Hira Kana", "Hani Hira Kana"}, |
502 {"\\u0061\\u30FC\\u3006", USPOOF_HIGHLY_RESTRICTIVE, "[]", "
Latn", "Hira Kana", "Hira Kana"}, | 500 {"\\u0061\\u30FC\\u3006", USPOOF_HIGHLY_RESTRICTIVE, "[]", "
Latn", "Hira Kana", "Hira Kana"}, |
503 {"\\u0061\\u30FC\\u3006\\u30A2", USPOOF_HIGHLY_RESTRICTIVE, "[]", "
Latn Kana", "", ""}, | 501 {"\\u0061\\u30FC\\u3006\\u30A2", USPOOF_HIGHLY_RESTRICTIVE, "[]", "
Latn Kana", "", ""}, |
504 {"\\u30A2\\u0061\\u30FC\\u3006", USPOOF_HIGHLY_RESTRICTIVE, "[]", "
Latn Kana", "", ""}, | 502 {"\\u30A2\\u0061\\u30FC\\u3006", USPOOF_HIGHLY_RESTRICTIVE, "[]", "
Latn Kana", "", ""}, |
505 {"\\u0061\\u0031\\u0661", USPOOF_UNRESTRICTIVE, "[\\u00
30\\u0660]", "Latn", "Arab Thaa", "Arab Thaa"}, | 503 {"\\u0061\\u0031\\u0661", USPOOF_UNRESTRICTIVE, "[\\u00
30\\u0660]", "Latn", "Arab Thaa", "Arab Thaa"}, |
506 {"\\u0061\\u0031\\u0661\\u06F1", USPOOF_UNRESTRICTIVE, "[\\u00
30\\u0660\\u06F0]", "Latn Arab", "", ""}, | 504 {"\\u0061\\u0031\\u0661\\u06F1", USPOOF_UNRESTRICTIVE, "[\\u00
30\\u0660\\u06F0]", "Latn Arab", "", ""}, |
507 {"\\u0661\\u30FC\\u3006\\u0061\\u30A2\\u0031\\u0967\\u06F1", USPOOF
_UNRESTRICTIVE, | 505 {"\\u0661\\u30FC\\u3006\\u0061\\u30A2\\u0031\\u0967\\u06F1", USPOOF
_UNRESTRICTIVE, |
508 "[\\u0030\\u0660\\u06F0\\u0966]", "Latn Kana Arab", "Deva Kthi
", "Deva Kthi"}, | 506 "[\\u0030\\u0660\\u06F0\\u0966]", "Latn Kana Arab", "Deva Kthi
Mahj", "Deva Kthi Mahj"}, |
509 {"\\u0061\\u30A2\\u30FC\\u3006\\u0031\\u0967\\u0661\\u06F1", USPOOF
_UNRESTRICTIVE, | 507 {"\\u0061\\u30A2\\u30FC\\u3006\\u0031\\u0967\\u0661\\u06F1", USPOOF
_UNRESTRICTIVE, |
510 "[\\u0030\\u0660\\u06F0\\u0966]", "Latn Kana Arab", "Deva Kthi
", "Deva Kthi"} | 508 "[\\u0030\\u0660\\u06F0\\u0966]", "Latn Kana Arab", "Deva Kthi
Mahj", "Deva Kthi Mahj"} |
511 }; | 509 }; |
512 | 510 |
513 int testNum; | 511 int testNum; |
514 for (testNum = 0; testNum < LENGTHOF(tests); testNum++) { | 512 for (testNum = 0; testNum < UPRV_LENGTHOF(tests); testNum++) { |
515 char testNumStr[40]; | 513 char testNumStr[40]; |
516 sprintf(testNumStr, "testNum = %d", testNum); | 514 sprintf(testNumStr, "testNum = %d", testNum); |
517 Test &test = tests[testNum]; | 515 Test &test = tests[testNum]; |
518 status = U_ZERO_ERROR; | 516 status = U_ZERO_ERROR; |
519 UnicodeString testString(test.fTestString); // Note: may do charset con
version. | 517 UnicodeString testString(test.fTestString); // Note: may do charset con
version. |
520 testString = testString.unescape(); | 518 testString = testString.unescape(); |
521 IdentifierInfo idInfo(status); | 519 IdentifierInfo idInfo(status); |
522 TEST_ASSERT_SUCCESS(status); | 520 TEST_ASSERT_SUCCESS(status); |
523 idInfo.setIdentifierProfile(*uspoof_getRecommendedUnicodeSet(&status)); | 521 idInfo.setIdentifierProfile(*uspoof_getRecommendedUnicodeSet(&status)); |
524 idInfo.setIdentifier(testString, status); | 522 idInfo.setIdentifier(testString, status); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 {"Hello1234\\u0300", 1}, // Common and Inherited are ignored. | 566 {"Hello1234\\u0300", 1}, // Common and Inherited are ignored. |
569 {"\\u0030", 0}, | 567 {"\\u0030", 0}, |
570 {"abc\\u0951", 1}, | 568 {"abc\\u0951", 1}, |
571 {"abc\\u3013", 2}, | 569 {"abc\\u3013", 2}, |
572 {"\\uA838\\u0951", 1}, // Triggers commonAmongAlternates path. | 570 {"\\uA838\\u0951", 1}, // Triggers commonAmongAlternates path. |
573 {"\\u3013\\uA838", 2} | 571 {"\\u3013\\uA838", 2} |
574 }; | 572 }; |
575 | 573 |
576 status = U_ZERO_ERROR; | 574 status = U_ZERO_ERROR; |
577 IdentifierInfo identifierInfo(status); | 575 IdentifierInfo identifierInfo(status); |
578 for (testNum=0; testNum<LENGTHOF(scriptTests); testNum++) { | 576 for (testNum=0; testNum<UPRV_LENGTHOF(scriptTests); testNum++) { |
579 ScriptTest &test = scriptTests[testNum]; | 577 ScriptTest &test = scriptTests[testNum]; |
580 char msgBuf[100]; | 578 char msgBuf[100]; |
581 sprintf(msgBuf, "testNum = %d ", testNum); | 579 sprintf(msgBuf, "testNum = %d ", testNum); |
582 UnicodeString testString = UnicodeString(test.fTestString).unescape(); | 580 UnicodeString testString = UnicodeString(test.fTestString).unescape(); |
583 | 581 |
584 status = U_ZERO_ERROR; | 582 status = U_ZERO_ERROR; |
585 identifierInfo.setIdentifier(testString, status); | 583 identifierInfo.setIdentifier(testString, status); |
586 int32_t scriptCount = identifierInfo.getScriptCount(); | 584 int32_t scriptCount = identifierInfo.getScriptCount(); |
587 TEST_ASSERT_MSG(test.fScriptCount == scriptCount, msgBuf); | 585 TEST_ASSERT_MSG(test.fScriptCount == scriptCount, msgBuf); |
588 } | 586 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 } | 666 } |
669 | 667 |
670 | 668 |
671 void IntlTestSpoof::testRestrictionLevel() { | 669 void IntlTestSpoof::testRestrictionLevel() { |
672 struct Test { | 670 struct Test { |
673 const char *fId; | 671 const char *fId; |
674 URestrictionLevel fExpectedRestrictionLevel; | 672 URestrictionLevel fExpectedRestrictionLevel; |
675 } tests[] = { | 673 } tests[] = { |
676 {"\\u0061\\u03B3\\u2665", USPOOF_UNRESTRICTIVE}, | 674 {"\\u0061\\u03B3\\u2665", USPOOF_UNRESTRICTIVE}, |
677 {"a", USPOOF_ASCII}, | 675 {"a", USPOOF_ASCII}, |
678 {"\\u03B3", USPOOF_HIGHLY_RESTRICTIVE}, | 676 {"\\u03B3", USPOOF_SINGLE_SCRIPT_RESTRICTIVE}, |
679 {"\\u0061\\u30A2\\u30FC", USPOOF_HIGHLY_RESTRICTIVE}, | 677 {"\\u0061\\u30A2\\u30FC", USPOOF_HIGHLY_RESTRICTIVE}, |
680 {"\\u0061\\u0904", USPOOF_MODERATELY_RESTRICTIVE}, | 678 {"\\u0061\\u0904", USPOOF_MODERATELY_RESTRICTIVE}, |
681 {"\\u0061\\u03B3", USPOOF_MINIMALLY_RESTRICTIVE} | 679 {"\\u0061\\u03B3", USPOOF_MINIMALLY_RESTRICTIVE} |
682 }; | 680 }; |
683 char msgBuffer[100]; | 681 char msgBuffer[100]; |
684 | 682 |
685 URestrictionLevel restrictionLevels[] = { USPOOF_ASCII, USPOOF_HIGHLY_RESTRI
CTIVE, | 683 URestrictionLevel restrictionLevels[] = { USPOOF_ASCII, USPOOF_SINGLE_SCRIPT
_RESTRICTIVE, |
686 USPOOF_MODERATELY_RESTRICTIVE, USPOOF_MINIMALLY_RESTRICTIVE, USPOOF_UNR
ESTRICTIVE}; | 684 USPOOF_HIGHLY_RESTRICTIVE, USPOOF_MODERATELY_RESTRICTIVE, USPOOF_MINIMA
LLY_RESTRICTIVE, |
| 685 USPOOF_UNRESTRICTIVE}; |
687 | 686 |
688 UErrorCode status = U_ZERO_ERROR; | 687 UErrorCode status = U_ZERO_ERROR; |
689 IdentifierInfo idInfo(status); | 688 IdentifierInfo idInfo(status); |
690 TEST_ASSERT_SUCCESS(status); | 689 TEST_ASSERT_SUCCESS(status); |
691 idInfo.setIdentifierProfile(*uspoof_getRecommendedUnicodeSet(&status)); | 690 idInfo.setIdentifierProfile(*uspoof_getRecommendedUnicodeSet(&status)); |
692 TEST_ASSERT_SUCCESS(status); | 691 TEST_ASSERT_SUCCESS(status); |
693 for (int32_t testNum=0; testNum < LENGTHOF(tests); testNum++) { | 692 for (int32_t testNum=0; testNum < UPRV_LENGTHOF(tests); testNum++) { |
694 status = U_ZERO_ERROR; | 693 status = U_ZERO_ERROR; |
695 const Test &test = tests[testNum]; | 694 const Test &test = tests[testNum]; |
696 UnicodeString testString = UnicodeString(test.fId).unescape(); | 695 UnicodeString testString = UnicodeString(test.fId).unescape(); |
697 URestrictionLevel expectedLevel = test.fExpectedRestrictionLevel; | 696 URestrictionLevel expectedLevel = test.fExpectedRestrictionLevel; |
698 idInfo.setIdentifier(testString, status); | 697 idInfo.setIdentifier(testString, status); |
699 sprintf(msgBuffer, "testNum = %d ", testNum); | 698 sprintf(msgBuffer, "testNum = %d ", testNum); |
700 TEST_ASSERT_SUCCESS(status); | 699 TEST_ASSERT_SUCCESS(status); |
701 TEST_ASSERT_MSG(expectedLevel == idInfo.getRestrictionLevel(status), msg
Buffer); | 700 TEST_ASSERT_MSG(expectedLevel == idInfo.getRestrictionLevel(status), msg
Buffer); |
702 for (int levelIndex=0; levelIndex<LENGTHOF(restrictionLevels); levelInde
x++) { | 701 for (int levelIndex=0; levelIndex<UPRV_LENGTHOF(restrictionLevels); leve
lIndex++) { |
703 status = U_ZERO_ERROR; | 702 status = U_ZERO_ERROR; |
704 URestrictionLevel levelSetInSpoofChecker = restrictionLevels[levelIn
dex]; | 703 URestrictionLevel levelSetInSpoofChecker = restrictionLevels[levelIn
dex]; |
705 USpoofChecker *sc = uspoof_open(&status); | 704 USpoofChecker *sc = uspoof_open(&status); |
706 uspoof_setChecks(sc, USPOOF_RESTRICTION_LEVEL, &status); | 705 uspoof_setChecks(sc, USPOOF_RESTRICTION_LEVEL, &status); |
707 uspoof_setAllowedChars(sc, uspoof_getRecommendedSet(&status), &statu
s); | 706 uspoof_setAllowedChars(sc, uspoof_getRecommendedSet(&status), &statu
s); |
708 uspoof_setRestrictionLevel(sc, levelSetInSpoofChecker); | 707 uspoof_setRestrictionLevel(sc, levelSetInSpoofChecker); |
709 UBool actualValue = uspoof_checkUnicodeString(sc, testString, NULL,
&status) != 0; | 708 int32_t actualValue = uspoof_checkUnicodeString(sc, testString, NULL
, &status); |
| 709 |
| 710 // we want to fail if the text is (say) MODERATE and the testLevel i
s ASCII |
| 711 int32_t expectedValue = 0; |
| 712 if (expectedLevel > levelSetInSpoofChecker) { |
| 713 expectedValue |= USPOOF_RESTRICTION_LEVEL; |
| 714 } |
| 715 if (!uspoof_getRecommendedUnicodeSet(&status)->containsAll(testStrin
g)) { |
| 716 expectedValue |= USPOOF_CHAR_LIMIT; |
| 717 } |
| 718 sprintf(msgBuffer, "testNum = %d, levelIndex = %d, expected = %#x, a
ctual = %#x", |
| 719 testNum, levelIndex, expectedValue, actualValue); |
| 720 TEST_ASSERT_MSG(expectedValue == actualValue, msgBuffer); |
| 721 TEST_ASSERT_SUCCESS(status); |
710 | 722 |
711 // we want to fail if the text is (say) MODERATE and the testLevel i
s ASCII | 723 // Run the same check again, with the Spoof Checker configured to re
turn |
712 UBool expectedFailure = expectedLevel > levelSetInSpoofChecker || | 724 // the actual restriction level. |
713 !uspoof_getRecommendedUnicodeSet(&status)->c
ontainsAll(testString); | 725 uspoof_setChecks(sc, USPOOF_AUX_INFO | USPOOF_RESTRICTION_LEVEL, &st
atus); |
714 sprintf(msgBuffer, "testNum = %d, levelIndex = %d", testNum, levelIn
dex); | 726 uspoof_setAllowedChars(sc, uspoof_getRecommendedSet(&status), &statu
s); |
715 TEST_ASSERT_MSG(expectedFailure == actualValue, msgBuffer); | 727 uspoof_setRestrictionLevel(sc, levelSetInSpoofChecker); |
| 728 int32_t result = uspoof_checkUnicodeString(sc, testString, NULL, &st
atus); |
716 TEST_ASSERT_SUCCESS(status); | 729 TEST_ASSERT_SUCCESS(status); |
| 730 if (U_SUCCESS(status)) { |
| 731 TEST_ASSERT_EQ(expectedLevel, result & USPOOF_RESTRICTION_LEVEL_
MASK); |
| 732 TEST_ASSERT_EQ(expectedValue, result & USPOOF_ALL_CHECKS); |
| 733 } |
717 uspoof_close(sc); | 734 uspoof_close(sc); |
718 } | 735 } |
719 } | 736 } |
720 } | 737 } |
721 | 738 |
722 | 739 |
723 void IntlTestSpoof::testMixedNumbers() { | 740 void IntlTestSpoof::testMixedNumbers() { |
724 struct Test { | 741 struct Test { |
725 const char *fTestString; | 742 const char *fTestString; |
726 const char *fExpectedSet; | 743 const char *fExpectedSet; |
727 } tests[] = { | 744 } tests[] = { |
728 {"1", "[0]"}, | 745 {"1", "[0]"}, |
729 {"\\u0967", "[\\u0966]"}, | 746 {"\\u0967", "[\\u0966]"}, |
730 {"1\\u0967", "[0\\u0966]"}, | 747 {"1\\u0967", "[0\\u0966]"}, |
731 {"\\u0661\\u06F1", "[\\u0660\\u06F0]"} | 748 {"\\u0661\\u06F1", "[\\u0660\\u06F0]"} |
732 }; | 749 }; |
733 UErrorCode status = U_ZERO_ERROR; | 750 UErrorCode status = U_ZERO_ERROR; |
734 IdentifierInfo idInfo(status); | 751 IdentifierInfo idInfo(status); |
735 for (int32_t testNum=0; testNum < LENGTHOF(tests); testNum++) { | 752 for (int32_t testNum=0; testNum < UPRV_LENGTHOF(tests); testNum++) { |
736 char msgBuf[100]; | 753 char msgBuf[100]; |
737 sprintf(msgBuf, "testNum = %d ", testNum); | 754 sprintf(msgBuf, "testNum = %d ", testNum); |
738 Test &test = tests[testNum]; | 755 Test &test = tests[testNum]; |
739 | 756 |
740 status = U_ZERO_ERROR; | 757 status = U_ZERO_ERROR; |
741 UnicodeString testString = UnicodeString(test.fTestString).unescape(); | 758 UnicodeString testString = UnicodeString(test.fTestString).unescape(); |
742 UnicodeSet expectedSet(UnicodeString(test.fExpectedSet).unescape(), stat
us); | 759 UnicodeSet expectedSet(UnicodeString(test.fExpectedSet).unescape(), stat
us); |
743 idInfo.setIdentifier(testString, status); | 760 idInfo.setIdentifier(testString, status); |
744 TEST_ASSERT_SUCCESS(status); | 761 TEST_ASSERT_SUCCESS(status); |
745 TEST_ASSERT_MSG(expectedSet == *idInfo.getNumerics(), msgBuf); | 762 TEST_ASSERT_MSG(expectedSet == *idInfo.getNumerics(), msgBuf); |
746 | 763 |
747 status = U_ZERO_ERROR; | 764 status = U_ZERO_ERROR; |
748 USpoofChecker *sc = uspoof_open(&status); | 765 USpoofChecker *sc = uspoof_open(&status); |
749 uspoof_setChecks(sc, USPOOF_MIXED_NUMBERS, &status); // only check this | 766 uspoof_setChecks(sc, USPOOF_MIXED_NUMBERS, &status); // only check this |
750 int32_t result = uspoof_checkUnicodeString(sc, testString, NULL, &status
); | 767 int32_t result = uspoof_checkUnicodeString(sc, testString, NULL, &status
); |
751 UBool mixedNumberFailure = ((result & USPOOF_MIXED_NUMBERS) != 0); | 768 UBool mixedNumberFailure = ((result & USPOOF_MIXED_NUMBERS) != 0); |
752 TEST_ASSERT_MSG((expectedSet.size() > 1) == mixedNumberFailure, msgBuf); | 769 TEST_ASSERT_MSG((expectedSet.size() > 1) == mixedNumberFailure, msgBuf); |
753 uspoof_close(sc); | 770 uspoof_close(sc); |
754 } | 771 } |
755 } | 772 } |
756 | 773 |
757 #endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS && !UCONFIG_NO_NORMALIZATION && !UCONF
IG_NO_FILE_IO */ | 774 #endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS && !UCONFIG_NO_NORMALIZATION && !UCONF
IG_NO_FILE_IO */ |
OLD | NEW |