| OLD | NEW |
| 1 /* | 1 /* |
| 2 ********************************************************************** | 2 ********************************************************************** |
| 3 * Copyright (C) 2011-2014, International Business Machines Corporation | 3 * Copyright (C) 2011-2015, 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 170 |
| 171 #define CHECK_SKELETON(type, input, expected) { \ | 171 #define CHECK_SKELETON(type, input, expected) { \ |
| 172 checkSkeleton(sc, type, input, expected, __LINE__); \ | 172 checkSkeleton(sc, type, input, expected, __LINE__); \ |
| 173 } | 173 } |
| 174 | 174 |
| 175 | 175 |
| 176 // testSkeleton. Spot check a number of confusable skeleton substitutions from
the | 176 // testSkeleton. Spot check a number of confusable skeleton substitutions from
the |
| 177 // Unicode data file confusables.txt | 177 // Unicode data file confusables.txt |
| 178 // Test cases chosen for substitutions of various lengths, and | 178 // Test cases chosen for substitutions of various lengths, and |
| 179 // membership in different mapping tables. | 179 // membership in different mapping tables. |
| 180 // Note: for ICU 55, all tables collapsed to the MA table data. |
| 181 // TODO: for ICU 56 with Unicode 8, revisit this test. |
| 182 // |
| 180 void IntlTestSpoof::testSkeleton() { | 183 void IntlTestSpoof::testSkeleton() { |
| 181 const uint32_t ML = 0; | 184 const uint32_t ML = 0; |
| 182 const uint32_t SL = USPOOF_SINGLE_SCRIPT_CONFUSABLE; | 185 const uint32_t SL = USPOOF_SINGLE_SCRIPT_CONFUSABLE; |
| 183 const uint32_t MA = USPOOF_ANY_CASE; | 186 const uint32_t MA = USPOOF_ANY_CASE; |
| 184 const uint32_t SA = USPOOF_SINGLE_SCRIPT_CONFUSABLE | USPOOF_ANY_CASE; | 187 const uint32_t SA = USPOOF_SINGLE_SCRIPT_CONFUSABLE | USPOOF_ANY_CASE; |
| 185 | 188 |
| 186 TEST_SETUP | 189 TEST_SETUP |
| 187 // A long "identifier" that will overflow implementation stack buffers,
forcing heap allocations. | |
| 188 CHECK_SKELETON(SL, " A 1ong \\u02b9identifier' that will overflow implem
entation stack buffers, forcing heap allocations." | |
| 189 " A 1ong 'identifier' that will overflow implementati
on stack buffers, forcing heap allocations." | |
| 190 " A 1ong 'identifier' that will overflow implementati
on stack buffers, forcing heap allocations." | |
| 191 " A 1ong 'identifier' that will overflow implementati
on stack buffers, forcing heap allocations.", | |
| 192 | |
| 193 " A long 'identifier' that vvill overflovv irnplernentation stack
buffers, forcing heap allocations." | |
| 194 " A long 'identifier' that vvill overflovv irnplernentation stack
buffers, forcing heap allocations." | |
| 195 " A long 'identifier' that vvill overflovv irnplernentation stack
buffers, forcing heap allocations." | |
| 196 " A long 'identifier' that vvill overflovv irnplernentation stack
buffers, forcing heap allocations.") | |
| 197 | |
| 198 CHECK_SKELETON(SL, "nochange", "nochange"); | 190 CHECK_SKELETON(SL, "nochange", "nochange"); |
| 191 CHECK_SKELETON(SA, "nochange", "nochange"); |
| 192 CHECK_SKELETON(ML, "nochange", "nochange"); |
| 193 CHECK_SKELETON(MA, "nochange", "nochange"); |
| 199 CHECK_SKELETON(MA, "love", "love"); | 194 CHECK_SKELETON(MA, "love", "love"); |
| 200 CHECK_SKELETON(MA, "1ove", "love"); // Digit 1 to letter l | 195 CHECK_SKELETON(MA, "1ove", "love"); // Digit 1 to letter l |
| 201 CHECK_SKELETON(ML, "OOPS", "OOPS"); | 196 CHECK_SKELETON(ML, "OOPS", "OOPS"); |
| 202 CHECK_SKELETON(ML, "00PS", "00PS"); // Digit 0 unchanged in lower case
mode. | 197 CHECK_SKELETON(ML, "00PS", "OOPS"); |
| 203 CHECK_SKELETON(MA, "OOPS", "OOPS"); | 198 CHECK_SKELETON(MA, "OOPS", "OOPS"); |
| 204 CHECK_SKELETON(MA, "00PS", "OOPS"); // Digit 0 to letter O in any case
mode only | 199 CHECK_SKELETON(MA, "00PS", "OOPS"); // Digit 0 to letter O in any case
mode only |
| 205 CHECK_SKELETON(SL, "\\u059c", "\\u0301"); | 200 CHECK_SKELETON(SL, "\\u059c", "\\u0301"); |
| 206 CHECK_SKELETON(SL, "\\u2A74", "\\u003A\\u003A\\u003D"); | 201 CHECK_SKELETON(SL, "\\u2A74", "\\u003A\\u003A\\u003D"); |
| 207 CHECK_SKELETON(SL, "\\u247E", "\\u0028\\u006C\\u006C\\u0029"); // "(ll)
" | 202 CHECK_SKELETON(SL, "\\u247E", "\\u0028\\u006C\\u006C\\u0029"); // "(ll)
" |
| 208 CHECK_SKELETON(SL, "\\uFDFB", "\\u062C\\u0644\\u0020\\u062C\\u0644\\u062
7\\u0644\\u0647"); | 203 CHECK_SKELETON(SL, "\\uFDFB", "\\u062C\\u0644\\u0020\\u062C\\u0644\\u006
c\\u0644\\u006f"); |
| 209 | 204 |
| 210 // This mapping exists in the ML and MA tables, does not exist in SL, SA | 205 // This mapping exists in the ML and MA tables, does not exist in SL, SA |
| 211 //0C83 ;» 0C03 ;» | 206 // 0C83 ;» 0983 ;» ML |
| 212 CHECK_SKELETON(SL, "\\u0C83", "\\u0C83"); | 207 // 0C83 ;» 0983 ;» MA |
| 213 CHECK_SKELETON(SA, "\\u0C83", "\\u0C83"); | 208 // |
| 209 |
| 210 CHECK_SKELETON(SL, "\\u0C83", "\\u0983"); |
| 211 CHECK_SKELETON(SA, "\\u0C83", "\\u0983"); |
| 214 CHECK_SKELETON(ML, "\\u0C83", "\\u0983"); | 212 CHECK_SKELETON(ML, "\\u0C83", "\\u0983"); |
| 215 CHECK_SKELETON(MA, "\\u0C83", "\\u0983"); | 213 CHECK_SKELETON(MA, "\\u0C83", "\\u0983"); |
| 216 | 214 |
| 217 // 0391 ; 0041 ; | 215 // 0391 mappings exist only in MA and SA tables. |
| 218 // This mapping exists only in the MA table. | |
| 219 CHECK_SKELETON(MA, "\\u0391", "A"); | 216 CHECK_SKELETON(MA, "\\u0391", "A"); |
| 220 CHECK_SKELETON(SA, "\\u0391", "\\u0391"); | 217 CHECK_SKELETON(SA, "\\u0391", "A"); |
| 221 CHECK_SKELETON(ML, "\\u0391", "\\u0391"); | 218 CHECK_SKELETON(ML, "\\u0391", "A"); |
| 222 CHECK_SKELETON(SL, "\\u0391", "\\u0391"); | 219 CHECK_SKELETON(SL, "\\u0391", "A"); |
| 223 | 220 |
| 224 // 13CF ; 0062 ; | 221 // 13CF Mappings in all four tables, different in MA. |
| 225 // This mapping exists in the ML and MA tables | |
| 226 CHECK_SKELETON(ML, "\\u13CF", "b"); | 222 CHECK_SKELETON(ML, "\\u13CF", "b"); |
| 227 CHECK_SKELETON(MA, "\\u13CF", "b"); | 223 CHECK_SKELETON(MA, "\\u13CF", "b"); |
| 228 CHECK_SKELETON(SL, "\\u13CF", "\\u13CF"); | 224 CHECK_SKELETON(SL, "\\u13CF", "b"); |
| 229 CHECK_SKELETON(SA, "\\u13CF", "\\u13CF"); | 225 CHECK_SKELETON(SA, "\\u13CF", "b"); |
| 230 | 226 |
| 231 // 0022 ; 0027 0027 ; | 227 // 0022 ; 0027 0027 ; |
| 232 // all tables. | 228 // all tables. |
| 233 CHECK_SKELETON(SL, "\\u0022", "\\u0027\\u0027"); | 229 CHECK_SKELETON(SL, "\\u0022", "\\u0027\\u0027"); |
| 234 CHECK_SKELETON(SA, "\\u0022", "\\u0027\\u0027"); | 230 CHECK_SKELETON(SA, "\\u0022", "\\u0027\\u0027"); |
| 235 CHECK_SKELETON(ML, "\\u0022", "\\u0027\\u0027"); | 231 CHECK_SKELETON(ML, "\\u0022", "\\u0027\\u0027"); |
| 236 CHECK_SKELETON(MA, "\\u0022", "\\u0027\\u0027"); | 232 CHECK_SKELETON(MA, "\\u0022", "\\u0027\\u0027"); |
| 237 | 233 |
| 238 // 017F ; 0066 ; | 234 // 017F mappings exist only in MA and SA tables. |
| 239 // This mapping exists in the SA and MA tables | |
| 240 CHECK_SKELETON(MA, "\\u017F", "f"); | 235 CHECK_SKELETON(MA, "\\u017F", "f"); |
| 241 CHECK_SKELETON(SA, "\\u017F", "f"); | 236 CHECK_SKELETON(SA, "\\u017F", "f"); |
| 237 CHECK_SKELETON(ML, "\\u017F", "f"); |
| 238 CHECK_SKELETON(SL, "\\u017F", "f"); |
| 242 | 239 |
| 243 TEST_TEARDOWN; | 240 TEST_TEARDOWN; |
| 244 } | 241 } |
| 245 | 242 |
| 246 | 243 |
| 247 // | 244 // |
| 248 // Run a single confusable skeleton transformation test case. | 245 // Run a single confusable skeleton transformation test case. |
| 249 // | 246 // |
| 250 void IntlTestSpoof::checkSkeleton(const USpoofChecker *sc, uint32_t type, | 247 void IntlTestSpoof::checkSkeleton(const USpoofChecker *sc, uint32_t type, |
| 251 const char *input, const char *expected, int32
_t lineNum) { | 248 const char *input, const char *expected, int32
_t lineNum) { |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 USpoofChecker *sc = uspoof_open(&status); | 762 USpoofChecker *sc = uspoof_open(&status); |
| 766 uspoof_setChecks(sc, USPOOF_MIXED_NUMBERS, &status); // only check this | 763 uspoof_setChecks(sc, USPOOF_MIXED_NUMBERS, &status); // only check this |
| 767 int32_t result = uspoof_checkUnicodeString(sc, testString, NULL, &status
); | 764 int32_t result = uspoof_checkUnicodeString(sc, testString, NULL, &status
); |
| 768 UBool mixedNumberFailure = ((result & USPOOF_MIXED_NUMBERS) != 0); | 765 UBool mixedNumberFailure = ((result & USPOOF_MIXED_NUMBERS) != 0); |
| 769 TEST_ASSERT_MSG((expectedSet.size() > 1) == mixedNumberFailure, msgBuf); | 766 TEST_ASSERT_MSG((expectedSet.size() > 1) == mixedNumberFailure, msgBuf); |
| 770 uspoof_close(sc); | 767 uspoof_close(sc); |
| 771 } | 768 } |
| 772 } | 769 } |
| 773 | 770 |
| 774 #endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS && !UCONFIG_NO_NORMALIZATION && !UCONF
IG_NO_FILE_IO */ | 771 #endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS && !UCONFIG_NO_NORMALIZATION && !UCONF
IG_NO_FILE_IO */ |
| OLD | NEW |