// 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 = "" " " " " " January" " February" " March" " April" " May" " June" " July" " August" " September" " October" " November" " December" " " " " " Jan" " Feb" " Mar" " Apr" " May" " Jun" " Jul" " Aug" " Sep" " Oct" " Nov" " Dec" " " " " " Sunday" " Monday" " Tuesday" " Wednesday" " Thursday" " Friday" " Saturday" " " " " " Sun" " Mon" " Tue" " Wed" " Thu" " Fri" " Sat" " " " " " AM" " PM" " " " " " BC" " AD" " " " " " " " EEEE, MMMM D, YYYY" " MMMM D, YYYY" " MMM D, YYYY" " M/D/YY" " " " " " h:MM:SS A Z" " h:MM:SS A Z" " h:MM:SS A" " h:MM A" " " " GyMdkHmsSEDFwWahKzZ" " " " z,zz9.zzz" " $z,zz9.99|($z,zz9.99)" " z,zz9%" " " " " " ." " ," " %" " -" " 0" " " " " " $" " USD" " ." " " ""; std::unique_ptr LoadLocale() { auto span = pdfium::make_span(reinterpret_cast(const_cast(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()); 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)); }