2 *******************************************************************************
3 * Copyright (C) 2014, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
7 * File QUANTITYFORMATTERTEST.CPP
9 ********************************************************************************
13 #include "quantityformatter.h"
14 #include "simplepatternformatter.h"
15 #include "unicode/numfmt.h"
16 #include "unicode/plurrule.h"
19 class QuantityFormatterTest
: public IntlTest
{
21 QuantityFormatterTest() {
24 void runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
=0);
28 void QuantityFormatterTest::runIndexedTest(int32_t index
, UBool exec
, const char* &name
, char* /*par*/) {
30 TESTCASE_AUTO(TestBasic
);
34 void QuantityFormatterTest::TestBasic() {
35 UErrorCode status
= U_ZERO_ERROR
;
36 #if !UCONFIG_NO_FORMATTING
37 QuantityFormatter fmt
;
40 fmt
.add("a bad variant", "{0} pounds", status
));
41 assertEquals("adding bad variant status", U_ILLEGAL_ARGUMENT_ERROR
, status
);
42 status
= U_ZERO_ERROR
;
45 fmt
.add("other", "{0} {1} too many placeholders", status
));
46 assertEquals("adding bad pattern status", U_ILLEGAL_ARGUMENT_ERROR
, status
);
47 status
= U_ZERO_ERROR
;
48 assertFalse("isValid with no patterns", fmt
.isValid());
50 "Adding good pattern with no placeholders",
51 fmt
.add("other", "no placeholder", status
));
53 "Adding good pattern",
54 fmt
.add("other", "{0} pounds", status
));
55 assertTrue("isValid with other", fmt
.isValid());
57 "Adding good pattern",
58 fmt
.add("one", "{0} pound", status
));
62 fmt
.getByVariant("bad variant")->getPatternWithNoPlaceholders(),
66 fmt
.getByVariant("other")->getPatternWithNoPlaceholders(),
70 fmt
.getByVariant("one")->getPatternWithNoPlaceholders(),
74 fmt
.getByVariant("few")->getPatternWithNoPlaceholders(),
77 // Test copy constructor
79 QuantityFormatter
copied(fmt
);
81 "copied getByVariant",
82 copied
.getByVariant("other")->getPatternWithNoPlaceholders(),
85 "copied getByVariant",
86 copied
.getByVariant("one")->getPatternWithNoPlaceholders(),
89 "copied getByVariant",
90 copied
.getByVariant("few")->getPatternWithNoPlaceholders(),
96 QuantityFormatter assigned
;
99 "assigned getByVariant",
100 assigned
.getByVariant("other")->getPatternWithNoPlaceholders(),
103 "assigned getByVariant",
104 assigned
.getByVariant("one")->getPatternWithNoPlaceholders(),
107 "assigned getByVariant",
108 assigned
.getByVariant("few")->getPatternWithNoPlaceholders(),
114 LocalPointer
<NumberFormat
> numfmt(
115 NumberFormat::createInstance(Locale::getEnglish(), status
));
116 LocalPointer
<PluralRules
> plurrule(
117 PluralRules::forLocale("en", status
));
118 FieldPosition
pos(FieldPosition::DONT_CARE
);
119 UnicodeString appendTo
;
143 assertFalse("isValid after reset", fmt
.isValid());
145 assertSuccess("", status
);
148 extern IntlTest
*createQuantityFormatterTest() {
149 return new QuantityFormatterTest();