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

Side by Side Diff: source/test/intltest/tufmtts.cpp

Issue 1621943002: ICU 56 step 4: Apply post-56 fixes for measure/date format (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@56goog
Patch Set: Created 4 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 unified diff | Download patch
« no previous file with comments | « source/test/intltest/tufmtts.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /******************************************************************** 1 /********************************************************************
2 * Copyright (c) 2008-2014, International Business Machines Corporation and 2 * Copyright (c) 2008-2015, International Business Machines Corporation and
3 * others. All Rights Reserved. 3 * others. All Rights Reserved.
4 ********************************************************************/ 4 ********************************************************************/
5 5
6 #include "unicode/utypes.h" 6 #include "unicode/utypes.h"
7 7
8 #if !UCONFIG_NO_FORMATTING 8 #if !UCONFIG_NO_FORMATTING
9 9
10 #include "unicode/decimfmt.h" 10 #include "unicode/decimfmt.h"
11 #include "unicode/tmunit.h" 11 #include "unicode/tmunit.h"
12 #include "unicode/tmutamt.h" 12 #include "unicode/tmutamt.h"
13 #include "unicode/tmutfmt.h" 13 #include "unicode/tmutfmt.h"
14 #include "tufmtts.h" 14 #include "unicode/ustring.h"
15 #include "cmemory.h" 15 #include "cmemory.h"
16 #include "unicode/ustring.h" 16 #include "intltest.h"
17 17
18 //TODO: put as compilation flag 18 //TODO: put as compilation flag
19 //#define TUFMTTS_DEBUG 1 19 //#define TUFMTTS_DEBUG 1
20 20
21 #ifdef TUFMTTS_DEBUG 21 #ifdef TUFMTTS_DEBUG
22 #include <iostream> 22 #include <iostream>
23 #endif 23 #endif
24 24
25 void TimeUnitTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ ) { 25 class TimeUnitTest : public IntlTest {
26 if (exec) logln("TestSuite TimeUnitTest"); 26 void runIndexedTest(int32_t index, UBool exec, const char* &name, char* /*pa r*/ ) {
27 switch (index) { 27 if (exec) logln("TestSuite TimeUnitTest");
28 TESTCASE(0, testBasic); 28 TESTCASE_AUTO_BEGIN;
29 TESTCASE(1, testAPI); 29 TESTCASE_AUTO(testBasic);
30 TESTCASE(2, testGreekWithFallback); 30 TESTCASE_AUTO(testAPI);
31 TESTCASE(3, testGreekWithSanitization); 31 TESTCASE_AUTO(testGreekWithFallback);
32 TESTCASE(4, test10219Plurals); 32 TESTCASE_AUTO(testGreekWithSanitization);
33 default: name = ""; break; 33 TESTCASE_AUTO(test10219Plurals);
34 TESTCASE_AUTO(TestBritishShortHourFallback);
35 TESTCASE_AUTO_END;
34 } 36 }
37
38 public:
39 /**
40 * Performs basic tests
41 **/
42 void testBasic();
43
44 /**
45 * Performs API tests
46 **/
47 void testAPI();
48
49 /**
50 * Performs tests for Greek
51 * This tests that requests for short unit names correctly fall back
52 * to long unit names for a locale where the locale data does not
53 * provide short unit names. As of CLDR 1.9, Greek is one such language.
54 **/
55 void testGreekWithFallback();
56
57 /**
58 * Performs tests for Greek
59 * This tests that if the plural count listed in time unit format does not
60 * match those in the plural rules for the locale, those plural count in
61 * time unit format will be ingored and subsequently, fall back will kick in
62 * which is tested above.
63 * Without data sanitization, setNumberFormat() would crash.
64 * As of CLDR shiped in ICU4.8, Greek is one such language.
65 */
66 void testGreekWithSanitization();
67
68 /**
69 * Performs unit test for ticket 10219 making sure that plurals work
70 * correctly with rounding.
71 */
72 void test10219Plurals();
73
74 void TestBritishShortHourFallback();
75 };
76
77 extern IntlTest *createTimeUnitTest() {
78 return new TimeUnitTest();
35 } 79 }
36 80
37 // This function is more lenient than equals operator as it considers integer 3 hours and 81 // This function is more lenient than equals operator as it considers integer 3 hours and
38 // double 3.0 hours to be equal 82 // double 3.0 hours to be equal
39 static UBool tmaEqual(const TimeUnitAmount& left, const TimeUnitAmount& right) { 83 static UBool tmaEqual(const TimeUnitAmount& left, const TimeUnitAmount& right) {
40 if (left.getTimeUnitField() != right.getTimeUnitField()) { 84 if (left.getTimeUnitField() != right.getTimeUnitField()) {
41 return FALSE; 85 return FALSE;
42 } 86 }
43 UErrorCode status = U_ZERO_ERROR; 87 UErrorCode status = U_ZERO_ERROR;
44 if (!left.getNumber().isNumeric() || !right.getNumber().isNumeric()) { 88 if (!left.getNumber().isNumeric() || !right.getNumber().isNumeric()) {
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 // test parsing 506 // test parsing
463 Formattable result; 507 Formattable result;
464 ParsePosition pos; 508 ParsePosition pos;
465 UnicodeString formattedString = "1 minutes"; 509 UnicodeString formattedString = "1 minutes";
466 tuf.parseObject(formattedString, result, pos); 510 tuf.parseObject(formattedString, result, pos);
467 if (formattedString.length() != pos.getIndex()) { 511 if (formattedString.length() != pos.getIndex()) {
468 errln("Expect parsing to go all the way to the end of the string."); 512 errln("Expect parsing to go all the way to the end of the string.");
469 } 513 }
470 } 514 }
471 515
516 void TimeUnitTest::TestBritishShortHourFallback() {
517 // See ticket #11986 "incomplete fallback in MeasureFormat".
518 UErrorCode status = U_ZERO_ERROR;
519 Formattable oneHour(new TimeUnitAmount(1, TimeUnit::UTIMEUNIT_HOUR, status)) ;
520 Locale en_GB("en_GB");
521 TimeUnitFormat formatter(en_GB, UTMUTFMT_ABBREVIATED_STYLE, status);
522 UnicodeString result;
523 formatter.format(oneHour, result, status);
524 assertSuccess("TestBritishShortHourFallback()", status);
525 assertEquals("TestBritishShortHourFallback()", UNICODE_STRING_SIMPLE("1 hr") , result);
526 }
527
472 #endif 528 #endif
OLDNEW
« no previous file with comments | « source/test/intltest/tufmtts.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698