diff options
author | Lei Zhang <thestig@chromium.org> | 2018-07-25 20:13:48 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-07-25 20:13:48 +0000 |
commit | a5d2bf1131fed479195011cbf6463df3612d31f6 (patch) | |
tree | 170dc3ca4b242be2b4148fd0c718d25db8966210 /xfa | |
parent | c356472262b736607d3daf07046d4796c3a51eee (diff) | |
download | pdfium-a5d2bf1131fed479195011cbf6463df3612d31f6.tar.xz |
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 <thestig@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'xfa')
-rw-r--r-- | xfa/fxfa/parser/cxfa_document_parser.cpp | 7 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_document_parser.h | 6 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_document_parser_unittest.cpp | 38 |
3 files changed, 24 insertions, 27 deletions
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<IFX_SeekableStream>& pStream, - XFA_PacketType ePacketID) { +bool CXFA_DocumentParser::Parse( + const RetainPtr<IFX_SeekableReadStream>& 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<CFX_XMLDocument> CXFA_DocumentParser::LoadXML( - const RetainPtr<IFX_SeekableStream>& pStream) { + const RetainPtr<IFX_SeekableReadStream>& 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<IFX_SeekableStream>& pStream, + bool Parse(const RetainPtr<IFX_SeekableReadStream>& pStream, XFA_PacketType ePacketID); CFX_XMLNode* ParseXMLData(const ByteString& wsXML); @@ -35,7 +35,7 @@ class CXFA_DocumentParser { private: std::unique_ptr<CFX_XMLDocument> LoadXML( - const RetainPtr<IFX_SeekableStream>& pStream); + const RetainPtr<IFX_SeekableReadStream>& 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[] = "<config>\n" "<?originalXFAVersion http://www.xfa.org/schema/xfa-template/2.7 " "v2.7-scripting:0 ?>\n" "</config>"; EXPECT_FALSE(GetDoc()->HasFlag(XFA_DOCFLAG_Scripting)); - auto stream = pdfium::MakeRetain<CFX_MemoryStream>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input), - false); + auto stream = pdfium::MakeRetain<CFX_BufferSeekableReadStream>( + 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[] = "<config>\n" "<?originalXFAVersion http://www.xfa.org/schema/xfa-template/2.7 " "v2.7-scripting:1 ?>\n" @@ -57,9 +57,8 @@ TEST_F(CXFA_DocumentParserTest, XMLInstructionsScriptOn) { EXPECT_FALSE(GetDoc()->HasFlag(XFA_DOCFLAG_Scripting)); - auto stream = pdfium::MakeRetain<CFX_MemoryStream>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input), - false); + auto stream = pdfium::MakeRetain<CFX_BufferSeekableReadStream>( + 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[] = "<config>" "<?acrobat JavaScript strictScoping ?>\n" "</config>"; EXPECT_FALSE(GetDoc()->HasFlag(XFA_DOCFLAG_StrictScoping)); - auto stream = pdfium::MakeRetain<CFX_MemoryStream>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input), - false); + auto stream = pdfium::MakeRetain<CFX_BufferSeekableReadStream>( + 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[] = "<config>" "<?acrobat JavaScript otherScoping ?>\n" "</config>"; EXPECT_FALSE(GetDoc()->HasFlag(XFA_DOCFLAG_StrictScoping)); - auto stream = pdfium::MakeRetain<CFX_MemoryStream>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input), - false); + auto stream = pdfium::MakeRetain<CFX_BufferSeekableReadStream>( + 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[] = "<config>" "<?originalXFAVersion http://www.xfa.org/schema/xfa-template/2.7 " "v2.7-scripting:1 ?>\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<CFX_MemoryStream>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input), - false); + auto stream = pdfium::MakeRetain<CFX_BufferSeekableReadStream>( + pdfium::as_bytes(pdfium::make_span(input))); ASSERT_TRUE(GetParser()->Parse(stream, XFA_PacketType::Config)); CXFA_Node* root = GetParser()->GetRootNode(); |