1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
5 * Copyright (c) 1997-2016, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ********************************************************************/
11 * IntlTestUtilities is the medium level test class for everything in the directory "utility".
14 #include "unicode/utypes.h"
15 #include "unicode/errorcode.h"
16 #include "unicode/localpointer.h"
35 extern IntlTest
*createBytesTrieTest();
36 static IntlTest
*createLocalPointerTest();
37 extern IntlTest
*createUCharsTrieTest();
38 static IntlTest
*createEnumSetTest();
39 extern IntlTest
*createSimpleFormatterTest();
40 extern IntlTest
*createUnifiedCacheTest();
41 extern IntlTest
*createQuantityFormatterTest();
42 extern IntlTest
*createPluralMapTest();
45 #define CASE(id, test) case id: \
48 logln(#test "---"); logln(); \
54 void IntlTestUtilities::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* par
)
56 if (exec
) logln("TestSuite Utilities: ");
58 CASE(0, MultithreadTest
);
60 CASE(2, UnicodeStringTest
);
62 CASE(4, CharIterTest
);
65 CASE(7, ResourceBundleTest
);
66 CASE(8, NewResourceBundleTest
);
68 CASE(10, UVector32Test
);
69 CASE(11, UVectorTest
);
71 CASE(13, LocaleAliasTest
);
72 CASE(14, UnicodeSetTest
);
73 CASE(15, ErrorCodeTest
);
75 name
= "LocalPointerTest";
77 logln("TestSuite LocalPointerTest---"); logln();
78 LocalPointer
<IntlTest
> test(createLocalPointerTest());
83 name
= "BytesTrieTest";
85 logln("TestSuite BytesTrieTest---"); logln();
86 LocalPointer
<IntlTest
> test(createBytesTrieTest());
91 name
= "UCharsTrieTest";
93 logln("TestSuite UCharsTrieTest---"); logln();
94 LocalPointer
<IntlTest
> test(createUCharsTrieTest());
101 logln("TestSuite EnumSetTest---"); logln();
102 LocalPointer
<IntlTest
> test(createEnumSetTest());
103 callTest(*test
, par
);
107 name
= "SimpleFormatterTest";
109 logln("TestSuite SimpleFormatterTest---"); logln();
110 LocalPointer
<IntlTest
> test(createSimpleFormatterTest());
111 callTest(*test
, par
);
115 name
= "UnifiedCacheTest";
117 logln("TestSuite UnifiedCacheTest---"); logln();
118 LocalPointer
<IntlTest
> test(createUnifiedCacheTest());
119 callTest(*test
, par
);
123 name
= "QuantityFormatterTest";
125 logln("TestSuite QuantityFormatterTest---"); logln();
126 LocalPointer
<IntlTest
> test(createQuantityFormatterTest());
127 callTest(*test
, par
);
131 name
= "PluralMapTest";
133 logln("TestSuite PluralMapTest---"); logln();
134 LocalPointer
<IntlTest
> test(createPluralMapTest());
135 callTest(*test
, par
);
138 default: name
= ""; break; //needed to end loop
142 void ErrorCodeTest::runIndexedTest(int32_t index
, UBool exec
, const char* &name
, char* /*par*/) {
143 if (exec
) logln("TestSuite Utilities: ");
145 case 0: name
= "TestErrorCode"; if (exec
) TestErrorCode(); break;
146 case 1: name
= "TestSubclass"; if (exec
) TestSubclass(); break;
147 default: name
= ""; break; //needed to end loop
151 static void RefPlusOne(UErrorCode
&code
) { code
=(UErrorCode
)(code
+1); }
152 static void PtrPlusTwo(UErrorCode
*code
) { *code
=(UErrorCode
)(*code
+2); }
154 void ErrorCodeTest::TestErrorCode() {
156 if(errorCode
.get()!=U_ZERO_ERROR
|| !errorCode
.isSuccess() || errorCode
.isFailure()) {
157 errln("ErrorCode did not initialize properly");
160 errorCode
.assertSuccess();
161 if(errorCode
.errorName()!=u_errorName(U_ZERO_ERROR
)) {
162 errln("ErrorCode did not format error message string properly");
164 RefPlusOne(errorCode
);
165 if(errorCode
.get()!=U_ILLEGAL_ARGUMENT_ERROR
|| errorCode
.isSuccess() || !errorCode
.isFailure()) {
166 errln("ErrorCode did not yield a writable reference");
168 PtrPlusTwo(errorCode
);
169 if(errorCode
.get()!=U_INVALID_FORMAT_ERROR
|| errorCode
.isSuccess() || !errorCode
.isFailure()) {
170 errln("ErrorCode did not yield a writable pointer");
172 errorCode
.set(U_PARSE_ERROR
);
173 if(errorCode
.get()!=U_PARSE_ERROR
|| errorCode
.isSuccess() || !errorCode
.isFailure()) {
174 errln("ErrorCode.set() failed");
176 if( errorCode
.reset()!=U_PARSE_ERROR
|| errorCode
.get()!=U_ZERO_ERROR
||
177 !errorCode
.isSuccess() || errorCode
.isFailure()
179 errln("ErrorCode did not reset properly");
183 class MyErrorCode
: public ErrorCode
{
185 MyErrorCode(int32_t &countChecks
, int32_t &countDests
)
186 : checks(countChecks
), dests(countDests
) {}
193 virtual void handleFailure() const {
200 void ErrorCodeTest::TestSubclass() {
201 int32_t countChecks
=0;
202 int32_t countDests
=0;
204 MyErrorCode
errorCode(countChecks
, countDests
);
205 if( errorCode
.get()!=U_ZERO_ERROR
|| !errorCode
.isSuccess() || errorCode
.isFailure() ||
206 countChecks
!=0 || countDests
!=0
208 errln("ErrorCode did not initialize properly");
211 errorCode
.assertSuccess();
213 errln("ErrorCode.assertSuccess() called handleFailure() despite success");
215 RefPlusOne(errorCode
);
216 if(errorCode
.get()!=U_ILLEGAL_ARGUMENT_ERROR
|| errorCode
.isSuccess() || !errorCode
.isFailure()) {
217 errln("ErrorCode did not yield a writable reference");
219 errorCode
.assertSuccess();
221 errln("ErrorCode.assertSuccess() did not handleFailure()");
223 PtrPlusTwo(errorCode
);
224 if(errorCode
.get()!=U_INVALID_FORMAT_ERROR
|| errorCode
.isSuccess() || !errorCode
.isFailure()) {
225 errln("ErrorCode did not yield a writable pointer");
227 errorCode
.assertSuccess();
229 errln("ErrorCode.assertSuccess() did not handleFailure()");
231 errorCode
.set(U_PARSE_ERROR
);
232 if(errorCode
.get()!=U_PARSE_ERROR
|| errorCode
.isSuccess() || !errorCode
.isFailure()) {
233 errln("ErrorCode.set() failed");
235 if( errorCode
.reset()!=U_PARSE_ERROR
|| errorCode
.get()!=U_ZERO_ERROR
||
236 !errorCode
.isSuccess() || errorCode
.isFailure()
238 errln("ErrorCode did not reset properly");
240 errorCode
.assertSuccess();
242 errln("ErrorCode.assertSuccess() called handleFailure() despite success");
246 errln("MyErrorCode destructor detected failure despite success");
248 countChecks
=countDests
=0;
250 MyErrorCode
errorCode(countChecks
, countDests
);
251 errorCode
.set(U_PARSE_ERROR
);
254 errln("MyErrorCode destructor failed to detect failure");
258 class LocalPointerTest
: public IntlTest
{
260 LocalPointerTest() {}
262 void runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
=NULL
);
264 void TestLocalPointer();
265 void TestLocalPointerMoveSwap();
266 void TestLocalArray();
267 void TestLocalArrayMoveSwap();
268 void TestLocalXyzPointer();
269 void TestLocalXyzPointerMoveSwap();
270 void TestLocalXyzPointerNull();
273 static IntlTest
*createLocalPointerTest() {
274 return new LocalPointerTest();
277 void LocalPointerTest::runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char * /*par*/) {
279 logln("TestSuite LocalPointerTest: ");
282 TESTCASE_AUTO(TestLocalPointer
);
283 TESTCASE_AUTO(TestLocalPointerMoveSwap
);
284 TESTCASE_AUTO(TestLocalArray
);
285 TESTCASE_AUTO(TestLocalArrayMoveSwap
);
286 TESTCASE_AUTO(TestLocalXyzPointer
);
287 TESTCASE_AUTO(TestLocalXyzPointerMoveSwap
);
288 TESTCASE_AUTO(TestLocalXyzPointerNull
);
292 // Exercise almost every LocalPointer and LocalPointerBase method.
293 void LocalPointerTest::TestLocalPointer() {
295 LocalPointer
<UnicodeString
> s(new UnicodeString((UChar32
)0x50005));
296 // isNULL(), isValid(), operator==(), operator!=()
297 if(s
.isNull() || !s
.isValid() || s
==NULL
|| !(s
!=NULL
)) {
298 errln("LocalPointer constructor or NULL test failure");
301 // getAlias(), operator->, operator*
302 if(s
.getAlias()->length()!=2 || s
->length()!=2 || (*s
).length()!=2) {
303 errln("LocalPointer access failure");
305 // adoptInstead(), orphan()
306 s
.adoptInstead(new UnicodeString((UChar
)0xfffc));
308 errln("LocalPointer adoptInstead(U+FFFC) failure");
310 UnicodeString
*orphan
=s
.orphan();
311 if(orphan
==NULL
|| orphan
->length()!=1 || s
.isValid() || s
!=NULL
) {
312 errln("LocalPointer orphan() failure");
315 s
.adoptInstead(new UnicodeString());
317 errln("LocalPointer adoptInstead(empty) failure");
320 // LocalPointer(p, errorCode) sets U_MEMORY_ALLOCATION_ERROR if p==NULL.
321 UErrorCode errorCode
= U_ZERO_ERROR
;
322 LocalPointer
<CharString
> csx(new CharString("some chars", errorCode
), errorCode
);
323 if(csx
.isNull() && U_SUCCESS(errorCode
)) {
324 errln("LocalPointer(p, errorCode) failure");
327 errorCode
= U_ZERO_ERROR
;
328 csx
.adoptInsteadAndCheckErrorCode(new CharString("different chars", errorCode
), errorCode
);
329 if(csx
.isNull() && U_SUCCESS(errorCode
)) {
330 errln("adoptInsteadAndCheckErrorCode(p, errorCode) failure");
333 // Incoming failure: Keep the current object and delete the input object.
334 errorCode
= U_ILLEGAL_ARGUMENT_ERROR
;
335 csx
.adoptInsteadAndCheckErrorCode(new CharString("unused", errorCode
), errorCode
);
336 if(csx
.isValid() && strcmp(csx
->data(), "different chars") != 0) {
337 errln("adoptInsteadAndCheckErrorCode(p, U_FAILURE) did not retain the old object");
340 errorCode
= U_ZERO_ERROR
;
341 csx
.adoptInsteadAndCheckErrorCode(NULL
, errorCode
);
342 if(errorCode
!= U_MEMORY_ALLOCATION_ERROR
) {
343 errln("adoptInsteadAndCheckErrorCode(NULL, errorCode) did not set U_MEMORY_ALLOCATION_ERROR");
347 errln("adoptInsteadAndCheckErrorCode(NULL, errorCode) kept the object");
350 errorCode
= U_ZERO_ERROR
;
351 LocalPointer
<CharString
> null(NULL
, errorCode
);
352 if(errorCode
!= U_MEMORY_ALLOCATION_ERROR
) {
353 errln("LocalPointer(NULL, errorCode) did not set U_MEMORY_ALLOCATION_ERROR");
360 void LocalPointerTest::TestLocalPointerMoveSwap() {
361 UnicodeString
*p1
= new UnicodeString((UChar
)0x61);
362 UnicodeString
*p2
= new UnicodeString((UChar
)0x62);
363 LocalPointer
<UnicodeString
> s1(p1
);
364 LocalPointer
<UnicodeString
> s2(p2
);
366 if(s1
.getAlias() != p2
|| s2
.getAlias() != p1
) {
367 errln("LocalPointer.swap() did not swap");
370 if(s1
.getAlias() != p1
|| s2
.getAlias() != p2
) {
371 errln("swap(LocalPointer) did not swap back");
373 LocalPointer
<UnicodeString
> s3
;
375 if(s3
.getAlias() != p1
|| s1
.isValid()) {
376 errln("LocalPointer.moveFrom() did not move");
378 #if U_HAVE_RVALUE_REFERENCES
379 infoln("TestLocalPointerMoveSwap() with rvalue references");
380 s1
= static_cast<LocalPointer
<UnicodeString
> &&>(s3
);
381 if(s1
.getAlias() != p1
|| s3
.isValid()) {
382 errln("LocalPointer move assignment operator did not move");
384 LocalPointer
<UnicodeString
> s4(static_cast<LocalPointer
<UnicodeString
> &&>(s2
));
385 if(s4
.getAlias() != p2
|| s2
.isValid()) {
386 errln("LocalPointer move constructor did not move");
389 infoln("TestLocalPointerMoveSwap() without rvalue references");
392 // Move self assignment leaves the object valid but in an undefined state.
393 // Do it to make sure there is no crash,
394 // but do not check for any particular resulting value.
399 // Exercise almost every LocalArray method (but not LocalPointerBase).
400 void LocalPointerTest::TestLocalArray() {
402 LocalArray
<UnicodeString
> a(new UnicodeString
[2]);
404 a
[0].append((UChar
)0x61);
405 a
[1].append((UChar32
)0x60006);
406 if(a
[0].length()!=1 || a
[1].length()!=2) {
407 errln("LocalArray access failure");
410 a
.adoptInstead(new UnicodeString
[4]);
411 a
[3].append((UChar
)0x62).append((UChar
)0x63).reverse();
412 if(a
[3].length()!=2 || a
[3][1]!=0x62) {
413 errln("LocalArray adoptInstead() failure");
416 // LocalArray(p, errorCode) sets U_MEMORY_ALLOCATION_ERROR if p==NULL.
417 UErrorCode errorCode
= U_ZERO_ERROR
;
418 LocalArray
<UnicodeString
> ua(new UnicodeString
[3], errorCode
);
419 if(ua
.isNull() && U_SUCCESS(errorCode
)) {
420 errln("LocalArray(p, errorCode) failure");
423 errorCode
= U_ZERO_ERROR
;
424 UnicodeString
*u4
= new UnicodeString
[4];
425 ua
.adoptInsteadAndCheckErrorCode(u4
, errorCode
);
426 if(ua
.isNull() && U_SUCCESS(errorCode
)) {
427 errln("adoptInsteadAndCheckErrorCode(p, errorCode) failure");
430 // Incoming failure: Keep the current object and delete the input object.
431 errorCode
= U_ILLEGAL_ARGUMENT_ERROR
;
432 ua
.adoptInsteadAndCheckErrorCode(new UnicodeString
[5], errorCode
);
433 if(ua
.isValid() && ua
.getAlias() != u4
) {
434 errln("adoptInsteadAndCheckErrorCode(p, U_FAILURE) did not retain the old array");
437 errorCode
= U_ZERO_ERROR
;
438 ua
.adoptInsteadAndCheckErrorCode(NULL
, errorCode
);
439 if(errorCode
!= U_MEMORY_ALLOCATION_ERROR
) {
440 errln("adoptInsteadAndCheckErrorCode(NULL, errorCode) did not set U_MEMORY_ALLOCATION_ERROR");
444 errln("adoptInsteadAndCheckErrorCode(NULL, errorCode) kept the array");
447 errorCode
= U_ZERO_ERROR
;
448 LocalArray
<UnicodeString
> null(NULL
, errorCode
);
449 if(errorCode
!= U_MEMORY_ALLOCATION_ERROR
) {
450 errln("LocalArray(NULL, errorCode) did not set U_MEMORY_ALLOCATION_ERROR");
457 void LocalPointerTest::TestLocalArrayMoveSwap() {
458 UnicodeString
*p1
= new UnicodeString
[2];
459 UnicodeString
*p2
= new UnicodeString
[3];
460 LocalArray
<UnicodeString
> a1(p1
);
461 LocalArray
<UnicodeString
> a2(p2
);
463 if(a1
.getAlias() != p2
|| a2
.getAlias() != p1
) {
464 errln("LocalArray.swap() did not swap");
467 if(a1
.getAlias() != p1
|| a2
.getAlias() != p2
) {
468 errln("swap(LocalArray) did not swap back");
470 LocalArray
<UnicodeString
> a3
;
472 if(a3
.getAlias() != p1
|| a1
.isValid()) {
473 errln("LocalArray.moveFrom() did not move");
475 #if U_HAVE_RVALUE_REFERENCES
476 infoln("TestLocalArrayMoveSwap() with rvalue references");
477 a1
= static_cast<LocalArray
<UnicodeString
> &&>(a3
);
478 if(a1
.getAlias() != p1
|| a3
.isValid()) {
479 errln("LocalArray move assignment operator did not move");
481 LocalArray
<UnicodeString
> a4(static_cast<LocalArray
<UnicodeString
> &&>(a2
));
482 if(a4
.getAlias() != p2
|| a2
.isValid()) {
483 errln("LocalArray move constructor did not move");
486 infoln("TestLocalArrayMoveSwap() without rvalue references");
489 // Move self assignment leaves the object valid but in an undefined state.
490 // Do it to make sure there is no crash,
491 // but do not check for any particular resulting value.
496 #include "unicode/ucnvsel.h"
497 #include "unicode/ucal.h"
498 #include "unicode/udatpg.h"
499 #include "unicode/uidna.h"
500 #include "unicode/uldnames.h"
501 #include "unicode/umsg.h"
502 #include "unicode/unorm2.h"
503 #include "unicode/uregex.h"
504 #include "unicode/utrans.h"
506 // Use LocalXyzPointer types that are not covered elsewhere in the intltest suite.
507 void LocalPointerTest::TestLocalXyzPointer() {
508 IcuTestErrorCode
errorCode(*this, "TestLocalXyzPointer");
510 static const char *const encoding
="ISO-8859-1";
511 LocalUConverterSelectorPointer
sel(
512 ucnvsel_open(&encoding
, 1, NULL
, UCNV_ROUNDTRIP_SET
, errorCode
));
513 if(errorCode
.logIfFailureAndReset("ucnvsel_open()")) {
517 errln("LocalUConverterSelectorPointer failure");
521 #if !UCONFIG_NO_FORMATTING
522 LocalUCalendarPointer
cal(ucal_open(NULL
, 0, "root", UCAL_GREGORIAN
, errorCode
));
523 if(errorCode
.logDataIfFailureAndReset("ucal_open()")) {
527 errln("LocalUCalendarPointer failure");
531 LocalUDateTimePatternGeneratorPointer
patgen(udatpg_open("root", errorCode
));
532 if(errorCode
.logDataIfFailureAndReset("udatpg_open()")) {
535 if(patgen
.isNull()) {
536 errln("LocalUDateTimePatternGeneratorPointer failure");
540 LocalULocaleDisplayNamesPointer
ldn(uldn_open("de-CH", ULDN_STANDARD_NAMES
, errorCode
));
541 if(errorCode
.logIfFailureAndReset("uldn_open()")) {
545 errln("LocalULocaleDisplayNamesPointer failure");
549 UnicodeString hello
=UNICODE_STRING_SIMPLE("Hello {0}!");
550 LocalUMessageFormatPointer
msg(
551 umsg_open(hello
.getBuffer(), hello
.length(), "root", NULL
, errorCode
));
552 if(errorCode
.logIfFailureAndReset("umsg_open()")) {
556 errln("LocalUMessageFormatPointer failure");
559 #endif /* UCONFIG_NO_FORMATTING */
561 #if !UCONFIG_NO_NORMALIZATION
562 const UNormalizer2
*nfc
=unorm2_getNFCInstance(errorCode
);
564 LocalUNormalizer2Pointer
fn2(unorm2_openFiltered(nfc
, emptySet
.toUSet(), errorCode
));
565 if(errorCode
.logIfFailureAndReset("unorm2_openFiltered()")) {
569 errln("LocalUNormalizer2Pointer failure");
572 #endif /* !UCONFIG_NO_NORMALIZATION */
575 LocalUIDNAPointer
idna(uidna_openUTS46(0, errorCode
));
576 if(errorCode
.logIfFailureAndReset("uidna_openUTS46()")) {
580 errln("LocalUIDNAPointer failure");
583 #endif /* !UCONFIG_NO_IDNA */
585 #if !UCONFIG_NO_REGULAR_EXPRESSIONS
586 UnicodeString pattern
=UNICODE_STRING_SIMPLE("abc|xy+z");
587 LocalURegularExpressionPointer
regex(
588 uregex_open(pattern
.getBuffer(), pattern
.length(), 0, NULL
, errorCode
));
589 if(errorCode
.logIfFailureAndReset("uregex_open()")) {
593 errln("LocalURegularExpressionPointer failure");
596 #endif /* UCONFIG_NO_REGULAR_EXPRESSIONS */
598 #if !UCONFIG_NO_TRANSLITERATION
599 UnicodeString id
=UNICODE_STRING_SIMPLE("Grek-Latn");
600 LocalUTransliteratorPointer
trans(
601 utrans_openU(id
.getBuffer(), id
.length(), UTRANS_FORWARD
, NULL
, 0, NULL
, errorCode
));
602 if(errorCode
.logIfFailureAndReset("utrans_open()")) {
606 errln("LocalUTransliteratorPointer failure");
609 #endif /* !UCONFIG_NO_TRANSLITERATION */
614 void LocalPointerTest::TestLocalXyzPointerMoveSwap() {
615 #if !UCONFIG_NO_NORMALIZATION
616 IcuTestErrorCode
errorCode(*this, "TestLocalXyzPointerMoveSwap");
617 const UNormalizer2
*nfc
=unorm2_getNFCInstance(errorCode
);
618 const UNormalizer2
*nfd
=unorm2_getNFDInstance(errorCode
);
619 if(errorCode
.logIfFailureAndReset("unorm2_getNF[CD]Instance()")) {
623 UNormalizer2
*p1
= unorm2_openFiltered(nfc
, emptySet
.toUSet(), errorCode
);
624 UNormalizer2
*p2
= unorm2_openFiltered(nfd
, emptySet
.toUSet(), errorCode
);
625 LocalUNormalizer2Pointer
f1(p1
);
626 LocalUNormalizer2Pointer
f2(p2
);
627 if(errorCode
.logIfFailureAndReset("unorm2_openFiltered()")) {
630 if(f1
.isNull() || f2
.isNull()) {
631 errln("LocalUNormalizer2Pointer failure");
635 if(f1
.getAlias() != p2
|| f2
.getAlias() != p1
) {
636 errln("LocalUNormalizer2Pointer.swap() did not swap");
639 if(f1
.getAlias() != p1
|| f2
.getAlias() != p2
) {
640 errln("swap(LocalUNormalizer2Pointer) did not swap back");
642 LocalUNormalizer2Pointer f3
;
644 if(f3
.getAlias() != p1
|| f1
.isValid()) {
645 errln("LocalUNormalizer2Pointer.moveFrom() did not move");
647 #if U_HAVE_RVALUE_REFERENCES
648 infoln("TestLocalXyzPointerMoveSwap() with rvalue references");
649 f1
= static_cast<LocalUNormalizer2Pointer
&&>(f3
);
650 if(f1
.getAlias() != p1
|| f3
.isValid()) {
651 errln("LocalUNormalizer2Pointer move assignment operator did not move");
653 LocalUNormalizer2Pointer
f4(static_cast<LocalUNormalizer2Pointer
&&>(f2
));
654 if(f4
.getAlias() != p2
|| f2
.isValid()) {
655 errln("LocalUNormalizer2Pointer move constructor did not move");
658 infoln("TestLocalXyzPointerMoveSwap() without rvalue references");
660 // Move self assignment leaves the object valid but in an undefined state.
661 // Do it to make sure there is no crash,
662 // but do not check for any particular resulting value.
665 #endif /* !UCONFIG_NO_NORMALIZATION */
668 // Try LocalXyzPointer types with NULL pointers.
669 void LocalPointerTest::TestLocalXyzPointerNull() {
671 IcuTestErrorCode
errorCode(*this, "TestLocalXyzPointerNull/LocalUConverterSelectorPointer");
672 static const char *const encoding
="ISO-8859-1";
673 LocalUConverterSelectorPointer null
;
674 LocalUConverterSelectorPointer
sel(
675 ucnvsel_open(&encoding
, 1, NULL
, UCNV_ROUNDTRIP_SET
, errorCode
));
676 sel
.adoptInstead(NULL
);
678 #if !UCONFIG_NO_FORMATTING
680 IcuTestErrorCode
errorCode(*this, "TestLocalXyzPointerNull/LocalUCalendarPointer");
681 LocalUCalendarPointer null
;
682 LocalUCalendarPointer
cal(ucal_open(NULL
, 0, "root", UCAL_GREGORIAN
, errorCode
));
683 if(!errorCode
.logDataIfFailureAndReset("ucal_open()")) {
684 cal
.adoptInstead(NULL
);
688 IcuTestErrorCode
errorCode(*this, "TestLocalXyzPointerNull/LocalUDateTimePatternGeneratorPointer");
689 LocalUDateTimePatternGeneratorPointer null
;
690 LocalUDateTimePatternGeneratorPointer
patgen(udatpg_open("root", errorCode
));
691 patgen
.adoptInstead(NULL
);
694 IcuTestErrorCode
errorCode(*this, "TestLocalXyzPointerNull/LocalUMessageFormatPointer");
695 UnicodeString hello
=UNICODE_STRING_SIMPLE("Hello {0}!");
696 LocalUMessageFormatPointer null
;
697 LocalUMessageFormatPointer
msg(
698 umsg_open(hello
.getBuffer(), hello
.length(), "root", NULL
, errorCode
));
699 msg
.adoptInstead(NULL
);
701 #endif /* !UCONFIG_NO_FORMATTING */
703 #if !UCONFIG_NO_REGULAR_EXPRESSIONS
705 IcuTestErrorCode
errorCode(*this, "TestLocalXyzPointerNull/LocalURegularExpressionPointer");
706 UnicodeString pattern
=UNICODE_STRING_SIMPLE("abc|xy+z");
707 LocalURegularExpressionPointer null
;
708 LocalURegularExpressionPointer
regex(
709 uregex_open(pattern
.getBuffer(), pattern
.length(), 0, NULL
, errorCode
));
710 if(!errorCode
.logDataIfFailureAndReset("urege_open()")) {
711 regex
.adoptInstead(NULL
);
714 #endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS */
716 #if !UCONFIG_NO_TRANSLITERATION
718 IcuTestErrorCode
errorCode(*this, "TestLocalXyzPointerNull/LocalUTransliteratorPointer");
719 UnicodeString id
=UNICODE_STRING_SIMPLE("Grek-Latn");
720 LocalUTransliteratorPointer null
;
721 LocalUTransliteratorPointer
trans(
722 utrans_openU(id
.getBuffer(), id
.length(), UTRANS_FORWARD
, NULL
, 0, NULL
, errorCode
));
723 if(!errorCode
.logDataIfFailureAndReset("utrans_openU()")) {
724 trans
.adoptInstead(NULL
);
727 #endif /* !UCONFIG_NO_TRANSLITERATION */
732 #include "unicode/enumset.h"
734 class EnumSetTest
: public IntlTest
{
737 virtual void runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
=NULL
);
741 static IntlTest
*createEnumSetTest() {
742 return new EnumSetTest();
745 void EnumSetTest::runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char * /*par*/) {
747 TESTCASE_AUTO(TestEnumSet
);
758 void EnumSetTest::TestEnumSet() {
764 logln("Enum is from [%d..%d]\n", MAX_NONBOOLEAN
+1,
767 TEST_ASSERT_TRUE(flags
.get(THING1
) == FALSE
);
768 TEST_ASSERT_TRUE(flags
.get(THING2
) == FALSE
);
769 TEST_ASSERT_TRUE(flags
.get(THING3
) == FALSE
);
771 logln("get(thing1)=%d, get(thing2)=%d, get(thing3)=%d\n", flags
.get(THING1
), flags
.get(THING2
), flags
.get(THING3
));
772 logln("Value now: %d\n", flags
.getAll());
774 logln("clear -Value now: %d\n", flags
.getAll());
775 logln("get(thing1)=%d, get(thing2)=%d, get(thing3)=%d\n", flags
.get(THING1
), flags
.get(THING2
), flags
.get(THING3
));
776 TEST_ASSERT_TRUE(flags
.get(THING1
) == FALSE
);
777 TEST_ASSERT_TRUE(flags
.get(THING2
) == FALSE
);
778 TEST_ASSERT_TRUE(flags
.get(THING3
) == FALSE
);
780 logln("set THING1 -Value now: %d\n", flags
.getAll());
781 TEST_ASSERT_TRUE(flags
.get(THING1
) == TRUE
);
782 TEST_ASSERT_TRUE(flags
.get(THING2
) == FALSE
);
783 TEST_ASSERT_TRUE(flags
.get(THING3
) == FALSE
);
784 logln("get(thing1)=%d, get(thing2)=%d, get(thing3)=%d\n", flags
.get(THING1
), flags
.get(THING2
), flags
.get(THING3
));
786 logln("set THING3 -Value now: %d\n", flags
.getAll());
787 TEST_ASSERT_TRUE(flags
.get(THING1
) == TRUE
);
788 TEST_ASSERT_TRUE(flags
.get(THING2
) == FALSE
);
789 TEST_ASSERT_TRUE(flags
.get(THING3
) == TRUE
);
790 logln("get(thing1)=%d, get(thing2)=%d, get(thing3)=%d\n", flags
.get(THING1
), flags
.get(THING2
), flags
.get(THING3
));
791 flags
.remove(THING2
);
792 TEST_ASSERT_TRUE(flags
.get(THING1
) == TRUE
);
793 TEST_ASSERT_TRUE(flags
.get(THING2
) == FALSE
);
794 TEST_ASSERT_TRUE(flags
.get(THING3
) == TRUE
);
795 logln("remove THING2 -Value now: %d\n", flags
.getAll());
796 logln("get(thing1)=%d, get(thing2)=%d, get(thing3)=%d\n", flags
.get(THING1
), flags
.get(THING2
), flags
.get(THING3
));
797 flags
.remove(THING1
);
798 TEST_ASSERT_TRUE(flags
.get(THING1
) == FALSE
);
799 TEST_ASSERT_TRUE(flags
.get(THING2
) == FALSE
);
800 TEST_ASSERT_TRUE(flags
.get(THING3
) == TRUE
);
801 logln("remove THING1 -Value now: %d\n", flags
.getAll());
802 logln("get(thing1)=%d, get(thing2)=%d, get(thing3)=%d\n", flags
.get(THING1
), flags
.get(THING2
), flags
.get(THING3
));
805 logln("clear -Value now: %d\n", flags
.getAll());
806 logln("get(thing1)=%d, get(thing2)=%d, get(thing3)=%d\n", flags
.get(THING1
), flags
.get(THING2
), flags
.get(THING3
));
807 TEST_ASSERT_TRUE(flags
.get(THING1
) == FALSE
);
808 TEST_ASSERT_TRUE(flags
.get(THING2
) == FALSE
);
809 TEST_ASSERT_TRUE(flags
.get(THING3
) == FALSE
);