Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: source/test/intltest/quantityformattertest.cpp

Issue 845603002: Update ICU to 54.1 step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@master
Patch Set: remove unusued directories Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « source/test/intltest/plurults.cpp ('k') | source/test/intltest/rbbiapts.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: source/test/intltest/quantityformattertest.cpp
diff --git a/source/test/intltest/quantityformattertest.cpp b/source/test/intltest/quantityformattertest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0167075f5bc5babbd82a2424d0e06b79d44ecf5f
--- /dev/null
+++ b/source/test/intltest/quantityformattertest.cpp
@@ -0,0 +1,150 @@
+/*
+*******************************************************************************
+* Copyright (C) 2014, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+* File QUANTITYFORMATTERTEST.CPP
+*
+********************************************************************************
+*/
+#include "cstring.h"
+#include "intltest.h"
+#include "quantityformatter.h"
+#include "simplepatternformatter.h"
+#include "unicode/numfmt.h"
+#include "unicode/plurrule.h"
+
+
+class QuantityFormatterTest : public IntlTest {
+public:
+ QuantityFormatterTest() {
+ }
+ void TestBasic();
+ void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par=0);
+private:
+};
+
+void QuantityFormatterTest::runIndexedTest(int32_t index, UBool exec, const char* &name, char* /*par*/) {
+ TESTCASE_AUTO_BEGIN;
+ TESTCASE_AUTO(TestBasic);
+ TESTCASE_AUTO_END;
+}
+
+void QuantityFormatterTest::TestBasic() {
+ UErrorCode status = U_ZERO_ERROR;
+#if !UCONFIG_NO_FORMATTING
+ QuantityFormatter fmt;
+ assertFalse(
+ "adding bad variant",
+ fmt.add("a bad variant", "{0} pounds", status));
+ assertEquals("adding bad variant status", U_ILLEGAL_ARGUMENT_ERROR, status);
+ status = U_ZERO_ERROR;
+ assertFalse(
+ "Adding bad pattern",
+ fmt.add("other", "{0} {1} too many placeholders", status));
+ assertEquals("adding bad pattern status", U_ILLEGAL_ARGUMENT_ERROR, status);
+ status = U_ZERO_ERROR;
+ assertFalse("isValid with no patterns", fmt.isValid());
+ assertTrue(
+ "Adding good pattern with no placeholders",
+ fmt.add("other", "no placeholder", status));
+ assertTrue(
+ "Adding good pattern",
+ fmt.add("other", "{0} pounds", status));
+ assertTrue("isValid with other", fmt.isValid());
+ assertTrue(
+ "Adding good pattern",
+ fmt.add("one", "{0} pound", status));
+
+ assertEquals(
+ "getByVariant",
+ fmt.getByVariant("bad variant")->getPatternWithNoPlaceholders(),
+ " pounds");
+ assertEquals(
+ "getByVariant",
+ fmt.getByVariant("other")->getPatternWithNoPlaceholders(),
+ " pounds");
+ assertEquals(
+ "getByVariant",
+ fmt.getByVariant("one")->getPatternWithNoPlaceholders(),
+ " pound");
+ assertEquals(
+ "getByVariant",
+ fmt.getByVariant("few")->getPatternWithNoPlaceholders(),
+ " pounds");
+
+ // Test copy constructor
+ {
+ QuantityFormatter copied(fmt);
+ assertEquals(
+ "copied getByVariant",
+ copied.getByVariant("other")->getPatternWithNoPlaceholders(),
+ " pounds");
+ assertEquals(
+ "copied getByVariant",
+ copied.getByVariant("one")->getPatternWithNoPlaceholders(),
+ " pound");
+ assertEquals(
+ "copied getByVariant",
+ copied.getByVariant("few")->getPatternWithNoPlaceholders(),
+ " pounds");
+ }
+
+ // Test assignment
+ {
+ QuantityFormatter assigned;
+ assigned = fmt;
+ assertEquals(
+ "assigned getByVariant",
+ assigned.getByVariant("other")->getPatternWithNoPlaceholders(),
+ " pounds");
+ assertEquals(
+ "assigned getByVariant",
+ assigned.getByVariant("one")->getPatternWithNoPlaceholders(),
+ " pound");
+ assertEquals(
+ "assigned getByVariant",
+ assigned.getByVariant("few")->getPatternWithNoPlaceholders(),
+ " pounds");
+ }
+
+ // Test format.
+ {
+ LocalPointer<NumberFormat> numfmt(
+ NumberFormat::createInstance(Locale::getEnglish(), status));
+ LocalPointer<PluralRules> plurrule(
+ PluralRules::forLocale("en", status));
+ FieldPosition pos(FieldPosition::DONT_CARE);
+ UnicodeString appendTo;
+ assertEquals(
+ "format singular",
+ "1 pound",
+ fmt.format(
+ 1,
+ *numfmt,
+ *plurrule,
+ appendTo,
+ pos,
+ status), TRUE);
+ appendTo.remove();
+ assertEquals(
+ "format plural",
+ "2 pounds",
+ fmt.format(
+ 2,
+ *numfmt,
+ *plurrule,
+ appendTo,
+ pos,
+ status), TRUE);
+ }
+ fmt.reset();
+ assertFalse("isValid after reset", fmt.isValid());
+#endif
+ assertSuccess("", status);
+}
+
+extern IntlTest *createQuantityFormatterTest() {
+ return new QuantityFormatterTest();
+}
« no previous file with comments | « source/test/intltest/plurults.cpp ('k') | source/test/intltest/rbbiapts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698