+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
-* Copyright (C) 2013-2015, International Business Machines Corporation and *
-* others. All Rights Reserved. *
+* Copyright (C) 2013-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
*******************************************************************************
*
* File RELDATEFMTTEST.CPP
};
static WithQuantityExpected kSerbianNarrow[] = {
- {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "\\u0437\\u0430 0 \\u043c\\u0435\\u0441."},
- {1.2, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "\\u0437\\u0430 1,2 \\u043c\\u0435\\u0441."},
- {21.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "\\u0437\\u0430 21 \\u043c\\u0435\\u0441."}
+ {0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "\\u0437\\u0430 0 \\u043c."},
+ {1.2, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "\\u0437\\u0430 1,2 \\u043c."},
+ {21.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, "\\u0437\\u0430 21 \\u043c."}
};
static WithoutQuantityExpected kEnglishNoQuantity[] = {
const RelativeDateTimeFormatter& fmt,
UDateDirection direction,
UDateAbsoluteUnit unit);
+ void TestSidewaysDataLoading(void);
};
void RelativeDateTimeFormatterTest::runIndexedTest(
TESTCASE_AUTO(TestGetters);
TESTCASE_AUTO(TestCombineDateAndTime);
TESTCASE_AUTO(TestBadDisplayContext);
+ TESTCASE_AUTO(TestSidewaysDataLoading);
TESTCASE_AUTO_END;
}
// copy and assignment.
RelativeDateTimeFormatter fmt2(fmt);
fmt3 = fmt2;
- assertEquals("style", UDAT_STYLE_NARROW, fmt3.getFormatStyle());
+ assertEquals("style", (int32_t)UDAT_STYLE_NARROW, fmt3.getFormatStyle());
assertEquals(
"context",
- UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,
+ (int32_t)UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,
fmt3.getCapitalizationContext());
assertSuccess("", status);
}
}
}
+/* Add tests to check "sideways" data loading. */
+void RelativeDateTimeFormatterTest::TestSidewaysDataLoading(void) {
+ UErrorCode status = U_ZERO_ERROR;
+ UnicodeString actual;
+ UnicodeString expected;
+ Locale enGbLocale("en_GB");
+
+ RelativeDateTimeFormatter fmt(enGbLocale, NULL, UDAT_STYLE_NARROW,
+ UDISPCTX_CAPITALIZATION_NONE, status);
+ if (U_FAILURE(status)) {
+ dataerrln("Unable to create RelativeDateTimeFormatter - %s", u_errorName(status));
+ return;
+ }
+
+ status = U_ZERO_ERROR;
+ actual = "";
+ fmt.format(3.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_MONTHS, actual, status);
+ expected = "in 3 mo";
+ assertEquals("narrow in 3 mo", expected, actual);
+
+ fmt.format(3.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_DAYS, actual.remove(), status);
+ expected = "3 days ago";
+ assertEquals("3 days ago (positive 3.0): ", expected, actual);
+
+ expected = "-3 days ago";
+ fmt.format(-3.0, UDAT_DIRECTION_LAST, UDAT_RELATIVE_DAYS, actual.remove(), status);
+ assertEquals("3 days ago (negative 3.0): ", expected, actual);
+
+ expected = "next yr.";
+ fmt.format(UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_YEAR, actual.remove(), status);
+ assertEquals("next year: ", expected, actual);
+
+ // Testing the SHORT style
+ RelativeDateTimeFormatter fmtshort(enGbLocale, NULL, UDAT_STYLE_SHORT,
+ UDISPCTX_CAPITALIZATION_NONE, status);
+ expected = "now";
+ fmtshort.format(0.0, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_SECONDS, actual.remove(), status);
+
+ expected = "next yr.";
+ fmt.format(UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_YEAR, actual.remove(), status);
+ assertEquals("next year: ", expected, actual);
+}
+
static const char *kLast2 = "Last_2";
static const char *kLast = "Last";
static const char *kThis = "This";