| OLD | NEW |
| (Empty) |
| 1 /******************************************************************** | |
| 2 * COPYRIGHT: | |
| 3 * Copyright (c) 2009-2015, International Business Machines Corporation and | |
| 4 * others. All Rights Reserved. | |
| 5 ********************************************************************/ | |
| 6 /*******************************************************************************
* | |
| 7 * | |
| 8 * File spooftest.c | |
| 9 * | |
| 10 ********************************************************************************
*/ | |
| 11 /*C API TEST for the uspoof Unicode Indentifier Spoofing and Security API */ | |
| 12 /** | |
| 13 * This is an API test for ICU spoof detection in plain C. It doesn't test ver
y many cases, and doesn't | |
| 14 * try to test the full functionality. It just calls each function and verifie
s that it | |
| 15 * works on a basic level. | |
| 16 * | |
| 17 * More complete testing of spoof detection functionality is done with the C++
tests. | |
| 18 **/ | |
| 19 | |
| 20 #include "unicode/utypes.h" | |
| 21 #if !UCONFIG_NO_REGULAR_EXPRESSIONS && !UCONFIG_NO_NORMALIZATION | |
| 22 | |
| 23 #include <stdlib.h> | |
| 24 #include <stdio.h> | |
| 25 #include <string.h> | |
| 26 #include "unicode/uspoof.h" | |
| 27 #include "unicode/ustring.h" | |
| 28 #include "unicode/uset.h" | |
| 29 #include "cintltst.h" | |
| 30 | |
| 31 #define TEST_ASSERT_SUCCESS(status) {if (U_FAILURE(status)) { \ | |
| 32 log_err_status(status, "Failure at file %s, line %d, error = %s\n", __FILE__
, __LINE__, u_errorName(status));}} | |
| 33 | |
| 34 #define TEST_ASSERT(expr) {if ((expr)==FALSE) { \ | |
| 35 log_err("Test Failure at file %s, line %d: \"%s\" is false.\n", __FILE__, __LINE
__, #expr);};} | |
| 36 | |
| 37 #define TEST_ASSERT_EQ(a, b) { if ((a) != (b)) { \ | |
| 38 log_err("Test Failure at file %s, line %d: \"%s\" (%d) != \"%s\" (%d) \n", \ | |
| 39 __FILE__, __LINE__, #a, (a), #b, (b)); }} | |
| 40 | |
| 41 #define TEST_ASSERT_NE(a, b) { if ((a) == (b)) { \ | |
| 42 log_err("Test Failure at file %s, line %d: \"%s\" (%d) == \"%s\" (%d) \n", \ | |
| 43 __FILE__, __LINE__, #a, (a), #b, (b)); }} | |
| 44 | |
| 45 | |
| 46 /* | |
| 47 * TEST_SETUP and TEST_TEARDOWN | |
| 48 * macros to handle the boilerplate around setting up test case. | |
| 49 * Put arbitrary test code between SETUP and TEARDOWN. | |
| 50 * "sc" is the ready-to-go SpoofChecker for use in the tests. | |
| 51 */ | |
| 52 #define TEST_SETUP { \ | |
| 53 UErrorCode status = U_ZERO_ERROR; \ | |
| 54 USpoofChecker *sc; \ | |
| 55 sc = uspoof_open(&status); \ | |
| 56 TEST_ASSERT_SUCCESS(status); \ | |
| 57 if (U_SUCCESS(status)){ | |
| 58 | |
| 59 #define TEST_TEARDOWN \ | |
| 60 } \ | |
| 61 TEST_ASSERT_SUCCESS(status); \ | |
| 62 uspoof_close(sc); \ | |
| 63 } | |
| 64 | |
| 65 static void TestOpenFromSource(void); | |
| 66 static void TestUSpoofCAPI(void); | |
| 67 | |
| 68 void addUSpoofTest(TestNode** root); | |
| 69 | |
| 70 void addUSpoofTest(TestNode** root) | |
| 71 { | |
| 72 #if !UCONFIG_NO_FILE_IO | |
| 73 addTest(root, &TestOpenFromSource, "uspoof/TestOpenFromSource"); | |
| 74 #endif | |
| 75 addTest(root, &TestUSpoofCAPI, "uspoof/TestUSpoofCAPI"); | |
| 76 } | |
| 77 | |
| 78 /* | |
| 79 * Identifiers for verifying that spoof checking is minimally alive and working
. | |
| 80 */ | |
| 81 const UChar goodLatin[] = {(UChar)0x75, (UChar)0x7a, 0}; /* "uz", all ASCII
*/ | |
| 82 /* (not confusable
) */ | |
| 83 const UChar scMixed[] = {(UChar)0x73, (UChar)0x0441, 0}; /* "sc", with Cyrill
ic 'c' */ | |
| 84 /* (mixed script,
confusable */ | |
| 85 | |
| 86 const UChar scLatin[] = {(UChar)0x73, (UChar)0x63, 0}; /* "sc", plain ascii
. */ | |
| 87 const UChar goodCyrl[] = {(UChar)0x438, (UChar)0x43B, 0}; /* Plain lower case
Cyrillic letters, | |
| 88 no latin confusab
les */ | |
| 89 | |
| 90 const UChar goodGreek[] = {(UChar)0x3c0, (UChar)0x3c6, 0}; /* Plain lower ca
se Greek letters */ | |
| 91 | |
| 92 const UChar lll_Latin_a[] = {(UChar)0x6c, (UChar)0x49, (UChar)0x31, 0}; /* lI1
, all ASCII */ | |
| 93 | |
| 94 /* Full-width I, Small Roman Numeral fifty, Latin
Cap Letter IOTA*/ | |
| 95 const UChar lll_Latin_b[] = {(UChar)0xff29, (UChar)0x217c, (UChar)0x196, 0};
| |
| 96 | |
| 97 const UChar lll_Cyrl[] = {(UChar)0x0406, (UChar)0x04C0, (UChar)0x31, 0}; | |
| 98 | |
| 99 /* The skeleton transform for all of thes 'lll' lookalikes is all lower case l.
*/ | |
| 100 const UChar lll_Skel[] = {(UChar)0x6c, (UChar)0x6c, (UChar)0x6c, 0}; | |
| 101 | |
| 102 const UChar han_Hiragana[] = {(UChar)0x3086, (UChar)0x308A, (UChar)0x0020, (UCha
r)0x77F3, (UChar)0x7530, 0}; | |
| 103 | |
| 104 /* Provide better code coverage */ | |
| 105 const char goodLatinUTF8[] = {0x75, 0x77, 0}; | |
| 106 | |
| 107 // Test open from source rules. | |
| 108 // Run this in isolation to verify initialization. | |
| 109 static void TestOpenFromSource() { | |
| 110 // No TEST_SETUP because that calls uspoof_open(). | |
| 111 UErrorCode status = U_ZERO_ERROR; | |
| 112 const char *dataSrcDir; | |
| 113 char *fileName; | |
| 114 char *confusables; | |
| 115 int confusablesLength = 0; | |
| 116 char *confusablesWholeScript; | |
| 117 int confusablesWholeScriptLength = 0; | |
| 118 FILE *f; | |
| 119 UParseError pe; | |
| 120 int32_t errType; | |
| 121 int32_t checkResults; | |
| 122 USpoofChecker *rsc; | |
| 123 | |
| 124 dataSrcDir = ctest_dataSrcDir(); | |
| 125 fileName = malloc(strlen(dataSrcDir) + 100); | |
| 126 strcpy(fileName, dataSrcDir); | |
| 127 strcat(fileName, U_FILE_SEP_STRING "unidata" U_FILE_SEP_STRING "confusables.
txt"); | |
| 128 f = fopen(fileName, "rb"); | |
| 129 TEST_ASSERT_NE(f, NULL); | |
| 130 confusables = malloc(3000000); | |
| 131 if (f != NULL) { | |
| 132 confusablesLength = fread(confusables, 1, 3000000, f); | |
| 133 fclose(f); | |
| 134 } | |
| 135 | |
| 136 strcpy(fileName, dataSrcDir); | |
| 137 strcat(fileName, U_FILE_SEP_STRING "unidata" U_FILE_SEP_STRING "confusablesW
holeScript.txt"); | |
| 138 f = fopen(fileName, "rb"); | |
| 139 TEST_ASSERT_NE(f, NULL); | |
| 140 confusablesWholeScript = malloc(1000000); | |
| 141 if (f != NULL) { | |
| 142 confusablesWholeScriptLength = fread(confusablesWholeScript, 1, 1000000,
f); | |
| 143 fclose(f); | |
| 144 } | |
| 145 | |
| 146 rsc = uspoof_openFromSource(confusables, confusablesLength, | |
| 147 confusablesWholeScript, confusablesWholeScriptLe
ngth, | |
| 148 &errType, &pe, &status); | |
| 149 TEST_ASSERT_SUCCESS(status); | |
| 150 | |
| 151 // Ticket #11860: uspoof_openFromSource() did not initialize for use. | |
| 152 // Verify that the spoof checker does not crash. | |
| 153 checkResults = uspoof_check(rsc, goodLatin, -1, NULL, &status); | |
| 154 TEST_ASSERT_SUCCESS(status); | |
| 155 TEST_ASSERT_EQ(0, checkResults); | |
| 156 | |
| 157 free(confusablesWholeScript); | |
| 158 free(confusables); | |
| 159 free(fileName); | |
| 160 uspoof_close(rsc); | |
| 161 /* printf("ParseError Line is %d\n", pe.line); */ | |
| 162 } | |
| 163 | |
| 164 /* | |
| 165 * Spoof Detection C API Tests | |
| 166 */ | |
| 167 static void TestUSpoofCAPI(void) { | |
| 168 | |
| 169 /* | |
| 170 * basic uspoof_open(). | |
| 171 */ | |
| 172 { | |
| 173 USpoofChecker *sc; | |
| 174 UErrorCode status = U_ZERO_ERROR; | |
| 175 sc = uspoof_open(&status); | |
| 176 TEST_ASSERT_SUCCESS(status); | |
| 177 if (U_FAILURE(status)) { | |
| 178 /* If things are so broken that we can't even open a default spoof c
hecker, */ | |
| 179 /* don't even try the rest of the tests. They would all fail.
*/ | |
| 180 return; | |
| 181 } | |
| 182 uspoof_close(sc); | |
| 183 } | |
| 184 | |
| 185 /* | |
| 186 * openFromSerialized and serialize | |
| 187 */ | |
| 188 TEST_SETUP | |
| 189 int32_t serializedSize = 0; | |
| 190 int32_t actualLength = 0; | |
| 191 char *buf; | |
| 192 USpoofChecker *sc2; | |
| 193 int32_t checkResults; | |
| 194 | |
| 195 | |
| 196 serializedSize = uspoof_serialize(sc, NULL, 0, &status); | |
| 197 TEST_ASSERT_EQ(status, U_BUFFER_OVERFLOW_ERROR); | |
| 198 TEST_ASSERT(serializedSize > 0); | |
| 199 | |
| 200 /* Serialize the default spoof checker */ | |
| 201 status = U_ZERO_ERROR; | |
| 202 buf = (char *)malloc(serializedSize + 10); | |
| 203 TEST_ASSERT(buf != NULL); | |
| 204 buf[serializedSize] = 42; | |
| 205 uspoof_serialize(sc, buf, serializedSize, &status); | |
| 206 TEST_ASSERT_SUCCESS(status); | |
| 207 TEST_ASSERT_EQ(42, buf[serializedSize]); | |
| 208 | |
| 209 /* Create a new spoof checker from the freshly serialized data */ | |
| 210 sc2 = uspoof_openFromSerialized(buf, serializedSize+10, &actualLength, &
status); | |
| 211 TEST_ASSERT_SUCCESS(status); | |
| 212 TEST_ASSERT_NE(NULL, sc2); | |
| 213 TEST_ASSERT_EQ(serializedSize, actualLength); | |
| 214 | |
| 215 /* Verify that the new spoof checker at least wiggles */ | |
| 216 checkResults = uspoof_check(sc2, goodLatin, -1, NULL, &status); | |
| 217 TEST_ASSERT_SUCCESS(status); | |
| 218 TEST_ASSERT_EQ(0, checkResults); | |
| 219 | |
| 220 checkResults = uspoof_check(sc2, scMixed, -1, NULL, &status); | |
| 221 TEST_ASSERT_SUCCESS(status); | |
| 222 TEST_ASSERT_EQ(USPOOF_SINGLE_SCRIPT | USPOOF_MIXED_SCRIPT_CONFUSABLE, ch
eckResults); | |
| 223 | |
| 224 uspoof_close(sc2); | |
| 225 free(buf); | |
| 226 TEST_TEARDOWN; | |
| 227 | |
| 228 | |
| 229 | |
| 230 /* | |
| 231 * Set & Get Check Flags | |
| 232 */ | |
| 233 TEST_SETUP | |
| 234 int32_t t; | |
| 235 uspoof_setChecks(sc, USPOOF_ALL_CHECKS, &status); | |
| 236 TEST_ASSERT_SUCCESS(status); | |
| 237 t = uspoof_getChecks(sc, &status); | |
| 238 TEST_ASSERT_EQ(t, USPOOF_ALL_CHECKS); | |
| 239 | |
| 240 uspoof_setChecks(sc, 0, &status); | |
| 241 TEST_ASSERT_SUCCESS(status); | |
| 242 t = uspoof_getChecks(sc, &status); | |
| 243 TEST_ASSERT_EQ(0, t); | |
| 244 | |
| 245 uspoof_setChecks(sc, | |
| 246 USPOOF_WHOLE_SCRIPT_CONFUSABLE | USPOOF_MIXED_SCRIPT_CON
FUSABLE | USPOOF_ANY_CASE, | |
| 247 &status); | |
| 248 TEST_ASSERT_SUCCESS(status); | |
| 249 t = uspoof_getChecks(sc, &status); | |
| 250 TEST_ASSERT_SUCCESS(status); | |
| 251 TEST_ASSERT_EQ(USPOOF_WHOLE_SCRIPT_CONFUSABLE | USPOOF_MIXED_SCRIPT_CONF
USABLE | USPOOF_ANY_CASE, t); | |
| 252 TEST_TEARDOWN; | |
| 253 | |
| 254 /* | |
| 255 * get & setAllowedChars | |
| 256 */ | |
| 257 TEST_SETUP | |
| 258 USet *us; | |
| 259 const USet *uset; | |
| 260 | |
| 261 uset = uspoof_getAllowedChars(sc, &status); | |
| 262 TEST_ASSERT_SUCCESS(status); | |
| 263 TEST_ASSERT(uset_isFrozen(uset)); | |
| 264 us = uset_open((UChar32)0x41, (UChar32)0x5A); /* [A-Z] */ | |
| 265 uspoof_setAllowedChars(sc, us, &status); | |
| 266 TEST_ASSERT_SUCCESS(status); | |
| 267 TEST_ASSERT_NE(us, uspoof_getAllowedChars(sc, &status)); | |
| 268 TEST_ASSERT(uset_equals(us, uspoof_getAllowedChars(sc, &status))); | |
| 269 TEST_ASSERT_SUCCESS(status); | |
| 270 uset_close(us); | |
| 271 TEST_TEARDOWN; | |
| 272 | |
| 273 /* | |
| 274 * clone() | |
| 275 */ | |
| 276 | |
| 277 TEST_SETUP | |
| 278 USpoofChecker *clone1 = NULL; | |
| 279 USpoofChecker *clone2 = NULL; | |
| 280 int32_t checkResults = 0; | |
| 281 | |
| 282 clone1 = uspoof_clone(sc, &status); | |
| 283 TEST_ASSERT_SUCCESS(status); | |
| 284 TEST_ASSERT_NE(clone1, sc); | |
| 285 | |
| 286 clone2 = uspoof_clone(clone1, &status); | |
| 287 TEST_ASSERT_SUCCESS(status); | |
| 288 TEST_ASSERT_NE(clone2, clone1); | |
| 289 | |
| 290 uspoof_close(clone1); | |
| 291 | |
| 292 /* Verify that the cloned spoof checker is alive */ | |
| 293 checkResults = uspoof_check(clone2, goodLatin, -1, NULL, &status); | |
| 294 TEST_ASSERT_SUCCESS(status); | |
| 295 TEST_ASSERT_EQ(0, checkResults); | |
| 296 | |
| 297 checkResults = uspoof_check(clone2, scMixed, -1, NULL, &status); | |
| 298 TEST_ASSERT_SUCCESS(status); | |
| 299 TEST_ASSERT_EQ(USPOOF_SINGLE_SCRIPT | USPOOF_MIXED_SCRIPT_CONFUSABLE, ch
eckResults); | |
| 300 uspoof_close(clone2); | |
| 301 TEST_TEARDOWN; | |
| 302 | |
| 303 /* | |
| 304 * basic uspoof_check() | |
| 305 */ | |
| 306 TEST_SETUP | |
| 307 int32_t result; | |
| 308 result = uspoof_check(sc, goodLatin, -1, NULL, &status); | |
| 309 TEST_ASSERT_SUCCESS(status); | |
| 310 TEST_ASSERT_EQ(0, result); | |
| 311 | |
| 312 result = uspoof_check(sc, han_Hiragana, -1, NULL, &status); | |
| 313 TEST_ASSERT_SUCCESS(status); | |
| 314 TEST_ASSERT_EQ(0, result); | |
| 315 | |
| 316 result = uspoof_check(sc, scMixed, -1, NULL, &status); | |
| 317 TEST_ASSERT_SUCCESS(status); | |
| 318 TEST_ASSERT_EQ(USPOOF_SINGLE_SCRIPT | USPOOF_MIXED_SCRIPT_CONFUSABLE, r
esult); | |
| 319 TEST_TEARDOWN | |
| 320 | |
| 321 | |
| 322 /* | |
| 323 * get & set Checks | |
| 324 */ | |
| 325 TEST_SETUP | |
| 326 int32_t checks; | |
| 327 int32_t checks2; | |
| 328 int32_t checkResults; | |
| 329 | |
| 330 checks = uspoof_getChecks(sc, &status); | |
| 331 TEST_ASSERT_SUCCESS(status); | |
| 332 TEST_ASSERT_EQ(USPOOF_ALL_CHECKS, checks); | |
| 333 | |
| 334 checks &= ~(USPOOF_SINGLE_SCRIPT | USPOOF_MIXED_SCRIPT_CONFUSABLE); | |
| 335 uspoof_setChecks(sc, checks, &status); | |
| 336 TEST_ASSERT_SUCCESS(status); | |
| 337 checks2 = uspoof_getChecks(sc, &status); | |
| 338 TEST_ASSERT_EQ(checks, checks2); | |
| 339 | |
| 340 /* The checks that were disabled just above are the same ones that the "
scMixed" test fails. | |
| 341 So with those tests gone checking that Identifier should now succeed
*/ | |
| 342 checkResults = uspoof_check(sc, scMixed, -1, NULL, &status); | |
| 343 TEST_ASSERT_SUCCESS(status); | |
| 344 TEST_ASSERT_EQ(0, checkResults); | |
| 345 TEST_TEARDOWN; | |
| 346 | |
| 347 /* | |
| 348 * AllowedLoacles | |
| 349 */ | |
| 350 | |
| 351 TEST_SETUP | |
| 352 const char *allowedLocales; | |
| 353 int32_t checkResults; | |
| 354 | |
| 355 /* Default allowed locales list should be empty */ | |
| 356 allowedLocales = uspoof_getAllowedLocales(sc, &status); | |
| 357 TEST_ASSERT_SUCCESS(status); | |
| 358 TEST_ASSERT(strcmp("", allowedLocales) == 0) | |
| 359 | |
| 360 /* Allow en and ru, which should enable Latin and Cyrillic only to pass
*/ | |
| 361 uspoof_setAllowedLocales(sc, "en, ru_RU", &status); | |
| 362 TEST_ASSERT_SUCCESS(status); | |
| 363 allowedLocales = uspoof_getAllowedLocales(sc, &status); | |
| 364 TEST_ASSERT_SUCCESS(status); | |
| 365 TEST_ASSERT(strstr(allowedLocales, "en") != NULL); | |
| 366 TEST_ASSERT(strstr(allowedLocales, "ru") != NULL); | |
| 367 | |
| 368 /* Limit checks to USPOOF_CHAR_LIMIT. Some of the test data has whole s
cript confusables also, | |
| 369 * which we don't want to see in this test. */ | |
| 370 uspoof_setChecks(sc, USPOOF_CHAR_LIMIT, &status); | |
| 371 TEST_ASSERT_SUCCESS(status); | |
| 372 | |
| 373 checkResults = uspoof_check(sc, goodLatin, -1, NULL, &status); | |
| 374 TEST_ASSERT_SUCCESS(status); | |
| 375 TEST_ASSERT_EQ(0, checkResults); | |
| 376 | |
| 377 checkResults = uspoof_check(sc, goodGreek, -1, NULL, &status); | |
| 378 TEST_ASSERT_SUCCESS(status); | |
| 379 TEST_ASSERT_EQ(USPOOF_CHAR_LIMIT, checkResults); | |
| 380 | |
| 381 checkResults = uspoof_check(sc, goodCyrl, -1, NULL, &status); | |
| 382 TEST_ASSERT_SUCCESS(status); | |
| 383 TEST_ASSERT_EQ(0, checkResults); | |
| 384 | |
| 385 /* Reset with an empty locale list, which should allow all characters to
pass */ | |
| 386 uspoof_setAllowedLocales(sc, " ", &status); | |
| 387 TEST_ASSERT_SUCCESS(status); | |
| 388 | |
| 389 checkResults = uspoof_check(sc, goodGreek, -1, NULL, &status); | |
| 390 TEST_ASSERT_SUCCESS(status); | |
| 391 TEST_ASSERT_EQ(0, checkResults); | |
| 392 TEST_TEARDOWN; | |
| 393 | |
| 394 /* | |
| 395 * AllowedChars set/get the USet of allowed characters. | |
| 396 */ | |
| 397 TEST_SETUP | |
| 398 const USet *set; | |
| 399 USet *tmpSet; | |
| 400 int32_t checkResults; | |
| 401 | |
| 402 /* By default, we should see no restriction; the USet should allow all c
haracters. */ | |
| 403 set = uspoof_getAllowedChars(sc, &status); | |
| 404 TEST_ASSERT_SUCCESS(status); | |
| 405 tmpSet = uset_open(0, 0x10ffff); | |
| 406 TEST_ASSERT(uset_equals(tmpSet, set)); | |
| 407 | |
| 408 /* Setting the allowed chars should enable the check. */ | |
| 409 uspoof_setChecks(sc, USPOOF_ALL_CHECKS & ~USPOOF_CHAR_LIMIT, &status); | |
| 410 TEST_ASSERT_SUCCESS(status); | |
| 411 | |
| 412 /* Remove a character that is in our good Latin test identifier from the
allowed chars set. */ | |
| 413 uset_remove(tmpSet, goodLatin[1]); | |
| 414 uspoof_setAllowedChars(sc, tmpSet, &status); | |
| 415 TEST_ASSERT_SUCCESS(status); | |
| 416 uset_close(tmpSet); | |
| 417 | |
| 418 /* Latin Identifier should now fail; other non-latin test cases should s
till be OK | |
| 419 * Note: fail of CHAR_LIMIT also causes the restriction level to be USP
OOF_UNRESTRICTIVE | |
| 420 * which will give us a USPOOF_RESTRICTION_LEVEL failure. | |
| 421 */ | |
| 422 checkResults = uspoof_check(sc, goodLatin, -1, NULL, &status); | |
| 423 TEST_ASSERT_SUCCESS(status); | |
| 424 TEST_ASSERT_EQ(USPOOF_CHAR_LIMIT | USPOOF_RESTRICTION_LEVEL, checkResult
s); | |
| 425 | |
| 426 checkResults = uspoof_check(sc, goodGreek, -1, NULL, &status); | |
| 427 TEST_ASSERT_SUCCESS(status); | |
| 428 TEST_ASSERT_EQ(USPOOF_WHOLE_SCRIPT_CONFUSABLE, checkResults); | |
| 429 TEST_TEARDOWN; | |
| 430 | |
| 431 /* | |
| 432 * check UTF-8 | |
| 433 */ | |
| 434 TEST_SETUP | |
| 435 char utf8buf[200]; | |
| 436 int32_t checkResults; | |
| 437 int32_t position; | |
| 438 | |
| 439 u_strToUTF8(utf8buf, sizeof(utf8buf), NULL, goodLatin, -1, &status); | |
| 440 TEST_ASSERT_SUCCESS(status); | |
| 441 position = 666; | |
| 442 checkResults = uspoof_checkUTF8(sc, utf8buf, -1, &position, &status); | |
| 443 TEST_ASSERT_SUCCESS(status); | |
| 444 TEST_ASSERT_EQ(0, checkResults); | |
| 445 TEST_ASSERT_EQ(0, position); | |
| 446 | |
| 447 u_strToUTF8(utf8buf, sizeof(utf8buf), NULL, goodCyrl, -1, &status); | |
| 448 TEST_ASSERT_SUCCESS(status); | |
| 449 checkResults = uspoof_checkUTF8(sc, utf8buf, -1, &position, &status); | |
| 450 TEST_ASSERT_SUCCESS(status); | |
| 451 TEST_ASSERT_EQ(0, checkResults); | |
| 452 | |
| 453 u_strToUTF8(utf8buf, sizeof(utf8buf), NULL, scMixed, -1, &status); | |
| 454 TEST_ASSERT_SUCCESS(status); | |
| 455 position = 666; | |
| 456 checkResults = uspoof_checkUTF8(sc, utf8buf, -1, &position, &status); | |
| 457 TEST_ASSERT_SUCCESS(status); | |
| 458 TEST_ASSERT_EQ(USPOOF_MIXED_SCRIPT_CONFUSABLE | USPOOF_SINGLE_SCRIPT , c
heckResults); | |
| 459 TEST_ASSERT_EQ(0, position); | |
| 460 | |
| 461 TEST_TEARDOWN; | |
| 462 | |
| 463 /* | |
| 464 * uspoof_areConfusable() | |
| 465 */ | |
| 466 TEST_SETUP | |
| 467 int32_t checkResults; | |
| 468 | |
| 469 checkResults = uspoof_areConfusable(sc, scLatin, -1, scMixed, -1, &statu
s); | |
| 470 TEST_ASSERT_SUCCESS(status); | |
| 471 TEST_ASSERT_EQ(USPOOF_MIXED_SCRIPT_CONFUSABLE, checkResults); | |
| 472 | |
| 473 checkResults = uspoof_areConfusable(sc, goodGreek, -1, scLatin, -1, &sta
tus); | |
| 474 TEST_ASSERT_SUCCESS(status); | |
| 475 TEST_ASSERT_EQ(0, checkResults); | |
| 476 | |
| 477 checkResults = uspoof_areConfusable(sc, lll_Latin_a, -1, lll_Latin_b, -1
, &status); | |
| 478 TEST_ASSERT_SUCCESS(status); | |
| 479 TEST_ASSERT_EQ(USPOOF_SINGLE_SCRIPT_CONFUSABLE, checkResults); | |
| 480 | |
| 481 TEST_TEARDOWN; | |
| 482 | |
| 483 /* | |
| 484 * areConfusableUTF8 | |
| 485 */ | |
| 486 TEST_SETUP | |
| 487 int32_t checkResults; | |
| 488 char s1[200]; | |
| 489 char s2[200]; | |
| 490 | |
| 491 | |
| 492 u_strToUTF8(s1, sizeof(s1), NULL, scLatin, -1, &status); | |
| 493 u_strToUTF8(s2, sizeof(s2), NULL, scMixed, -1, &status); | |
| 494 TEST_ASSERT_SUCCESS(status); | |
| 495 checkResults = uspoof_areConfusableUTF8(sc, s1, -1, s2, -1, &status); | |
| 496 TEST_ASSERT_SUCCESS(status); | |
| 497 TEST_ASSERT_EQ(USPOOF_MIXED_SCRIPT_CONFUSABLE, checkResults); | |
| 498 | |
| 499 u_strToUTF8(s1, sizeof(s1), NULL, goodGreek, -1, &status); | |
| 500 u_strToUTF8(s2, sizeof(s2), NULL, scLatin, -1, &status); | |
| 501 TEST_ASSERT_SUCCESS(status); | |
| 502 checkResults = uspoof_areConfusableUTF8(sc, s1, -1, s2, -1, &status); | |
| 503 TEST_ASSERT_SUCCESS(status); | |
| 504 TEST_ASSERT_EQ(0, checkResults); | |
| 505 | |
| 506 u_strToUTF8(s1, sizeof(s1), NULL, lll_Latin_a, -1, &status); | |
| 507 u_strToUTF8(s2, sizeof(s2), NULL, lll_Latin_b, -1, &status); | |
| 508 TEST_ASSERT_SUCCESS(status); | |
| 509 checkResults = uspoof_areConfusableUTF8(sc, s1, -1, s2, -1, &status); | |
| 510 TEST_ASSERT_SUCCESS(status); | |
| 511 TEST_ASSERT_EQ(USPOOF_SINGLE_SCRIPT_CONFUSABLE, checkResults); | |
| 512 | |
| 513 TEST_TEARDOWN; | |
| 514 | |
| 515 | |
| 516 /* | |
| 517 * getSkeleton | |
| 518 */ | |
| 519 | |
| 520 TEST_SETUP | |
| 521 UChar dest[100]; | |
| 522 int32_t skelLength; | |
| 523 | |
| 524 skelLength = uspoof_getSkeleton(sc, USPOOF_ANY_CASE, lll_Latin_a, -1, de
st, sizeof(dest)/sizeof(UChar), &status); | |
| 525 TEST_ASSERT_SUCCESS(status); | |
| 526 TEST_ASSERT_EQ(0, u_strcmp(lll_Skel, dest)); | |
| 527 TEST_ASSERT_EQ(u_strlen(lll_Skel), skelLength); | |
| 528 | |
| 529 skelLength = uspoof_getSkeletonUTF8(sc, USPOOF_ANY_CASE, goodLatinUTF8,
-1, (char*)dest, | |
| 530 sizeof(dest)/sizeof(UChar), &status)
; | |
| 531 TEST_ASSERT_SUCCESS(status); | |
| 532 | |
| 533 skelLength = uspoof_getSkeleton(sc, USPOOF_ANY_CASE, lll_Latin_a, -1, NU
LL, 0, &status); | |
| 534 TEST_ASSERT_EQ(U_BUFFER_OVERFLOW_ERROR, status); | |
| 535 TEST_ASSERT_EQ(3, skelLength); | |
| 536 status = U_ZERO_ERROR; | |
| 537 | |
| 538 TEST_TEARDOWN; | |
| 539 | |
| 540 /* | |
| 541 * get Inclusion and Recommended sets | |
| 542 */ | |
| 543 TEST_SETUP | |
| 544 const USet *inclusions = NULL; | |
| 545 const USet *recommended = NULL; | |
| 546 | |
| 547 inclusions = uspoof_getInclusionSet(&status); | |
| 548 TEST_ASSERT_SUCCESS(status); | |
| 549 TEST_ASSERT_EQ(TRUE, uset_isFrozen(inclusions)); | |
| 550 | |
| 551 status = U_ZERO_ERROR; | |
| 552 recommended = uspoof_getRecommendedSet(&status); | |
| 553 TEST_ASSERT_SUCCESS(status); | |
| 554 TEST_ASSERT_EQ(TRUE, uset_isFrozen(recommended)); | |
| 555 TEST_TEARDOWN; | |
| 556 | |
| 557 } | |
| 558 | |
| 559 #endif /* UCONFIG_NO_REGULAR_EXPRESSIONS */ | |
| OLD | NEW |