// 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"
static 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"
"."
""
"";
TEST(CXFA_XMLLocaleTest, Create) {
auto span =
pdfium::make_span(reinterpret_cast(const_cast(xml_data)),
strlen(xml_data));
auto locale = CXFA_XMLLocale::Create(span);
EXPECT_TRUE(locale != nullptr);
}
TEST(CXFA_XMLLocaleTest, CreateBadXML) {
auto locale = CXFA_XMLLocale::Create(pdfium::span());
EXPECT_TRUE(locale == nullptr);
}
TEST(CXFA_XMLLocaleTest, GetName) {
auto span =
pdfium::make_span(reinterpret_cast(const_cast(xml_data)),
strlen(xml_data));
auto locale = CXFA_XMLLocale::Create(span);
ASSERT_TRUE(locale != nullptr);
EXPECT_EQ(L"en_US", locale->GetName());
}
TEST(CXFA_XMLLocaleTest, GetNumericSymbols) {
auto span =
pdfium::make_span(reinterpret_cast(const_cast(xml_data)),
strlen(xml_data));
auto locale = CXFA_XMLLocale::Create(span);
ASSERT_TRUE(locale != nullptr);
EXPECT_EQ(L".", locale->GetDecimalSymbol());
EXPECT_EQ(L",", locale->GetGroupingSymbol());
EXPECT_EQ(L"%", locale->GetPercentSymbol());
EXPECT_EQ(L"-", locale->GetMinusSymbol());
EXPECT_EQ(L"$", locale->GetCurrencySymbol());
}
TEST(CXFA_XMLLocaleTest, GetDateTimeSymbols) {
auto span =
pdfium::make_span(reinterpret_cast(const_cast(xml_data)),
strlen(xml_data));
auto locale = CXFA_XMLLocale::Create(span);
ASSERT_TRUE(locale != nullptr);
EXPECT_EQ(L"GyMdkHmsSEDFwWahKzZ", locale->GetDateTimeSymbols());
}
TEST(CXFA_XMLLocaleTest, GetMonthName) {
auto span =
pdfium::make_span(reinterpret_cast(const_cast(xml_data)),
strlen(xml_data));
auto locale = CXFA_XMLLocale::Create(span);
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 span =
pdfium::make_span(reinterpret_cast(const_cast(xml_data)),
strlen(xml_data));
auto locale = CXFA_XMLLocale::Create(span);
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 span =
pdfium::make_span(reinterpret_cast(const_cast(xml_data)),
strlen(xml_data));
auto locale = CXFA_XMLLocale::Create(span);
ASSERT_TRUE(locale != nullptr);
EXPECT_EQ(L"AM", locale->GetMeridiemName(true));
EXPECT_EQ(L"PM", locale->GetMeridiemName(false));
}
TEST(CXFA_XMLLocaleTest, GetEraName) {
auto span =
pdfium::make_span(reinterpret_cast(const_cast(xml_data)),
strlen(xml_data));
auto locale = CXFA_XMLLocale::Create(span);
ASSERT_TRUE(locale != nullptr);
EXPECT_EQ(L"AD", locale->GetEraName(true));
EXPECT_EQ(L"BC", locale->GetEraName(false));
}
TEST(CXFA_XMLLocaleTest, GetDatePattern) {
auto span =
pdfium::make_span(reinterpret_cast(const_cast(xml_data)),
strlen(xml_data));
auto locale = CXFA_XMLLocale::Create(span);
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 span =
pdfium::make_span(reinterpret_cast(const_cast(xml_data)),
strlen(xml_data));
auto locale = CXFA_XMLLocale::Create(span);
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 span =
pdfium::make_span(reinterpret_cast(const_cast(xml_data)),
strlen(xml_data));
auto locale = CXFA_XMLLocale::Create(span);
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));
}