summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-07-19 17:21:25 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-07-19 17:21:25 +0000
commit591c7c54ac89aa28fb782745ed8116414d6a04fd (patch)
tree0c2863d9f5da700b25bd908be5bdd9a4f7859326 /xfa
parentc15c0b3a1e9ab6292349402066b4c4b002a8e093 (diff)
downloadpdfium-591c7c54ac89aa28fb782745ed8116414d6a04fd.tar.xz
Use pdfium::as_writable_bytes() in cxfa_xmllocale_unittest.cpp
This is a cleaner way of getting the required argument. Add helper function and anonymous namespace as misc. cleanups along the way. Change-Id: I600074b7f6597ffd9b451a21ee374f937a8e9940 Reviewed-on: https://pdfium-review.googlesource.com/38310 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'xfa')
-rw-r--r--xfa/fxfa/parser/cxfa_xmllocale_unittest.cpp68
1 files changed, 23 insertions, 45 deletions
diff --git a/xfa/fxfa/parser/cxfa_xmllocale_unittest.cpp b/xfa/fxfa/parser/cxfa_xmllocale_unittest.cpp
index 32abdeb063..5b56531551 100644
--- a/xfa/fxfa/parser/cxfa_xmllocale_unittest.cpp
+++ b/xfa/fxfa/parser/cxfa_xmllocale_unittest.cpp
@@ -4,10 +4,14 @@
#include "xfa/fxfa/parser/cxfa_xmllocale.h"
+#include <memory>
+
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/test_support.h"
-static const char* xml_data =
+namespace {
+
+const char kXMLData[] =
"<locale name=\"en_US\" desc=\"English(America)\">"
"<calendarSymbols name=\"gregorian\"><monthNames><month>January</month>"
"<month>February</month>"
@@ -85,11 +89,15 @@ static const char* xml_data =
"</currencySymbols>"
"</locale>";
+std::unique_ptr<CXFA_XMLLocale> CreateLocaleHelper() {
+ return CXFA_XMLLocale::Create(pdfium::as_writable_bytes(
+ pdfium::make_span(const_cast<char*>(kXMLData), strlen(kXMLData))));
+}
+
+} // namespace
+
TEST(CXFA_XMLLocaleTest, Create) {
- auto span =
- pdfium::make_span(reinterpret_cast<uint8_t*>(const_cast<char*>(xml_data)),
- strlen(xml_data));
- auto locale = CXFA_XMLLocale::Create(span);
+ auto locale = CreateLocaleHelper();
EXPECT_TRUE(locale != nullptr);
}
@@ -99,20 +107,14 @@ TEST(CXFA_XMLLocaleTest, CreateBadXML) {
}
TEST(CXFA_XMLLocaleTest, GetName) {
- auto span =
- pdfium::make_span(reinterpret_cast<uint8_t*>(const_cast<char*>(xml_data)),
- strlen(xml_data));
- auto locale = CXFA_XMLLocale::Create(span);
+ auto locale = CreateLocaleHelper();
ASSERT_TRUE(locale != nullptr);
EXPECT_EQ(L"en_US", locale->GetName());
}
TEST(CXFA_XMLLocaleTest, GetNumericSymbols) {
- auto span =
- pdfium::make_span(reinterpret_cast<uint8_t*>(const_cast<char*>(xml_data)),
- strlen(xml_data));
- auto locale = CXFA_XMLLocale::Create(span);
+ auto locale = CreateLocaleHelper();
ASSERT_TRUE(locale != nullptr);
EXPECT_EQ(L".", locale->GetDecimalSymbol());
@@ -123,20 +125,14 @@ TEST(CXFA_XMLLocaleTest, GetNumericSymbols) {
}
TEST(CXFA_XMLLocaleTest, GetDateTimeSymbols) {
- auto span =
- pdfium::make_span(reinterpret_cast<uint8_t*>(const_cast<char*>(xml_data)),
- strlen(xml_data));
- auto locale = CXFA_XMLLocale::Create(span);
+ auto locale = CreateLocaleHelper();
ASSERT_TRUE(locale != nullptr);
EXPECT_EQ(L"GyMdkHmsSEDFwWahKzZ", locale->GetDateTimeSymbols());
}
TEST(CXFA_XMLLocaleTest, GetMonthName) {
- auto span =
- pdfium::make_span(reinterpret_cast<uint8_t*>(const_cast<char*>(xml_data)),
- strlen(xml_data));
- auto locale = CXFA_XMLLocale::Create(span);
+ auto locale = CreateLocaleHelper();
ASSERT_TRUE(locale != nullptr);
EXPECT_EQ(L"", locale->GetMonthName(24, false));
@@ -146,10 +142,7 @@ TEST(CXFA_XMLLocaleTest, GetMonthName) {
}
TEST(CXFA_XMLLocaleTest, GetDayName) {
- auto span =
- pdfium::make_span(reinterpret_cast<uint8_t*>(const_cast<char*>(xml_data)),
- strlen(xml_data));
- auto locale = CXFA_XMLLocale::Create(span);
+ auto locale = CreateLocaleHelper();
ASSERT_TRUE(locale != nullptr);
EXPECT_EQ(L"", locale->GetDayName(24, false));
@@ -159,10 +152,7 @@ TEST(CXFA_XMLLocaleTest, GetDayName) {
}
TEST(CXFA_XMLLocaleTest, GetMeridiemName) {
- auto span =
- pdfium::make_span(reinterpret_cast<uint8_t*>(const_cast<char*>(xml_data)),
- strlen(xml_data));
- auto locale = CXFA_XMLLocale::Create(span);
+ auto locale = CreateLocaleHelper();
ASSERT_TRUE(locale != nullptr);
EXPECT_EQ(L"AM", locale->GetMeridiemName(true));
@@ -170,10 +160,7 @@ TEST(CXFA_XMLLocaleTest, GetMeridiemName) {
}
TEST(CXFA_XMLLocaleTest, GetEraName) {
- auto span =
- pdfium::make_span(reinterpret_cast<uint8_t*>(const_cast<char*>(xml_data)),
- strlen(xml_data));
- auto locale = CXFA_XMLLocale::Create(span);
+ auto locale = CreateLocaleHelper();
ASSERT_TRUE(locale != nullptr);
EXPECT_EQ(L"AD", locale->GetEraName(true));
@@ -181,10 +168,7 @@ TEST(CXFA_XMLLocaleTest, GetEraName) {
}
TEST(CXFA_XMLLocaleTest, GetDatePattern) {
- auto span =
- pdfium::make_span(reinterpret_cast<uint8_t*>(const_cast<char*>(xml_data)),
- strlen(xml_data));
- auto locale = CXFA_XMLLocale::Create(span);
+ auto locale = CreateLocaleHelper();
ASSERT_TRUE(locale != nullptr);
EXPECT_EQ(L"M/D/YY",
@@ -200,10 +184,7 @@ TEST(CXFA_XMLLocaleTest, GetDatePattern) {
}
TEST(CXFA_XMLLocaleTest, GetTimePattern) {
- auto span =
- pdfium::make_span(reinterpret_cast<uint8_t*>(const_cast<char*>(xml_data)),
- strlen(xml_data));
- auto locale = CXFA_XMLLocale::Create(span);
+ auto locale = CreateLocaleHelper();
ASSERT_TRUE(locale != nullptr);
EXPECT_EQ(L"h:MM A",
@@ -219,10 +200,7 @@ TEST(CXFA_XMLLocaleTest, GetTimePattern) {
}
TEST(CXFA_XMLLocaleTest, GetNumPattern) {
- auto span =
- pdfium::make_span(reinterpret_cast<uint8_t*>(const_cast<char*>(xml_data)),
- strlen(xml_data));
- auto locale = CXFA_XMLLocale::Create(span);
+ auto locale = CreateLocaleHelper();
ASSERT_TRUE(locale != nullptr);
EXPECT_EQ(L"z,zzz,zzz,zzz,zzz,zzz%",