From a5d2bf1131fed479195011cbf6463df3612d31f6 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 25 Jul 2018 20:13:48 +0000 Subject: Remove CFX_MemoryStream uses in tests. Replace with CFX_BufferSeekableReadStream, which allows for spans and const inputs. Change CXFA_DocumentParser to take IFX_SeekableReadStream instead of IFX_SeekableStream in the process. Change-Id: I0168451350c9fc250231f0414c38738a4d86ca42 Reviewed-on: https://pdfium-review.googlesource.com/38852 Commit-Queue: Lei Zhang Reviewed-by: Ryan Harrison --- core/fxcrt/xml/cfx_xmlinstruction_unittest.cpp | 17 ++++----- core/fxcrt/xml/cfx_xmlparser_unittest.cpp | 53 ++++++++++++-------------- 2 files changed, 33 insertions(+), 37 deletions(-) (limited to 'core/fxcrt') diff --git a/core/fxcrt/xml/cfx_xmlinstruction_unittest.cpp b/core/fxcrt/xml/cfx_xmlinstruction_unittest.cpp index 0c43c59ccd..74ef87e344 100644 --- a/core/fxcrt/xml/cfx_xmlinstruction_unittest.cpp +++ b/core/fxcrt/xml/cfx_xmlinstruction_unittest.cpp @@ -3,10 +3,11 @@ // found in the LICENSE file. #include "core/fxcrt/xml/cfx_xmlinstruction.h" -#include "core/fxcrt/cfx_memorystream.h" + #include "core/fxcrt/xml/cfx_xmldocument.h" #include "core/fxcrt/xml/cfx_xmlelement.h" #include "core/fxcrt/xml/cfx_xmlparser.h" +#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/string_write_stream.h" #include "testing/test_support.h" @@ -82,13 +83,12 @@ TEST(CFX_XMLInstructionTest, SaveAcrobat) { } TEST(CFX_XMLInstructionTest, ParseAndReSave) { - const char* input = + static const char input[] = "\n" ""; - auto in_stream = pdfium::MakeRetain( - reinterpret_cast(const_cast(input)), strlen(input), - false); + auto in_stream = pdfium::MakeRetain( + pdfium::as_bytes(pdfium::make_span(input))); CFX_XMLParser parser(in_stream); std::unique_ptr doc = parser.Parse(); @@ -116,14 +116,13 @@ TEST(CFX_XMLInstructionTest, ParseAndReSave) { } TEST(CFX_XMLInstructionTest, ParseAndReSaveInnerInstruction) { - const char* input = + static const char input[] = "\n" "\n" ""; - auto in_stream = pdfium::MakeRetain( - reinterpret_cast(const_cast(input)), strlen(input), - false); + auto in_stream = pdfium::MakeRetain( + pdfium::as_bytes(pdfium::make_span(input))); CFX_XMLParser parser(in_stream); std::unique_ptr doc = parser.Parse(); diff --git a/core/fxcrt/xml/cfx_xmlparser_unittest.cpp b/core/fxcrt/xml/cfx_xmlparser_unittest.cpp index 072c18ce3f..300131db95 100644 --- a/core/fxcrt/xml/cfx_xmlparser_unittest.cpp +++ b/core/fxcrt/xml/cfx_xmlparser_unittest.cpp @@ -6,36 +6,33 @@ #include -#include "core/fxcrt/cfx_memorystream.h" #include "core/fxcrt/fx_codepage.h" #include "core/fxcrt/xml/cfx_xmldocument.h" #include "core/fxcrt/xml/cfx_xmlelement.h" #include "core/fxcrt/xml/cfx_xmlinstruction.h" +#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/test_support.h" #include "third_party/base/ptr_util.h" class CFX_XMLParserTest : public testing::Test { public: - std::unique_ptr Parse(const char* input) { - auto stream = pdfium::MakeRetain( - reinterpret_cast(const_cast(input)), strlen(input), - false); - - CFX_XMLParser parser(stream); + std::unique_ptr Parse(pdfium::span input) { + CFX_XMLParser parser(pdfium::MakeRetain( + pdfium::as_bytes(input))); return parser.Parse(); } }; TEST_F(CFX_XMLParserTest, AttributesMustBeQuoted) { - const char* input = + static const char input[] = ""; ASSERT_TRUE(Parse(input) == nullptr); } TEST_F(CFX_XMLParserTest, Attributes) { - const char* input = + static const char input[] = ""; @@ -50,7 +47,7 @@ TEST_F(CFX_XMLParserTest, Attributes) { } TEST_F(CFX_XMLParserTest, CData) { - const char* input = + static const char input[] = ""; - const wchar_t* cdata = + static const wchar_t cdata[] = L"\n \n" L" if (a[1] < 3)\n" L" app.alert(\"Tclams\");\n" @@ -73,7 +70,7 @@ TEST_F(CFX_XMLParserTest, CData) { } TEST_F(CFX_XMLParserTest, CDataWithInnerScript) { - const char* input = + static const char input[] = ""; - const wchar_t* cdata = + static const wchar_t cdata[] = L"\n \n" L" if (a[1] < 3)\n" L" app.alert(\"Tclams\");\n" @@ -98,7 +95,7 @@ TEST_F(CFX_XMLParserTest, CDataWithInnerScript) { } TEST_F(CFX_XMLParserTest, ArrowBangArrow) { - const char* input = + static const char input[] = ""; @@ -112,7 +109,7 @@ TEST_F(CFX_XMLParserTest, ArrowBangArrow) { } TEST_F(CFX_XMLParserTest, ArrowBangBracketArrow) { - const char* input = + static const char input[] = ""; @@ -126,7 +123,7 @@ TEST_F(CFX_XMLParserTest, ArrowBangBracketArrow) { } TEST_F(CFX_XMLParserTest, IncompleteCData) { - const char* input = + static const char input[] = ""; @@ -140,7 +137,7 @@ TEST_F(CFX_XMLParserTest, IncompleteCData) { } TEST_F(CFX_XMLParserTest, UnClosedCData) { - const char* input = + static const char input[] = ""; @@ -154,7 +151,7 @@ TEST_F(CFX_XMLParserTest, UnClosedCData) { } TEST_F(CFX_XMLParserTest, EmptyCData) { - const char* input = + static const char input[] = ""; @@ -168,7 +165,7 @@ TEST_F(CFX_XMLParserTest, EmptyCData) { } TEST_F(CFX_XMLParserTest, Comment) { - const char* input = + static const char input[] = ""; @@ -182,7 +179,7 @@ TEST_F(CFX_XMLParserTest, Comment) { } TEST_F(CFX_XMLParserTest, IncorrectCommentStart) { - const char* input = + static const char input[] = ""; @@ -196,7 +193,7 @@ TEST_F(CFX_XMLParserTest, IncorrectCommentStart) { } TEST_F(CFX_XMLParserTest, CommentEmpty) { - const char* input = + static const char input[] = ""; @@ -210,7 +207,7 @@ TEST_F(CFX_XMLParserTest, CommentEmpty) { } TEST_F(CFX_XMLParserTest, CommentThreeDash) { - const char* input = + static const char input[] = ""; @@ -224,7 +221,7 @@ TEST_F(CFX_XMLParserTest, CommentThreeDash) { } TEST_F(CFX_XMLParserTest, CommentTwoDash) { - const char* input = + static const char input[] = ""; @@ -237,7 +234,7 @@ TEST_F(CFX_XMLParserTest, CommentTwoDash) { } TEST_F(CFX_XMLParserTest, Entities) { - const char* input = + static const char input[] = ""; -- cgit v1.2.3