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 --- xfa/fxfa/parser/cxfa_document_parser.cpp | 7 +++-- xfa/fxfa/parser/cxfa_document_parser.h | 6 ++-- xfa/fxfa/parser/cxfa_document_parser_unittest.cpp | 38 ++++++++++------------- 3 files changed, 24 insertions(+), 27 deletions(-) (limited to 'xfa') diff --git a/xfa/fxfa/parser/cxfa_document_parser.cpp b/xfa/fxfa/parser/cxfa_document_parser.cpp index 27d80cde15..b126d8267f 100644 --- a/xfa/fxfa/parser/cxfa_document_parser.cpp +++ b/xfa/fxfa/parser/cxfa_document_parser.cpp @@ -318,8 +318,9 @@ CXFA_DocumentParser::CXFA_DocumentParser(CXFA_Document* pFactory) CXFA_DocumentParser::~CXFA_DocumentParser() = default; -bool CXFA_DocumentParser::Parse(const RetainPtr& pStream, - XFA_PacketType ePacketID) { +bool CXFA_DocumentParser::Parse( + const RetainPtr& pStream, + XFA_PacketType ePacketID) { xml_doc_ = LoadXML(pStream); if (!xml_doc_) return false; @@ -342,7 +343,7 @@ CFX_XMLNode* CXFA_DocumentParser::ParseXMLData(const ByteString& wsXML) { } std::unique_ptr CXFA_DocumentParser::LoadXML( - const RetainPtr& pStream) { + const RetainPtr& pStream) { ASSERT(pStream); CFX_XMLParser parser(pStream); diff --git a/xfa/fxfa/parser/cxfa_document_parser.h b/xfa/fxfa/parser/cxfa_document_parser.h index 4e75db935a..064475aee3 100644 --- a/xfa/fxfa/parser/cxfa_document_parser.h +++ b/xfa/fxfa/parser/cxfa_document_parser.h @@ -17,14 +17,14 @@ class CXFA_Document; class CXFA_Node; class CFX_XMLInstruction; -class IFX_SeekableStream; +class IFX_SeekableReadStream; class CXFA_DocumentParser { public: explicit CXFA_DocumentParser(CXFA_Document* pFactory); ~CXFA_DocumentParser(); - bool Parse(const RetainPtr& pStream, + bool Parse(const RetainPtr& pStream, XFA_PacketType ePacketID); CFX_XMLNode* ParseXMLData(const ByteString& wsXML); @@ -35,7 +35,7 @@ class CXFA_DocumentParser { private: std::unique_ptr LoadXML( - const RetainPtr& pStream); + const RetainPtr& pStream); CXFA_Node* ParseAsXDPPacket(CFX_XMLNode* pXMLDocumentNode, XFA_PacketType ePacketID); diff --git a/xfa/fxfa/parser/cxfa_document_parser_unittest.cpp b/xfa/fxfa/parser/cxfa_document_parser_unittest.cpp index b150abc3ea..62bd380326 100644 --- a/xfa/fxfa/parser/cxfa_document_parser_unittest.cpp +++ b/xfa/fxfa/parser/cxfa_document_parser_unittest.cpp @@ -3,7 +3,8 @@ // found in the LICENSE file. #include "xfa/fxfa/parser/cxfa_document_parser.h" -#include "core/fxcrt/cfx_memorystream.h" + +#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/test_support.h" #include "xfa/fxfa/parser/cxfa_document.h" @@ -31,16 +32,15 @@ class CXFA_DocumentParserTest : public testing::Test { }; TEST_F(CXFA_DocumentParserTest, XMLInstructionsScriptOff) { - const char* input = + static const char input[] = "\n" "\n" ""; EXPECT_FALSE(GetDoc()->HasFlag(XFA_DOCFLAG_Scripting)); - auto stream = pdfium::MakeRetain( - reinterpret_cast(const_cast(input)), strlen(input), - false); + auto stream = pdfium::MakeRetain( + pdfium::as_bytes(pdfium::make_span(input))); ASSERT_TRUE(GetParser()->Parse(stream, XFA_PacketType::Config)); CXFA_Node* root = GetParser()->GetRootNode(); @@ -49,7 +49,7 @@ TEST_F(CXFA_DocumentParserTest, XMLInstructionsScriptOff) { } TEST_F(CXFA_DocumentParserTest, XMLInstructionsScriptOn) { - const char* input = + static const char input[] = "\n" "\n" @@ -57,9 +57,8 @@ TEST_F(CXFA_DocumentParserTest, XMLInstructionsScriptOn) { EXPECT_FALSE(GetDoc()->HasFlag(XFA_DOCFLAG_Scripting)); - auto stream = pdfium::MakeRetain( - reinterpret_cast(const_cast(input)), strlen(input), - false); + auto stream = pdfium::MakeRetain( + pdfium::as_bytes(pdfium::make_span(input))); ASSERT_TRUE(GetParser()->Parse(stream, XFA_PacketType::Config)); CXFA_Node* root = GetParser()->GetRootNode(); @@ -68,16 +67,15 @@ TEST_F(CXFA_DocumentParserTest, XMLInstructionsScriptOn) { } TEST_F(CXFA_DocumentParserTest, XMLInstructionsStrictScope) { - const char* input = + static const char input[] = "" "\n" ""; EXPECT_FALSE(GetDoc()->HasFlag(XFA_DOCFLAG_StrictScoping)); - auto stream = pdfium::MakeRetain( - reinterpret_cast(const_cast(input)), strlen(input), - false); + auto stream = pdfium::MakeRetain( + pdfium::as_bytes(pdfium::make_span(input))); ASSERT_TRUE(GetParser()->Parse(stream, XFA_PacketType::Config)); CXFA_Node* root = GetParser()->GetRootNode(); @@ -86,16 +84,15 @@ TEST_F(CXFA_DocumentParserTest, XMLInstructionsStrictScope) { } TEST_F(CXFA_DocumentParserTest, XMLInstructionsStrictScopeBad) { - const char* input = + static const char input[] = "" "\n" ""; EXPECT_FALSE(GetDoc()->HasFlag(XFA_DOCFLAG_StrictScoping)); - auto stream = pdfium::MakeRetain( - reinterpret_cast(const_cast(input)), strlen(input), - false); + auto stream = pdfium::MakeRetain( + pdfium::as_bytes(pdfium::make_span(input))); ASSERT_TRUE(GetParser()->Parse(stream, XFA_PacketType::Config)); CXFA_Node* root = GetParser()->GetRootNode(); @@ -104,7 +101,7 @@ TEST_F(CXFA_DocumentParserTest, XMLInstructionsStrictScopeBad) { } TEST_F(CXFA_DocumentParserTest, MultipleXMLInstructions) { - const char* input = + static const char input[] = "" "\n" @@ -114,9 +111,8 @@ TEST_F(CXFA_DocumentParserTest, MultipleXMLInstructions) { EXPECT_FALSE(GetDoc()->HasFlag(XFA_DOCFLAG_Scripting)); EXPECT_FALSE(GetDoc()->HasFlag(XFA_DOCFLAG_StrictScoping)); - auto stream = pdfium::MakeRetain( - reinterpret_cast(const_cast(input)), strlen(input), - false); + auto stream = pdfium::MakeRetain( + pdfium::as_bytes(pdfium::make_span(input))); ASSERT_TRUE(GetParser()->Parse(stream, XFA_PacketType::Config)); CXFA_Node* root = GetParser()->GetRootNode(); -- cgit v1.2.3