OLD | NEW |
1 /******************************************************************** | 1 /******************************************************************** |
2 * COPYRIGHT: | 2 * COPYRIGHT: |
3 * Copyright (c) 2005-2012, International Business Machines Corporation and | 3 * Copyright (c) 2005-2014, International Business Machines Corporation and |
4 * others. All Rights Reserved. | 4 * others. All Rights Reserved. |
5 ********************************************************************/ | 5 ********************************************************************/ |
6 /************************************************************************ | 6 /************************************************************************ |
7 * Tests for the UText and UTextIterator text abstraction classses | 7 * Tests for the UText and UTextIterator text abstraction classses |
8 * | 8 * |
9 ************************************************************************/ | 9 ************************************************************************/ |
10 | 10 |
11 #include <string.h> | 11 #include <string.h> |
12 #include <stdio.h> | 12 #include <stdio.h> |
13 #include <stdlib.h> | 13 #include <stdlib.h> |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 case 0: name = "TextTest"; | 50 case 0: name = "TextTest"; |
51 if (exec) TextTest(); break; | 51 if (exec) TextTest(); break; |
52 case 1: name = "ErrorTest"; | 52 case 1: name = "ErrorTest"; |
53 if (exec) ErrorTest(); break; | 53 if (exec) ErrorTest(); break; |
54 case 2: name = "FreezeTest"; | 54 case 2: name = "FreezeTest"; |
55 if (exec) FreezeTest(); break; | 55 if (exec) FreezeTest(); break; |
56 case 3: name = "Ticket5560"; | 56 case 3: name = "Ticket5560"; |
57 if (exec) Ticket5560(); break; | 57 if (exec) Ticket5560(); break; |
58 case 4: name = "Ticket6847"; | 58 case 4: name = "Ticket6847"; |
59 if (exec) Ticket6847(); break; | 59 if (exec) Ticket6847(); break; |
| 60 case 5: name = "Ticket10562"; |
| 61 if (exec) Ticket10562(); break; |
| 62 case 6: name = "Ticket10983"; |
| 63 if (exec) Ticket10983(); break; |
60 default: name = ""; break; | 64 default: name = ""; break; |
61 } | 65 } |
62 } | 66 } |
63 | 67 |
64 // | 68 // |
65 // Quick and dirty random number generator. | 69 // Quick and dirty random number generator. |
66 // (don't use library so that results are portable. | 70 // (don't use library so that results are portable. |
67 static uint32_t m_seed = 1; | 71 static uint32_t m_seed = 1; |
68 static uint32_t m_rand() | 72 static uint32_t m_rand() |
69 { | 73 { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 // Exercise the mapping, and the varying sized buffer. | 123 // Exercise the mapping, and the varying sized buffer. |
120 // | 124 // |
121 s.truncate(0); | 125 s.truncate(0); |
122 UChar32 c1 = 0; | 126 UChar32 c1 = 0; |
123 UChar32 c2 = 0x100; | 127 UChar32 c2 = 0x100; |
124 UChar32 c3 = 0xa000; | 128 UChar32 c3 = 0xa000; |
125 UChar32 c4 = 0x11000; | 129 UChar32 c4 = 0x11000; |
126 for (i=0; i<1000; i++) { | 130 for (i=0; i<1000; i++) { |
127 int len8 = m_rand()%4 + 1; | 131 int len8 = m_rand()%4 + 1; |
128 switch (len8) { | 132 switch (len8) { |
129 case 1: | 133 case 1: |
130 c1 = (c1+1)%0x80; | 134 c1 = (c1+1)%0x80; |
131 // don't put 0 into string (0 terminated strings for some tests) | 135 // don't put 0 into string (0 terminated strings for some tests) |
132 // don't put '\', will cause unescape() to fail. | 136 // don't put '\', will cause unescape() to fail. |
133 if (c1==0x5c || c1==0) { | 137 if (c1==0x5c || c1==0) { |
134 c1++; | 138 c1++; |
135 } | 139 } |
136 s.append(c1); | 140 s.append(c1); |
137 break; | 141 break; |
138 case 2: | 142 case 2: |
139 s.append(c2++); | 143 s.append(c2++); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 // | 175 // |
172 m *cpMap = new m[sa.length() + 1]; | 176 m *cpMap = new m[sa.length() + 1]; |
173 j = 0; | 177 j = 0; |
174 for (i=0; i<sa.length(); i=sa.moveIndex32(i, 1)) { | 178 for (i=0; i<sa.length(); i=sa.moveIndex32(i, 1)) { |
175 c = sa.char32At(i); | 179 c = sa.char32At(i); |
176 cpMap[j].nativeIdx = i; | 180 cpMap[j].nativeIdx = i; |
177 cpMap[j].cp = c; | 181 cpMap[j].cp = c; |
178 j++; | 182 j++; |
179 cpCount++; | 183 cpCount++; |
180 } | 184 } |
181 cpMap[j].nativeIdx = i; // position following the last char in utf-16 stri
ng. | 185 cpMap[j].nativeIdx = i; // position following the last char in utf-16 stri
ng. |
182 | 186 |
183 | 187 |
184 // UChar * test, null terminated | 188 // UChar * test, null terminated |
185 status = U_ZERO_ERROR; | 189 status = U_ZERO_ERROR; |
186 UChar *buf = new UChar[saLen+1]; | 190 UChar *buf = new UChar[saLen+1]; |
187 sa.extract(buf, saLen+1, status); | 191 sa.extract(buf, saLen+1, status); |
188 TEST_SUCCESS(status); | 192 TEST_SUCCESS(status); |
189 ut = utext_openUChars(NULL, buf, -1, &status); | 193 ut = utext_openUChars(NULL, buf, -1, &status); |
190 TEST_SUCCESS(status); | 194 TEST_SUCCESS(status); |
191 TestAccess(sa, ut, cpCount, cpMap); | 195 TestAccess(sa, ut, cpCount, cpMap); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 // Character Iterator Tests | 236 // Character Iterator Tests |
233 status = U_ZERO_ERROR; | 237 status = U_ZERO_ERROR; |
234 const UChar *cbuf = sa.getBuffer(); | 238 const UChar *cbuf = sa.getBuffer(); |
235 CharacterIterator *ci = new UCharCharacterIterator(cbuf, saLen, status); | 239 CharacterIterator *ci = new UCharCharacterIterator(cbuf, saLen, status); |
236 TEST_SUCCESS(status); | 240 TEST_SUCCESS(status); |
237 ut = utext_openCharacterIterator(NULL, ci, &status); | 241 ut = utext_openCharacterIterator(NULL, ci, &status); |
238 TEST_SUCCESS(status); | 242 TEST_SUCCESS(status); |
239 TestAccess(sa, ut, cpCount, cpMap); | 243 TestAccess(sa, ut, cpCount, cpMap); |
240 utext_close(ut); | 244 utext_close(ut); |
241 delete ci; | 245 delete ci; |
242 | 246 |
243 | 247 |
244 // Fragmented UnicodeString (Chunk size of one) | 248 // Fragmented UnicodeString (Chunk size of one) |
245 // | 249 // |
246 status = U_ZERO_ERROR; | 250 status = U_ZERO_ERROR; |
247 ut = openFragmentedUnicodeString(NULL, &sa, &status); | 251 ut = openFragmentedUnicodeString(NULL, &sa, &status); |
248 TEST_SUCCESS(status); | 252 TEST_SUCCESS(status); |
249 TestAccess(sa, ut, cpCount, cpMap); | 253 TestAccess(sa, ut, cpCount, cpMap); |
250 utext_close(ut); | 254 utext_close(ut); |
251 | 255 |
252 // | 256 // |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 | 288 |
285 // TestCMR test Copy, Move and Replace operations. | 289 // TestCMR test Copy, Move and Replace operations. |
286 // us UnicodeString containing the test text. | 290 // us UnicodeString containing the test text. |
287 // ut UText containing the same test text. | 291 // ut UText containing the same test text. |
288 // cpCount number of code points in the test text. | 292 // cpCount number of code points in the test text. |
289 // nativeMap Mapping from code points to native indexes for the UT
ext. | 293 // nativeMap Mapping from code points to native indexes for the UT
ext. |
290 // u16Map Mapping from code points to UTF-16 indexes, for use w
ith the UnicodeString. | 294 // u16Map Mapping from code points to UTF-16 indexes, for use w
ith the UnicodeString. |
291 // | 295 // |
292 // This function runs a whole series of opertions on each incoming UText. | 296 // This function runs a whole series of opertions on each incoming UText. |
293 // The UText is deep-cloned prior to each operation, so that the original UT
ext remains unchanged. | 297 // The UText is deep-cloned prior to each operation, so that the original UT
ext remains unchanged. |
294 // | 298 // |
295 void UTextTest::TestCMR(const UnicodeString &us, UText *ut, int cpCount, m *nati
veMap, m *u16Map) { | 299 void UTextTest::TestCMR(const UnicodeString &us, UText *ut, int cpCount, m *nati
veMap, m *u16Map) { |
296 TEST_ASSERT(utext_isWritable(ut) == TRUE); | 300 TEST_ASSERT(utext_isWritable(ut) == TRUE); |
297 | 301 |
298 int srcLengthType; // Loop variables for selecting the postion and le
ngth | 302 int srcLengthType; // Loop variables for selecting the postion and le
ngth |
299 int srcPosType; // of the block to operate on within the source
text. | 303 int srcPosType; // of the block to operate on within the source
text. |
300 int destPosType; | 304 int destPosType; |
301 | 305 |
302 int srcIndex = 0; // Code Point indexes of the block to operate on f
or | 306 int srcIndex = 0; // Code Point indexes of the block to operate on f
or |
303 int srcLength = 0; // a specific test. | 307 int srcLength = 0; // a specific test. |
304 | 308 |
305 int destIndex = 0; // Code point index of the destination for a copy/
move test. | 309 int destIndex = 0; // Code point index of the destination for a copy/
move test. |
306 | 310 |
307 int32_t nativeStart = 0; // Native unit indexes for a test. | 311 int32_t nativeStart = 0; // Native unit indexes for a test. |
308 int32_t nativeLimit = 0; | 312 int32_t nativeLimit = 0; |
309 int32_t nativeDest = 0; | 313 int32_t nativeDest = 0; |
310 | 314 |
(...skipping 12 matching lines...) Expand all Loading... |
323 } | 327 } |
324 for (srcPosType=1; srcPosType<=5; srcPosType++) { | 328 for (srcPosType=1; srcPosType<=5; srcPosType++) { |
325 switch (srcPosType) { | 329 switch (srcPosType) { |
326 case 1: srcIndex = 0; break; | 330 case 1: srcIndex = 0; break; |
327 case 2: srcIndex = 1; break; | 331 case 2: srcIndex = 1; break; |
328 case 3: srcIndex = cpCount - srcLength; break; | 332 case 3: srcIndex = cpCount - srcLength; break; |
329 case 4: srcIndex = cpCount - srcLength - 1; break; | 333 case 4: srcIndex = cpCount - srcLength - 1; break; |
330 case 5: srcIndex = cpCount / 2; break; | 334 case 5: srcIndex = cpCount / 2; break; |
331 } | 335 } |
332 if (srcIndex < 0 || srcIndex + srcLength > cpCount) { | 336 if (srcIndex < 0 || srcIndex + srcLength > cpCount) { |
333 // filter out bogus test cases - | 337 // filter out bogus test cases - |
334 // those with a source range that falls of an edge of the stri
ng. | 338 // those with a source range that falls of an edge of the stri
ng. |
335 continue; | 339 continue; |
336 } | 340 } |
337 | 341 |
338 // | 342 // |
339 // Copy and move tests. | 343 // Copy and move tests. |
340 // iterate over a variety of destination positions. | 344 // iterate over a variety of destination positions. |
341 // | 345 // |
342 for (destPosType=1; destPosType<=4; destPosType++) { | 346 for (destPosType=1; destPosType<=4; destPosType++) { |
343 switch (destPosType) { | 347 switch (destPosType) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 } | 398 } |
395 | 399 |
396 } | 400 } |
397 | 401 |
398 // | 402 // |
399 // TestCopyMove run a single test case for utext_copy. | 403 // TestCopyMove run a single test case for utext_copy. |
400 // Test cases are created in TestCMR and dispatched here for e
xecution. | 404 // Test cases are created in TestCMR and dispatched here for e
xecution. |
401 // | 405 // |
402 void UTextTest::TestCopyMove(const UnicodeString &us, UText *ut, UBool move, | 406 void UTextTest::TestCopyMove(const UnicodeString &us, UText *ut, UBool move, |
403 int32_t nativeStart, int32_t nativeLimit, int32_t nativeDest
, | 407 int32_t nativeStart, int32_t nativeLimit, int32_t nativeDest
, |
404 int32_t u16Start, int32_t u16Limit, int32_t u16Dest) | 408 int32_t u16Start, int32_t u16Limit, int32_t u16Dest) |
405 { | 409 { |
406 UErrorCode status = U_ZERO_ERROR; | 410 UErrorCode status = U_ZERO_ERROR; |
407 UText *targetUT = NULL; | 411 UText *targetUT = NULL; |
408 gTestNum++; | 412 gTestNum++; |
409 gFailed = FALSE; | 413 gFailed = FALSE; |
410 | 414 |
411 // | 415 // |
412 // clone the UText. The test will be run in the cloned copy | 416 // clone the UText. The test will be run in the cloned copy |
413 // so that we don't alter the original. | 417 // so that we don't alter the original. |
414 // | 418 // |
(...skipping 16 matching lines...) Expand all Loading... |
431 // Do the same operation in the UText under test | 435 // Do the same operation in the UText under test |
432 utext_copy(targetUT, nativeStart, nativeLimit, nativeDest, move, &status); | 436 utext_copy(targetUT, nativeStart, nativeLimit, nativeDest, move, &status); |
433 if (nativeDest > nativeStart && nativeDest < nativeLimit) { | 437 if (nativeDest > nativeStart && nativeDest < nativeLimit) { |
434 TEST_ASSERT(status == U_INDEX_OUTOFBOUNDS_ERROR); | 438 TEST_ASSERT(status == U_INDEX_OUTOFBOUNDS_ERROR); |
435 } else { | 439 } else { |
436 TEST_SUCCESS(status); | 440 TEST_SUCCESS(status); |
437 | 441 |
438 // Compare the results of the two parallel tests | 442 // Compare the results of the two parallel tests |
439 int32_t usi = 0; // UnicodeString postion, utf-16 index. | 443 int32_t usi = 0; // UnicodeString postion, utf-16 index. |
440 int64_t uti = 0; // UText position, native index. | 444 int64_t uti = 0; // UText position, native index. |
441 int32_t cpi; // char32 position (code point index) | 445 int32_t cpi; // char32 position (code point index) |
442 UChar32 usc; // code point from Unicode String | 446 UChar32 usc; // code point from Unicode String |
443 UChar32 utc; // code point from UText | 447 UChar32 utc; // code point from UText |
444 utext_setNativeIndex(targetUT, 0); | 448 utext_setNativeIndex(targetUT, 0); |
445 for (cpi=0; ; cpi++) { | 449 for (cpi=0; ; cpi++) { |
446 usc = targetUS.char32At(usi); | 450 usc = targetUS.char32At(usi); |
447 utc = utext_next32(targetUT); | 451 utc = utext_next32(targetUT); |
448 if (utc < 0) { | 452 if (utc < 0) { |
449 break; | 453 break; |
450 } | 454 } |
451 TEST_ASSERT(uti == usi); | 455 TEST_ASSERT(uti == usi); |
452 TEST_ASSERT(utc == usc); | 456 TEST_ASSERT(utc == usc); |
453 usi = targetUS.moveIndex32(usi, 1); | 457 usi = targetUS.moveIndex32(usi, 1); |
454 uti = utext_getNativeIndex(targetUT); | 458 uti = utext_getNativeIndex(targetUT); |
455 if (gFailed) { | 459 if (gFailed) { |
456 goto cleanupAndReturn; | 460 goto cleanupAndReturn; |
457 } | 461 } |
458 } | 462 } |
459 int64_t expectedNativeLength = utext_nativeLength(ut); | 463 int64_t expectedNativeLength = utext_nativeLength(ut); |
460 if (move == FALSE) { | 464 if (move == FALSE) { |
461 expectedNativeLength += nativeLimit - nativeStart; | 465 expectedNativeLength += nativeLimit - nativeStart; |
462 } | 466 } |
463 uti = utext_getNativeIndex(targetUT); | 467 uti = utext_getNativeIndex(targetUT); |
464 TEST_ASSERT(uti == expectedNativeLength); | 468 TEST_ASSERT(uti == expectedNativeLength); |
465 } | 469 } |
466 | 470 |
467 cleanupAndReturn: | 471 cleanupAndReturn: |
468 utext_close(targetUT); | 472 utext_close(targetUT); |
469 } | 473 } |
470 | 474 |
471 | 475 |
472 // | 476 // |
473 // TestReplace Test a single Replace operation. | 477 // TestReplace Test a single Replace operation. |
474 // | 478 // |
475 void UTextTest::TestReplace( | 479 void UTextTest::TestReplace( |
476 const UnicodeString &us, // reference UnicodeString in which to
do the replace | 480 const UnicodeString &us, // reference UnicodeString in which to
do the replace |
477 UText *ut, // UnicodeText object under test. | 481 UText *ut, // UnicodeText object under test. |
478 int32_t nativeStart, // Range to be replaced, in UText
native units. | 482 int32_t nativeStart, // Range to be replaced, in UText
native units. |
479 int32_t nativeLimit, | 483 int32_t nativeLimit, |
480 int32_t u16Start, // Range to be replaced, in UTF-16
units | 484 int32_t u16Start, // Range to be replaced, in UTF-16
units |
481 int32_t u16Limit, // for use in the reference Uni
codeString. | 485 int32_t u16Limit, // for use in the reference Uni
codeString. |
482 const UnicodeString &repStr) // The replacement string | 486 const UnicodeString &repStr) // The replacement string |
483 { | 487 { |
484 UErrorCode status = U_ZERO_ERROR; | 488 UErrorCode status = U_ZERO_ERROR; |
485 UText *targetUT = NULL; | 489 UText *targetUT = NULL; |
486 gTestNum++; | 490 gTestNum++; |
487 gFailed = FALSE; | 491 gFailed = FALSE; |
488 | 492 |
489 // | 493 // |
490 // clone the target UText. The test will be run in the cloned copy | 494 // clone the target UText. The test will be run in the cloned copy |
491 // so that we don't alter the original. | 495 // so that we don't alter the original. |
492 // | 496 // |
493 targetUT = utext_clone(NULL, ut, TRUE, FALSE, &status); | 497 targetUT = utext_clone(NULL, ut, TRUE, FALSE, &status); |
494 TEST_SUCCESS(status); | 498 TEST_SUCCESS(status); |
495 UnicodeString targetUS(us); // And copy the reference string. | 499 UnicodeString targetUS(us); // And copy the reference string. |
496 | 500 |
497 // | 501 // |
498 // Do the replace operation in the Unicode String, to | 502 // Do the replace operation in the Unicode String, to |
499 // produce a reference result. | 503 // produce a reference result. |
500 // | 504 // |
501 targetUS.replace(u16Start, u16Limit-u16Start, repStr); | 505 targetUS.replace(u16Start, u16Limit-u16Start, repStr); |
502 | 506 |
503 // | 507 // |
504 // Do the replace on the UText under test | 508 // Do the replace on the UText under test |
505 // | 509 // |
506 const UChar *rs = repStr.getBuffer(); | 510 const UChar *rs = repStr.getBuffer(); |
507 int32_t rsLen = repStr.length(); | 511 int32_t rsLen = repStr.length(); |
508 int32_t actualDelta = utext_replace(targetUT, nativeStart, nativeLimit, rs,
rsLen, &status); | 512 int32_t actualDelta = utext_replace(targetUT, nativeStart, nativeLimit, rs,
rsLen, &status); |
509 int32_t expectedDelta = repStr.length() - (nativeLimit - nativeStart); | 513 int32_t expectedDelta = repStr.length() - (nativeLimit - nativeStart); |
510 TEST_ASSERT(actualDelta == expectedDelta); | 514 TEST_ASSERT(actualDelta == expectedDelta); |
511 | 515 |
512 // | 516 // |
513 // Compare the results | 517 // Compare the results |
514 // | 518 // |
515 int32_t usi = 0; // UnicodeString postion, utf-16 index. | 519 int32_t usi = 0; // UnicodeString postion, utf-16 index. |
516 int64_t uti = 0; // UText position, native index. | 520 int64_t uti = 0; // UText position, native index. |
517 int32_t cpi; // char32 position (code point index) | 521 int32_t cpi; // char32 position (code point index) |
518 UChar32 usc; // code point from Unicode String | 522 UChar32 usc; // code point from Unicode String |
519 UChar32 utc; // code point from UText | 523 UChar32 utc; // code point from UText |
520 int64_t expectedNativeLength = 0; | 524 int64_t expectedNativeLength = 0; |
521 utext_setNativeIndex(targetUT, 0); | 525 utext_setNativeIndex(targetUT, 0); |
522 for (cpi=0; ; cpi++) { | 526 for (cpi=0; ; cpi++) { |
523 usc = targetUS.char32At(usi); | 527 usc = targetUS.char32At(usi); |
524 utc = utext_next32(targetUT); | 528 utc = utext_next32(targetUT); |
525 if (utc < 0) { | 529 if (utc < 0) { |
526 break; | 530 break; |
527 } | 531 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 status = U_ZERO_ERROR; | 569 status = U_ZERO_ERROR; |
566 utext_setNativeIndex(shallowClone, 0); | 570 utext_setNativeIndex(shallowClone, 0); |
567 UText *deepClone = utext_clone(NULL, shallowClone, TRUE, FALSE, &status); | 571 UText *deepClone = utext_clone(NULL, shallowClone, TRUE, FALSE, &status); |
568 utext_close(shallowClone); | 572 utext_close(shallowClone); |
569 if (status != U_UNSUPPORTED_ERROR) { | 573 if (status != U_UNSUPPORTED_ERROR) { |
570 TEST_SUCCESS(status); | 574 TEST_SUCCESS(status); |
571 TestAccessNoClone(us, deepClone, cpCount, cpMap); | 575 TestAccessNoClone(us, deepClone, cpCount, cpMap); |
572 } | 576 } |
573 utext_close(deepClone); | 577 utext_close(deepClone); |
574 } | 578 } |
575 | 579 |
576 | 580 |
577 // | 581 // |
578 // TestAccessNoClone() Test the read only access functions on a UText. | 582 // TestAccessNoClone() Test the read only access functions on a UText. |
579 // The text is accessed in a variety of ways, and compar
ed with | 583 // The text is accessed in a variety of ways, and compar
ed with |
580 // the reference UnicodeString. | 584 // the reference UnicodeString. |
581 // | 585 // |
582 void UTextTest::TestAccessNoClone(const UnicodeString &us, UText *ut, int cpCoun
t, m *cpMap) { | 586 void UTextTest::TestAccessNoClone(const UnicodeString &us, UText *ut, int cpCoun
t, m *cpMap) { |
583 UErrorCode status = U_ZERO_ERROR; | 587 UErrorCode status = U_ZERO_ERROR; |
584 gTestNum++; | 588 gTestNum++; |
585 | 589 |
(...skipping 14 matching lines...) Expand all Loading... |
600 int64_t foundIndex = 0; | 604 int64_t foundIndex = 0; |
601 UChar32 expectedC; | 605 UChar32 expectedC; |
602 UChar32 foundC; | 606 UChar32 foundC; |
603 int64_t len; | 607 int64_t len; |
604 | 608 |
605 for (i=0; i<cpCount; i++) { | 609 for (i=0; i<cpCount; i++) { |
606 expectedIndex = cpMap[i].nativeIdx; | 610 expectedIndex = cpMap[i].nativeIdx; |
607 foundIndex = utext_getNativeIndex(ut); | 611 foundIndex = utext_getNativeIndex(ut); |
608 TEST_ASSERT(expectedIndex == foundIndex); | 612 TEST_ASSERT(expectedIndex == foundIndex); |
609 expectedC = cpMap[i].cp; | 613 expectedC = cpMap[i].cp; |
610 foundC = utext_next32(ut); | 614 foundC = utext_next32(ut); |
611 TEST_ASSERT(expectedC == foundC); | 615 TEST_ASSERT(expectedC == foundC); |
612 foundIndex = utext_getPreviousNativeIndex(ut); | 616 foundIndex = utext_getPreviousNativeIndex(ut); |
613 TEST_ASSERT(expectedIndex == foundIndex); | 617 TEST_ASSERT(expectedIndex == foundIndex); |
614 if (gFailed) { | 618 if (gFailed) { |
615 return; | 619 return; |
616 } | 620 } |
617 } | 621 } |
618 foundC = utext_next32(ut); | 622 foundC = utext_next32(ut); |
619 TEST_ASSERT(foundC == U_SENTINEL); | 623 TEST_ASSERT(foundC == U_SENTINEL); |
620 | 624 |
621 // Repeat above, using macros | 625 // Repeat above, using macros |
622 utext_setNativeIndex(ut, 0); | 626 utext_setNativeIndex(ut, 0); |
623 for (i=0; i<cpCount; i++) { | 627 for (i=0; i<cpCount; i++) { |
624 expectedIndex = cpMap[i].nativeIdx; | 628 expectedIndex = cpMap[i].nativeIdx; |
625 foundIndex = UTEXT_GETNATIVEINDEX(ut); | 629 foundIndex = UTEXT_GETNATIVEINDEX(ut); |
626 TEST_ASSERT(expectedIndex == foundIndex); | 630 TEST_ASSERT(expectedIndex == foundIndex); |
627 expectedC = cpMap[i].cp; | 631 expectedC = cpMap[i].cp; |
628 foundC = UTEXT_NEXT32(ut); | 632 foundC = UTEXT_NEXT32(ut); |
629 TEST_ASSERT(expectedC == foundC); | 633 TEST_ASSERT(expectedC == foundC); |
630 if (gFailed) { | 634 if (gFailed) { |
631 return; | 635 return; |
632 } | 636 } |
633 } | 637 } |
634 foundC = UTEXT_NEXT32(ut); | 638 foundC = UTEXT_NEXT32(ut); |
635 TEST_ASSERT(foundC == U_SENTINEL); | 639 TEST_ASSERT(foundC == U_SENTINEL); |
636 | 640 |
637 // | 641 // |
638 // Forward iteration (above) should have left index at the | 642 // Forward iteration (above) should have left index at the |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR); | 834 TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR); |
831 } | 835 } |
832 } | 836 } |
833 | 837 |
834 delete []buf; | 838 delete []buf; |
835 } | 839 } |
836 | 840 |
837 // | 841 // |
838 // ErrorTest() Check various error and edge cases. | 842 // ErrorTest() Check various error and edge cases. |
839 // | 843 // |
840 void UTextTest::ErrorTest() | 844 void UTextTest::ErrorTest() |
841 { | 845 { |
842 // Close of an unitialized UText. Shouldn't blow up. | 846 // Close of an unitialized UText. Shouldn't blow up. |
843 { | 847 { |
844 UText ut; | 848 UText ut; |
845 memset(&ut, 0, sizeof(UText)); | 849 memset(&ut, 0, sizeof(UText)); |
846 utext_close(&ut); | 850 utext_close(&ut); |
847 utext_close(NULL); | 851 utext_close(NULL); |
848 } | 852 } |
849 | 853 |
850 // Double-close of a UText. Shouldn't blow up. UText should still be usabl
e. | 854 // Double-close of a UText. Shouldn't blow up. UText should still be usabl
e. |
851 { | 855 { |
852 UErrorCode status = U_ZERO_ERROR; | 856 UErrorCode status = U_ZERO_ERROR; |
853 UText ut = UTEXT_INITIALIZER; | 857 UText ut = UTEXT_INITIALIZER; |
854 UnicodeString s("Hello, World"); | 858 UnicodeString s("Hello, World"); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 utp = utext_openUnicodeString(&ut, &s1, &status); | 903 utp = utext_openUnicodeString(&ut, &s1, &status); |
900 TEST_SUCCESS(status); | 904 TEST_SUCCESS(status); |
901 TEST_ASSERT(utp == &ut); | 905 TEST_ASSERT(utp == &ut); |
902 } | 906 } |
903 | 907 |
904 // Invalid parameters on open | 908 // Invalid parameters on open |
905 // | 909 // |
906 { | 910 { |
907 UErrorCode status = U_ZERO_ERROR; | 911 UErrorCode status = U_ZERO_ERROR; |
908 UText ut = UTEXT_INITIALIZER; | 912 UText ut = UTEXT_INITIALIZER; |
909 | 913 |
910 utext_openUChars(&ut, NULL, 5, &status); | 914 utext_openUChars(&ut, NULL, 5, &status); |
911 TEST_ASSERT(status == U_ILLEGAL_ARGUMENT_ERROR); | 915 TEST_ASSERT(status == U_ILLEGAL_ARGUMENT_ERROR); |
912 | 916 |
913 status = U_ZERO_ERROR; | 917 status = U_ZERO_ERROR; |
914 utext_openUChars(&ut, NULL, -1, &status); | 918 utext_openUChars(&ut, NULL, -1, &status); |
915 TEST_ASSERT(status == U_ILLEGAL_ARGUMENT_ERROR); | 919 TEST_ASSERT(status == U_ILLEGAL_ARGUMENT_ERROR); |
916 | 920 |
917 status = U_ZERO_ERROR; | 921 status = U_ZERO_ERROR; |
918 utext_openUTF8(&ut, NULL, 4, &status); | 922 utext_openUTF8(&ut, NULL, 4, &status); |
919 TEST_ASSERT(status == U_ILLEGAL_ARGUMENT_ERROR); | 923 TEST_ASSERT(status == U_ILLEGAL_ARGUMENT_ERROR); |
920 | 924 |
921 status = U_ZERO_ERROR; | 925 status = U_ZERO_ERROR; |
922 utext_openUTF8(&ut, NULL, -1, &status); | 926 utext_openUTF8(&ut, NULL, -1, &status); |
923 TEST_ASSERT(status == U_ILLEGAL_ARGUMENT_ERROR); | 927 TEST_ASSERT(status == U_ILLEGAL_ARGUMENT_ERROR); |
924 } | 928 } |
925 | 929 |
926 // | 930 // |
927 // UTF-8 with malformed sequences. | 931 // UTF-8 with malformed sequences. |
928 // These should come through as the Unicode replacement char, \ufffd | 932 // These should come through as the Unicode replacement char, \ufffd |
929 // | 933 // |
930 { | 934 { |
931 UErrorCode status = U_ZERO_ERROR; | 935 UErrorCode status = U_ZERO_ERROR; |
932 UText *ut = NULL; | 936 UText *ut = NULL; |
933 const char *badUTF8 = "\x41\x81\x42\xf0\x81\x81\x43"; | 937 const char *badUTF8 = "\x41\x81\x42\xf0\x81\x81\x43"; |
934 UChar32 c; | 938 UChar32 c; |
935 | 939 |
936 ut = utext_openUTF8(NULL, badUTF8, -1, &status); | 940 ut = utext_openUTF8(NULL, badUTF8, -1, &status); |
937 TEST_SUCCESS(status); | 941 TEST_SUCCESS(status); |
938 c = utext_char32At(ut, 1); | 942 c = utext_char32At(ut, 1); |
939 TEST_ASSERT(c == 0xfffd); | 943 TEST_ASSERT(c == 0xfffd); |
940 c = utext_char32At(ut, 3); | 944 c = utext_char32At(ut, 3); |
941 TEST_ASSERT(c == 0xfffd); | 945 TEST_ASSERT(c == 0xfffd); |
942 c = utext_char32At(ut, 5); | 946 c = utext_char32At(ut, 5); |
943 TEST_ASSERT(c == 0xfffd); | 947 TEST_ASSERT(c == 0xfffd); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 } | 990 } |
987 | 991 |
988 // | 992 // |
989 // Index to positions not on code point boundaries. | 993 // Index to positions not on code point boundaries. |
990 // | 994 // |
991 { | 995 { |
992 const char *u8str = "\xc8\x81\xe1\x82\x83\xf1\x84\x85\x86"; | 996 const char *u8str = "\xc8\x81\xe1\x82\x83\xf1\x84\x85\x86"; |
993 int32_t startMap[] = { 0, 0, 2, 2, 2, 5, 5, 5, 5, 9,
9}; | 997 int32_t startMap[] = { 0, 0, 2, 2, 2, 5, 5, 5, 5, 9,
9}; |
994 int32_t nextMap[] = { 2, 2, 5, 5, 5, 9, 9, 9, 9, 9,
9}; | 998 int32_t nextMap[] = { 2, 2, 5, 5, 5, 9, 9, 9, 9, 9,
9}; |
995 int32_t prevMap[] = { 0, 0, 0, 0, 0, 2, 2, 2, 2, 5,
5}; | 999 int32_t prevMap[] = { 0, 0, 0, 0, 0, 2, 2, 2, 2, 5,
5}; |
996 UChar32 c32Map[] = {0x201, 0x201, 0x1083, 0x1083, 0x1083, 0x044146,
0x044146, 0x044146, 0x044146, -1, -1}; | 1000 UChar32 c32Map[] = {0x201, 0x201, 0x1083, 0x1083, 0x1083, 0x044146,
0x044146, 0x044146, 0x044146, -1, -1}; |
997 UChar32 pr32Map[] = { -1, -1, 0x201, 0x201, 0x201, 0x1083,
0x1083, 0x1083, 0x1083, 0x044146, 0x044146}; | 1001 UChar32 pr32Map[] = { -1, -1, 0x201, 0x201, 0x201, 0x1083,
0x1083, 0x1083, 0x1083, 0x044146, 0x044146}; |
998 | 1002 |
999 // extractLen is the size, in UChars, of what will be extracted between
index and index+1. | 1003 // extractLen is the size, in UChars, of what will be extracted between
index and index+1. |
1000 // is zero when both index positions lie within the same code point. | 1004 // is zero when both index positions lie within the same code point. |
1001 int32_t exLen[] = { 0, 1, 0, 0, 1, 0, 0, 0, 2, 0,
0}; | 1005 int32_t exLen[] = { 0, 1, 0, 0, 1, 0, 0, 0, 2, 0,
0}; |
1002 | 1006 |
1003 | 1007 |
1004 UErrorCode status = U_ZERO_ERROR; | 1008 UErrorCode status = U_ZERO_ERROR; |
1005 UText *ut = utext_openUTF8(NULL, u8str, -1, &status); | 1009 UText *ut = utext_openUTF8(NULL, u8str, -1, &status); |
1006 TEST_SUCCESS(status); | 1010 TEST_SUCCESS(status); |
1007 | 1011 |
(...skipping 16 matching lines...) Expand all Loading... |
1024 TEST_ASSERT(cpIndex == startMap[i]); | 1028 TEST_ASSERT(cpIndex == startMap[i]); |
1025 } | 1029 } |
1026 | 1030 |
1027 // Check utext_next32From | 1031 // Check utext_next32From |
1028 for (i=0; i<startMapLimit; i++) { | 1032 for (i=0; i<startMapLimit; i++) { |
1029 UChar32 c32 = utext_next32From(ut, i); | 1033 UChar32 c32 = utext_next32From(ut, i); |
1030 TEST_ASSERT(c32 == c32Map[i]); | 1034 TEST_ASSERT(c32 == c32Map[i]); |
1031 int64_t cpIndex = utext_getNativeIndex(ut); | 1035 int64_t cpIndex = utext_getNativeIndex(ut); |
1032 TEST_ASSERT(cpIndex == nextMap[i]); | 1036 TEST_ASSERT(cpIndex == nextMap[i]); |
1033 } | 1037 } |
1034 | 1038 |
1035 // check utext_previous32From | 1039 // check utext_previous32From |
1036 for (i=0; i<startMapLimit; i++) { | 1040 for (i=0; i<startMapLimit; i++) { |
1037 gTestNum++; | 1041 gTestNum++; |
1038 UChar32 c32 = utext_previous32From(ut, i); | 1042 UChar32 c32 = utext_previous32From(ut, i); |
1039 TEST_ASSERT(c32 == pr32Map[i]); | 1043 TEST_ASSERT(c32 == pr32Map[i]); |
1040 int64_t cpIndex = utext_getNativeIndex(ut); | 1044 int64_t cpIndex = utext_getNativeIndex(ut); |
1041 TEST_ASSERT(cpIndex == prevMap[i]); | 1045 TEST_ASSERT(cpIndex == prevMap[i]); |
1042 } | 1046 } |
1043 | 1047 |
1044 // check Extract | 1048 // check Extract |
(...skipping 12 matching lines...) Expand all Loading... |
1057 TEST_ASSERT(c32 == c32Map[i]); | 1061 TEST_ASSERT(c32 == c32Map[i]); |
1058 } | 1062 } |
1059 } | 1063 } |
1060 | 1064 |
1061 utext_close(ut); | 1065 utext_close(ut); |
1062 } | 1066 } |
1063 | 1067 |
1064 | 1068 |
1065 { // Similar test, with utf16 instead of utf8 | 1069 { // Similar test, with utf16 instead of utf8 |
1066 // TODO: merge the common parts of these tests. | 1070 // TODO: merge the common parts of these tests. |
1067 | 1071 |
1068 UnicodeString u16str("\\u1000\\U00011000\\u2000\\U00022000", -1, US_INV)
; | 1072 UnicodeString u16str("\\u1000\\U00011000\\u2000\\U00022000", -1, US_INV)
; |
1069 int32_t startMap[] ={ 0, 1, 1, 3, 4, 4, 6, 6}; | 1073 int32_t startMap[] ={ 0, 1, 1, 3, 4, 4, 6, 6}; |
1070 int32_t nextMap[] = { 1, 3, 3, 4, 6, 6, 6, 6}; | 1074 int32_t nextMap[] = { 1, 3, 3, 4, 6, 6, 6, 6}; |
1071 int32_t prevMap[] = { 0, 0, 0, 1, 3, 3, 4, 4}; | 1075 int32_t prevMap[] = { 0, 0, 0, 1, 3, 3, 4, 4}; |
1072 UChar32 c32Map[] = {0x1000, 0x11000, 0x11000, 0x2000, 0x22000, 0x2200
0, -1, -1}; | 1076 UChar32 c32Map[] = {0x1000, 0x11000, 0x11000, 0x2000, 0x22000, 0x2200
0, -1, -1}; |
1073 UChar32 pr32Map[] = { -1, 0x1000, 0x1000, 0x11000, 0x2000, 0x2000
, 0x22000, 0x22000}; | 1077 UChar32 pr32Map[] = { -1, 0x1000, 0x1000, 0x11000, 0x2000, 0x2000
, 0x22000, 0x22000}; |
1074 int32_t exLen[] = { 1, 0, 2, 1, 0, 2, 0, 0,}; | 1078 int32_t exLen[] = { 1, 0, 2, 1, 0, 2, 0, 0,}; |
1075 | 1079 |
1076 u16str = u16str.unescape(); | 1080 u16str = u16str.unescape(); |
1077 UErrorCode status = U_ZERO_ERROR; | 1081 UErrorCode status = U_ZERO_ERROR; |
1078 UText *ut = utext_openUnicodeString(NULL, &u16str, &status); | 1082 UText *ut = utext_openUnicodeString(NULL, &u16str, &status); |
1079 TEST_SUCCESS(status); | 1083 TEST_SUCCESS(status); |
1080 | 1084 |
1081 int32_t startMapLimit = sizeof(startMap) / sizeof(int32_t); | 1085 int32_t startMapLimit = sizeof(startMap) / sizeof(int32_t); |
1082 int i; | 1086 int i; |
1083 for (i=0; i<startMapLimit; i++) { | 1087 for (i=0; i<startMapLimit; i++) { |
(...skipping 10 matching lines...) Expand all Loading... |
1094 TEST_ASSERT(cpIndex == startMap[i]); | 1098 TEST_ASSERT(cpIndex == startMap[i]); |
1095 } | 1099 } |
1096 | 1100 |
1097 // Check utext_next32From | 1101 // Check utext_next32From |
1098 for (i=0; i<startMapLimit; i++) { | 1102 for (i=0; i<startMapLimit; i++) { |
1099 UChar32 c32 = utext_next32From(ut, i); | 1103 UChar32 c32 = utext_next32From(ut, i); |
1100 TEST_ASSERT(c32 == c32Map[i]); | 1104 TEST_ASSERT(c32 == c32Map[i]); |
1101 int64_t cpIndex = utext_getNativeIndex(ut); | 1105 int64_t cpIndex = utext_getNativeIndex(ut); |
1102 TEST_ASSERT(cpIndex == nextMap[i]); | 1106 TEST_ASSERT(cpIndex == nextMap[i]); |
1103 } | 1107 } |
1104 | 1108 |
1105 // check utext_previous32From | 1109 // check utext_previous32From |
1106 for (i=0; i<startMapLimit; i++) { | 1110 for (i=0; i<startMapLimit; i++) { |
1107 UChar32 c32 = utext_previous32From(ut, i); | 1111 UChar32 c32 = utext_previous32From(ut, i); |
1108 TEST_ASSERT(c32 == pr32Map[i]); | 1112 TEST_ASSERT(c32 == pr32Map[i]); |
1109 int64_t cpIndex = utext_getNativeIndex(ut); | 1113 int64_t cpIndex = utext_getNativeIndex(ut); |
1110 TEST_ASSERT(cpIndex == prevMap[i]); | 1114 TEST_ASSERT(cpIndex == prevMap[i]); |
1111 } | 1115 } |
1112 | 1116 |
1113 // check Extract | 1117 // check Extract |
1114 // Extract from i to i+1, which may be zero or one code points, | 1118 // Extract from i to i+1, which may be zero or one code points, |
(...skipping 10 matching lines...) Expand all Loading... |
1125 U16_GET(buf, 0, extractedLen-extractedLen, extractedLen, c32); | 1129 U16_GET(buf, 0, extractedLen-extractedLen, extractedLen, c32); |
1126 TEST_ASSERT(c32 == c32Map[i]); | 1130 TEST_ASSERT(c32 == c32Map[i]); |
1127 } | 1131 } |
1128 } | 1132 } |
1129 | 1133 |
1130 utext_close(ut); | 1134 utext_close(ut); |
1131 } | 1135 } |
1132 | 1136 |
1133 { // Similar test, with UText over Replaceable | 1137 { // Similar test, with UText over Replaceable |
1134 // TODO: merge the common parts of these tests. | 1138 // TODO: merge the common parts of these tests. |
1135 | 1139 |
1136 UnicodeString u16str("\\u1000\\U00011000\\u2000\\U00022000", -1, US_INV)
; | 1140 UnicodeString u16str("\\u1000\\U00011000\\u2000\\U00022000", -1, US_INV)
; |
1137 int32_t startMap[] ={ 0, 1, 1, 3, 4, 4, 6, 6}; | 1141 int32_t startMap[] ={ 0, 1, 1, 3, 4, 4, 6, 6}; |
1138 int32_t nextMap[] = { 1, 3, 3, 4, 6, 6, 6, 6}; | 1142 int32_t nextMap[] = { 1, 3, 3, 4, 6, 6, 6, 6}; |
1139 int32_t prevMap[] = { 0, 0, 0, 1, 3, 3, 4, 4}; | 1143 int32_t prevMap[] = { 0, 0, 0, 1, 3, 3, 4, 4}; |
1140 UChar32 c32Map[] = {0x1000, 0x11000, 0x11000, 0x2000, 0x22000, 0x2200
0, -1, -1}; | 1144 UChar32 c32Map[] = {0x1000, 0x11000, 0x11000, 0x2000, 0x22000, 0x2200
0, -1, -1}; |
1141 UChar32 pr32Map[] = { -1, 0x1000, 0x1000, 0x11000, 0x2000, 0x2000
, 0x22000, 0x22000}; | 1145 UChar32 pr32Map[] = { -1, 0x1000, 0x1000, 0x11000, 0x2000, 0x2000
, 0x22000, 0x22000}; |
1142 int32_t exLen[] = { 1, 0, 2, 1, 0, 2, 0, 0,}; | 1146 int32_t exLen[] = { 1, 0, 2, 1, 0, 2, 0, 0,}; |
1143 | 1147 |
1144 u16str = u16str.unescape(); | 1148 u16str = u16str.unescape(); |
1145 UErrorCode status = U_ZERO_ERROR; | 1149 UErrorCode status = U_ZERO_ERROR; |
1146 UText *ut = utext_openReplaceable(NULL, &u16str, &status); | 1150 UText *ut = utext_openReplaceable(NULL, &u16str, &status); |
1147 TEST_SUCCESS(status); | 1151 TEST_SUCCESS(status); |
1148 | 1152 |
1149 int32_t startMapLimit = sizeof(startMap) / sizeof(int32_t); | 1153 int32_t startMapLimit = sizeof(startMap) / sizeof(int32_t); |
1150 int i; | 1154 int i; |
1151 for (i=0; i<startMapLimit; i++) { | 1155 for (i=0; i<startMapLimit; i++) { |
(...skipping 10 matching lines...) Expand all Loading... |
1162 TEST_ASSERT(cpIndex == startMap[i]); | 1166 TEST_ASSERT(cpIndex == startMap[i]); |
1163 } | 1167 } |
1164 | 1168 |
1165 // Check utext_next32From | 1169 // Check utext_next32From |
1166 for (i=0; i<startMapLimit; i++) { | 1170 for (i=0; i<startMapLimit; i++) { |
1167 UChar32 c32 = utext_next32From(ut, i); | 1171 UChar32 c32 = utext_next32From(ut, i); |
1168 TEST_ASSERT(c32 == c32Map[i]); | 1172 TEST_ASSERT(c32 == c32Map[i]); |
1169 int64_t cpIndex = utext_getNativeIndex(ut); | 1173 int64_t cpIndex = utext_getNativeIndex(ut); |
1170 TEST_ASSERT(cpIndex == nextMap[i]); | 1174 TEST_ASSERT(cpIndex == nextMap[i]); |
1171 } | 1175 } |
1172 | 1176 |
1173 // check utext_previous32From | 1177 // check utext_previous32From |
1174 for (i=0; i<startMapLimit; i++) { | 1178 for (i=0; i<startMapLimit; i++) { |
1175 UChar32 c32 = utext_previous32From(ut, i); | 1179 UChar32 c32 = utext_previous32From(ut, i); |
1176 TEST_ASSERT(c32 == pr32Map[i]); | 1180 TEST_ASSERT(c32 == pr32Map[i]); |
1177 int64_t cpIndex = utext_getNativeIndex(ut); | 1181 int64_t cpIndex = utext_getNativeIndex(ut); |
1178 TEST_ASSERT(cpIndex == prevMap[i]); | 1182 TEST_ASSERT(cpIndex == prevMap[i]); |
1179 } | 1183 } |
1180 | 1184 |
1181 // check Extract | 1185 // check Extract |
1182 // Extract from i to i+1, which may be zero or one code points, | 1186 // Extract from i to i+1, which may be zero or one code points, |
(...skipping 15 matching lines...) Expand all Loading... |
1198 utext_close(ut); | 1202 utext_close(ut); |
1199 } | 1203 } |
1200 } | 1204 } |
1201 | 1205 |
1202 | 1206 |
1203 void UTextTest::FreezeTest() { | 1207 void UTextTest::FreezeTest() { |
1204 // Check isWritable() and freeze() behavior. | 1208 // Check isWritable() and freeze() behavior. |
1205 // | 1209 // |
1206 | 1210 |
1207 UnicodeString ustr("Hello, World."); | 1211 UnicodeString ustr("Hello, World."); |
1208 const char u8str[] = {char(0x31), (char)0x32, (char)0x33, 0}; | 1212 const char u8str[] = {char(0x31), (char)0x32, (char)0x33, 0}; |
1209 const UChar u16str[] = {(UChar)0x31, (UChar)0x32, (UChar)0x44, 0}; | 1213 const UChar u16str[] = {(UChar)0x31, (UChar)0x32, (UChar)0x44, 0}; |
1210 | 1214 |
1211 UErrorCode status = U_ZERO_ERROR; | 1215 UErrorCode status = U_ZERO_ERROR; |
1212 UText *ut = NULL; | 1216 UText *ut = NULL; |
1213 UText *ut2 = NULL; | 1217 UText *ut2 = NULL; |
1214 | 1218 |
1215 ut = utext_openUTF8(ut, u8str, -1, &status); | 1219 ut = utext_openUTF8(ut, u8str, -1, &status); |
1216 TEST_SUCCESS(status); | 1220 TEST_SUCCESS(status); |
1217 UBool writable = utext_isWritable(ut); | 1221 UBool writable = utext_isWritable(ut); |
1218 TEST_ASSERT(writable == FALSE); | 1222 TEST_ASSERT(writable == FALSE); |
(...skipping 11 matching lines...) Expand all Loading... |
1230 status = U_ZERO_ERROR; | 1234 status = U_ZERO_ERROR; |
1231 ut = utext_openUnicodeString(ut, &ustr, &status); | 1235 ut = utext_openUnicodeString(ut, &ustr, &status); |
1232 TEST_SUCCESS(status); | 1236 TEST_SUCCESS(status); |
1233 writable = utext_isWritable(ut); | 1237 writable = utext_isWritable(ut); |
1234 TEST_ASSERT(writable == TRUE); | 1238 TEST_ASSERT(writable == TRUE); |
1235 utext_freeze(ut); | 1239 utext_freeze(ut); |
1236 writable = utext_isWritable(ut); | 1240 writable = utext_isWritable(ut); |
1237 TEST_ASSERT(writable == FALSE); | 1241 TEST_ASSERT(writable == FALSE); |
1238 utext_copy(ut, 1, 2, 0, TRUE, &status); | 1242 utext_copy(ut, 1, 2, 0, TRUE, &status); |
1239 TEST_ASSERT(status == U_NO_WRITE_PERMISSION); | 1243 TEST_ASSERT(status == U_NO_WRITE_PERMISSION); |
1240 | 1244 |
1241 status = U_ZERO_ERROR; | 1245 status = U_ZERO_ERROR; |
1242 ut = utext_openUnicodeString(ut, &ustr, &status); | 1246 ut = utext_openUnicodeString(ut, &ustr, &status); |
1243 TEST_SUCCESS(status); | 1247 TEST_SUCCESS(status); |
1244 ut2 = utext_clone(ut2, ut, FALSE, FALSE, &status); // clone with readonly =
false | 1248 ut2 = utext_clone(ut2, ut, FALSE, FALSE, &status); // clone with readonly =
false |
1245 TEST_SUCCESS(status); | 1249 TEST_SUCCESS(status); |
1246 writable = utext_isWritable(ut2); | 1250 writable = utext_isWritable(ut2); |
1247 TEST_ASSERT(writable == TRUE); | 1251 TEST_ASSERT(writable == TRUE); |
1248 ut2 = utext_clone(ut2, ut, FALSE, TRUE, &status); // clone with readonly =
true | 1252 ut2 = utext_clone(ut2, ut, FALSE, TRUE, &status); // clone with readonly =
true |
1249 TEST_SUCCESS(status); | 1253 TEST_SUCCESS(status); |
1250 writable = utext_isWritable(ut2); | 1254 writable = utext_isWritable(ut2); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1313 return true; | 1317 return true; |
1314 } | 1318 } |
1315 if (!forward && index>0 && index <=length) { | 1319 if (!forward && index>0 && index <=length) { |
1316 c = us->charAt((int32_t)index-1); | 1320 c = us->charAt((int32_t)index-1); |
1317 ut->b = c | c<<16; | 1321 ut->b = c | c<<16; |
1318 ut->chunkOffset = 1; | 1322 ut->chunkOffset = 1; |
1319 ut->chunkLength = 1; | 1323 ut->chunkLength = 1; |
1320 ut->chunkNativeStart = index-1; | 1324 ut->chunkNativeStart = index-1; |
1321 ut->chunkNativeLimit = index; | 1325 ut->chunkNativeLimit = index; |
1322 return true; | 1326 return true; |
1323 } | 1327 } |
1324 ut->b = 0; | 1328 ut->b = 0; |
1325 ut->chunkOffset = 0; | 1329 ut->chunkOffset = 0; |
1326 ut->chunkLength = 0; | 1330 ut->chunkLength = 0; |
1327 if (index <= 0) { | 1331 if (index <= 0) { |
1328 ut->chunkNativeStart = 0; | 1332 ut->chunkNativeStart = 0; |
1329 ut->chunkNativeLimit = 0; | 1333 ut->chunkNativeLimit = 0; |
1330 } else { | 1334 } else { |
1331 ut->chunkNativeStart = length; | 1335 ut->chunkNativeStart = length; |
1332 ut->chunkNativeLimit = length; | 1336 ut->chunkNativeLimit = length; |
1333 } | 1337 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1380 | 1384 |
1381 // Regression test for Ticket 5560 | 1385 // Regression test for Ticket 5560 |
1382 // Clone fails to update chunkContentPointer in the cloned copy. | 1386 // Clone fails to update chunkContentPointer in the cloned copy. |
1383 // This is only an issue for UText types that work in a local buffer, | 1387 // This is only an issue for UText types that work in a local buffer, |
1384 // (UTF-8 wrapper, for example) | 1388 // (UTF-8 wrapper, for example) |
1385 // | 1389 // |
1386 // The test: | 1390 // The test: |
1387 // 1. Create an inital UText | 1391 // 1. Create an inital UText |
1388 // 2. Deep clone it. Contents should match original. | 1392 // 2. Deep clone it. Contents should match original. |
1389 // 3. Reset original to something different. | 1393 // 3. Reset original to something different. |
1390 // 4. Check that clone contents did not change. | 1394 // 4. Check that clone contents did not change. |
1391 // | 1395 // |
1392 void UTextTest::Ticket5560() { | 1396 void UTextTest::Ticket5560() { |
1393 /* The following two strings are in UTF-8 even on EBCDIC platforms. */ | 1397 /* The following two strings are in UTF-8 even on EBCDIC platforms. */ |
1394 static const char s1[] = {0x41,0x42,0x43,0x44,0x45,0x46,0}; /* "ABCDEF" */ | 1398 static const char s1[] = {0x41,0x42,0x43,0x44,0x45,0x46,0}; /* "ABCDEF" */ |
1395 static const char s2[] = {0x31,0x32,0x33,0x34,0x35,0x36,0}; /* "123456" */ | 1399 static const char s2[] = {0x31,0x32,0x33,0x34,0x35,0x36,0}; /* "123456" */ |
1396 UErrorCode status = U_ZERO_ERROR; | 1400 UErrorCode status = U_ZERO_ERROR; |
1397 | 1401 |
1398 UText ut1 = UTEXT_INITIALIZER; | 1402 UText ut1 = UTEXT_INITIALIZER; |
1399 UText ut2 = UTEXT_INITIALIZER; | 1403 UText ut2 = UTEXT_INITIALIZER; |
1400 | 1404 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1445 count++; | 1449 count++; |
1446 nativeIndex = UTEXT_GETNATIVEINDEX(ut); | 1450 nativeIndex = UTEXT_GETNATIVEINDEX(ut); |
1447 TEST_ASSERT(nativeIndex == count); | 1451 TEST_ASSERT(nativeIndex == count); |
1448 } | 1452 } |
1449 TEST_ASSERT(count == STRLEN); | 1453 TEST_ASSERT(count == STRLEN); |
1450 nativeIndex = UTEXT_GETNATIVEINDEX(ut); | 1454 nativeIndex = UTEXT_GETNATIVEINDEX(ut); |
1451 TEST_ASSERT(nativeIndex == STRLEN); | 1455 TEST_ASSERT(nativeIndex == STRLEN); |
1452 utext_close(ut); | 1456 utext_close(ut); |
1453 } | 1457 } |
1454 | 1458 |
| 1459 |
| 1460 void UTextTest::Ticket10562() { |
| 1461 // Note: failures show as a heap error when the test is run under valgrind. |
| 1462 UErrorCode status = U_ZERO_ERROR; |
| 1463 |
| 1464 const char *utf8_string = "\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\
x41\x41\x41"; |
| 1465 UText *utf8Text = utext_openUTF8(NULL, utf8_string, -1, &status); |
| 1466 TEST_SUCCESS(status); |
| 1467 UText *deepClone = utext_clone(NULL, utf8Text, TRUE, FALSE, &status); |
| 1468 TEST_SUCCESS(status); |
| 1469 UText *shallowClone = utext_clone(NULL, deepClone, FALSE, FALSE, &status); |
| 1470 TEST_SUCCESS(status); |
| 1471 utext_close(shallowClone); |
| 1472 utext_close(deepClone); |
| 1473 utext_close(utf8Text); |
| 1474 |
| 1475 status = U_ZERO_ERROR; |
| 1476 UnicodeString usString("Hello, World."); |
| 1477 UText *usText = utext_openUnicodeString(NULL, &usString, &status); |
| 1478 TEST_SUCCESS(status); |
| 1479 UText *usDeepClone = utext_clone(NULL, usText, TRUE, FALSE, &status); |
| 1480 TEST_SUCCESS(status); |
| 1481 UText *usShallowClone = utext_clone(NULL, usDeepClone, FALSE, FALSE, &status
); |
| 1482 TEST_SUCCESS(status); |
| 1483 utext_close(usShallowClone); |
| 1484 utext_close(usDeepClone); |
| 1485 utext_close(usText); |
| 1486 } |
| 1487 |
| 1488 |
| 1489 void UTextTest::Ticket10983() { |
| 1490 // Note: failure shows as a seg fault when the defect is present. |
| 1491 |
| 1492 UErrorCode status = U_ZERO_ERROR; |
| 1493 UnicodeString s("Hello, World"); |
| 1494 UText *ut = utext_openConstUnicodeString(NULL, &s, &status); |
| 1495 TEST_SUCCESS(status); |
| 1496 |
| 1497 status = U_INVALID_STATE_ERROR; |
| 1498 UText *cloned = utext_clone(NULL, ut, TRUE, TRUE, &status); |
| 1499 TEST_ASSERT(cloned == NULL); |
| 1500 TEST_ASSERT(status == U_INVALID_STATE_ERROR); |
| 1501 |
| 1502 utext_close(ut); |
| 1503 } |
OLD | NEW |