From 591c7c54ac89aa28fb782745ed8116414d6a04fd Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 19 Jul 2018 17:21:25 +0000 Subject: 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 Reviewed-by: Lei Zhang --- xfa/fxfa/parser/cxfa_xmllocale_unittest.cpp | 68 ++++++++++------------------- 1 file 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 + #include "testing/gtest/include/gtest/gtest.h" #include "testing/test_support.h" -static const char* xml_data = +namespace { + +const char kXMLData[] = "" "January" "February" @@ -85,11 +89,15 @@ static const char* xml_data = "" ""; +std::unique_ptr CreateLocaleHelper() { + return CXFA_XMLLocale::Create(pdfium::as_writable_bytes( + pdfium::make_span(const_cast(kXMLData), strlen(kXMLData)))); +} + +} // namespace + TEST(CXFA_XMLLocaleTest, Create) { - auto span = - pdfium::make_span(reinterpret_cast(const_cast(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(const_cast(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(const_cast(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(const_cast(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(const_cast(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(const_cast(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(const_cast(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(const_cast(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(const_cast(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(const_cast(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(const_cast(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%", -- cgit v1.2.3