From 082cbac7fcaf29ecb38f8b466b59a046d00f07f4 Mon Sep 17 00:00:00 2001 From: Shane Carr Date: Wed, 13 Sep 2017 07:48:09 +0000 Subject: [PATCH] ICU-13351 Tests for new CurrencyUnit constructors. X-SVN-Rev: 40390 --- icu4c/source/test/intltest/numfmtst.cpp | 32 +++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/icu4c/source/test/intltest/numfmtst.cpp b/icu4c/source/test/intltest/numfmtst.cpp index ec251f1b483..8c77859d90a 100644 --- a/icu4c/source/test/intltest/numfmtst.cpp +++ b/icu4c/source/test/intltest/numfmtst.cpp @@ -2366,13 +2366,16 @@ void NumberFormatTest::TestCurrencyNames(void) { void NumberFormatTest::TestCurrencyUnit(void){ UErrorCode ec = U_ZERO_ERROR; static const UChar USD[] = {85, 83, 68, 0}; /*USD*/ + static const char USD8[] = {85, 83, 68, 0}; static const UChar BAD[] = {63, 63, 63, 0}; /*???*/ static const UChar BAD2[] = {63, 63, 65, 0}; /*???*/ + static const UChar XXX[] = u"XXX"; + static const char XXX8[] = {88, 88, 88}; CurrencyUnit cu(USD, ec); assertSuccess("CurrencyUnit", ec); - const UChar * r = cu.getISOCurrency(); // who is the buffer owner ? - assertEquals("getISOCurrency()", USD, r); + assertEquals("getISOCurrency()", USD, cu.getISOCurrency()); + assertEquals("getSubtype()", USD8, cu.getSubtype()); CurrencyUnit cu2(cu); if (!(cu2 == cu)){ @@ -2401,6 +2404,31 @@ void NumberFormatTest::TestCurrencyUnit(void){ errln("Currency unit assignment should be the same."); } delete cu3; + + // Test default constructor + CurrencyUnit def; + assertEquals("Default currency", XXX, def.getISOCurrency()); + assertEquals("Default currency as subtype", XXX8, def.getSubtype()); + + // Test slicing + MeasureUnit sliced1 = cu; + MeasureUnit sliced2 = cu; + assertEquals("Subtype after slicing 1", USD8, sliced1.getSubtype()); + assertEquals("Subtype after slicing 2", USD8, sliced2.getSubtype()); + CurrencyUnit restored1(sliced1, ec); + CurrencyUnit restored2(sliced2, ec); + assertSuccess("Restoring from MeasureUnit", ec); + assertEquals("Subtype after restoring 1", USD8, restored1.getSubtype()); + assertEquals("Subtype after restoring 2", USD8, restored2.getSubtype()); + assertEquals("ISO Code after restoring 1", USD, restored1.getISOCurrency()); + assertEquals("ISO Code after restoring 2", USD, restored2.getISOCurrency()); + + // Test copy constructor failure + LocalPointer meter(MeasureUnit::createMeter(ec)); + assertSuccess("Creating meter", ec); + CurrencyUnit failure(*meter, ec); + assertEquals("Copying from meter should fail", ec, U_ILLEGAL_ARGUMENT_ERROR); + assertEquals("Copying should not give uninitialized ISO code", u"", failure.getISOCurrency()); } void NumberFormatTest::TestCurrencyAmount(void){ -- 2.40.0