1 /********************************************************************
3 * Copyright (c) 1997-2016, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
9 * IntlTestUtilities is the medium level test class for everything in the directory "utility".
12 #include "unicode/utypes.h"
13 #include "unicode/errorcode.h"
14 #include "unicode/localpointer.h"
33 extern IntlTest
*createBytesTrieTest();
34 static IntlTest
*createLocalPointerTest();
35 extern IntlTest
*createUCharsTrieTest();
36 static IntlTest
*createEnumSetTest();
37 extern IntlTest
*createSimpleFormatterTest();
38 extern IntlTest
*createUnifiedCacheTest();
39 extern IntlTest
*createQuantityFormatterTest();
40 extern IntlTest
*createPluralMapTest();
43 #define CASE(id, test) case id: \
46 logln(#test "---"); logln(); \
52 void IntlTestUtilities::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* par
)
54 if (exec
) logln("TestSuite Utilities: ");
56 CASE(0, MultithreadTest
);
58 CASE(2, UnicodeStringTest
);
60 CASE(4, CharIterTest
);
63 CASE(7, ResourceBundleTest
);
64 CASE(8, NewResourceBundleTest
);
66 CASE(10, UVector32Test
);
67 CASE(11, UVectorTest
);
69 CASE(13, LocaleAliasTest
);
70 CASE(14, UnicodeSetTest
);
71 CASE(15, ErrorCodeTest
);
73 name
= "LocalPointerTest";
75 logln("TestSuite LocalPointerTest---"); logln();
76 LocalPointer
<IntlTest
> test(createLocalPointerTest());
81 name
= "BytesTrieTest";
83 logln("TestSuite BytesTrieTest---"); logln();
84 LocalPointer
<IntlTest
> test(createBytesTrieTest());
89 name
= "UCharsTrieTest";
91 logln("TestSuite UCharsTrieTest---"); logln();
92 LocalPointer
<IntlTest
> test(createUCharsTrieTest());
99 logln("TestSuite EnumSetTest---"); logln();
100 LocalPointer
<IntlTest
> test(createEnumSetTest());
101 callTest(*test
, par
);
105 name
= "SimpleFormatterTest";
107 logln("TestSuite SimpleFormatterTest---"); logln();
108 LocalPointer
<IntlTest
> test(createSimpleFormatterTest());
109 callTest(*test
, par
);
113 name
= "UnifiedCacheTest";
115 logln("TestSuite UnifiedCacheTest---"); logln();
116 LocalPointer
<IntlTest
> test(createUnifiedCacheTest());
117 callTest(*test
, par
);
121 name
= "QuantityFormatterTest";
123 logln("TestSuite QuantityFormatterTest---"); logln();
124 LocalPointer
<IntlTest
> test(createQuantityFormatterTest());
125 callTest(*test
, par
);
129 name
= "PluralMapTest";
131 logln("TestSuite PluralMapTest---"); logln();
132 LocalPointer
<IntlTest
> test(createPluralMapTest());
133 callTest(*test
, par
);
136 default: name
= ""; break; //needed to end loop
140 void ErrorCodeTest::runIndexedTest(int32_t index
, UBool exec
, const char* &name
, char* /*par*/) {
141 if (exec
) logln("TestSuite Utilities: ");
143 case 0: name
= "TestErrorCode"; if (exec
) TestErrorCode(); break;
144 case 1: name
= "TestSubclass"; if (exec
) TestSubclass(); break;
145 default: name
= ""; break; //needed to end loop
149 static void RefPlusOne(UErrorCode
&code
) { code
=(UErrorCode
)(code
+1); }
150 static void PtrPlusTwo(UErrorCode
*code
) { *code
=(UErrorCode
)(*code
+2); }
152 void ErrorCodeTest::TestErrorCode() {
154 if(errorCode
.get()!=U_ZERO_ERROR
|| !errorCode
.isSuccess() || errorCode
.isFailure()) {
155 errln("ErrorCode did not initialize properly");
158 errorCode
.assertSuccess();
159 if(errorCode
.errorName()!=u_errorName(U_ZERO_ERROR
)) {
160 errln("ErrorCode did not format error message string properly");
162 RefPlusOne(errorCode
);
163 if(errorCode
.get()!=U_ILLEGAL_ARGUMENT_ERROR
|| errorCode
.isSuccess() || !errorCode
.isFailure()) {
164 errln("ErrorCode did not yield a writable reference");
166 PtrPlusTwo(errorCode
);
167 if(errorCode
.get()!=U_INVALID_FORMAT_ERROR
|| errorCode
.isSuccess() || !errorCode
.isFailure()) {
168 errln("ErrorCode did not yield a writable pointer");
170 errorCode
.set(U_PARSE_ERROR
);
171 if(errorCode
.get()!=U_PARSE_ERROR
|| errorCode
.isSuccess() || !errorCode
.isFailure()) {
172 errln("ErrorCode.set() failed");
174 if( errorCode
.reset()!=U_PARSE_ERROR
|| errorCode
.get()!=U_ZERO_ERROR
||
175 !errorCode
.isSuccess() || errorCode
.isFailure()
177 errln("ErrorCode did not reset properly");
181 class MyErrorCode
: public ErrorCode
{
183 MyErrorCode(int32_t &countChecks
, int32_t &countDests
)
184 : checks(countChecks
), dests(countDests
) {}
191 virtual void handleFailure() const {
198 void ErrorCodeTest::TestSubclass() {
199 int32_t countChecks
=0;
200 int32_t countDests
=0;
202 MyErrorCode
errorCode(countChecks
, countDests
);
203 if( errorCode
.get()!=U_ZERO_ERROR
|| !errorCode
.isSuccess() || errorCode
.isFailure() ||
204 countChecks
!=0 || countDests
!=0
206 errln("ErrorCode did not initialize properly");
209 errorCode
.assertSuccess();
211 errln("ErrorCode.assertSuccess() called handleFailure() despite success");
213 RefPlusOne(errorCode
);
214 if(errorCode
.get()!=U_ILLEGAL_ARGUMENT_ERROR
|| errorCode
.isSuccess() || !errorCode
.isFailure()) {
215 errln("ErrorCode did not yield a writable reference");
217 errorCode
.assertSuccess();
219 errln("ErrorCode.assertSuccess() did not handleFailure()");
221 PtrPlusTwo(errorCode
);
222 if(errorCode
.get()!=U_INVALID_FORMAT_ERROR
|| errorCode
.isSuccess() || !errorCode
.isFailure()) {
223 errln("ErrorCode did not yield a writable pointer");
225 errorCode
.assertSuccess();
227 errln("ErrorCode.assertSuccess() did not handleFailure()");
229 errorCode
.set(U_PARSE_ERROR
);
230 if(errorCode
.get()!=U_PARSE_ERROR
|| errorCode
.isSuccess() || !errorCode
.isFailure()) {
231 errln("ErrorCode.set() failed");
233 if( errorCode
.reset()!=U_PARSE_ERROR
|| errorCode
.get()!=U_ZERO_ERROR
||
234 !errorCode
.isSuccess() || errorCode
.isFailure()
236 errln("ErrorCode did not reset properly");
238 errorCode
.assertSuccess();
240 errln("ErrorCode.assertSuccess() called handleFailure() despite success");
244 errln("MyErrorCode destructor detected failure despite success");
246 countChecks
=countDests
=0;
248 MyErrorCode
errorCode(countChecks
, countDests
);
249 errorCode
.set(U_PARSE_ERROR
);
252 errln("MyErrorCode destructor failed to detect failure");
256 class LocalPointerTest
: public IntlTest
{
258 LocalPointerTest() {}
260 void runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
=NULL
);
262 void TestLocalPointer();
263 void TestLocalPointerMoveSwap();
264 void TestLocalArray();
265 void TestLocalArrayMoveSwap();
266 void TestLocalXyzPointer();
267 void TestLocalXyzPointerMoveSwap();
268 void TestLocalXyzPointerNull();
271 static IntlTest
*createLocalPointerTest() {
272 return new LocalPointerTest();
275 void LocalPointerTest::runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char * /*par*/) {
277 logln("TestSuite LocalPointerTest: ");
280 TESTCASE_AUTO(TestLocalPointer
);
281 TESTCASE_AUTO(TestLocalPointerMoveSwap
);
282 TESTCASE_AUTO(TestLocalArray
);
283 TESTCASE_AUTO(TestLocalArrayMoveSwap
);
284 TESTCASE_AUTO(TestLocalXyzPointer
);
285 TESTCASE_AUTO(TestLocalXyzPointerMoveSwap
);
286 TESTCASE_AUTO(TestLocalXyzPointerNull
);
290 // Exercise almost every LocalPointer and LocalPointerBase method.
291 void LocalPointerTest::TestLocalPointer() {
293 LocalPointer
<UnicodeString
> s(new UnicodeString((UChar32
)0x50005));
294 // isNULL(), isValid(), operator==(), operator!=()
295 if(s
.isNull() || !s
.isValid() || s
==NULL
|| !(s
!=NULL
)) {
296 errln("LocalPointer constructor or NULL test failure");
299 // getAlias(), operator->, operator*
300 if(s
.getAlias()->length()!=2 || s
->length()!=2 || (*s
).length()!=2) {
301 errln("LocalPointer access failure");
303 // adoptInstead(), orphan()
304 s
.adoptInstead(new UnicodeString((UChar
)0xfffc));
306 errln("LocalPointer adoptInstead(U+FFFC) failure");
308 UnicodeString
*orphan
=s
.orphan();
309 if(orphan
==NULL
|| orphan
->length()!=1 || s
.isValid() || s
!=NULL
) {
310 errln("LocalPointer orphan() failure");
313 s
.adoptInstead(new UnicodeString());
315 errln("LocalPointer adoptInstead(empty) failure");
318 // LocalPointer(p, errorCode) sets U_MEMORY_ALLOCATION_ERROR if p==NULL.
319 UErrorCode errorCode
= U_ZERO_ERROR
;
320 LocalPointer
<CharString
> csx(new CharString("some chars", errorCode
), errorCode
);
321 if(csx
.isNull() && U_SUCCESS(errorCode
)) {
322 errln("LocalPointer(p, errorCode) failure");
325 errorCode
= U_ZERO_ERROR
;
326 csx
.adoptInsteadAndCheckErrorCode(new CharString("different chars", errorCode
), errorCode
);
327 if(csx
.isNull() && U_SUCCESS(errorCode
)) {
328 errln("adoptInsteadAndCheckErrorCode(p, errorCode) failure");
331 // Incoming failure: Keep the current object and delete the input object.
332 errorCode
= U_ILLEGAL_ARGUMENT_ERROR
;
333 csx
.adoptInsteadAndCheckErrorCode(new CharString("unused", errorCode
), errorCode
);
334 if(csx
.isValid() && strcmp(csx
->data(), "different chars") != 0) {
335 errln("adoptInsteadAndCheckErrorCode(p, U_FAILURE) did not retain the old object");
338 errorCode
= U_ZERO_ERROR
;
339 csx
.adoptInsteadAndCheckErrorCode(NULL
, errorCode
);
340 if(errorCode
!= U_MEMORY_ALLOCATION_ERROR
) {
341 errln("adoptInsteadAndCheckErrorCode(NULL, errorCode) did not set U_MEMORY_ALLOCATION_ERROR");
345 errln("adoptInsteadAndCheckErrorCode(NULL, errorCode) kept the object");
348 errorCode
= U_ZERO_ERROR
;
349 LocalPointer
<CharString
> null(NULL
, errorCode
);
350 if(errorCode
!= U_MEMORY_ALLOCATION_ERROR
) {
351 errln("LocalPointer(NULL, errorCode) did not set U_MEMORY_ALLOCATION_ERROR");
358 void LocalPointerTest::TestLocalPointerMoveSwap() {
359 UnicodeString
*p1
= new UnicodeString((UChar
)0x61);
360 UnicodeString
*p2
= new UnicodeString((UChar
)0x62);
361 LocalPointer
<UnicodeString
> s1(p1
);
362 LocalPointer
<UnicodeString
> s2(p2
);
364 if(s1
.getAlias() != p2
|| s2
.getAlias() != p1
) {
365 errln("LocalPointer.swap() did not swap");
368 if(s1
.getAlias() != p1
|| s2
.getAlias() != p2
) {
369 errln("swap(LocalPointer) did not swap back");
371 LocalPointer
<UnicodeString
> s3
;
373 if(s3
.getAlias() != p1
|| s1
.isValid()) {
374 errln("LocalPointer.moveFrom() did not move");
376 #if U_HAVE_RVALUE_REFERENCES
377 infoln("TestLocalPointerMoveSwap() with rvalue references");
378 s1
= static_cast<LocalPointer
<UnicodeString
> &&>(s3
);
379 if(s1
.getAlias() != p1
|| s3
.isValid()) {
380 errln("LocalPointer move assignment operator did not move");
382 LocalPointer
<UnicodeString
> s4(static_cast<LocalPointer
<UnicodeString
> &&>(s2
));
383 if(s4
.getAlias() != p2
|| s2
.isValid()) {
384 errln("LocalPointer move constructor did not move");
387 infoln("TestLocalPointerMoveSwap() without rvalue references");
390 // Move self assignment leaves the object valid but in an undefined state.
391 // Do it to make sure there is no crash,
392 // but do not check for any particular resulting value.
397 // Exercise almost every LocalArray method (but not LocalPointerBase).
398 void LocalPointerTest::TestLocalArray() {
400 LocalArray
<UnicodeString
> a(new UnicodeString
[2]);
402 a
[0].append((UChar
)0x61);
403 a
[1].append((UChar32
)0x60006);
404 if(a
[0].length()!=1 || a
[1].length()!=2) {
405 errln("LocalArray access failure");
408 a
.adoptInstead(new UnicodeString
[4]);
409 a
[3].append((UChar
)0x62).append((UChar
)0x63).reverse();
410 if(a
[3].length()!=2 || a
[3][1]!=0x62) {
411 errln("LocalArray adoptInstead() failure");
414 // LocalArray(p, errorCode) sets U_MEMORY_ALLOCATION_ERROR if p==NULL.
415 UErrorCode errorCode
= U_ZERO_ERROR
;
416 LocalArray
<UnicodeString
> ua(new UnicodeString
[3], errorCode
);
417 if(ua
.isNull() && U_SUCCESS(errorCode
)) {
418 errln("LocalArray(p, errorCode) failure");
421 errorCode
= U_ZERO_ERROR
;
422 UnicodeString
*u4
= new UnicodeString
[4];
423 ua
.adoptInsteadAndCheckErrorCode(u4
, errorCode
);
424 if(ua
.isNull() && U_SUCCESS(errorCode
)) {
425 errln("adoptInsteadAndCheckErrorCode(p, errorCode) failure");
428 // Incoming failure: Keep the current object and delete the input object.
429 errorCode
= U_ILLEGAL_ARGUMENT_ERROR
;
430 ua
.adoptInsteadAndCheckErrorCode(new UnicodeString
[5], errorCode
);
431 if(ua
.isValid() && ua
.getAlias() != u4
) {
432 errln("adoptInsteadAndCheckErrorCode(p, U_FAILURE) did not retain the old array");
435 errorCode
= U_ZERO_ERROR
;
436 ua
.adoptInsteadAndCheckErrorCode(NULL
, errorCode
);
437 if(errorCode
!= U_MEMORY_ALLOCATION_ERROR
) {
438 errln("adoptInsteadAndCheckErrorCode(NULL, errorCode) did not set U_MEMORY_ALLOCATION_ERROR");
442 errln("adoptInsteadAndCheckErrorCode(NULL, errorCode) kept the array");
445 errorCode
= U_ZERO_ERROR
;
446 LocalArray
<UnicodeString
> null(NULL
, errorCode
);
447 if(errorCode
!= U_MEMORY_ALLOCATION_ERROR
) {
448 errln("LocalArray(NULL, errorCode) did not set U_MEMORY_ALLOCATION_ERROR");
455 void LocalPointerTest::TestLocalArrayMoveSwap() {
456 UnicodeString
*p1
= new UnicodeString
[2];
457 UnicodeString
*p2
= new UnicodeString
[3];
458 LocalArray
<UnicodeString
> a1(p1
);
459 LocalArray
<UnicodeString
> a2(p2
);
461 if(a1
.getAlias() != p2
|| a2
.getAlias() != p1
) {
462 errln("LocalArray.swap() did not swap");
465 if(a1
.getAlias() != p1
|| a2
.getAlias() != p2
) {
466 errln("swap(LocalArray) did not swap back");
468 LocalArray
<UnicodeString
> a3
;
470 if(a3
.getAlias() != p1
|| a1
.isValid()) {
471 errln("LocalArray.moveFrom() did not move");
473 #if U_HAVE_RVALUE_REFERENCES
474 infoln("TestLocalArrayMoveSwap() with rvalue references");
475 a1
= static_cast<LocalArray
<UnicodeString
> &&>(a3
);
476 if(a1
.getAlias() != p1
|| a3
.isValid()) {
477 errln("LocalArray move assignment operator did not move");
479 LocalArray
<UnicodeString
> a4(static_cast<LocalArray
<UnicodeString
> &&>(a2
));
480 if(a4
.getAlias() != p2
|| a2
.isValid()) {
481 errln("LocalArray move constructor did not move");
484 infoln("TestLocalArrayMoveSwap() without rvalue references");
487 // Move self assignment leaves the object valid but in an undefined state.
488 // Do it to make sure there is no crash,
489 // but do not check for any particular resulting value.
494 #include "unicode/ucnvsel.h"
495 #include "unicode/ucal.h"
496 #include "unicode/udatpg.h"
497 #include "unicode/uidna.h"
498 #include "unicode/uldnames.h"
499 #include "unicode/umsg.h"
500 #include "unicode/unorm2.h"
501 #include "unicode/uregex.h"
502 #include "unicode/utrans.h"
504 // Use LocalXyzPointer types that are not covered elsewhere in the intltest suite.
505 void LocalPointerTest::TestLocalXyzPointer() {
506 IcuTestErrorCode
errorCode(*this, "TestLocalXyzPointer");
508 static const char *const encoding
="ISO-8859-1";
509 LocalUConverterSelectorPointer
sel(
510 ucnvsel_open(&encoding
, 1, NULL
, UCNV_ROUNDTRIP_SET
, errorCode
));
511 if(errorCode
.logIfFailureAndReset("ucnvsel_open()")) {
515 errln("LocalUConverterSelectorPointer failure");
519 #if !UCONFIG_NO_FORMATTING
520 LocalUCalendarPointer
cal(ucal_open(NULL
, 0, "root", UCAL_GREGORIAN
, errorCode
));
521 if(errorCode
.logDataIfFailureAndReset("ucal_open()")) {
525 errln("LocalUCalendarPointer failure");
529 LocalUDateTimePatternGeneratorPointer
patgen(udatpg_open("root", errorCode
));
530 if(errorCode
.logDataIfFailureAndReset("udatpg_open()")) {
533 if(patgen
.isNull()) {
534 errln("LocalUDateTimePatternGeneratorPointer failure");
538 LocalULocaleDisplayNamesPointer
ldn(uldn_open("de-CH", ULDN_STANDARD_NAMES
, errorCode
));
539 if(errorCode
.logIfFailureAndReset("uldn_open()")) {
543 errln("LocalULocaleDisplayNamesPointer failure");
547 UnicodeString hello
=UNICODE_STRING_SIMPLE("Hello {0}!");
548 LocalUMessageFormatPointer
msg(
549 umsg_open(hello
.getBuffer(), hello
.length(), "root", NULL
, errorCode
));
550 if(errorCode
.logIfFailureAndReset("umsg_open()")) {
554 errln("LocalUMessageFormatPointer failure");
557 #endif /* UCONFIG_NO_FORMATTING */
559 #if !UCONFIG_NO_NORMALIZATION
560 const UNormalizer2
*nfc
=unorm2_getNFCInstance(errorCode
);
562 LocalUNormalizer2Pointer
fn2(unorm2_openFiltered(nfc
, emptySet
.toUSet(), errorCode
));
563 if(errorCode
.logIfFailureAndReset("unorm2_openFiltered()")) {
567 errln("LocalUNormalizer2Pointer failure");
570 #endif /* !UCONFIG_NO_NORMALIZATION */
573 LocalUIDNAPointer
idna(uidna_openUTS46(0, errorCode
));
574 if(errorCode
.logIfFailureAndReset("uidna_openUTS46()")) {
578 errln("LocalUIDNAPointer failure");
581 #endif /* !UCONFIG_NO_IDNA */
583 #if !UCONFIG_NO_REGULAR_EXPRESSIONS
584 UnicodeString pattern
=UNICODE_STRING_SIMPLE("abc|xy+z");
585 LocalURegularExpressionPointer
regex(
586 uregex_open(pattern
.getBuffer(), pattern
.length(), 0, NULL
, errorCode
));
587 if(errorCode
.logIfFailureAndReset("uregex_open()")) {
591 errln("LocalURegularExpressionPointer failure");
594 #endif /* UCONFIG_NO_REGULAR_EXPRESSIONS */
596 #if !UCONFIG_NO_TRANSLITERATION
597 UnicodeString id
=UNICODE_STRING_SIMPLE("Grek-Latn");
598 LocalUTransliteratorPointer
trans(
599 utrans_openU(id
.getBuffer(), id
.length(), UTRANS_FORWARD
, NULL
, 0, NULL
, errorCode
));
600 if(errorCode
.logIfFailureAndReset("utrans_open()")) {
604 errln("LocalUTransliteratorPointer failure");
607 #endif /* !UCONFIG_NO_TRANSLITERATION */
612 void LocalPointerTest::TestLocalXyzPointerMoveSwap() {
613 #if !UCONFIG_NO_NORMALIZATION
614 IcuTestErrorCode
errorCode(*this, "TestLocalXyzPointerMoveSwap");
615 const UNormalizer2
*nfc
=unorm2_getNFCInstance(errorCode
);
616 const UNormalizer2
*nfd
=unorm2_getNFDInstance(errorCode
);
617 if(errorCode
.logIfFailureAndReset("unorm2_getNF[CD]Instance()")) {
621 UNormalizer2
*p1
= unorm2_openFiltered(nfc
, emptySet
.toUSet(), errorCode
);
622 UNormalizer2
*p2
= unorm2_openFiltered(nfd
, emptySet
.toUSet(), errorCode
);
623 LocalUNormalizer2Pointer
f1(p1
);
624 LocalUNormalizer2Pointer
f2(p2
);
625 if(errorCode
.logIfFailureAndReset("unorm2_openFiltered()")) {
628 if(f1
.isNull() || f2
.isNull()) {
629 errln("LocalUNormalizer2Pointer failure");
633 if(f1
.getAlias() != p2
|| f2
.getAlias() != p1
) {
634 errln("LocalUNormalizer2Pointer.swap() did not swap");
637 if(f1
.getAlias() != p1
|| f2
.getAlias() != p2
) {
638 errln("swap(LocalUNormalizer2Pointer) did not swap back");
640 LocalUNormalizer2Pointer f3
;
642 if(f3
.getAlias() != p1
|| f1
.isValid()) {
643 errln("LocalUNormalizer2Pointer.moveFrom() did not move");
645 #if U_HAVE_RVALUE_REFERENCES
646 infoln("TestLocalXyzPointerMoveSwap() with rvalue references");
647 f1
= static_cast<LocalUNormalizer2Pointer
&&>(f3
);
648 if(f1
.getAlias() != p1
|| f3
.isValid()) {
649 errln("LocalUNormalizer2Pointer move assignment operator did not move");
651 LocalUNormalizer2Pointer
f4(static_cast<LocalUNormalizer2Pointer
&&>(f2
));
652 if(f4
.getAlias() != p2
|| f2
.isValid()) {
653 errln("LocalUNormalizer2Pointer move constructor did not move");
656 infoln("TestLocalXyzPointerMoveSwap() without rvalue references");
658 // Move self assignment leaves the object valid but in an undefined state.
659 // Do it to make sure there is no crash,
660 // but do not check for any particular resulting value.
663 #endif /* !UCONFIG_NO_NORMALIZATION */
666 // Try LocalXyzPointer types with NULL pointers.
667 void LocalPointerTest::TestLocalXyzPointerNull() {
669 IcuTestErrorCode
errorCode(*this, "TestLocalXyzPointerNull/LocalUConverterSelectorPointer");
670 static const char *const encoding
="ISO-8859-1";
671 LocalUConverterSelectorPointer null
;
672 LocalUConverterSelectorPointer
sel(
673 ucnvsel_open(&encoding
, 1, NULL
, UCNV_ROUNDTRIP_SET
, errorCode
));
674 sel
.adoptInstead(NULL
);
676 #if !UCONFIG_NO_FORMATTING
678 IcuTestErrorCode
errorCode(*this, "TestLocalXyzPointerNull/LocalUCalendarPointer");
679 LocalUCalendarPointer null
;
680 LocalUCalendarPointer
cal(ucal_open(NULL
, 0, "root", UCAL_GREGORIAN
, errorCode
));
681 if(!errorCode
.logDataIfFailureAndReset("ucal_open()")) {
682 cal
.adoptInstead(NULL
);
686 IcuTestErrorCode
errorCode(*this, "TestLocalXyzPointerNull/LocalUDateTimePatternGeneratorPointer");
687 LocalUDateTimePatternGeneratorPointer null
;
688 LocalUDateTimePatternGeneratorPointer
patgen(udatpg_open("root", errorCode
));
689 patgen
.adoptInstead(NULL
);
692 IcuTestErrorCode
errorCode(*this, "TestLocalXyzPointerNull/LocalUMessageFormatPointer");
693 UnicodeString hello
=UNICODE_STRING_SIMPLE("Hello {0}!");
694 LocalUMessageFormatPointer null
;
695 LocalUMessageFormatPointer
msg(
696 umsg_open(hello
.getBuffer(), hello
.length(), "root", NULL
, errorCode
));
697 msg
.adoptInstead(NULL
);
699 #endif /* !UCONFIG_NO_FORMATTING */
701 #if !UCONFIG_NO_REGULAR_EXPRESSIONS
703 IcuTestErrorCode
errorCode(*this, "TestLocalXyzPointerNull/LocalURegularExpressionPointer");
704 UnicodeString pattern
=UNICODE_STRING_SIMPLE("abc|xy+z");
705 LocalURegularExpressionPointer null
;
706 LocalURegularExpressionPointer
regex(
707 uregex_open(pattern
.getBuffer(), pattern
.length(), 0, NULL
, errorCode
));
708 if(!errorCode
.logDataIfFailureAndReset("urege_open()")) {
709 regex
.adoptInstead(NULL
);
712 #endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS */
714 #if !UCONFIG_NO_TRANSLITERATION
716 IcuTestErrorCode
errorCode(*this, "TestLocalXyzPointerNull/LocalUTransliteratorPointer");
717 UnicodeString id
=UNICODE_STRING_SIMPLE("Grek-Latn");
718 LocalUTransliteratorPointer null
;
719 LocalUTransliteratorPointer
trans(
720 utrans_openU(id
.getBuffer(), id
.length(), UTRANS_FORWARD
, NULL
, 0, NULL
, errorCode
));
721 if(!errorCode
.logDataIfFailureAndReset("utrans_openU()")) {
722 trans
.adoptInstead(NULL
);
725 #endif /* !UCONFIG_NO_TRANSLITERATION */
730 #include "unicode/enumset.h"
732 class EnumSetTest
: public IntlTest
{
735 virtual void runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
=NULL
);
739 static IntlTest
*createEnumSetTest() {
740 return new EnumSetTest();
743 void EnumSetTest::runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char * /*par*/) {
745 TESTCASE_AUTO(TestEnumSet
);
756 void EnumSetTest::TestEnumSet() {
762 logln("Enum is from [%d..%d]\n", MAX_NONBOOLEAN
+1,
765 TEST_ASSERT_TRUE(flags
.get(THING1
) == FALSE
);
766 TEST_ASSERT_TRUE(flags
.get(THING2
) == FALSE
);
767 TEST_ASSERT_TRUE(flags
.get(THING3
) == FALSE
);
769 logln("get(thing1)=%d, get(thing2)=%d, get(thing3)=%d\n", flags
.get(THING1
), flags
.get(THING2
), flags
.get(THING3
));
770 logln("Value now: %d\n", flags
.getAll());
772 logln("clear -Value now: %d\n", flags
.getAll());
773 logln("get(thing1)=%d, get(thing2)=%d, get(thing3)=%d\n", flags
.get(THING1
), flags
.get(THING2
), flags
.get(THING3
));
774 TEST_ASSERT_TRUE(flags
.get(THING1
) == FALSE
);
775 TEST_ASSERT_TRUE(flags
.get(THING2
) == FALSE
);
776 TEST_ASSERT_TRUE(flags
.get(THING3
) == FALSE
);
778 logln("set THING1 -Value now: %d\n", flags
.getAll());
779 TEST_ASSERT_TRUE(flags
.get(THING1
) == TRUE
);
780 TEST_ASSERT_TRUE(flags
.get(THING2
) == FALSE
);
781 TEST_ASSERT_TRUE(flags
.get(THING3
) == FALSE
);
782 logln("get(thing1)=%d, get(thing2)=%d, get(thing3)=%d\n", flags
.get(THING1
), flags
.get(THING2
), flags
.get(THING3
));
784 logln("set THING3 -Value now: %d\n", flags
.getAll());
785 TEST_ASSERT_TRUE(flags
.get(THING1
) == TRUE
);
786 TEST_ASSERT_TRUE(flags
.get(THING2
) == FALSE
);
787 TEST_ASSERT_TRUE(flags
.get(THING3
) == TRUE
);
788 logln("get(thing1)=%d, get(thing2)=%d, get(thing3)=%d\n", flags
.get(THING1
), flags
.get(THING2
), flags
.get(THING3
));
789 flags
.remove(THING2
);
790 TEST_ASSERT_TRUE(flags
.get(THING1
) == TRUE
);
791 TEST_ASSERT_TRUE(flags
.get(THING2
) == FALSE
);
792 TEST_ASSERT_TRUE(flags
.get(THING3
) == TRUE
);
793 logln("remove THING2 -Value now: %d\n", flags
.getAll());
794 logln("get(thing1)=%d, get(thing2)=%d, get(thing3)=%d\n", flags
.get(THING1
), flags
.get(THING2
), flags
.get(THING3
));
795 flags
.remove(THING1
);
796 TEST_ASSERT_TRUE(flags
.get(THING1
) == FALSE
);
797 TEST_ASSERT_TRUE(flags
.get(THING2
) == FALSE
);
798 TEST_ASSERT_TRUE(flags
.get(THING3
) == TRUE
);
799 logln("remove THING1 -Value now: %d\n", flags
.getAll());
800 logln("get(thing1)=%d, get(thing2)=%d, get(thing3)=%d\n", flags
.get(THING1
), flags
.get(THING2
), flags
.get(THING3
));
803 logln("clear -Value now: %d\n", flags
.getAll());
804 logln("get(thing1)=%d, get(thing2)=%d, get(thing3)=%d\n", flags
.get(THING1
), flags
.get(THING2
), flags
.get(THING3
));
805 TEST_ASSERT_TRUE(flags
.get(THING1
) == FALSE
);
806 TEST_ASSERT_TRUE(flags
.get(THING2
) == FALSE
);
807 TEST_ASSERT_TRUE(flags
.get(THING3
) == FALSE
);