Bug 1355465 - Enhance TestDateTimeFormat.cpp with non-en-US locale. r=emk
authorJorg K <jorgk@jorgk.com>
Tue, 11 Apr 2017 11:07:00 -0400
changeset 353027 1ca47045ab082e3df8d5918e47a8a86fc7c07e20
parent 353026 52ba40a2c1335cca00d7641e638ca67ee651a404
child 353028 2c4240b6dff9bb426804d9ed6f7c0c5003c615f1
push id40747
push userryanvm@gmail.com
push dateFri, 14 Apr 2017 01:47:32 +0000
treeherderautoland@78b39a056304 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemk
bugs1355465
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1355465 - Enhance TestDateTimeFormat.cpp with non-en-US locale. r=emk
intl/locale/DateTimeFormat.h
intl/locale/tests/gtest/TestDateTimeFormat.cpp
--- a/intl/locale/DateTimeFormat.h
+++ b/intl/locale/DateTimeFormat.h
@@ -42,16 +42,18 @@ public:
 
 private:
   DateTimeFormat() = delete;
 
   static nsresult Initialize();
 
   FRIEND_TEST(DateTimeFormat, FormatPRExplodedTime);
   FRIEND_TEST(DateTimeFormat, DateFormatSelectors);
+  FRIEND_TEST(DateTimeFormat, FormatPRExplodedTimeForeign);
+  FRIEND_TEST(DateTimeFormat, DateFormatSelectorsForeign);
 
 #ifdef ENABLE_INTL_API
   // performs a locale sensitive date formatting operation on the UDate parameter
   static nsresult FormatUDateTime(const nsDateFormatSelector aDateFormatSelector,
                                   const nsTimeFormatSelector aTimeFormatSelector,
                                   const UDate aUDateTime,
                                   const PRTimeParameters* aTimeParameters,
                                   nsAString& aStringOut);
--- a/intl/locale/tests/gtest/TestDateTimeFormat.cpp
+++ b/intl/locale/tests/gtest/TestDateTimeFormat.cpp
@@ -108,9 +108,114 @@ TEST(DateTimeFormat, DateFormatSelectors
   ASSERT_TRUE(NS_SUCCEEDED(rv));
   ASSERT_STREQ("Thu, 12:00 AM", nt(NS_ConvertUTF16toUTF8(formattedTime)).get());
 
   rv = mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatWeekday, kTimeFormatSeconds, &prExplodedTime, formattedTime);
   ASSERT_TRUE(NS_SUCCEEDED(rv));
   ASSERT_STREQ("Thu, 12:00:00 AM", nt(NS_ConvertUTF16toUTF8(formattedTime)).get());
 }
 
+// Normalise time.
+static nsAutoCString ntd(nsAutoCString aDatetime)
+{
+  nsAutoCString datetime = aDatetime;
+
+  // Strip trailing " GMT" (found on Mac/Linux).
+  int32_t ind = datetime.Find(" GMT");
+  if (ind != kNotFound)
+    datetime.Truncate(ind);
+
+  // Strip leading "Donnerstag, " or "Mittwoch, " (found on Windows).
+  ind = datetime.Find("Donnerstag, ");
+  if (ind == 0)
+    datetime.Replace(0, 12, "");
+  ind = datetime.Find("Mittwoch, ");
+  if (ind == 0)
+    datetime.Replace(0, 10, "");
+
+  return datetime;
 }
