summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser
diff options
context:
space:
mode:
authordan sinclair <dsinclair@chromium.org>2018-04-16 17:50:07 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-16 17:50:07 +0000
commitcce4d31e6e746bae72f2f31676c12f1d2851ade3 (patch)
treec8fd72f0229926e1da2aa972e4514972b5bd6f62 /xfa/fxfa/parser
parentd08667c174fa302d7dd05ab0b33d61b91fcda63c (diff)
downloadpdfium-cce4d31e6e746bae72f2f31676c12f1d2851ade3.tar.xz
Add CXFA_XMLLocale unittests
This CL adds unittests for the CXFA_XMLLocale class. Change-Id: I1a610754933e5f33e87cb4c13b9bf540e366e6ed Reviewed-on: https://pdfium-review.googlesource.com/30692 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r--xfa/fxfa/parser/cxfa_xmllocale_unittest.cpp228
1 files changed, 228 insertions, 0 deletions
diff --git a/xfa/fxfa/parser/cxfa_xmllocale_unittest.cpp b/xfa/fxfa/parser/cxfa_xmllocale_unittest.cpp
new file mode 100644
index 0000000000..a9bda60085
--- /dev/null
+++ b/xfa/fxfa/parser/cxfa_xmllocale_unittest.cpp
@@ -0,0 +1,228 @@
+// Copyright 2018 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "xfa/fxfa/parser/cxfa_xmllocale.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/test_support.h"
+
+namespace {
+
+const char* xml_data =
+ "<locale name=\"en_US\" desc=\"English(America)\">"
+ " <calendarSymbols name=\"gregorian\">"
+ " <monthNames>"
+ " <month>January</month>"
+ " <month>February</month>"
+ " <month>March</month>"
+ " <month>April</month>"
+ " <month>May</month>"
+ " <month>June</month>"
+ " <month>July</month>"
+ " <month>August</month>"
+ " <month>September</month>"
+ " <month>October</month>"
+ " <month>November</month>"
+ " <month>December</month>"
+ " </monthNames>"
+ " <monthNames abbr=\"1\">"
+ " <month>Jan</month>"
+ " <month>Feb</month>"
+ " <month>Mar</month>"
+ " <month>Apr</month>"
+ " <month>May</month>"
+ " <month>Jun</month>"
+ " <month>Jul</month>"
+ " <month>Aug</month>"
+ " <month>Sep</month>"
+ " <month>Oct</month>"
+ " <month>Nov</month>"
+ " <month>Dec</month>"
+ " </monthNames>"
+ " <dayNames>"
+ " <day>Sunday</day>"
+ " <day>Monday</day>"
+ " <day>Tuesday</day>"
+ " <day>Wednesday</day>"
+ " <day>Thursday</day>"
+ " <day>Friday</day>"
+ " <day>Saturday</day>"
+ " </dayNames>"
+ " <dayNames abbr=\"1\">"
+ " <day>Sun</day>"
+ " <day>Mon</day>"
+ " <day>Tue</day>"
+ " <day>Wed</day>"
+ " <day>Thu</day>"
+ " <day>Fri</day>"
+ " <day>Sat</day>"
+ " </dayNames>"
+ " <meridiemNames>"
+ " <meridiem>AM</meridiem>"
+ " <meridiem>PM</meridiem>"
+ " </meridiemNames>"
+ " <eraNames>"
+ " <era>BC</era>"
+ " <era>AD</era>"
+ " </eraNames>"
+ " </calendarSymbols>"
+ " <datePatterns>"
+ " <datePattern name=\"full\">EEEE, MMMM D, YYYY</datePattern>"
+ " <datePattern name=\"long\">MMMM D, YYYY</datePattern>"
+ " <datePattern name=\"med\">MMM D, YYYY</datePattern>"
+ " <datePattern name=\"short\">M/D/YY</datePattern>"
+ " </datePatterns>"
+ " <timePatterns>"
+ " <timePattern name=\"full\">h:MM:SS A Z</timePattern>"
+ " <timePattern name=\"long\">h:MM:SS A Z</timePattern>"
+ " <timePattern name=\"med\">h:MM:SS A</timePattern>"
+ " <timePattern name=\"short\">h:MM A</timePattern>"
+ " </timePatterns>"
+ " <dateTimeSymbols>GyMdkHmsSEDFwWahKzZ</dateTimeSymbols>"
+ " <numberPatterns>"
+ " <numberPattern name=\"numeric\">z,zz9.zzz</numberPattern>"
+ " <numberPattern name=\"currency\">$z,zz9.99|($z,zz9.99)</numberPattern>"
+ " <numberPattern name=\"percent\">z,zz9%</numberPattern>"
+ " </numberPatterns>"
+ " <numberSymbols>"
+ " <numberSymbol name=\"decimal\">.</numberSymbol>"
+ " <numberSymbol name=\"grouping\">,</numberSymbol>"
+ " <numberSymbol name=\"percent\">%</numberSymbol>"
+ " <numberSymbol name=\"minus\">-</numberSymbol>"
+ " <numberSymbol name=\"zero\">0</numberSymbol>"
+ " </numberSymbols>"
+ " <currencySymbols>"
+ " <currencySymbol name=\"symbol\">$</currencySymbol>"
+ " <currencySymbol name=\"isoname\">USD</currencySymbol>"
+ " <currencySymbol name=\"decimal\">.</currencySymbol>"
+ " </currencySymbols>"
+ "</locale>";
+
+std::unique_ptr<CXFA_XMLLocale> LoadLocale() {
+ auto span =
+ pdfium::make_span(reinterpret_cast<uint8_t*>(const_cast<char*>(xml_data)),
+ strlen(xml_data));
+ return CXFA_XMLLocale::Create(span);
+}
+
+} // namespace
+
+TEST(CXFA_XMLLocaleTest, Create) {
+ auto locale = LoadLocale();
+ EXPECT_TRUE(locale != nullptr);
+}
+
+TEST(CXFA_XMLLocaleTest, CreateBadXML) {
+ auto locale = CXFA_XMLLocale::Create(pdfium::span<uint8_t>());
+ EXPECT_TRUE(locale == nullptr);
+}
+
+TEST(CXFA_XMLLocaleTest, GetName) {
+ auto locale = LoadLocale();
+ ASSERT_TRUE(locale != nullptr);
+
+ EXPECT_EQ(L"en_US", locale->GetName());
+}
+
+TEST(CXFA_XMLLocaleTest, GetNumbericSymbol) {
+ auto locale = LoadLocale();
+ ASSERT_TRUE(locale != nullptr);
+
+ EXPECT_EQ(L".", locale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal));
+ EXPECT_EQ(L",", locale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Grouping));
+ EXPECT_EQ(L"%", locale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Percent));
+ EXPECT_EQ(L"-", locale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus));
+ EXPECT_EQ(L"0", locale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Zero));
+ EXPECT_EQ(L"$", locale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_CurrencySymbol));
+ EXPECT_EQ(L"USD", locale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_CurrencyName));
+}
+
+TEST(CXFA_XMLLocaleTest, GetDateTimeSymbols) {
+ auto locale = LoadLocale();
+ ASSERT_TRUE(locale != nullptr);
+
+ EXPECT_EQ(L"GyMdkHmsSEDFwWahKzZ", locale->GetDateTimeSymbols());
+}
+
+TEST(CXFA_XMLLocaleTest, GetMonthName) {
+ auto locale = LoadLocale();
+ ASSERT_TRUE(locale != nullptr);
+
+ EXPECT_EQ(L"", locale->GetMonthName(24, false));
+ EXPECT_EQ(L"", locale->GetMonthName(-5, false));
+ EXPECT_EQ(L"Feb", locale->GetMonthName(1, true));
+ EXPECT_EQ(L"February", locale->GetMonthName(1, false));
+}
+
+TEST(CXFA_XMLLocaleTest, GetDayName) {
+ auto locale = LoadLocale();
+ ASSERT_TRUE(locale != nullptr);
+
+ EXPECT_EQ(L"", locale->GetDayName(24, false));
+ EXPECT_EQ(L"", locale->GetDayName(-5, false));
+ EXPECT_EQ(L"Mon", locale->GetDayName(1, true));
+ EXPECT_EQ(L"Monday", locale->GetDayName(1, false));
+}
+
+TEST(CXFA_XMLLocaleTest, GetMeridiemName) {
+ auto locale = LoadLocale();
+ ASSERT_TRUE(locale != nullptr);
+
+ EXPECT_EQ(L"AM", locale->GetMeridiemName(true));
+ EXPECT_EQ(L"PM", locale->GetMeridiemName(false));
+}
+
+TEST(CXFA_XMLLocaleTest, GetEraName) {
+ auto locale = LoadLocale();
+ ASSERT_TRUE(locale != nullptr);
+
+ EXPECT_EQ(L"AD", locale->GetEraName(true));
+ EXPECT_EQ(L"BC", locale->GetEraName(false));
+}
+
+TEST(CXFA_XMLLocaleTest, GetDatePattern) {
+ auto locale = LoadLocale();
+ ASSERT_TRUE(locale != nullptr);
+
+ EXPECT_EQ(L"M/D/YY",
+ locale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Short));
+ EXPECT_EQ(L"MMM D, YYYY",
+ locale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Default));
+ EXPECT_EQ(L"MMM D, YYYY",
+ locale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Medium));
+ EXPECT_EQ(L"EEEE, MMMM D, YYYY",
+ locale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Full));
+ EXPECT_EQ(L"MMMM D, YYYY",
+ locale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Long));
+}
+
+TEST(CXFA_XMLLocaleTest, GetTimePattern) {
+ auto locale = LoadLocale();
+ ASSERT_TRUE(locale != nullptr);
+
+ EXPECT_EQ(L"h:MM A",
+ locale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Short));
+ EXPECT_EQ(L"h:MM:SS A",
+ locale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default));
+ EXPECT_EQ(L"h:MM:SS A",
+ locale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Medium));
+ EXPECT_EQ(L"h:MM:SS A Z",
+ locale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Full));
+ EXPECT_EQ(L"h:MM:SS A Z",
+ locale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Long));
+}
+
+TEST(CXFA_XMLLocaleTest, GetNumPattern) {
+ auto locale = LoadLocale();
+ ASSERT_TRUE(locale != nullptr);
+
+ EXPECT_EQ(L"z,zzz,zzz,zzz,zzz,zzz%",
+ locale->GetNumPattern(FX_LOCALENUMPATTERN_Percent));
+ EXPECT_EQ(L"$z,zzz,zzz,zzz,zzz,zz9.99",
+ locale->GetNumPattern(FX_LOCALENUMPATTERN_Currency));
+ EXPECT_EQ(L"z,zzz,zzz,zzz,zzz,zz9.zzz",
+ locale->GetNumPattern(FX_LOCALENUMPATTERN_Decimal));
+ EXPECT_EQ(L"z,zzz,zzz,zzz,zzz,zzz",
+ locale->GetNumPattern(FX_LOCALENUMPATTERN_Integer));
+}