+#include "unicode/ucnvsel.h"
+#include "unicode/ucal.h"
+#include "unicode/udatpg.h"
+#include "unicode/uidna.h"
+#include "unicode/uldnames.h"
+#include "unicode/umsg.h"
+#include "unicode/unorm2.h"
+#include "unicode/uregex.h"
+#include "unicode/utrans.h"
+
+// Use LocalXyzPointer types that are not covered elsewhere in the intltest suite.
+void LocalPointerTest::TestLocalXyzPointer() {
+ IcuTestErrorCode errorCode(*this, "TestLocalXyzPointer");
+
+ static const char *const encoding="ISO-8859-1";
+ LocalUConverterSelectorPointer sel(
+ ucnvsel_open(&encoding, 1, NULL, UCNV_ROUNDTRIP_SET, errorCode));
+ if(errorCode.logIfFailureAndReset("ucnvsel_open()")) {
+ return;
+ }
+ if(sel.isNull()) {
+ errln("LocalUConverterSelectorPointer failure");
+ return;
+ }
+
+#if !UCONFIG_NO_FORMATTING
+ LocalUCalendarPointer cal(ucal_open(NULL, 0, "root", UCAL_GREGORIAN, errorCode));
+ if(errorCode.logDataIfFailureAndReset("ucal_open()")) {
+ return;
+ }
+ if(cal.isNull()) {
+ errln("LocalUCalendarPointer failure");
+ return;
+ }
+
+ LocalUDateTimePatternGeneratorPointer patgen(udatpg_open("root", errorCode));
+ if(errorCode.logDataIfFailureAndReset("udatpg_open()")) {
+ return;
+ }
+ if(patgen.isNull()) {
+ errln("LocalUDateTimePatternGeneratorPointer failure");
+ return;
+ }
+
+ LocalULocaleDisplayNamesPointer ldn(uldn_open("de-CH", ULDN_STANDARD_NAMES, errorCode));
+ if(errorCode.logIfFailureAndReset("uldn_open()")) {
+ return;
+ }
+ if(ldn.isNull()) {
+ errln("LocalULocaleDisplayNamesPointer failure");
+ return;
+ }
+
+ UnicodeString hello=UNICODE_STRING_SIMPLE("Hello {0}!");
+ LocalUMessageFormatPointer msg(
+ umsg_open(hello.getBuffer(), hello.length(), "root", NULL, errorCode));
+ if(errorCode.logIfFailureAndReset("umsg_open()")) {
+ return;
+ }
+ if(msg.isNull()) {
+ errln("LocalUMessageFormatPointer failure");
+ return;
+ }
+#endif /* UCONFIG_NO_FORMATTING */
+
+#if !UCONFIG_NO_NORMALIZATION
+ const UNormalizer2 *nfc=unorm2_getNFCInstance(errorCode);
+ UnicodeSet emptySet;
+ LocalUNormalizer2Pointer fn2(unorm2_openFiltered(nfc, emptySet.toUSet(), errorCode));
+ if(errorCode.logIfFailureAndReset("unorm2_openFiltered()")) {
+ return;
+ }
+ if(fn2.isNull()) {
+ errln("LocalUNormalizer2Pointer failure");
+ return;
+ }
+#endif /* !UCONFIG_NO_NORMALIZATION */
+
+#if !UCONFIG_NO_IDNA
+ LocalUIDNAPointer idna(uidna_openUTS46(0, errorCode));
+ if(errorCode.logIfFailureAndReset("uidna_openUTS46()")) {
+ return;
+ }
+ if(idna.isNull()) {
+ errln("LocalUIDNAPointer failure");
+ return;
+ }
+#endif /* !UCONFIG_NO_IDNA */
+
+#if !UCONFIG_NO_REGULAR_EXPRESSIONS
+ UnicodeString pattern=UNICODE_STRING_SIMPLE("abc|xy+z");
+ LocalURegularExpressionPointer regex(
+ uregex_open(pattern.getBuffer(), pattern.length(), 0, NULL, errorCode));
+ if(errorCode.logIfFailureAndReset("uregex_open()")) {
+ return;
+ }
+ if(regex.isNull()) {
+ errln("LocalURegularExpressionPointer failure");
+ return;
+ }
+#endif /* UCONFIG_NO_REGULAR_EXPRESSIONS */
+
+#if !UCONFIG_NO_TRANSLITERATION
+ UnicodeString id=UNICODE_STRING_SIMPLE("Grek-Latn");
+ LocalUTransliteratorPointer trans(
+ utrans_openU(id.getBuffer(), id.length(), UTRANS_FORWARD, NULL, 0, NULL, errorCode));
+ if(errorCode.logIfFailureAndReset("utrans_open()")) {
+ return;
+ }
+ if(trans.isNull()) {
+ errln("LocalUTransliteratorPointer failure");
+ return;
+ }
+#endif /* !UCONFIG_NO_TRANSLITERATION */
+
+ // destructors
+}
+
+// Try LocalXyzPointer types with NULL pointers.
+void LocalPointerTest::TestLocalXyzPointerNull() {
+ {
+ IcuTestErrorCode errorCode(*this, "TestLocalXyzPointerNull/LocalUConverterSelectorPointer");
+ static const char *const encoding="ISO-8859-1";
+ LocalUConverterSelectorPointer null;
+ LocalUConverterSelectorPointer sel(
+ ucnvsel_open(&encoding, 1, NULL, UCNV_ROUNDTRIP_SET, errorCode));
+ sel.adoptInstead(NULL);
+ }
+#if !UCONFIG_NO_FORMATTING
+ {
+ IcuTestErrorCode errorCode(*this, "TestLocalXyzPointerNull/LocalUCalendarPointer");
+ LocalUCalendarPointer null;
+ LocalUCalendarPointer cal(ucal_open(NULL, 0, "root", UCAL_GREGORIAN, errorCode));
+ if(!errorCode.logDataIfFailureAndReset("ucal_open()")) {
+ cal.adoptInstead(NULL);
+ }
+ }
+ {
+ IcuTestErrorCode errorCode(*this, "TestLocalXyzPointerNull/LocalUDateTimePatternGeneratorPointer");
+ LocalUDateTimePatternGeneratorPointer null;
+ LocalUDateTimePatternGeneratorPointer patgen(udatpg_open("root", errorCode));
+ patgen.adoptInstead(NULL);
+ }
+ {
+ IcuTestErrorCode errorCode(*this, "TestLocalXyzPointerNull/LocalUMessageFormatPointer");
+ UnicodeString hello=UNICODE_STRING_SIMPLE("Hello {0}!");
+ LocalUMessageFormatPointer null;
+ LocalUMessageFormatPointer msg(
+ umsg_open(hello.getBuffer(), hello.length(), "root", NULL, errorCode));
+ msg.adoptInstead(NULL);
+ }
+#endif /* !UCONFIG_NO_FORMATTING */
+
+#if !UCONFIG_NO_REGULAR_EXPRESSIONS
+ {
+ IcuTestErrorCode errorCode(*this, "TestLocalXyzPointerNull/LocalURegularExpressionPointer");
+ UnicodeString pattern=UNICODE_STRING_SIMPLE("abc|xy+z");
+ LocalURegularExpressionPointer null;
+ LocalURegularExpressionPointer regex(
+ uregex_open(pattern.getBuffer(), pattern.length(), 0, NULL, errorCode));
+ if(!errorCode.logDataIfFailureAndReset("urege_open()")) {
+ regex.adoptInstead(NULL);
+ }
+ }
+#endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS */
+
+#if !UCONFIG_NO_TRANSLITERATION
+ {
+ IcuTestErrorCode errorCode(*this, "TestLocalXyzPointerNull/LocalUTransliteratorPointer");
+ UnicodeString id=UNICODE_STRING_SIMPLE("Grek-Latn");
+ LocalUTransliteratorPointer null;
+ LocalUTransliteratorPointer trans(
+ utrans_openU(id.getBuffer(), id.length(), UTRANS_FORWARD, NULL, 0, NULL, errorCode));
+ if(!errorCode.logDataIfFailureAndReset("utrans_openU()")) {
+ trans.adoptInstead(NULL);
+ }
+ }
+#endif /* !UCONFIG_NO_TRANSLITERATION */
+
+}
+
+/** EnumSet test **/
+#include "unicode/enumset.h"
+
+class EnumSetTest : public IntlTest {
+public:
+ EnumSetTest() {}
+ virtual void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par=NULL);
+ void TestEnumSet();
+};
+
+static IntlTest *createEnumSetTest() {
+ return new EnumSetTest();
+}
+
+void EnumSetTest::runIndexedTest(int32_t index, UBool exec, const char *&name, char * /*par*/) {
+ TESTCASE_AUTO_BEGIN;
+ TESTCASE_AUTO(TestEnumSet);
+ TESTCASE_AUTO_END;
+}
+enum myEnum {
+ MAX_NONBOOLEAN=-1,
+ THING1,
+ THING2,
+ THING3,
+ LIMIT_BOOLEAN
+};
+
+void EnumSetTest::TestEnumSet() {
+ EnumSet<myEnum,
+ MAX_NONBOOLEAN+1,
+ LIMIT_BOOLEAN>
+ flags;
+
+ logln("Enum is from [%d..%d]\n", MAX_NONBOOLEAN+1,
+ LIMIT_BOOLEAN);
+
+ TEST_ASSERT_TRUE(flags.get(THING1) == FALSE);
+ TEST_ASSERT_TRUE(flags.get(THING2) == FALSE);
+ TEST_ASSERT_TRUE(flags.get(THING3) == FALSE);
+
+ logln("get(thing1)=%d, get(thing2)=%d, get(thing3)=%d\n", flags.get(THING1), flags.get(THING2), flags.get(THING3));
+ logln("Value now: %d\n", flags.getAll());
+ flags.clear();
+ logln("clear -Value now: %d\n", flags.getAll());
+ logln("get(thing1)=%d, get(thing2)=%d, get(thing3)=%d\n", flags.get(THING1), flags.get(THING2), flags.get(THING3));
+ TEST_ASSERT_TRUE(flags.get(THING1) == FALSE);
+ TEST_ASSERT_TRUE(flags.get(THING2) == FALSE);
+ TEST_ASSERT_TRUE(flags.get(THING3) == FALSE);
+ flags.add(THING1);
+ logln("set THING1 -Value now: %d\n", flags.getAll());
+ TEST_ASSERT_TRUE(flags.get(THING1) == TRUE);
+ TEST_ASSERT_TRUE(flags.get(THING2) == FALSE);
+ TEST_ASSERT_TRUE(flags.get(THING3) == FALSE);
+ logln("get(thing1)=%d, get(thing2)=%d, get(thing3)=%d\n", flags.get(THING1), flags.get(THING2), flags.get(THING3));
+ flags.add(THING3);
+ logln("set THING3 -Value now: %d\n", flags.getAll());
+ TEST_ASSERT_TRUE(flags.get(THING1) == TRUE);
+ TEST_ASSERT_TRUE(flags.get(THING2) == FALSE);
+ TEST_ASSERT_TRUE(flags.get(THING3) == TRUE);
+ logln("get(thing1)=%d, get(thing2)=%d, get(thing3)=%d\n", flags.get(THING1), flags.get(THING2), flags.get(THING3));
+ flags.remove(THING2);
+ TEST_ASSERT_TRUE(flags.get(THING1) == TRUE);
+ TEST_ASSERT_TRUE(flags.get(THING2) == FALSE);
+ TEST_ASSERT_TRUE(flags.get(THING3) == TRUE);
+ logln("remove THING2 -Value now: %d\n", flags.getAll());
+ logln("get(thing1)=%d, get(thing2)=%d, get(thing3)=%d\n", flags.get(THING1), flags.get(THING2), flags.get(THING3));
+ flags.remove(THING1);
+ TEST_ASSERT_TRUE(flags.get(THING1) == FALSE);
+ TEST_ASSERT_TRUE(flags.get(THING2) == FALSE);
+ TEST_ASSERT_TRUE(flags.get(THING3) == TRUE);
+ logln("remove THING1 -Value now: %d\n", flags.getAll());
+ logln("get(thing1)=%d, get(thing2)=%d, get(thing3)=%d\n", flags.get(THING1), flags.get(THING2), flags.get(THING3));
+
+ flags.clear();
+ logln("clear -Value now: %d\n", flags.getAll());
+ logln("get(thing1)=%d, get(thing2)=%d, get(thing3)=%d\n", flags.get(THING1), flags.get(THING2), flags.get(THING3));
+ TEST_ASSERT_TRUE(flags.get(THING1) == FALSE);
+ TEST_ASSERT_TRUE(flags.get(THING2) == FALSE);
+ TEST_ASSERT_TRUE(flags.get(THING3) == FALSE);
+}