| OLD | NEW |
| 1 /******************************************************************** | 1 /******************************************************************** |
| 2 * COPYRIGHT: | 2 * COPYRIGHT: |
| 3 * Copyright (c) 2004-2013, International Business Machines Corporation and | 3 * Copyright (c) 2004-2014, International Business Machines Corporation and |
| 4 * others. All Rights Reserved. | 4 * others. All Rights Reserved. |
| 5 ********************************************************************/ | 5 ********************************************************************/ |
| 6 /*******************************************************************************
* | 6 /*******************************************************************************
* |
| 7 * | 7 * |
| 8 * File reapits.c | 8 * File reapits.c |
| 9 * | 9 * |
| 10 ********************************************************************************
*/ | 10 ********************************************************************************
*/ |
| 11 /*C API TEST FOR Regular Expressions */ | 11 /*C API TEST FOR Regular Expressions */ |
| 12 /** | 12 /** |
| 13 * This is an API test for ICU regular expressions in C. It doesn't test very
many cases, and doesn't | 13 * This is an API test for ICU regular expressions in C. It doesn't test very
many cases, and doesn't |
| 14 * try to test the full functionality. It just calls each function and verifie
s that it | 14 * try to test the full functionality. It just calls each function and verifie
s that it |
| 15 * works on a basic level. | 15 * works on a basic level. |
| 16 * | 16 * |
| 17 * More complete testing of regular expression functionality is done with the C
++ tests. | 17 * More complete testing of regular expression functionality is done with the C
++ tests. |
| 18 **/ | 18 **/ |
| 19 | 19 |
| 20 #include "unicode/utypes.h" | 20 #include "unicode/utypes.h" |
| 21 | 21 |
| 22 #if !UCONFIG_NO_REGULAR_EXPRESSIONS | 22 #if !UCONFIG_NO_REGULAR_EXPRESSIONS |
| 23 | 23 |
| 24 #include <stdlib.h> | 24 #include <stdlib.h> |
| 25 #include <string.h> | 25 #include <string.h> |
| 26 #include "unicode/uloc.h" | 26 #include "unicode/uloc.h" |
| 27 #include "unicode/uregex.h" | 27 #include "unicode/uregex.h" |
| 28 #include "unicode/ustring.h" | 28 #include "unicode/ustring.h" |
| 29 #include "unicode/utext.h" | 29 #include "unicode/utext.h" |
| 30 #include "cintltst.h" | 30 #include "cintltst.h" |
| 31 #include "cmemory.h" |
| 31 | 32 |
| 32 #define TEST_ASSERT_SUCCESS(status) {if (U_FAILURE(status)) { \ | 33 #define TEST_ASSERT_SUCCESS(status) {if (U_FAILURE(status)) { \ |
| 33 log_data_err("Failure at file %s, line %d, error = %s (Are you missing data?)\n"
, __FILE__, __LINE__, u_errorName(status));}} | 34 log_data_err("Failure at file %s:%d - error = %s (Are you missing data?)\n", __F
ILE__, __LINE__, u_errorName(status));}} |
| 34 | 35 |
| 35 #define TEST_ASSERT(expr) {if ((expr)==FALSE) { \ | 36 #define TEST_ASSERT(expr) {if ((expr)==FALSE) { \ |
| 36 log_data_err("Test Failure at file %s, line %d (Are you missing data?)\n", __FIL
E__, __LINE__);}} | 37 log_err("Test Failure at file %s:%d - ASSERT(%s) failed.\n", __FILE__, __LINE__,
#expr);}} |
| 37 | 38 |
| 38 /* | 39 /* |
| 39 * TEST_SETUP and TEST_TEARDOWN | 40 * TEST_SETUP and TEST_TEARDOWN |
| 40 * macros to handle the boilerplate around setting up regex test cases. | 41 * macros to handle the boilerplate around setting up regex test cases. |
| 41 * parameteres to setup: | 42 * parameteres to setup: |
| 42 * pattern: The regex pattern, a (char *) null terminated C str
ing. | 43 * pattern: The regex pattern, a (char *) null terminated C str
ing. |
| 43 * testString: The string data, also a (char *) C string. | 44 * testString: The string data, also a (char *) C string. |
| 44 * flags: Regex flags to set when compiling the pattern | 45 * flags: Regex flags to set when compiling the pattern |
| 45 * | 46 * |
| 46 * Put arbitrary test code between SETUP and TEARDOWN. | 47 * Put arbitrary test code between SETUP and TEARDOWN. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 } | 152 } |
| 152 | 153 |
| 153 | 154 |
| 154 | 155 |
| 155 | 156 |
| 156 static void TestRegexCAPI(void); | 157 static void TestRegexCAPI(void); |
| 157 static void TestBug4315(void); | 158 static void TestBug4315(void); |
| 158 static void TestUTextAPI(void); | 159 static void TestUTextAPI(void); |
| 159 static void TestRefreshInput(void); | 160 static void TestRefreshInput(void); |
| 160 static void TestBug8421(void); | 161 static void TestBug8421(void); |
| 162 static void TestBug10815(void); |
| 161 | 163 |
| 162 void addURegexTest(TestNode** root); | 164 void addURegexTest(TestNode** root); |
| 163 | 165 |
| 164 void addURegexTest(TestNode** root) | 166 void addURegexTest(TestNode** root) |
| 165 { | 167 { |
| 166 addTest(root, &TestRegexCAPI, "regex/TestRegexCAPI"); | 168 addTest(root, &TestRegexCAPI, "regex/TestRegexCAPI"); |
| 167 addTest(root, &TestBug4315, "regex/TestBug4315"); | 169 addTest(root, &TestBug4315, "regex/TestBug4315"); |
| 168 addTest(root, &TestUTextAPI, "regex/TestUTextAPI"); | 170 addTest(root, &TestUTextAPI, "regex/TestUTextAPI"); |
| 169 addTest(root, &TestRefreshInput, "regex/TestRefreshInput"); | 171 addTest(root, &TestRefreshInput, "regex/TestRefreshInput"); |
| 170 addTest(root, &TestBug8421, "regex/TestBug8421"); | 172 addTest(root, &TestBug8421, "regex/TestBug8421"); |
| 173 addTest(root, &TestBug10815, "regex/TestBug10815"); |
| 171 } | 174 } |
| 172 | 175 |
| 173 /* | 176 /* |
| 174 * Call back function and context struct used for testing | 177 * Call back function and context struct used for testing |
| 175 * regular expression user callbacks. This test is mostly the same as | 178 * regular expression user callbacks. This test is mostly the same as |
| 176 * the corresponding C++ test in intltest. | 179 * the corresponding C++ test in intltest. |
| 177 */ | 180 */ |
| 178 typedef struct callBackContext { | 181 typedef struct callBackContext { |
| 179 int32_t maxCalls; | 182 int32_t maxCalls; |
| 180 int32_t numCalls; | 183 int32_t numCalls; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 197 */ | 200 */ |
| 198 static void TestRegexCAPI(void) { | 201 static void TestRegexCAPI(void) { |
| 199 UErrorCode status = U_ZERO_ERROR; | 202 UErrorCode status = U_ZERO_ERROR; |
| 200 URegularExpression *re; | 203 URegularExpression *re; |
| 201 UChar pat[200]; | 204 UChar pat[200]; |
| 202 UChar *minus1; | 205 UChar *minus1; |
| 203 | 206 |
| 204 memset(&minus1, -1, sizeof(minus1)); | 207 memset(&minus1, -1, sizeof(minus1)); |
| 205 | 208 |
| 206 /* Mimimalist open/close */ | 209 /* Mimimalist open/close */ |
| 207 u_uastrncpy(pat, "abc*", sizeof(pat)/2); | 210 u_uastrncpy(pat, "abc*", UPRV_LENGTHOF(pat)); |
| 208 re = uregex_open(pat, -1, 0, 0, &status); | 211 re = uregex_open(pat, -1, 0, 0, &status); |
| 209 if (U_FAILURE(status)) { | 212 if (U_FAILURE(status)) { |
| 210 log_data_err("Failed to open regular expression, %s:%d, error is \"%s\"
(Are you missing data?)\n", __FILE__, __LINE__, u_errorName(status)); | 213 log_data_err("Failed to open regular expression, %s:%d, error is \"%s\"
(Are you missing data?)\n", __FILE__, __LINE__, u_errorName(status)); |
| 211 return; | 214 return; |
| 212 } | 215 } |
| 213 uregex_close(re); | 216 uregex_close(re); |
| 214 | 217 |
| 215 /* Open with all flag values set */ | 218 /* Open with all flag values set */ |
| 216 status = U_ZERO_ERROR; | 219 status = U_ZERO_ERROR; |
| 217 re = uregex_open(pat, -1, | 220 re = uregex_open(pat, -1, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 const UChar *p; | 252 const UChar *p; |
| 250 int32_t len; | 253 int32_t len; |
| 251 status = U_ZERO_ERROR; | 254 status = U_ZERO_ERROR; |
| 252 re = uregex_openC("abc*", 0, 0, &status); | 255 re = uregex_openC("abc*", 0, 0, &status); |
| 253 TEST_ASSERT_SUCCESS(status); | 256 TEST_ASSERT_SUCCESS(status); |
| 254 p = uregex_pattern(re, &len, &status); | 257 p = uregex_pattern(re, &len, &status); |
| 255 TEST_ASSERT_SUCCESS(status); | 258 TEST_ASSERT_SUCCESS(status); |
| 256 | 259 |
| 257 /* The TEST_ASSERT_SUCCESS above should change too... */ | 260 /* The TEST_ASSERT_SUCCESS above should change too... */ |
| 258 if(U_SUCCESS(status)) { | 261 if(U_SUCCESS(status)) { |
| 259 u_uastrncpy(pat, "abc*", sizeof(pat)/2); | 262 u_uastrncpy(pat, "abc*", UPRV_LENGTHOF(pat)); |
| 260 TEST_ASSERT(u_strcmp(pat, p) == 0); | 263 TEST_ASSERT(u_strcmp(pat, p) == 0); |
| 261 TEST_ASSERT(len==(int32_t)strlen("abc*")); | 264 TEST_ASSERT(len==(int32_t)strlen("abc*")); |
| 262 } | 265 } |
| 263 | 266 |
| 264 uregex_close(re); | 267 uregex_close(re); |
| 265 | 268 |
| 266 /* TODO: Open with ParseError parameter */ | 269 /* TODO: Open with ParseError parameter */ |
| 267 } | 270 } |
| 268 | 271 |
| 269 /* | 272 /* |
| (...skipping 19 matching lines...) Expand all Loading... |
| 289 clone2 = uregex_clone(re, &status); | 292 clone2 = uregex_clone(re, &status); |
| 290 TEST_ASSERT_SUCCESS(status); | 293 TEST_ASSERT_SUCCESS(status); |
| 291 TEST_ASSERT(clone2 != NULL); | 294 TEST_ASSERT(clone2 != NULL); |
| 292 uregex_close(re); | 295 uregex_close(re); |
| 293 | 296 |
| 294 status = U_ZERO_ERROR; | 297 status = U_ZERO_ERROR; |
| 295 clone3 = uregex_clone(clone2, &status); | 298 clone3 = uregex_clone(clone2, &status); |
| 296 TEST_ASSERT_SUCCESS(status); | 299 TEST_ASSERT_SUCCESS(status); |
| 297 TEST_ASSERT(clone3 != NULL); | 300 TEST_ASSERT(clone3 != NULL); |
| 298 | 301 |
| 299 u_uastrncpy(testString1, "abcccd", sizeof(pat)/2); | 302 u_uastrncpy(testString1, "abcccd", UPRV_LENGTHOF(pat)); |
| 300 u_uastrncpy(testString2, "xxxabcccd", sizeof(pat)/2); | 303 u_uastrncpy(testString2, "xxxabcccd", UPRV_LENGTHOF(pat)); |
| 301 | 304 |
| 302 status = U_ZERO_ERROR; | 305 status = U_ZERO_ERROR; |
| 303 uregex_setText(clone1, testString1, -1, &status); | 306 uregex_setText(clone1, testString1, -1, &status); |
| 304 TEST_ASSERT_SUCCESS(status); | 307 TEST_ASSERT_SUCCESS(status); |
| 305 result = uregex_lookingAt(clone1, 0, &status); | 308 result = uregex_lookingAt(clone1, 0, &status); |
| 306 TEST_ASSERT_SUCCESS(status); | 309 TEST_ASSERT_SUCCESS(status); |
| 307 TEST_ASSERT(result==TRUE); | 310 TEST_ASSERT(result==TRUE); |
| 308 | 311 |
| 309 status = U_ZERO_ERROR; | 312 status = U_ZERO_ERROR; |
| 310 uregex_setText(clone2, testString2, -1, &status); | 313 uregex_setText(clone2, testString2, -1, &status); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 321 uregex_close(clone3); | 324 uregex_close(clone3); |
| 322 | 325 |
| 323 } | 326 } |
| 324 | 327 |
| 325 /* | 328 /* |
| 326 * pattern() | 329 * pattern() |
| 327 */ | 330 */ |
| 328 { | 331 { |
| 329 const UChar *resultPat; | 332 const UChar *resultPat; |
| 330 int32_t resultLen; | 333 int32_t resultLen; |
| 331 u_uastrncpy(pat, "hello", sizeof(pat)/2); | 334 u_uastrncpy(pat, "hello", UPRV_LENGTHOF(pat)); |
| 332 status = U_ZERO_ERROR; | 335 status = U_ZERO_ERROR; |
| 333 re = uregex_open(pat, -1, 0, NULL, &status); | 336 re = uregex_open(pat, -1, 0, NULL, &status); |
| 334 resultPat = uregex_pattern(re, &resultLen, &status); | 337 resultPat = uregex_pattern(re, &resultLen, &status); |
| 335 TEST_ASSERT_SUCCESS(status); | 338 TEST_ASSERT_SUCCESS(status); |
| 336 | 339 |
| 337 /* The TEST_ASSERT_SUCCESS above should change too... */ | 340 /* The TEST_ASSERT_SUCCESS above should change too... */ |
| 338 if (U_SUCCESS(status)) { | 341 if (U_SUCCESS(status)) { |
| 339 TEST_ASSERT(resultLen == -1); | 342 TEST_ASSERT(resultLen == -1); |
| 340 TEST_ASSERT(u_strcmp(resultPat, pat) == 0); | 343 TEST_ASSERT(u_strcmp(resultPat, pat) == 0); |
| 341 } | 344 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 } | 390 } |
| 388 | 391 |
| 389 /* | 392 /* |
| 390 * setText() and lookingAt() | 393 * setText() and lookingAt() |
| 391 */ | 394 */ |
| 392 { | 395 { |
| 393 UChar text1[50]; | 396 UChar text1[50]; |
| 394 UChar text2[50]; | 397 UChar text2[50]; |
| 395 UBool result; | 398 UBool result; |
| 396 | 399 |
| 397 u_uastrncpy(text1, "abcccd", sizeof(text1)/2); | 400 u_uastrncpy(text1, "abcccd", UPRV_LENGTHOF(text1)); |
| 398 u_uastrncpy(text2, "abcccxd", sizeof(text2)/2); | 401 u_uastrncpy(text2, "abcccxd", UPRV_LENGTHOF(text2)); |
| 399 status = U_ZERO_ERROR; | 402 status = U_ZERO_ERROR; |
| 400 u_uastrncpy(pat, "abc*d", sizeof(pat)/2); | 403 u_uastrncpy(pat, "abc*d", UPRV_LENGTHOF(pat)); |
| 401 re = uregex_open(pat, -1, 0, NULL, &status); | 404 re = uregex_open(pat, -1, 0, NULL, &status); |
| 402 TEST_ASSERT_SUCCESS(status); | 405 TEST_ASSERT_SUCCESS(status); |
| 403 | 406 |
| 404 /* Operation before doing a setText should fail... */ | 407 /* Operation before doing a setText should fail... */ |
| 405 status = U_ZERO_ERROR; | 408 status = U_ZERO_ERROR; |
| 406 uregex_lookingAt(re, 0, &status); | 409 uregex_lookingAt(re, 0, &status); |
| 407 TEST_ASSERT( status== U_REGEX_INVALID_STATE); | 410 TEST_ASSERT( status== U_REGEX_INVALID_STATE); |
| 408 | 411 |
| 409 status = U_ZERO_ERROR; | 412 status = U_ZERO_ERROR; |
| 410 uregex_setText(re, text1, -1, &status); | 413 uregex_setText(re, text1, -1, &status); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 | 445 |
| 443 /* | 446 /* |
| 444 * getText() | 447 * getText() |
| 445 */ | 448 */ |
| 446 { | 449 { |
| 447 UChar text1[50]; | 450 UChar text1[50]; |
| 448 UChar text2[50]; | 451 UChar text2[50]; |
| 449 const UChar *result; | 452 const UChar *result; |
| 450 int32_t textLength; | 453 int32_t textLength; |
| 451 | 454 |
| 452 u_uastrncpy(text1, "abcccd", sizeof(text1)/2); | 455 u_uastrncpy(text1, "abcccd", UPRV_LENGTHOF(text1)); |
| 453 u_uastrncpy(text2, "abcccxd", sizeof(text2)/2); | 456 u_uastrncpy(text2, "abcccxd", UPRV_LENGTHOF(text2)); |
| 454 status = U_ZERO_ERROR; | 457 status = U_ZERO_ERROR; |
| 455 u_uastrncpy(pat, "abc*d", sizeof(pat)/2); | 458 u_uastrncpy(pat, "abc*d", UPRV_LENGTHOF(pat)); |
| 456 re = uregex_open(pat, -1, 0, NULL, &status); | 459 re = uregex_open(pat, -1, 0, NULL, &status); |
| 457 | 460 |
| 458 uregex_setText(re, text1, -1, &status); | 461 uregex_setText(re, text1, -1, &status); |
| 459 result = uregex_getText(re, &textLength, &status); | 462 result = uregex_getText(re, &textLength, &status); |
| 460 TEST_ASSERT(result == text1); | 463 TEST_ASSERT(result == text1); |
| 461 TEST_ASSERT(textLength == -1); | 464 TEST_ASSERT(textLength == -1); |
| 462 TEST_ASSERT_SUCCESS(status); | 465 TEST_ASSERT_SUCCESS(status); |
| 463 | 466 |
| 464 status = U_ZERO_ERROR; | 467 status = U_ZERO_ERROR; |
| 465 uregex_setText(re, text2, 7, &status); | 468 uregex_setText(re, text2, 7, &status); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 479 | 482 |
| 480 /* | 483 /* |
| 481 * matches() | 484 * matches() |
| 482 */ | 485 */ |
| 483 { | 486 { |
| 484 UChar text1[50]; | 487 UChar text1[50]; |
| 485 UBool result; | 488 UBool result; |
| 486 int len; | 489 int len; |
| 487 UChar nullString[] = {0,0,0}; | 490 UChar nullString[] = {0,0,0}; |
| 488 | 491 |
| 489 u_uastrncpy(text1, "abcccde", sizeof(text1)/2); | 492 u_uastrncpy(text1, "abcccde", UPRV_LENGTHOF(text1)); |
| 490 status = U_ZERO_ERROR; | 493 status = U_ZERO_ERROR; |
| 491 u_uastrncpy(pat, "abc*d", sizeof(pat)/2); | 494 u_uastrncpy(pat, "abc*d", UPRV_LENGTHOF(pat)); |
| 492 re = uregex_open(pat, -1, 0, NULL, &status); | 495 re = uregex_open(pat, -1, 0, NULL, &status); |
| 493 | 496 |
| 494 uregex_setText(re, text1, -1, &status); | 497 uregex_setText(re, text1, -1, &status); |
| 495 result = uregex_matches(re, 0, &status); | 498 result = uregex_matches(re, 0, &status); |
| 496 TEST_ASSERT(result == FALSE); | 499 TEST_ASSERT(result == FALSE); |
| 497 TEST_ASSERT_SUCCESS(status); | 500 TEST_ASSERT_SUCCESS(status); |
| 498 | 501 |
| 499 status = U_ZERO_ERROR; | 502 status = U_ZERO_ERROR; |
| 500 uregex_setText(re, text1, 6, &status); | 503 uregex_setText(re, text1, 6, &status); |
| 501 result = uregex_matches(re, 0, &status); | 504 result = uregex_matches(re, 0, &status); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 531 * lookingAt() Used in setText test. | 534 * lookingAt() Used in setText test. |
| 532 */ | 535 */ |
| 533 | 536 |
| 534 | 537 |
| 535 /* | 538 /* |
| 536 * find(), findNext, start, end, reset | 539 * find(), findNext, start, end, reset |
| 537 */ | 540 */ |
| 538 { | 541 { |
| 539 UChar text1[50]; | 542 UChar text1[50]; |
| 540 UBool result; | 543 UBool result; |
| 541 u_uastrncpy(text1, "012rx5rx890rxrx...", sizeof(text1)/2); | 544 u_uastrncpy(text1, "012rx5rx890rxrx...", UPRV_LENGTHOF(text1)); |
| 542 status = U_ZERO_ERROR; | 545 status = U_ZERO_ERROR; |
| 543 re = uregex_openC("rx", 0, NULL, &status); | 546 re = uregex_openC("rx", 0, NULL, &status); |
| 544 | 547 |
| 545 uregex_setText(re, text1, -1, &status); | 548 uregex_setText(re, text1, -1, &status); |
| 546 result = uregex_find(re, 0, &status); | 549 result = uregex_find(re, 0, &status); |
| 547 TEST_ASSERT(result == TRUE); | 550 TEST_ASSERT(result == TRUE); |
| 548 TEST_ASSERT(uregex_start(re, 0, &status) == 3); | 551 TEST_ASSERT(uregex_start(re, 0, &status) == 3); |
| 549 TEST_ASSERT(uregex_end(re, 0, &status) == 5); | 552 TEST_ASSERT(uregex_end(re, 0, &status) == 5); |
| 550 TEST_ASSERT_SUCCESS(status); | 553 TEST_ASSERT_SUCCESS(status); |
| 551 | 554 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 | 617 |
| 615 | 618 |
| 616 /* | 619 /* |
| 617 * group() | 620 * group() |
| 618 */ | 621 */ |
| 619 { | 622 { |
| 620 UChar text1[80]; | 623 UChar text1[80]; |
| 621 UChar buf[80]; | 624 UChar buf[80]; |
| 622 UBool result; | 625 UBool result; |
| 623 int32_t resultSz; | 626 int32_t resultSz; |
| 624 u_uastrncpy(text1, "noise abc interior def, and this is off the end", s
izeof(text1)/2); | 627 u_uastrncpy(text1, "noise abc interior def, and this is off the end", U
PRV_LENGTHOF(text1)); |
| 625 | 628 |
| 626 status = U_ZERO_ERROR; | 629 status = U_ZERO_ERROR; |
| 627 re = uregex_openC("abc(.*?)def", 0, NULL, &status); | 630 re = uregex_openC("abc(.*?)def", 0, NULL, &status); |
| 628 TEST_ASSERT_SUCCESS(status); | 631 TEST_ASSERT_SUCCESS(status); |
| 629 | 632 |
| 630 | 633 |
| 631 uregex_setText(re, text1, -1, &status); | 634 uregex_setText(re, text1, -1, &status); |
| 632 result = uregex_find(re, 0, &status); | 635 result = uregex_find(re, 0, &status); |
| 633 TEST_ASSERT(result==TRUE); | 636 TEST_ASSERT(result==TRUE); |
| 634 | 637 |
| 635 /* Capture Group 0, the full match. Should succeed. */ | 638 /* Capture Group 0, the full match. Should succeed. */ |
| 636 status = U_ZERO_ERROR; | 639 status = U_ZERO_ERROR; |
| 637 resultSz = uregex_group(re, 0, buf, sizeof(buf)/2, &status); | 640 resultSz = uregex_group(re, 0, buf, UPRV_LENGTHOF(buf), &status); |
| 638 TEST_ASSERT_SUCCESS(status); | 641 TEST_ASSERT_SUCCESS(status); |
| 639 TEST_ASSERT_STRING("abc interior def", buf, TRUE); | 642 TEST_ASSERT_STRING("abc interior def", buf, TRUE); |
| 640 TEST_ASSERT(resultSz == (int32_t)strlen("abc interior def")); | 643 TEST_ASSERT(resultSz == (int32_t)strlen("abc interior def")); |
| 641 | 644 |
| 642 /* Capture group #1. Should succeed. */ | 645 /* Capture group #1. Should succeed. */ |
| 643 status = U_ZERO_ERROR; | 646 status = U_ZERO_ERROR; |
| 644 resultSz = uregex_group(re, 1, buf, sizeof(buf)/2, &status); | 647 resultSz = uregex_group(re, 1, buf, UPRV_LENGTHOF(buf), &status); |
| 645 TEST_ASSERT_SUCCESS(status); | 648 TEST_ASSERT_SUCCESS(status); |
| 646 TEST_ASSERT_STRING(" interior ", buf, TRUE); | 649 TEST_ASSERT_STRING(" interior ", buf, TRUE); |
| 647 TEST_ASSERT(resultSz == (int32_t)strlen(" interior ")); | 650 TEST_ASSERT(resultSz == (int32_t)strlen(" interior ")); |
| 648 | 651 |
| 649 /* Capture group out of range. Error. */ | 652 /* Capture group out of range. Error. */ |
| 650 status = U_ZERO_ERROR; | 653 status = U_ZERO_ERROR; |
| 651 uregex_group(re, 2, buf, sizeof(buf)/2, &status); | 654 uregex_group(re, 2, buf, UPRV_LENGTHOF(buf), &status); |
| 652 TEST_ASSERT(status == U_INDEX_OUTOFBOUNDS_ERROR); | 655 TEST_ASSERT(status == U_INDEX_OUTOFBOUNDS_ERROR); |
| 653 | 656 |
| 654 /* NULL buffer, pure pre-flight */ | 657 /* NULL buffer, pure pre-flight */ |
| 655 status = U_ZERO_ERROR; | 658 status = U_ZERO_ERROR; |
| 656 resultSz = uregex_group(re, 0, NULL, 0, &status); | 659 resultSz = uregex_group(re, 0, NULL, 0, &status); |
| 657 TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR); | 660 TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR); |
| 658 TEST_ASSERT(resultSz == (int32_t)strlen("abc interior def")); | 661 TEST_ASSERT(resultSz == (int32_t)strlen("abc interior def")); |
| 659 | 662 |
| 660 /* Too small buffer, truncated string */ | 663 /* Too small buffer, truncated string */ |
| 661 status = U_ZERO_ERROR; | 664 status = U_ZERO_ERROR; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 685 | 688 |
| 686 /* SetRegion(), getRegion() do something */ | 689 /* SetRegion(), getRegion() do something */ |
| 687 TEST_SETUP(".*", "0123456789ABCDEF", 0) | 690 TEST_SETUP(".*", "0123456789ABCDEF", 0) |
| 688 UChar resultString[40]; | 691 UChar resultString[40]; |
| 689 TEST_ASSERT(uregex_regionStart(re, &status) == 0); | 692 TEST_ASSERT(uregex_regionStart(re, &status) == 0); |
| 690 TEST_ASSERT(uregex_regionEnd(re, &status) == 16); | 693 TEST_ASSERT(uregex_regionEnd(re, &status) == 16); |
| 691 uregex_setRegion(re, 3, 6, &status); | 694 uregex_setRegion(re, 3, 6, &status); |
| 692 TEST_ASSERT(uregex_regionStart(re, &status) == 3); | 695 TEST_ASSERT(uregex_regionStart(re, &status) == 3); |
| 693 TEST_ASSERT(uregex_regionEnd(re, &status) == 6); | 696 TEST_ASSERT(uregex_regionEnd(re, &status) == 6); |
| 694 TEST_ASSERT(uregex_findNext(re, &status)); | 697 TEST_ASSERT(uregex_findNext(re, &status)); |
| 695 TEST_ASSERT(uregex_group(re, 0, resultString, sizeof(resultString)/2, &s
tatus) == 3) | 698 TEST_ASSERT(uregex_group(re, 0, resultString, UPRV_LENGTHOF(resultString
), &status) == 3) |
| 696 TEST_ASSERT_STRING("345", resultString, TRUE); | 699 TEST_ASSERT_STRING("345", resultString, TRUE); |
| 697 TEST_TEARDOWN; | 700 TEST_TEARDOWN; |
| 698 | 701 |
| 699 /* find(start=-1) uses regions */ | 702 /* find(start=-1) uses regions */ |
| 700 TEST_SETUP(".*", "0123456789ABCDEF", 0); | 703 TEST_SETUP(".*", "0123456789ABCDEF", 0); |
| 701 uregex_setRegion(re, 4, 6, &status); | 704 uregex_setRegion(re, 4, 6, &status); |
| 702 TEST_ASSERT(uregex_find(re, -1, &status) == TRUE); | 705 TEST_ASSERT(uregex_find(re, -1, &status) == TRUE); |
| 703 TEST_ASSERT(uregex_start(re, 0, &status) == 4); | 706 TEST_ASSERT(uregex_start(re, 0, &status) == 4); |
| 704 TEST_ASSERT(uregex_end(re, 0, &status) == 6); | 707 TEST_ASSERT(uregex_end(re, 0, &status) == 6); |
| 705 TEST_TEARDOWN; | 708 TEST_TEARDOWN; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 | 812 |
| 810 /* | 813 /* |
| 811 * replaceFirst() | 814 * replaceFirst() |
| 812 */ | 815 */ |
| 813 { | 816 { |
| 814 UChar text1[80]; | 817 UChar text1[80]; |
| 815 UChar text2[80]; | 818 UChar text2[80]; |
| 816 UChar replText[80]; | 819 UChar replText[80]; |
| 817 UChar buf[80]; | 820 UChar buf[80]; |
| 818 int32_t resultSz; | 821 int32_t resultSz; |
| 819 u_uastrncpy(text1, "Replace xaax x1x x...x.", sizeof(text1)/2); | 822 u_uastrncpy(text1, "Replace xaax x1x x...x.", UPRV_LENGTHOF(text1)); |
| 820 u_uastrncpy(text2, "No match here.", sizeof(text2)/2); | 823 u_uastrncpy(text2, "No match here.", UPRV_LENGTHOF(text2)); |
| 821 u_uastrncpy(replText, "<$1>", sizeof(replText)/2); | 824 u_uastrncpy(replText, "<$1>", UPRV_LENGTHOF(replText)); |
| 822 | 825 |
| 823 status = U_ZERO_ERROR; | 826 status = U_ZERO_ERROR; |
| 824 re = uregex_openC("x(.*?)x", 0, NULL, &status); | 827 re = uregex_openC("x(.*?)x", 0, NULL, &status); |
| 825 TEST_ASSERT_SUCCESS(status); | 828 TEST_ASSERT_SUCCESS(status); |
| 826 | 829 |
| 827 /* Normal case, with match */ | 830 /* Normal case, with match */ |
| 828 uregex_setText(re, text1, -1, &status); | 831 uregex_setText(re, text1, -1, &status); |
| 829 resultSz = uregex_replaceFirst(re, replText, -1, buf, sizeof(buf)/2, &st
atus); | 832 resultSz = uregex_replaceFirst(re, replText, -1, buf, UPRV_LENGTHOF(buf)
, &status); |
| 830 TEST_ASSERT_SUCCESS(status); | 833 TEST_ASSERT_SUCCESS(status); |
| 831 TEST_ASSERT_STRING("Replace <aa> x1x x...x.", buf, TRUE); | 834 TEST_ASSERT_STRING("Replace <aa> x1x x...x.", buf, TRUE); |
| 832 TEST_ASSERT(resultSz == (int32_t)strlen("Replace xaax x1x x...x.")); | 835 TEST_ASSERT(resultSz == (int32_t)strlen("Replace xaax x1x x...x.")); |
| 833 | 836 |
| 834 /* No match. Text should copy to output with no changes. */ | 837 /* No match. Text should copy to output with no changes. */ |
| 835 status = U_ZERO_ERROR; | 838 status = U_ZERO_ERROR; |
| 836 uregex_setText(re, text2, -1, &status); | 839 uregex_setText(re, text2, -1, &status); |
| 837 resultSz = uregex_replaceFirst(re, replText, -1, buf, sizeof(buf)/2, &st
atus); | 840 resultSz = uregex_replaceFirst(re, replText, -1, buf, UPRV_LENGTHOF(buf)
, &status); |
| 838 TEST_ASSERT_SUCCESS(status); | 841 TEST_ASSERT_SUCCESS(status); |
| 839 TEST_ASSERT_STRING("No match here.", buf, TRUE); | 842 TEST_ASSERT_STRING("No match here.", buf, TRUE); |
| 840 TEST_ASSERT(resultSz == (int32_t)strlen("No match here.")); | 843 TEST_ASSERT(resultSz == (int32_t)strlen("No match here.")); |
| 841 | 844 |
| 842 /* Match, output just fills buffer, no termination warning. */ | 845 /* Match, output just fills buffer, no termination warning. */ |
| 843 status = U_ZERO_ERROR; | 846 status = U_ZERO_ERROR; |
| 844 uregex_setText(re, text1, -1, &status); | 847 uregex_setText(re, text1, -1, &status); |
| 845 memset(buf, -1, sizeof(buf)); | 848 memset(buf, -1, sizeof(buf)); |
| 846 resultSz = uregex_replaceFirst(re, replText, -1, buf, strlen("Replace <a
a> x1x x...x."), &status); | 849 resultSz = uregex_replaceFirst(re, replText, -1, buf, strlen("Replace <a
a> x1x x...x."), &status); |
| 847 TEST_ASSERT(status == U_STRING_NOT_TERMINATED_WARNING); | 850 TEST_ASSERT(status == U_STRING_NOT_TERMINATED_WARNING); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 UChar replText2[80]; /* "<<$1>>" */ | 892 UChar replText2[80]; /* "<<$1>>" */ |
| 890 const char * pattern = "x(.*?)x"; | 893 const char * pattern = "x(.*?)x"; |
| 891 const char * expectedResult = "Replace <aa> <1> <...>."; | 894 const char * expectedResult = "Replace <aa> <1> <...>."; |
| 892 const char * expectedResult2 = "Replace <<aa>> <<1>> <<...>>."; | 895 const char * expectedResult2 = "Replace <<aa>> <<1>> <<...>>."; |
| 893 UChar buf[80]; | 896 UChar buf[80]; |
| 894 int32_t resultSize; | 897 int32_t resultSize; |
| 895 int32_t expectedResultSize; | 898 int32_t expectedResultSize; |
| 896 int32_t expectedResultSize2; | 899 int32_t expectedResultSize2; |
| 897 int32_t i; | 900 int32_t i; |
| 898 | 901 |
| 899 u_uastrncpy(text1, "Replace xaax x1x x...x.", sizeof(text1)/2); | 902 u_uastrncpy(text1, "Replace xaax x1x x...x.", UPRV_LENGTHOF(text1)); |
| 900 u_uastrncpy(text2, "No match here.", sizeof(text2)/2); | 903 u_uastrncpy(text2, "No match here.", UPRV_LENGTHOF(text2)); |
| 901 u_uastrncpy(replText, "<$1>", sizeof(replText)/2); | 904 u_uastrncpy(replText, "<$1>", UPRV_LENGTHOF(replText)); |
| 902 u_uastrncpy(replText2, "<<$1>>", sizeof(replText2)/2); | 905 u_uastrncpy(replText2, "<<$1>>", UPRV_LENGTHOF(replText2)); |
| 903 expectedResultSize = strlen(expectedResult); | 906 expectedResultSize = strlen(expectedResult); |
| 904 expectedResultSize2 = strlen(expectedResult2); | 907 expectedResultSize2 = strlen(expectedResult2); |
| 905 | 908 |
| 906 status = U_ZERO_ERROR; | 909 status = U_ZERO_ERROR; |
| 907 re = uregex_openC(pattern, 0, NULL, &status); | 910 re = uregex_openC(pattern, 0, NULL, &status); |
| 908 TEST_ASSERT_SUCCESS(status); | 911 TEST_ASSERT_SUCCESS(status); |
| 909 | 912 |
| 910 /* Normal case, with match */ | 913 /* Normal case, with match */ |
| 911 uregex_setText(re, text1, -1, &status); | 914 uregex_setText(re, text1, -1, &status); |
| 912 resultSize = uregex_replaceAll(re, replText, -1, buf, sizeof(buf)/2, &st
atus); | 915 resultSize = uregex_replaceAll(re, replText, -1, buf, UPRV_LENGTHOF(buf)
, &status); |
| 913 TEST_ASSERT_SUCCESS(status); | 916 TEST_ASSERT_SUCCESS(status); |
| 914 TEST_ASSERT_STRING(expectedResult, buf, TRUE); | 917 TEST_ASSERT_STRING(expectedResult, buf, TRUE); |
| 915 TEST_ASSERT(resultSize == expectedResultSize); | 918 TEST_ASSERT(resultSize == expectedResultSize); |
| 916 | 919 |
| 917 /* No match. Text should copy to output with no changes. */ | 920 /* No match. Text should copy to output with no changes. */ |
| 918 status = U_ZERO_ERROR; | 921 status = U_ZERO_ERROR; |
| 919 uregex_setText(re, text2, -1, &status); | 922 uregex_setText(re, text2, -1, &status); |
| 920 resultSize = uregex_replaceAll(re, replText, -1, buf, sizeof(buf)/2, &st
atus); | 923 resultSize = uregex_replaceAll(re, replText, -1, buf, UPRV_LENGTHOF(buf)
, &status); |
| 921 TEST_ASSERT_SUCCESS(status); | 924 TEST_ASSERT_SUCCESS(status); |
| 922 TEST_ASSERT_STRING("No match here.", buf, TRUE); | 925 TEST_ASSERT_STRING("No match here.", buf, TRUE); |
| 923 TEST_ASSERT(resultSize == u_strlen(text2)); | 926 TEST_ASSERT(resultSize == u_strlen(text2)); |
| 924 | 927 |
| 925 /* Match, output just fills buffer, no termination warning. */ | 928 /* Match, output just fills buffer, no termination warning. */ |
| 926 status = U_ZERO_ERROR; | 929 status = U_ZERO_ERROR; |
| 927 uregex_setText(re, text1, -1, &status); | 930 uregex_setText(re, text1, -1, &status); |
| 928 memset(buf, -1, sizeof(buf)); | 931 memset(buf, -1, sizeof(buf)); |
| 929 resultSize = uregex_replaceAll(re, replText, -1, buf, expectedResultSize
, &status); | 932 resultSize = uregex_replaceAll(re, replText, -1, buf, expectedResultSize
, &status); |
| 930 TEST_ASSERT(status == U_STRING_NOT_TERMINATED_WARNING); | 933 TEST_ASSERT(status == U_STRING_NOT_TERMINATED_WARNING); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 UChar repl[100]; | 997 UChar repl[100]; |
| 995 UChar buf[100]; | 998 UChar buf[100]; |
| 996 UChar *bufPtr; | 999 UChar *bufPtr; |
| 997 int32_t bufCap; | 1000 int32_t bufCap; |
| 998 | 1001 |
| 999 | 1002 |
| 1000 status = U_ZERO_ERROR; | 1003 status = U_ZERO_ERROR; |
| 1001 re = uregex_openC(".*", 0, 0, &status); | 1004 re = uregex_openC(".*", 0, 0, &status); |
| 1002 TEST_ASSERT_SUCCESS(status); | 1005 TEST_ASSERT_SUCCESS(status); |
| 1003 | 1006 |
| 1004 u_uastrncpy(text, "whatever", sizeof(text)/2); | 1007 u_uastrncpy(text, "whatever", UPRV_LENGTHOF(text)); |
| 1005 u_uastrncpy(repl, "some other", sizeof(repl)/2); | 1008 u_uastrncpy(repl, "some other", UPRV_LENGTHOF(repl)); |
| 1006 uregex_setText(re, text, -1, &status); | 1009 uregex_setText(re, text, -1, &status); |
| 1007 | 1010 |
| 1008 /* match covers whole target string */ | 1011 /* match covers whole target string */ |
| 1009 uregex_find(re, 0, &status); | 1012 uregex_find(re, 0, &status); |
| 1010 TEST_ASSERT_SUCCESS(status); | 1013 TEST_ASSERT_SUCCESS(status); |
| 1011 bufPtr = buf; | 1014 bufPtr = buf; |
| 1012 bufCap = sizeof(buf) / 2; | 1015 bufCap = UPRV_LENGTHOF(buf); |
| 1013 uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); | 1016 uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); |
| 1014 TEST_ASSERT_SUCCESS(status); | 1017 TEST_ASSERT_SUCCESS(status); |
| 1015 TEST_ASSERT_STRING("some other", buf, TRUE); | 1018 TEST_ASSERT_STRING("some other", buf, TRUE); |
| 1016 | 1019 |
| 1017 /* Match has \u \U escapes */ | 1020 /* Match has \u \U escapes */ |
| 1018 uregex_find(re, 0, &status); | 1021 uregex_find(re, 0, &status); |
| 1019 TEST_ASSERT_SUCCESS(status); | 1022 TEST_ASSERT_SUCCESS(status); |
| 1020 bufPtr = buf; | 1023 bufPtr = buf; |
| 1021 bufCap = sizeof(buf) / 2; | 1024 bufCap = UPRV_LENGTHOF(buf); |
| 1022 u_uastrncpy(repl, "abc\\u0041\\U00000042 \\\\ $ \\abc", sizeof(repl)/2); | 1025 u_uastrncpy(repl, "abc\\u0041\\U00000042 \\\\ $ \\abc", UPRV_LENGTHOF(re
pl)); |
| 1023 uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); | 1026 uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); |
| 1024 TEST_ASSERT_SUCCESS(status); | 1027 TEST_ASSERT_SUCCESS(status); |
| 1025 TEST_ASSERT_STRING("abcAB \\ $ abc", buf, TRUE); | 1028 TEST_ASSERT_STRING("abcAB \\ $ abc", buf, TRUE); |
| 1026 | 1029 |
| 1027 /* Bug 6813, parameter check of NULL destCapacity; crashed before fix. *
/ | 1030 /* Bug 6813, parameter check of NULL destCapacity; crashed before fix. *
/ |
| 1028 status = U_ZERO_ERROR; | 1031 status = U_ZERO_ERROR; |
| 1029 uregex_find(re, 0, &status); | 1032 uregex_find(re, 0, &status); |
| 1030 TEST_ASSERT_SUCCESS(status); | 1033 TEST_ASSERT_SUCCESS(status); |
| 1031 bufPtr = buf; | 1034 bufPtr = buf; |
| 1032 status = U_BUFFER_OVERFLOW_ERROR; | 1035 status = U_BUFFER_OVERFLOW_ERROR; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1047 { | 1050 { |
| 1048 UChar textToSplit[80]; | 1051 UChar textToSplit[80]; |
| 1049 UChar text2[80]; | 1052 UChar text2[80]; |
| 1050 UChar buf[200]; | 1053 UChar buf[200]; |
| 1051 UChar *fields[10]; | 1054 UChar *fields[10]; |
| 1052 int32_t numFields; | 1055 int32_t numFields; |
| 1053 int32_t requiredCapacity; | 1056 int32_t requiredCapacity; |
| 1054 int32_t spaceNeeded; | 1057 int32_t spaceNeeded; |
| 1055 int32_t sz; | 1058 int32_t sz; |
| 1056 | 1059 |
| 1057 u_uastrncpy(textToSplit, "first : second: third", sizeof(textToSplit)/
2); | 1060 u_uastrncpy(textToSplit, "first : second: third", UPRV_LENGTHOF(textTo
Split)); |
| 1058 u_uastrncpy(text2, "No match here.", sizeof(text2)/2); | 1061 u_uastrncpy(text2, "No match here.", UPRV_LENGTHOF(text2)); |
| 1059 | 1062 |
| 1060 status = U_ZERO_ERROR; | 1063 status = U_ZERO_ERROR; |
| 1061 re = uregex_openC(":", 0, NULL, &status); | 1064 re = uregex_openC(":", 0, NULL, &status); |
| 1062 | 1065 |
| 1063 | 1066 |
| 1064 /* Simple split */ | 1067 /* Simple split */ |
| 1065 | 1068 |
| 1066 uregex_setText(re, textToSplit, -1, &status); | 1069 uregex_setText(re, textToSplit, -1, &status); |
| 1067 TEST_ASSERT_SUCCESS(status); | 1070 TEST_ASSERT_SUCCESS(status); |
| 1068 | 1071 |
| 1069 /* The TEST_ASSERT_SUCCESS call above should change too... */ | 1072 /* The TEST_ASSERT_SUCCESS call above should change too... */ |
| 1070 if (U_SUCCESS(status)) { | 1073 if (U_SUCCESS(status)) { |
| 1071 memset(fields, -1, sizeof(fields)); | 1074 memset(fields, -1, sizeof(fields)); |
| 1072 numFields = | 1075 numFields = |
| 1073 uregex_split(re, buf, sizeof(buf)/2, &requiredCapacity, fields,
10, &status); | 1076 uregex_split(re, buf, UPRV_LENGTHOF(buf), &requiredCapacity, fie
lds, 10, &status); |
| 1074 TEST_ASSERT_SUCCESS(status); | 1077 TEST_ASSERT_SUCCESS(status); |
| 1075 | 1078 |
| 1076 /* The TEST_ASSERT_SUCCESS call above should change too... */ | 1079 /* The TEST_ASSERT_SUCCESS call above should change too... */ |
| 1077 if(U_SUCCESS(status)) { | 1080 if(U_SUCCESS(status)) { |
| 1078 TEST_ASSERT(numFields == 3); | 1081 TEST_ASSERT(numFields == 3); |
| 1079 TEST_ASSERT_STRING("first ", fields[0], TRUE); | 1082 TEST_ASSERT_STRING("first ", fields[0], TRUE); |
| 1080 TEST_ASSERT_STRING(" second", fields[1], TRUE); | 1083 TEST_ASSERT_STRING(" second", fields[1], TRUE); |
| 1081 TEST_ASSERT_STRING(" third", fields[2], TRUE); | 1084 TEST_ASSERT_STRING(" third", fields[2], TRUE); |
| 1082 TEST_ASSERT(fields[3] == NULL); | 1085 TEST_ASSERT(fields[3] == NULL); |
| 1083 | 1086 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1095 /* Split with too few output strings available */ | 1098 /* Split with too few output strings available */ |
| 1096 status = U_ZERO_ERROR; | 1099 status = U_ZERO_ERROR; |
| 1097 re = uregex_openC(":", 0, NULL, &status); | 1100 re = uregex_openC(":", 0, NULL, &status); |
| 1098 uregex_setText(re, textToSplit, -1, &status); | 1101 uregex_setText(re, textToSplit, -1, &status); |
| 1099 TEST_ASSERT_SUCCESS(status); | 1102 TEST_ASSERT_SUCCESS(status); |
| 1100 | 1103 |
| 1101 /* The TEST_ASSERT_SUCCESS call above should change too... */ | 1104 /* The TEST_ASSERT_SUCCESS call above should change too... */ |
| 1102 if(U_SUCCESS(status)) { | 1105 if(U_SUCCESS(status)) { |
| 1103 memset(fields, -1, sizeof(fields)); | 1106 memset(fields, -1, sizeof(fields)); |
| 1104 numFields = | 1107 numFields = |
| 1105 uregex_split(re, buf, sizeof(buf)/2, &requiredCapacity, fields,
2, &status); | 1108 uregex_split(re, buf, UPRV_LENGTHOF(buf), &requiredCapacity, fie
lds, 2, &status); |
| 1106 TEST_ASSERT_SUCCESS(status); | 1109 TEST_ASSERT_SUCCESS(status); |
| 1107 | 1110 |
| 1108 /* The TEST_ASSERT_SUCCESS call above should change too... */ | 1111 /* The TEST_ASSERT_SUCCESS call above should change too... */ |
| 1109 if(U_SUCCESS(status)) { | 1112 if(U_SUCCESS(status)) { |
| 1110 TEST_ASSERT(numFields == 2); | 1113 TEST_ASSERT(numFields == 2); |
| 1111 TEST_ASSERT_STRING("first ", fields[0], TRUE); | 1114 TEST_ASSERT_STRING("first ", fields[0], TRUE); |
| 1112 TEST_ASSERT_STRING(" second: third", fields[1], TRUE); | 1115 TEST_ASSERT_STRING(" second: third", fields[1], TRUE); |
| 1113 TEST_ASSERT(!memcmp(&fields[2],&minus1,sizeof(UChar*))); | 1116 TEST_ASSERT(!memcmp(&fields[2],&minus1,sizeof(UChar*))); |
| 1114 | 1117 |
| 1115 spaceNeeded = u_strlen(textToSplit) - | 1118 spaceNeeded = u_strlen(textToSplit) - |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1153 * comes out as additional fields. */ | 1156 * comes out as additional fields. */ |
| 1154 { | 1157 { |
| 1155 UChar textToSplit[80]; | 1158 UChar textToSplit[80]; |
| 1156 UChar buf[200]; | 1159 UChar buf[200]; |
| 1157 UChar *fields[10]; | 1160 UChar *fields[10]; |
| 1158 int32_t numFields; | 1161 int32_t numFields; |
| 1159 int32_t requiredCapacity; | 1162 int32_t requiredCapacity; |
| 1160 int32_t spaceNeeded; | 1163 int32_t spaceNeeded; |
| 1161 int32_t sz; | 1164 int32_t sz; |
| 1162 | 1165 |
| 1163 u_uastrncpy(textToSplit, "first <tag-a> second<tag-b> third", sizeof(t
extToSplit)/2); | 1166 u_uastrncpy(textToSplit, "first <tag-a> second<tag-b> third", UPRV_LEN
GTHOF(textToSplit)); |
| 1164 | 1167 |
| 1165 status = U_ZERO_ERROR; | 1168 status = U_ZERO_ERROR; |
| 1166 re = uregex_openC("<(.*?)>", 0, NULL, &status); | 1169 re = uregex_openC("<(.*?)>", 0, NULL, &status); |
| 1167 | 1170 |
| 1168 uregex_setText(re, textToSplit, -1, &status); | 1171 uregex_setText(re, textToSplit, -1, &status); |
| 1169 TEST_ASSERT_SUCCESS(status); | 1172 TEST_ASSERT_SUCCESS(status); |
| 1170 | 1173 |
| 1171 /* The TEST_ASSERT_SUCCESS call above should change too... */ | 1174 /* The TEST_ASSERT_SUCCESS call above should change too... */ |
| 1172 if(U_SUCCESS(status)) { | 1175 if(U_SUCCESS(status)) { |
| 1173 memset(fields, -1, sizeof(fields)); | 1176 memset(fields, -1, sizeof(fields)); |
| 1174 numFields = | 1177 numFields = |
| 1175 uregex_split(re, buf, sizeof(buf)/2, &requiredCapacity, fields,
10, &status); | 1178 uregex_split(re, buf, UPRV_LENGTHOF(buf), &requiredCapacity, fie
lds, 10, &status); |
| 1176 TEST_ASSERT_SUCCESS(status); | 1179 TEST_ASSERT_SUCCESS(status); |
| 1177 | 1180 |
| 1178 /* The TEST_ASSERT_SUCCESS call above should change too... */ | 1181 /* The TEST_ASSERT_SUCCESS call above should change too... */ |
| 1179 if(U_SUCCESS(status)) { | 1182 if(U_SUCCESS(status)) { |
| 1180 TEST_ASSERT(numFields == 5); | 1183 TEST_ASSERT(numFields == 5); |
| 1181 TEST_ASSERT_STRING("first ", fields[0], TRUE); | 1184 TEST_ASSERT_STRING("first ", fields[0], TRUE); |
| 1182 TEST_ASSERT_STRING("tag-a", fields[1], TRUE); | 1185 TEST_ASSERT_STRING("tag-a", fields[1], TRUE); |
| 1183 TEST_ASSERT_STRING(" second", fields[2], TRUE); | 1186 TEST_ASSERT_STRING(" second", fields[2], TRUE); |
| 1184 TEST_ASSERT_STRING("tag-b", fields[3], TRUE); | 1187 TEST_ASSERT_STRING("tag-b", fields[3], TRUE); |
| 1185 TEST_ASSERT_STRING(" third", fields[4], TRUE); | 1188 TEST_ASSERT_STRING(" third", fields[4], TRUE); |
| 1186 TEST_ASSERT(fields[5] == NULL); | 1189 TEST_ASSERT(fields[5] == NULL); |
| 1187 spaceNeeded = strlen("first .tag-a. second.tag-b. third."); /*
"." at NUL positions */ | 1190 spaceNeeded = strlen("first .tag-a. second.tag-b. third."); /*
"." at NUL positions */ |
| 1188 TEST_ASSERT(spaceNeeded == requiredCapacity); | 1191 TEST_ASSERT(spaceNeeded == requiredCapacity); |
| 1189 } | 1192 } |
| 1190 } | 1193 } |
| 1191 | 1194 |
| 1192 /* Split with too few output strings available (2) */ | 1195 /* Split with too few output strings available (2) */ |
| 1193 status = U_ZERO_ERROR; | 1196 status = U_ZERO_ERROR; |
| 1194 memset(fields, -1, sizeof(fields)); | 1197 memset(fields, -1, sizeof(fields)); |
| 1195 numFields = | 1198 numFields = |
| 1196 uregex_split(re, buf, sizeof(buf)/2, &requiredCapacity, fields, 2, &
status); | 1199 uregex_split(re, buf, UPRV_LENGTHOF(buf), &requiredCapacity, fields,
2, &status); |
| 1197 TEST_ASSERT_SUCCESS(status); | 1200 TEST_ASSERT_SUCCESS(status); |
| 1198 | 1201 |
| 1199 /* The TEST_ASSERT_SUCCESS call above should change too... */ | 1202 /* The TEST_ASSERT_SUCCESS call above should change too... */ |
| 1200 if(U_SUCCESS(status)) { | 1203 if(U_SUCCESS(status)) { |
| 1201 TEST_ASSERT(numFields == 2); | 1204 TEST_ASSERT(numFields == 2); |
| 1202 TEST_ASSERT_STRING("first ", fields[0], TRUE); | 1205 TEST_ASSERT_STRING("first ", fields[0], TRUE); |
| 1203 TEST_ASSERT_STRING(" second<tag-b> third", fields[1], TRUE); | 1206 TEST_ASSERT_STRING(" second<tag-b> third", fields[1], TRUE); |
| 1204 TEST_ASSERT(!memcmp(&fields[2],&minus1,sizeof(UChar*))); | 1207 TEST_ASSERT(!memcmp(&fields[2],&minus1,sizeof(UChar*))); |
| 1205 | 1208 |
| 1206 spaceNeeded = strlen("first . second<tag-b> third."); /* "." at NU
L positions */ | 1209 spaceNeeded = strlen("first . second<tag-b> third."); /* "." at NU
L positions */ |
| 1207 TEST_ASSERT(spaceNeeded == requiredCapacity); | 1210 TEST_ASSERT(spaceNeeded == requiredCapacity); |
| 1208 } | 1211 } |
| 1209 | 1212 |
| 1210 /* Split with too few output strings available (3) */ | 1213 /* Split with too few output strings available (3) */ |
| 1211 status = U_ZERO_ERROR; | 1214 status = U_ZERO_ERROR; |
| 1212 memset(fields, -1, sizeof(fields)); | 1215 memset(fields, -1, sizeof(fields)); |
| 1213 numFields = | 1216 numFields = |
| 1214 uregex_split(re, buf, sizeof(buf)/2, &requiredCapacity, fields, 3, &
status); | 1217 uregex_split(re, buf, UPRV_LENGTHOF(buf), &requiredCapacity, fields,
3, &status); |
| 1215 TEST_ASSERT_SUCCESS(status); | 1218 TEST_ASSERT_SUCCESS(status); |
| 1216 | 1219 |
| 1217 /* The TEST_ASSERT_SUCCESS call above should change too... */ | 1220 /* The TEST_ASSERT_SUCCESS call above should change too... */ |
| 1218 if(U_SUCCESS(status)) { | 1221 if(U_SUCCESS(status)) { |
| 1219 TEST_ASSERT(numFields == 3); | 1222 TEST_ASSERT(numFields == 3); |
| 1220 TEST_ASSERT_STRING("first ", fields[0], TRUE); | 1223 TEST_ASSERT_STRING("first ", fields[0], TRUE); |
| 1221 TEST_ASSERT_STRING("tag-a", fields[1], TRUE); | 1224 TEST_ASSERT_STRING("tag-a", fields[1], TRUE); |
| 1222 TEST_ASSERT_STRING(" second<tag-b> third", fields[2], TRUE); | 1225 TEST_ASSERT_STRING(" second<tag-b> third", fields[2], TRUE); |
| 1223 TEST_ASSERT(!memcmp(&fields[3],&minus1,sizeof(UChar*))); | 1226 TEST_ASSERT(!memcmp(&fields[3],&minus1,sizeof(UChar*))); |
| 1224 | 1227 |
| 1225 spaceNeeded = strlen("first .tag-a. second<tag-b> third."); /* "."
at NUL positions */ | 1228 spaceNeeded = strlen("first .tag-a. second<tag-b> third."); /* "."
at NUL positions */ |
| 1226 TEST_ASSERT(spaceNeeded == requiredCapacity); | 1229 TEST_ASSERT(spaceNeeded == requiredCapacity); |
| 1227 } | 1230 } |
| 1228 | 1231 |
| 1229 /* Split with just enough output strings available (5) */ | 1232 /* Split with just enough output strings available (5) */ |
| 1230 status = U_ZERO_ERROR; | 1233 status = U_ZERO_ERROR; |
| 1231 memset(fields, -1, sizeof(fields)); | 1234 memset(fields, -1, sizeof(fields)); |
| 1232 numFields = | 1235 numFields = |
| 1233 uregex_split(re, buf, sizeof(buf)/2, &requiredCapacity, fields, 5, &
status); | 1236 uregex_split(re, buf, UPRV_LENGTHOF(buf), &requiredCapacity, fields,
5, &status); |
| 1234 TEST_ASSERT_SUCCESS(status); | 1237 TEST_ASSERT_SUCCESS(status); |
| 1235 | 1238 |
| 1236 /* The TEST_ASSERT_SUCCESS call above should change too... */ | 1239 /* The TEST_ASSERT_SUCCESS call above should change too... */ |
| 1237 if(U_SUCCESS(status)) { | 1240 if(U_SUCCESS(status)) { |
| 1238 TEST_ASSERT(numFields == 5); | 1241 TEST_ASSERT(numFields == 5); |
| 1239 TEST_ASSERT_STRING("first ", fields[0], TRUE); | 1242 TEST_ASSERT_STRING("first ", fields[0], TRUE); |
| 1240 TEST_ASSERT_STRING("tag-a", fields[1], TRUE); | 1243 TEST_ASSERT_STRING("tag-a", fields[1], TRUE); |
| 1241 TEST_ASSERT_STRING(" second", fields[2], TRUE); | 1244 TEST_ASSERT_STRING(" second", fields[2], TRUE); |
| 1242 TEST_ASSERT_STRING("tag-b", fields[3], TRUE); | 1245 TEST_ASSERT_STRING("tag-b", fields[3], TRUE); |
| 1243 TEST_ASSERT_STRING(" third", fields[4], TRUE); | 1246 TEST_ASSERT_STRING(" third", fields[4], TRUE); |
| 1244 TEST_ASSERT(!memcmp(&fields[5],&minus1,sizeof(UChar*))); | 1247 TEST_ASSERT(!memcmp(&fields[5],&minus1,sizeof(UChar*))); |
| 1245 | 1248 |
| 1246 spaceNeeded = strlen("first .tag-a. second.tag-b. third."); /* "."
at NUL positions */ | 1249 spaceNeeded = strlen("first .tag-a. second.tag-b. third."); /* "."
at NUL positions */ |
| 1247 TEST_ASSERT(spaceNeeded == requiredCapacity); | 1250 TEST_ASSERT(spaceNeeded == requiredCapacity); |
| 1248 } | 1251 } |
| 1249 | 1252 |
| 1250 /* Split, end of text is a field delimiter. */ | 1253 /* Split, end of text is a field delimiter. */ |
| 1251 status = U_ZERO_ERROR; | 1254 status = U_ZERO_ERROR; |
| 1252 sz = strlen("first <tag-a> second<tag-b>"); | 1255 sz = strlen("first <tag-a> second<tag-b>"); |
| 1253 uregex_setText(re, textToSplit, sz, &status); | 1256 uregex_setText(re, textToSplit, sz, &status); |
| 1254 TEST_ASSERT_SUCCESS(status); | 1257 TEST_ASSERT_SUCCESS(status); |
| 1255 | 1258 |
| 1256 /* The TEST_ASSERT_SUCCESS call above should change too... */ | 1259 /* The TEST_ASSERT_SUCCESS call above should change too... */ |
| 1257 if(U_SUCCESS(status)) { | 1260 if(U_SUCCESS(status)) { |
| 1258 memset(fields, -1, sizeof(fields)); | 1261 memset(fields, -1, sizeof(fields)); |
| 1259 numFields = | 1262 numFields = |
| 1260 uregex_split(re, buf, sizeof(buf)/2, &requiredCapacity, fields,
9, &status); | 1263 uregex_split(re, buf, UPRV_LENGTHOF(buf), &requiredCapacity, fie
lds, 9, &status); |
| 1261 TEST_ASSERT_SUCCESS(status); | 1264 TEST_ASSERT_SUCCESS(status); |
| 1262 | 1265 |
| 1263 /* The TEST_ASSERT_SUCCESS call above should change too... */ | 1266 /* The TEST_ASSERT_SUCCESS call above should change too... */ |
| 1264 if(U_SUCCESS(status)) { | 1267 if(U_SUCCESS(status)) { |
| 1265 TEST_ASSERT(numFields == 5); | 1268 TEST_ASSERT(numFields == 5); |
| 1266 TEST_ASSERT_STRING("first ", fields[0], TRUE); | 1269 TEST_ASSERT_STRING("first ", fields[0], TRUE); |
| 1267 TEST_ASSERT_STRING("tag-a", fields[1], TRUE); | 1270 TEST_ASSERT_STRING("tag-a", fields[1], TRUE); |
| 1268 TEST_ASSERT_STRING(" second", fields[2], TRUE); | 1271 TEST_ASSERT_STRING(" second", fields[2], TRUE); |
| 1269 TEST_ASSERT_STRING("tag-b", fields[3], TRUE); | 1272 TEST_ASSERT_STRING("tag-b", fields[3], TRUE); |
| 1270 TEST_ASSERT_STRING("", fields[4], TRUE); | 1273 TEST_ASSERT_STRING("", fields[4], TRUE); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 clone2 = uregex_clone(re, &status); | 1460 clone2 = uregex_clone(re, &status); |
| 1458 TEST_ASSERT_SUCCESS(status); | 1461 TEST_ASSERT_SUCCESS(status); |
| 1459 TEST_ASSERT(clone2 != NULL); | 1462 TEST_ASSERT(clone2 != NULL); |
| 1460 uregex_close(re); | 1463 uregex_close(re); |
| 1461 | 1464 |
| 1462 status = U_ZERO_ERROR; | 1465 status = U_ZERO_ERROR; |
| 1463 clone3 = uregex_clone(clone2, &status); | 1466 clone3 = uregex_clone(clone2, &status); |
| 1464 TEST_ASSERT_SUCCESS(status); | 1467 TEST_ASSERT_SUCCESS(status); |
| 1465 TEST_ASSERT(clone3 != NULL); | 1468 TEST_ASSERT(clone3 != NULL); |
| 1466 | 1469 |
| 1467 u_uastrncpy(testString1, "abcccd", sizeof(pat)/2); | 1470 u_uastrncpy(testString1, "abcccd", UPRV_LENGTHOF(pat)); |
| 1468 u_uastrncpy(testString2, "xxxabcccd", sizeof(pat)/2); | 1471 u_uastrncpy(testString2, "xxxabcccd", UPRV_LENGTHOF(pat)); |
| 1469 | 1472 |
| 1470 status = U_ZERO_ERROR; | 1473 status = U_ZERO_ERROR; |
| 1471 uregex_setText(clone1, testString1, -1, &status); | 1474 uregex_setText(clone1, testString1, -1, &status); |
| 1472 TEST_ASSERT_SUCCESS(status); | 1475 TEST_ASSERT_SUCCESS(status); |
| 1473 result = uregex_lookingAt(clone1, 0, &status); | 1476 result = uregex_lookingAt(clone1, 0, &status); |
| 1474 TEST_ASSERT_SUCCESS(status); | 1477 TEST_ASSERT_SUCCESS(status); |
| 1475 TEST_ASSERT(result==TRUE); | 1478 TEST_ASSERT(result==TRUE); |
| 1476 | 1479 |
| 1477 status = U_ZERO_ERROR; | 1480 status = U_ZERO_ERROR; |
| 1478 uregex_setText(clone2, testString2, -1, &status); | 1481 uregex_setText(clone2, testString2, -1, &status); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1492 | 1495 |
| 1493 /* | 1496 /* |
| 1494 * pattern() and patternText() | 1497 * pattern() and patternText() |
| 1495 */ | 1498 */ |
| 1496 { | 1499 { |
| 1497 const UChar *resultPat; | 1500 const UChar *resultPat; |
| 1498 int32_t resultLen; | 1501 int32_t resultLen; |
| 1499 UText *resultText; | 1502 UText *resultText; |
| 1500 const char str_hello[] = { 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00 }; /* hell
o */ | 1503 const char str_hello[] = { 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00 }; /* hell
o */ |
| 1501 const char str_hel[] = { 0x68, 0x65, 0x6c, 0x00 }; /* hel */ | 1504 const char str_hel[] = { 0x68, 0x65, 0x6c, 0x00 }; /* hel */ |
| 1502 u_uastrncpy(pat, "hello", sizeof(pat)/2); /* for comparison */ | 1505 u_uastrncpy(pat, "hello", UPRV_LENGTHOF(pat)); /* for comparison */ |
| 1503 status = U_ZERO_ERROR; | 1506 status = U_ZERO_ERROR; |
| 1504 | 1507 |
| 1505 utext_openUTF8(&patternText, str_hello, -1, &status); | 1508 utext_openUTF8(&patternText, str_hello, -1, &status); |
| 1506 re = uregex_open(pat, -1, 0, NULL, &status); | 1509 re = uregex_open(pat, -1, 0, NULL, &status); |
| 1507 resultPat = uregex_pattern(re, &resultLen, &status); | 1510 resultPat = uregex_pattern(re, &resultLen, &status); |
| 1508 TEST_ASSERT_SUCCESS(status); | 1511 TEST_ASSERT_SUCCESS(status); |
| 1509 | 1512 |
| 1510 /* The TEST_ASSERT_SUCCESS above should change too... */ | 1513 /* The TEST_ASSERT_SUCCESS above should change too... */ |
| 1511 if (U_SUCCESS(status)) { | 1514 if (U_SUCCESS(status)) { |
| 1512 TEST_ASSERT(resultLen == -1); | 1515 TEST_ASSERT(resultLen == -1); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1595 UText *resultText; | 1598 UText *resultText; |
| 1596 const UChar *result; | 1599 const UChar *result; |
| 1597 int32_t textLength; | 1600 int32_t textLength; |
| 1598 const char str_abcccd[] = { 0x62, 0x63, 0x64, 0x64, 0x64, 0x65, 0x00 };
/* abcccd */ | 1601 const char str_abcccd[] = { 0x62, 0x63, 0x64, 0x64, 0x64, 0x65, 0x00 };
/* abcccd */ |
| 1599 const char str_abcccxd[] = { 0x62, 0x63, 0x64, 0x64, 0x64, 0x79, 0x65, 0
x00 }; /* abcccxd */ | 1602 const char str_abcccxd[] = { 0x62, 0x63, 0x64, 0x64, 0x64, 0x79, 0x65, 0
x00 }; /* abcccxd */ |
| 1600 const char str_abcd[] = { 0x62, 0x63, 0x64, 0x2b, 0x65, 0x00 }; /* abc*d
*/ | 1603 const char str_abcd[] = { 0x62, 0x63, 0x64, 0x2b, 0x65, 0x00 }; /* abc*d
*/ |
| 1601 | 1604 |
| 1602 | 1605 |
| 1603 status = U_ZERO_ERROR; | 1606 status = U_ZERO_ERROR; |
| 1604 utext_openUTF8(&text1, str_abcccd, -1, &status); | 1607 utext_openUTF8(&text1, str_abcccd, -1, &status); |
| 1605 u_uastrncpy(text2Chars, str_abcccxd, sizeof(text2)/2); | 1608 u_uastrncpy(text2Chars, str_abcccxd, UPRV_LENGTHOF(text2Chars)); |
| 1606 utext_openUChars(&text2, text2Chars, -1, &status); | 1609 utext_openUChars(&text2, text2Chars, -1, &status); |
| 1607 | 1610 |
| 1608 utext_openUTF8(&patternText, str_abcd, -1, &status); | 1611 utext_openUTF8(&patternText, str_abcd, -1, &status); |
| 1609 re = uregex_openUText(&patternText, 0, NULL, &status); | 1612 re = uregex_openUText(&patternText, 0, NULL, &status); |
| 1610 | 1613 |
| 1611 /* First set a UText */ | 1614 /* First set a UText */ |
| 1612 uregex_setUText(re, &text1, &status); | 1615 uregex_setUText(re, &text1, &status); |
| 1613 resultText = uregex_getUText(re, NULL, &status); | 1616 resultText = uregex_getUText(re, NULL, &status); |
| 1614 TEST_ASSERT_SUCCESS(status); | 1617 TEST_ASSERT_SUCCESS(status); |
| 1615 TEST_ASSERT(resultText != &text1); | 1618 TEST_ASSERT(resultText != &text1); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1691 * lookingAt() Used in setText test. | 1694 * lookingAt() Used in setText test. |
| 1692 */ | 1695 */ |
| 1693 | 1696 |
| 1694 | 1697 |
| 1695 /* | 1698 /* |
| 1696 * find(), findNext, start, end, reset | 1699 * find(), findNext, start, end, reset |
| 1697 */ | 1700 */ |
| 1698 { | 1701 { |
| 1699 UChar text1[50]; | 1702 UChar text1[50]; |
| 1700 UBool result; | 1703 UBool result; |
| 1701 u_uastrncpy(text1, "012rx5rx890rxrx...", sizeof(text1)/2); | 1704 u_uastrncpy(text1, "012rx5rx890rxrx...", UPRV_LENGTHOF(text1)); |
| 1702 status = U_ZERO_ERROR; | 1705 status = U_ZERO_ERROR; |
| 1703 re = uregex_openC("rx", 0, NULL, &status); | 1706 re = uregex_openC("rx", 0, NULL, &status); |
| 1704 | 1707 |
| 1705 uregex_setText(re, text1, -1, &status); | 1708 uregex_setText(re, text1, -1, &status); |
| 1706 result = uregex_find(re, 0, &status); | 1709 result = uregex_find(re, 0, &status); |
| 1707 TEST_ASSERT(result == TRUE); | 1710 TEST_ASSERT(result == TRUE); |
| 1708 TEST_ASSERT(uregex_start(re, 0, &status) == 3); | 1711 TEST_ASSERT(uregex_start(re, 0, &status) == 3); |
| 1709 TEST_ASSERT(uregex_end(re, 0, &status) == 5); | 1712 TEST_ASSERT(uregex_end(re, 0, &status) == 5); |
| 1710 TEST_ASSERT_SUCCESS(status); | 1713 TEST_ASSERT_SUCCESS(status); |
| 1711 | 1714 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1755 */ | 1758 */ |
| 1756 { | 1759 { |
| 1757 UChar text1[80]; | 1760 UChar text1[80]; |
| 1758 UText *actual; | 1761 UText *actual; |
| 1759 UBool result; | 1762 UBool result; |
| 1760 | 1763 |
| 1761 const char str_abcinteriordef[] = { 0x61, 0x62, 0x63, 0x20, 0x69, 0x6e,
0x74, 0x65, 0x72, 0x69, 0x6f, 0x72, 0x20, 0x64, 0x65, 0x66, 0x00 }; /* abc inter
ior def */ | 1764 const char str_abcinteriordef[] = { 0x61, 0x62, 0x63, 0x20, 0x69, 0x6e,
0x74, 0x65, 0x72, 0x69, 0x6f, 0x72, 0x20, 0x64, 0x65, 0x66, 0x00 }; /* abc inter
ior def */ |
| 1762 const char str_interior[] = { 0x20, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x69,
0x6f, 0x72, 0x20, 0x00 }; /* ' interior ' */ | 1765 const char str_interior[] = { 0x20, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x69,
0x6f, 0x72, 0x20, 0x00 }; /* ' interior ' */ |
| 1763 | 1766 |
| 1764 | 1767 |
| 1765 u_uastrncpy(text1, "noise abc interior def, and this is off the end", s
izeof(text1)/2); | 1768 u_uastrncpy(text1, "noise abc interior def, and this is off the end", U
PRV_LENGTHOF(text1)); |
| 1766 | 1769 |
| 1767 status = U_ZERO_ERROR; | 1770 status = U_ZERO_ERROR; |
| 1768 re = uregex_openC("abc(.*?)def", 0, NULL, &status); | 1771 re = uregex_openC("abc(.*?)def", 0, NULL, &status); |
| 1769 TEST_ASSERT_SUCCESS(status); | 1772 TEST_ASSERT_SUCCESS(status); |
| 1770 | 1773 |
| 1771 uregex_setText(re, text1, -1, &status); | 1774 uregex_setText(re, text1, -1, &status); |
| 1772 result = uregex_find(re, 0, &status); | 1775 result = uregex_find(re, 0, &status); |
| 1773 TEST_ASSERT(result==TRUE); | 1776 TEST_ASSERT(result==TRUE); |
| 1774 | 1777 |
| 1775 /* Capture Group 0, the full match. Should succeed. */ | 1778 /* Capture Group 0, the full match. Should succeed. */ |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1833 UChar text1[80]; | 1836 UChar text1[80]; |
| 1834 UChar text2[80]; | 1837 UChar text2[80]; |
| 1835 UText replText = UTEXT_INITIALIZER; | 1838 UText replText = UTEXT_INITIALIZER; |
| 1836 UText *result; | 1839 UText *result; |
| 1837 const char str_Replxxx[] = { 0x52, 0x65, 0x70, 0x6c, 0x61, 0x63, 0x65, 0
x20, 0x3c, 0x61, 0x61, 0x3e, 0x20, 0x78, 0x31, 0x78, 0x20, 0x78, 0x2e, 0x2e, 0x2
e, 0x78, 0x2e, 0x00 }; /* Replace <aa> x1x x...x. */ | 1840 const char str_Replxxx[] = { 0x52, 0x65, 0x70, 0x6c, 0x61, 0x63, 0x65, 0
x20, 0x3c, 0x61, 0x61, 0x3e, 0x20, 0x78, 0x31, 0x78, 0x20, 0x78, 0x2e, 0x2e, 0x2
e, 0x78, 0x2e, 0x00 }; /* Replace <aa> x1x x...x. */ |
| 1838 const char str_Nomatchhere[] = { 0x4e, 0x6f, 0x20, 0x6d, 0x61, 0x74, 0x6
3, 0x68, 0x20, 0x68, 0x65, 0x72, 0x65, 0x2e, 0x00 }; /* No match here. */ | 1841 const char str_Nomatchhere[] = { 0x4e, 0x6f, 0x20, 0x6d, 0x61, 0x74, 0x6
3, 0x68, 0x20, 0x68, 0x65, 0x72, 0x65, 0x2e, 0x00 }; /* No match here. */ |
| 1839 const char str_u00411U00000042a[] = { 0x5c, 0x5c, 0x5c, 0x75, 0x30, 0x3
0, 0x34, 0x31, 0x24, 0x31, 0x5c, 0x55, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34,
0x32, 0x24, 0x5c, 0x61, 0x00 }; /* \\\u0041$1\U00000042$\a */ | 1842 const char str_u00411U00000042a[] = { 0x5c, 0x5c, 0x5c, 0x75, 0x30, 0x3
0, 0x34, 0x31, 0x24, 0x31, 0x5c, 0x55, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34,
0x32, 0x24, 0x5c, 0x61, 0x00 }; /* \\\u0041$1\U00000042$\a */ |
| 1840 const char str_1x[] = { 0x3c, 0x24, 0x31, 0x3e, 0x00 }; /* <$1> */ | 1843 const char str_1x[] = { 0x3c, 0x24, 0x31, 0x3e, 0x00 }; /* <$1> */ |
| 1841 const char str_ReplaceAaaBax1xxx[] = { 0x52, 0x65, 0x70, 0x6c, 0x61, 0x6
3, 0x65, 0x20, 0x5c, 0x41, 0x61, 0x61, 0x42, 0x24, 0x61, 0x20, 0x78, 0x31, 0x78,
0x20, 0x78, 0x2e, 0x2e, 0x2e, 0x78, 0x2e, 0x00 }; /* Replace \AaaB$a x1x x...x.
*/ | 1844 const char str_ReplaceAaaBax1xxx[] = { 0x52, 0x65, 0x70, 0x6c, 0x61, 0x6
3, 0x65, 0x20, 0x5c, 0x41, 0x61, 0x61, 0x42, 0x24, 0x61, 0x20, 0x78, 0x31, 0x78,
0x20, 0x78, 0x2e, 0x2e, 0x2e, 0x78, 0x2e, 0x00 }; /* Replace \AaaB$a x1x x...x.
*/ |
| 1842 status = U_ZERO_ERROR; | 1845 status = U_ZERO_ERROR; |
| 1843 u_uastrncpy(text1, "Replace xaax x1x x...x.", sizeof(text1)/2); | 1846 u_uastrncpy(text1, "Replace xaax x1x x...x.", UPRV_LENGTHOF(text1)); |
| 1844 u_uastrncpy(text2, "No match here.", sizeof(text2)/2); | 1847 u_uastrncpy(text2, "No match here.", UPRV_LENGTHOF(text2)); |
| 1845 utext_openUTF8(&replText, str_1x, -1, &status); | 1848 utext_openUTF8(&replText, str_1x, -1, &status); |
| 1846 | 1849 |
| 1847 re = uregex_openC("x(.*?)x", 0, NULL, &status); | 1850 re = uregex_openC("x(.*?)x", 0, NULL, &status); |
| 1848 TEST_ASSERT_SUCCESS(status); | 1851 TEST_ASSERT_SUCCESS(status); |
| 1849 | 1852 |
| 1850 /* Normal case, with match */ | 1853 /* Normal case, with match */ |
| 1851 uregex_setText(re, text1, -1, &status); | 1854 uregex_setText(re, text1, -1, &status); |
| 1852 result = uregex_replaceFirstUText(re, &replText, NULL, &status); | 1855 result = uregex_replaceFirstUText(re, &replText, NULL, &status); |
| 1853 TEST_ASSERT_SUCCESS(status); | 1856 TEST_ASSERT_SUCCESS(status); |
| 1854 TEST_ASSERT_UTEXT(str_Replxxx, result); | 1857 TEST_ASSERT_UTEXT(str_Replxxx, result); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1879 */ | 1882 */ |
| 1880 { | 1883 { |
| 1881 UChar text1[80]; | 1884 UChar text1[80]; |
| 1882 UChar text2[80]; | 1885 UChar text2[80]; |
| 1883 UText replText = UTEXT_INITIALIZER; | 1886 UText replText = UTEXT_INITIALIZER; |
| 1884 UText *result; | 1887 UText *result; |
| 1885 const char str_1[] = { 0x3c, 0x24, 0x31, 0x3e, 0x00 }; /* <$1> */ | 1888 const char str_1[] = { 0x3c, 0x24, 0x31, 0x3e, 0x00 }; /* <$1> */ |
| 1886 const char str_Replaceaa1[] = { 0x52, 0x65, 0x70, 0x6c, 0x61, 0x63, 0x65
, 0x20, 0x3c, 0x61, 0x61, 0x3e, 0x20, 0x3c, 0x31, 0x3e, 0x20, 0x3c, 0x2e, 0x2e,
0x2e, 0x3e, 0x2e, 0x00 }; /* Replace <aa> <1> <...>. */ | 1889 const char str_Replaceaa1[] = { 0x52, 0x65, 0x70, 0x6c, 0x61, 0x63, 0x65
, 0x20, 0x3c, 0x61, 0x61, 0x3e, 0x20, 0x3c, 0x31, 0x3e, 0x20, 0x3c, 0x2e, 0x2e,
0x2e, 0x3e, 0x2e, 0x00 }; /* Replace <aa> <1> <...>. */ |
| 1887 const char str_Nomatchhere[] = { 0x4e, 0x6f, 0x20, 0x6d, 0x61, 0x74, 0x6
3, 0x68, 0x20, 0x68, 0x65, 0x72, 0x65, 0x2e, 0x00 }; /* No match here. */ | 1890 const char str_Nomatchhere[] = { 0x4e, 0x6f, 0x20, 0x6d, 0x61, 0x74, 0x6
3, 0x68, 0x20, 0x68, 0x65, 0x72, 0x65, 0x2e, 0x00 }; /* No match here. */ |
| 1888 status = U_ZERO_ERROR; | 1891 status = U_ZERO_ERROR; |
| 1889 u_uastrncpy(text1, "Replace xaax x1x x...x.", sizeof(text1)/2); | 1892 u_uastrncpy(text1, "Replace xaax x1x x...x.", UPRV_LENGTHOF(text1)); |
| 1890 u_uastrncpy(text2, "No match here.", sizeof(text2)/2); | 1893 u_uastrncpy(text2, "No match here.", UPRV_LENGTHOF(text2)); |
| 1891 utext_openUTF8(&replText, str_1, -1, &status); | 1894 utext_openUTF8(&replText, str_1, -1, &status); |
| 1892 | 1895 |
| 1893 re = uregex_openC("x(.*?)x", 0, NULL, &status); | 1896 re = uregex_openC("x(.*?)x", 0, NULL, &status); |
| 1894 TEST_ASSERT_SUCCESS(status); | 1897 TEST_ASSERT_SUCCESS(status); |
| 1895 | 1898 |
| 1896 /* Normal case, with match */ | 1899 /* Normal case, with match */ |
| 1897 uregex_setText(re, text1, -1, &status); | 1900 uregex_setText(re, text1, -1, &status); |
| 1898 result = uregex_replaceAllUText(re, &replText, NULL, &status); | 1901 result = uregex_replaceAllUText(re, &replText, NULL, &status); |
| 1899 TEST_ASSERT_SUCCESS(status); | 1902 TEST_ASSERT_SUCCESS(status); |
| 1900 TEST_ASSERT_UTEXT(str_Replaceaa1, result); | 1903 TEST_ASSERT_UTEXT(str_Replaceaa1, result); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1919 UChar text[100]; | 1922 UChar text[100]; |
| 1920 UChar repl[100]; | 1923 UChar repl[100]; |
| 1921 UChar buf[100]; | 1924 UChar buf[100]; |
| 1922 UChar *bufPtr; | 1925 UChar *bufPtr; |
| 1923 int32_t bufCap; | 1926 int32_t bufCap; |
| 1924 | 1927 |
| 1925 status = U_ZERO_ERROR; | 1928 status = U_ZERO_ERROR; |
| 1926 re = uregex_openC(".*", 0, 0, &status); | 1929 re = uregex_openC(".*", 0, 0, &status); |
| 1927 TEST_ASSERT_SUCCESS(status); | 1930 TEST_ASSERT_SUCCESS(status); |
| 1928 | 1931 |
| 1929 u_uastrncpy(text, "whatever", sizeof(text)/2); | 1932 u_uastrncpy(text, "whatever", UPRV_LENGTHOF(text)); |
| 1930 u_uastrncpy(repl, "some other", sizeof(repl)/2); | 1933 u_uastrncpy(repl, "some other", UPRV_LENGTHOF(repl)); |
| 1931 uregex_setText(re, text, -1, &status); | 1934 uregex_setText(re, text, -1, &status); |
| 1932 | 1935 |
| 1933 /* match covers whole target string */ | 1936 /* match covers whole target string */ |
| 1934 uregex_find(re, 0, &status); | 1937 uregex_find(re, 0, &status); |
| 1935 TEST_ASSERT_SUCCESS(status); | 1938 TEST_ASSERT_SUCCESS(status); |
| 1936 bufPtr = buf; | 1939 bufPtr = buf; |
| 1937 bufCap = sizeof(buf) / 2; | 1940 bufCap = UPRV_LENGTHOF(buf); |
| 1938 uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); | 1941 uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); |
| 1939 TEST_ASSERT_SUCCESS(status); | 1942 TEST_ASSERT_SUCCESS(status); |
| 1940 TEST_ASSERT_STRING("some other", buf, TRUE); | 1943 TEST_ASSERT_STRING("some other", buf, TRUE); |
| 1941 | 1944 |
| 1942 /* Match has \u \U escapes */ | 1945 /* Match has \u \U escapes */ |
| 1943 uregex_find(re, 0, &status); | 1946 uregex_find(re, 0, &status); |
| 1944 TEST_ASSERT_SUCCESS(status); | 1947 TEST_ASSERT_SUCCESS(status); |
| 1945 bufPtr = buf; | 1948 bufPtr = buf; |
| 1946 bufCap = sizeof(buf) / 2; | 1949 bufCap = UPRV_LENGTHOF(buf); |
| 1947 u_uastrncpy(repl, "abc\\u0041\\U00000042 \\\\ $ \\abc", sizeof(repl)/2); | 1950 u_uastrncpy(repl, "abc\\u0041\\U00000042 \\\\ $ \\abc", UPRV_LENGTHOF(re
pl)); |
| 1948 uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); | 1951 uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); |
| 1949 TEST_ASSERT_SUCCESS(status); | 1952 TEST_ASSERT_SUCCESS(status); |
| 1950 TEST_ASSERT_STRING("abcAB \\ $ abc", buf, TRUE); | 1953 TEST_ASSERT_STRING("abcAB \\ $ abc", buf, TRUE); |
| 1951 | 1954 |
| 1952 uregex_close(re); | 1955 uregex_close(re); |
| 1953 } | 1956 } |
| 1954 | 1957 |
| 1955 | 1958 |
| 1956 /* | 1959 /* |
| 1957 * appendReplacement(), appendTail() checked in replaceFirst(), replaceAll(
). | 1960 * appendReplacement(), appendTail() checked in replaceFirst(), replaceAll(
). |
| 1958 */ | 1961 */ |
| 1959 | 1962 |
| 1960 /* | 1963 /* |
| 1961 * splitUText() | 1964 * splitUText() |
| 1962 */ | 1965 */ |
| 1963 { | 1966 { |
| 1964 UChar textToSplit[80]; | 1967 UChar textToSplit[80]; |
| 1965 UChar text2[80]; | 1968 UChar text2[80]; |
| 1966 UText *fields[10]; | 1969 UText *fields[10]; |
| 1967 int32_t numFields; | 1970 int32_t numFields; |
| 1968 int32_t i; | 1971 int32_t i; |
| 1969 | 1972 |
| 1970 u_uastrncpy(textToSplit, "first : second: third", sizeof(textToSplit)/
2); | 1973 u_uastrncpy(textToSplit, "first : second: third", UPRV_LENGTHOF(textTo
Split)); |
| 1971 u_uastrncpy(text2, "No match here.", sizeof(text2)/2); | 1974 u_uastrncpy(text2, "No match here.", UPRV_LENGTHOF(text2)); |
| 1972 | 1975 |
| 1973 status = U_ZERO_ERROR; | 1976 status = U_ZERO_ERROR; |
| 1974 re = uregex_openC(":", 0, NULL, &status); | 1977 re = uregex_openC(":", 0, NULL, &status); |
| 1975 | 1978 |
| 1976 | 1979 |
| 1977 /* Simple split */ | 1980 /* Simple split */ |
| 1978 | 1981 |
| 1979 uregex_setText(re, textToSplit, -1, &status); | 1982 uregex_setText(re, textToSplit, -1, &status); |
| 1980 TEST_ASSERT_SUCCESS(status); | 1983 TEST_ASSERT_SUCCESS(status); |
| 1981 | 1984 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2036 } | 2039 } |
| 2037 | 2040 |
| 2038 /* splitUText(), part 2. Patterns with capture groups. The capture group t
ext | 2041 /* splitUText(), part 2. Patterns with capture groups. The capture group t
ext |
| 2039 * comes out as additional fields. */ | 2042 * comes out as additional fields. */ |
| 2040 { | 2043 { |
| 2041 UChar textToSplit[80]; | 2044 UChar textToSplit[80]; |
| 2042 UText *fields[10]; | 2045 UText *fields[10]; |
| 2043 int32_t numFields; | 2046 int32_t numFields; |
| 2044 int32_t i; | 2047 int32_t i; |
| 2045 | 2048 |
| 2046 u_uastrncpy(textToSplit, "first <tag-a> second<tag-b> third", sizeof(t
extToSplit)/2); | 2049 u_uastrncpy(textToSplit, "first <tag-a> second<tag-b> third", UPRV_LEN
GTHOF(textToSplit)); |
| 2047 | 2050 |
| 2048 status = U_ZERO_ERROR; | 2051 status = U_ZERO_ERROR; |
| 2049 re = uregex_openC("<(.*?)>", 0, NULL, &status); | 2052 re = uregex_openC("<(.*?)>", 0, NULL, &status); |
| 2050 | 2053 |
| 2051 uregex_setText(re, textToSplit, -1, &status); | 2054 uregex_setText(re, textToSplit, -1, &status); |
| 2052 TEST_ASSERT_SUCCESS(status); | 2055 TEST_ASSERT_SUCCESS(status); |
| 2053 | 2056 |
| 2054 /* The TEST_ASSERT_SUCCESS call above should change too... */ | 2057 /* The TEST_ASSERT_SUCCESS call above should change too... */ |
| 2055 if(U_SUCCESS(status)) { | 2058 if(U_SUCCESS(status)) { |
| 2056 memset(fields, 0, sizeof(fields)); | 2059 memset(fields, 0, sizeof(fields)); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2259 | 2262 |
| 2260 uregex_setTimeLimit(re, 100, &status); | 2263 uregex_setTimeLimit(re, 100, &status); |
| 2261 TEST_ASSERT_SUCCESS(status); | 2264 TEST_ASSERT_SUCCESS(status); |
| 2262 limit = uregex_getTimeLimit(re, &status); | 2265 limit = uregex_getTimeLimit(re, &status); |
| 2263 TEST_ASSERT_SUCCESS(status); | 2266 TEST_ASSERT_SUCCESS(status); |
| 2264 TEST_ASSERT(limit == 100); | 2267 TEST_ASSERT(limit == 100); |
| 2265 | 2268 |
| 2266 uregex_close(re); | 2269 uregex_close(re); |
| 2267 } | 2270 } |
| 2268 | 2271 |
| 2272 static UBool U_CALLCONV FindCallback(const void* context , int64_t matchIndex) { |
| 2273 return FALSE; |
| 2274 } |
| 2275 |
| 2276 static UBool U_CALLCONV MatchCallback(const void *context, int32_t steps) { |
| 2277 return FALSE; |
| 2278 } |
| 2279 |
| 2280 static void TestBug10815() { |
| 2281 /* Bug 10815: uregex_findNext() does not set U_REGEX_STOPPED_BY_CALLER |
| 2282 * when the callback function specified by uregex_setMatchCallbac
k() returns FALSE |
| 2283 */ |
| 2284 URegularExpression *re; |
| 2285 UErrorCode status = U_ZERO_ERROR; |
| 2286 UChar text[100]; |
| 2287 |
| 2288 |
| 2289 // findNext() with a find progress callback function. |
| 2290 |
| 2291 re = uregex_openC(".z", 0, 0, &status); |
| 2292 TEST_ASSERT_SUCCESS(status); |
| 2293 |
| 2294 u_uastrncpy(text, "Hello, World.", UPRV_LENGTHOF(text)); |
| 2295 uregex_setText(re, text, -1, &status); |
| 2296 TEST_ASSERT_SUCCESS(status); |
| 2297 |
| 2298 uregex_setFindProgressCallback(re, FindCallback, NULL, &status); |
| 2299 TEST_ASSERT_SUCCESS(status); |
| 2300 |
| 2301 uregex_findNext(re, &status); |
| 2302 TEST_ASSERT(status == U_REGEX_STOPPED_BY_CALLER); |
| 2303 |
| 2304 uregex_close(re); |
| 2305 |
| 2306 // findNext() with a match progress callback function. |
| 2307 |
| 2308 status = U_ZERO_ERROR; |
| 2309 re = uregex_openC("((xxx)*)*y", 0, 0, &status); |
| 2310 TEST_ASSERT_SUCCESS(status); |
| 2311 |
| 2312 // Pattern + this text gives an exponential time match. Without the callback
to stop the match, |
| 2313 // it will appear to be stuck in a (near) infinite loop. |
| 2314 u_uastrncpy(text, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxx", UPRV_LENGTHOF(text)); |
| 2315 uregex_setText(re, text, -1, &status); |
| 2316 TEST_ASSERT_SUCCESS(status); |
| 2317 |
| 2318 uregex_setMatchCallback(re, MatchCallback, NULL, &status); |
| 2319 TEST_ASSERT_SUCCESS(status); |
| 2320 |
| 2321 uregex_findNext(re, &status); |
| 2322 TEST_ASSERT(status == U_REGEX_STOPPED_BY_CALLER); |
| 2323 |
| 2324 uregex_close(re); |
| 2325 } |
| 2326 |
| 2269 | 2327 |
| 2270 #endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS */ | 2328 #endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS */ |
| OLD | NEW |