+
+TEST(DateTimeFormat, FormatPRExplodedTimeForeign) {
+  PRTime prTime = 0;
+  PRExplodedTime prExplodedTime;
+  PR_ExplodeTime(prTime, PR_GMTParameters, &prExplodedTime);
+
+  mozilla::DateTimeFormat::mLocale = new nsCString("de-DE");
+
+  nsAutoString formattedTime;
+  nsresult rv = mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatLong, kTimeFormatSeconds, &prExplodedTime, formattedTime);
+  ASSERT_TRUE(NS_SUCCEEDED(rv));
+  ASSERT_STREQ("1. Januar 1970, 00:00:00", ntd(NS_ConvertUTF16toUTF8(formattedTime)).get());
+
+  prExplodedTime = { 0, 0, 19, 0, 1, 0, 1970, 4, 0, { (19 * 60), 0 } };
+  rv = mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatLong, kTimeFormatSeconds, &prExplodedTime, formattedTime);
+  ASSERT_TRUE(NS_SUCCEEDED(rv));
+  ASSERT_STREQ("1. Januar 1970, 00:19:00", ntd(NS_ConvertUTF16toUTF8(formattedTime)).get());
+
+  prExplodedTime = { 0, 0, 0, 7, 1, 0, 1970, 4, 0, { (6 * 60 * 60), (1 * 60 * 60) } };
+  rv = mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatLong, kTimeFormatSeconds, &prExplodedTime, formattedTime);
+  ASSERT_TRUE(NS_SUCCEEDED(rv));
+  ASSERT_STREQ("1. Januar 1970, 07:00:00", ntd(NS_ConvertUTF16toUTF8(formattedTime)).get());
+
+  prExplodedTime = { 0, 0, 29, 11, 1, 0, 1970, 4, 0, { (10 * 60 * 60) + (29 * 60), (1 * 60 * 60) } };
+  rv = mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatLong, kTimeFormatSeconds, &prExplodedTime, formattedTime);
+  ASSERT_TRUE(NS_SUCCEEDED(rv));
+  ASSERT_STREQ("1. Januar 1970, 11:29:00", ntd(NS_ConvertUTF16toUTF8(formattedTime)).get());
+
+  prExplodedTime = { 0, 0, 37, 23, 31, 11, 1969, 3, 364, { -(23 * 60), 0 } };
+  rv = mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatLong, kTimeFormatSeconds, &prExplodedTime, formattedTime);
+  ASSERT_TRUE(NS_SUCCEEDED(rv));
+  ASSERT_STREQ("31. Dezember 1969, 23:37:00", ntd(NS_ConvertUTF16toUTF8(formattedTime)).get());
+
+  prExplodedTime = { 0, 0, 0, 17, 31, 11, 1969, 3, 364, { -(7 * 60 * 60), 0 } };
+  rv = mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatLong, kTimeFormatSeconds, &prExplodedTime, formattedTime);
+  ASSERT_TRUE(NS_SUCCEEDED(rv));
+  ASSERT_STREQ("31. Dezember 1969, 17:00:00", ntd(NS_ConvertUTF16toUTF8(formattedTime)).get());
+
+  prExplodedTime = { 0, 0, 47, 14, 31, 11, 1969, 3, 364, { -((10 * 60 * 60) + (13 * 60)), (1 * 60 * 60) } };
+  rv = mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatLong, kTimeFormatSeconds, &prExplodedTime, formattedTime);
+  ASSERT_TRUE(NS_SUCCEEDED(rv));
+  ASSERT_STREQ("31. Dezember 1969, 14:47:00", ntd(NS_ConvertUTF16toUTF8(formattedTime)).get());
+}
+
+TEST(DateTimeFormat, DateFormatSelectorsForeign) {
+  PRTime prTime = 0;
+  PRExplodedTime prExplodedTime;
+  PR_ExplodeTime(prTime, PR_GMTParameters, &prExplodedTime);
+
+  mozilla::DateTimeFormat::mLocale = new nsCString("de-DE");
+
+  nsAutoString formattedTime;
+  nsresult rv = mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatYearMonth, kTimeFormatNone, &prExplodedTime, formattedTime);
+  ASSERT_TRUE(NS_SUCCEEDED(rv));
+  ASSERT_STREQ("01.1970", NS_ConvertUTF16toUTF8(formattedTime).get());
+
+  rv = mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatYearMonthLong, kTimeFormatNone, &prExplodedTime, formattedTime);
+  ASSERT_TRUE(NS_SUCCEEDED(rv));
+  ASSERT_STREQ("Januar 1970", NS_ConvertUTF16toUTF8(formattedTime).get());
+
+  rv = mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatMonthLong, kTimeFormatNone, &prExplodedTime, formattedTime);
+  ASSERT_TRUE(NS_SUCCEEDED(rv));
+  ASSERT_STREQ("Januar", NS_ConvertUTF16toUTF8(formattedTime).get());
+
+  rv = mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatYearMonth, kTimeFormatNoSeconds, &prExplodedTime, formattedTime);
+  ASSERT_TRUE(NS_SUCCEEDED(rv));
+  ASSERT_STREQ("01.1970, 00:00", ntd(NS_ConvertUTF16toUTF8(formattedTime)).get());
+
+  rv = mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatYearMonth, kTimeFormatSeconds, &prExplodedTime, formattedTime);
+  ASSERT_TRUE(NS_SUCCEEDED(rv));
+  ASSERT_STREQ("01.1970, 00:00:00", ntd(NS_ConvertUTF16toUTF8(formattedTime)).get());
+
+  rv = mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatWeekday, kTimeFormatNone, &prExplodedTime, formattedTime);
+  ASSERT_TRUE(NS_SUCCEEDED(rv));
+  ASSERT_STREQ("Do", NS_ConvertUTF16toUTF8(formattedTime).get());
+
+  rv = mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatWeekday, kTimeFormatNoSeconds, &prExplodedTime, formattedTime);
+  ASSERT_TRUE(NS_SUCCEEDED(rv));
+  ASSERT_STREQ("Do, 00:00", ntd(NS_ConvertUTF16toUTF8(formattedTime)).get());
+
+  rv = mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatWeekday, kTimeFormatSeconds, &prExplodedTime, formattedTime);
+  ASSERT_TRUE(NS_SUCCEEDED(rv));
+  ASSERT_STREQ("Do, 00:00:00", ntd(NS_ConvertUTF16toUTF8(formattedTime)).get());
+}
+
+}