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 | |
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>
-rw-r--r-- | core/fpdfapi/parser/cpdf_read_validator_unittest.cpp | 14 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp | 91 | ||||
-rw-r--r-- | core/fxcrt/xml/cfx_xmlinstruction_unittest.cpp | 17 | ||||
-rw-r--r-- | core/fxcrt/xml/cfx_xmlparser_unittest.cpp | 53 | ||||
-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 |
7 files changed, 106 insertions, 120 deletions
diff --git a/core/fpdfapi/parser/cpdf_read_validator_unittest.cpp b/core/fpdfapi/parser/cpdf_read_validator_unittest.cpp index 247abaa9f4..ccfb451dd8 100644 --- a/core/fpdfapi/parser/cpdf_read_validator_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_read_validator_unittest.cpp @@ -8,8 +8,6 @@ #include <utility> #include <vector> -#include "core/fxcrt/cfx_memorystream.h" -#include "core/fxcrt/fx_stream.h" #include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" @@ -67,8 +65,7 @@ class MockDownloadHints : public CPDF_DataAvail::DownloadHints { TEST(CPDF_ReadValidatorTest, UnavailableData) { std::vector<uint8_t> test_data(kTestDataSize); - auto file = pdfium::MakeRetain<CFX_MemoryStream>(test_data.data(), - test_data.size(), false); + auto file = pdfium::MakeRetain<CFX_BufferSeekableReadStream>(test_data); MockFileAvail file_avail; auto validator = pdfium::MakeRetain<CPDF_ReadValidator>(file, &file_avail); @@ -91,8 +88,7 @@ TEST(CPDF_ReadValidatorTest, UnavailableData) { TEST(CPDF_ReadValidatorTest, UnavailableDataWithHints) { std::vector<uint8_t> test_data(kTestDataSize); - auto file = pdfium::MakeRetain<CFX_MemoryStream>(test_data.data(), - test_data.size(), false); + auto file = pdfium::MakeRetain<CFX_BufferSeekableReadStream>(test_data); MockFileAvail file_avail; auto validator = pdfium::MakeRetain<CPDF_ReadValidator>(file, &file_avail); @@ -147,8 +143,7 @@ TEST(CPDF_ReadValidatorTest, ReadError) { TEST(CPDF_ReadValidatorTest, IntOverflow) { std::vector<uint8_t> test_data(kTestDataSize); - auto file = pdfium::MakeRetain<CFX_MemoryStream>(test_data.data(), - test_data.size(), false); + auto file = pdfium::MakeRetain<CFX_BufferSeekableReadStream>(test_data); MockFileAvail file_avail; auto validator = pdfium::MakeRetain<CPDF_ReadValidator>(file, &file_avail); @@ -246,8 +241,7 @@ TEST(CPDF_ReadValidatorTest, SessionReset) { TEST(CPDF_ReadValidatorTest, CheckDataRangeAndRequestIfUnavailable) { std::vector<uint8_t> test_data(kTestDataSize); - auto file = pdfium::MakeRetain<CFX_MemoryStream>(test_data.data(), - test_data.size(), false); + auto file = pdfium::MakeRetain<CFX_BufferSeekableReadStream>(test_data); MockFileAvail file_avail; auto validator = pdfium::MakeRetain<CPDF_ReadValidator>(file, &file_avail); diff --git a/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp b/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp index 57d26b1ed1..498eddf12b 100644 --- a/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp @@ -8,81 +8,80 @@ #include "core/fpdfapi/parser/cpdf_object.h" #include "core/fpdfapi/parser/cpdf_parser.h" #include "core/fpdfapi/parser/cpdf_syntax_parser.h" -#include "core/fxcrt/cfx_memorystream.h" #include "core/fxcrt/fx_extension.h" -#include "core/fxcrt/fx_stream.h" +#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/utils/path_service.h" TEST(cpdf_syntax_parser, ReadHexString) { { // Empty string. - uint8_t data[] = ""; - CPDF_SyntaxParser parser( - pdfium::MakeRetain<CFX_MemoryStream>(data, 0, false)); + static const uint8_t data[] = ""; + CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>( + pdfium::make_span(data, 0))); EXPECT_EQ("", parser.ReadHexString()); EXPECT_EQ(0, parser.GetPos()); } { // Blank string. - uint8_t data[] = " "; - CPDF_SyntaxParser parser( - pdfium::MakeRetain<CFX_MemoryStream>(data, 2, false)); + static const uint8_t data[] = " "; + CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>( + pdfium::make_span(data, 2))); EXPECT_EQ("", parser.ReadHexString()); EXPECT_EQ(2, parser.GetPos()); } { // Skips unknown characters. - uint8_t data[] = "z12b"; - CPDF_SyntaxParser parser( - pdfium::MakeRetain<CFX_MemoryStream>(data, 4, false)); + static const uint8_t data[] = "z12b"; + CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>( + pdfium::make_span(data, 4))); EXPECT_EQ("\x12\xb0", parser.ReadHexString()); EXPECT_EQ(4, parser.GetPos()); } { // Skips unknown characters. - uint8_t data[] = "*<&*#$^&@1"; - CPDF_SyntaxParser parser( - pdfium::MakeRetain<CFX_MemoryStream>(data, 10, false)); + static const uint8_t data[] = "*<&*#$^&@1"; + CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>( + pdfium::make_span(data, 10))); EXPECT_EQ("\x10", parser.ReadHexString()); EXPECT_EQ(10, parser.GetPos()); } { // Skips unknown characters. - uint8_t data[] = "\x80zab"; - CPDF_SyntaxParser parser( - pdfium::MakeRetain<CFX_MemoryStream>(data, 4, false)); + static const uint8_t data[] = "\x80zab"; + CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>( + pdfium::make_span(data, 4))); EXPECT_EQ("\xab", parser.ReadHexString()); EXPECT_EQ(4, parser.GetPos()); } { // Skips unknown characters. - uint8_t data[] = "\xffzab"; - CPDF_SyntaxParser parser( - pdfium::MakeRetain<CFX_MemoryStream>(data, 4, false)); + static const uint8_t data[] = "\xffzab"; + CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>( + pdfium::make_span(data, 4))); EXPECT_EQ("\xab", parser.ReadHexString()); EXPECT_EQ(4, parser.GetPos()); } { // Regular conversion. - uint8_t data[] = "1A2b>abcd"; - CPDF_SyntaxParser parser( - pdfium::MakeRetain<CFX_MemoryStream>(data, 9, false)); + static const uint8_t data[] = "1A2b>abcd"; + CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>( + pdfium::make_span(data, 9))); EXPECT_EQ("\x1a\x2b", parser.ReadHexString()); EXPECT_EQ(5, parser.GetPos()); } { // Position out of bounds. - uint8_t data[] = "12ab>"; - CPDF_SyntaxParser parser( - pdfium::MakeRetain<CFX_MemoryStream>(data, 5, false)); + static const uint8_t data[] = "12ab>"; + CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>( + pdfium::make_span(data, 5))); parser.SetPos(5); EXPECT_EQ("", parser.ReadHexString()); @@ -102,45 +101,45 @@ TEST(cpdf_syntax_parser, ReadHexString) { { // Missing ending >. - uint8_t data[] = "1A2b"; - CPDF_SyntaxParser parser( - pdfium::MakeRetain<CFX_MemoryStream>(data, 4, false)); + static const uint8_t data[] = "1A2b"; + CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>( + pdfium::make_span(data, 4))); EXPECT_EQ("\x1a\x2b", parser.ReadHexString()); EXPECT_EQ(4, parser.GetPos()); } { // Missing ending >. - uint8_t data[] = "12abz"; - CPDF_SyntaxParser parser( - pdfium::MakeRetain<CFX_MemoryStream>(data, 5, false)); + static const uint8_t data[] = "12abz"; + CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>( + pdfium::make_span(data, 5))); EXPECT_EQ("\x12\xab", parser.ReadHexString()); EXPECT_EQ(5, parser.GetPos()); } { // Uneven number of bytes. - uint8_t data[] = "1A2>asdf"; - CPDF_SyntaxParser parser( - pdfium::MakeRetain<CFX_MemoryStream>(data, 8, false)); + static const uint8_t data[] = "1A2>asdf"; + CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>( + pdfium::make_span(data, 8))); EXPECT_EQ("\x1a\x20", parser.ReadHexString()); EXPECT_EQ(4, parser.GetPos()); } { // Uneven number of bytes. - uint8_t data[] = "1A2zasdf"; - CPDF_SyntaxParser parser( - pdfium::MakeRetain<CFX_MemoryStream>(data, 8, false)); + static const uint8_t data[] = "1A2zasdf"; + CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>( + pdfium::make_span(data, 8))); EXPECT_EQ("\x1a\x2a\xdf", parser.ReadHexString()); EXPECT_EQ(8, parser.GetPos()); } { // Just ending character. - uint8_t data[] = ">"; - CPDF_SyntaxParser parser( - pdfium::MakeRetain<CFX_MemoryStream>(data, 1, false)); + static const uint8_t data[] = ">"; + CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>( + pdfium::make_span(data, 1))); EXPECT_EQ("", parser.ReadHexString()); EXPECT_EQ(1, parser.GetPos()); } @@ -148,17 +147,17 @@ TEST(cpdf_syntax_parser, ReadHexString) { TEST(cpdf_syntax_parser, GetInvalidReference) { // Data with a reference with number CPDF_Object::kInvalidObjNum - uint8_t data[] = "4294967295 0 R"; - CPDF_SyntaxParser parser( - pdfium::MakeRetain<CFX_MemoryStream>(data, 14, false)); + static const uint8_t data[] = "4294967295 0 R"; + CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>( + pdfium::make_span(data, 14))); std::unique_ptr<CPDF_Object> ref = parser.GetObjectBody(nullptr); EXPECT_FALSE(ref); } TEST(cpdf_syntax_parser, PeekNextWord) { - uint8_t data[] = " WORD "; + static const uint8_t data[] = " WORD "; CPDF_SyntaxParser parser( - pdfium::MakeRetain<CFX_MemoryStream>(data, sizeof(data), false)); + pdfium::MakeRetain<CFX_BufferSeekableReadStream>(data)); EXPECT_EQ("WORD", parser.PeekNextWord(nullptr)); EXPECT_EQ("WORD", parser.GetNextWord(nullptr)); } 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[] = "<?acrobat http://www.xfa.org/schema/xfa-template/3.3/ Display:1 ?>\n" "<node></node>"; - auto in_stream = pdfium::MakeRetain<CFX_MemoryStream>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input), - false); + auto in_stream = pdfium::MakeRetain<CFX_BufferSeekableReadStream>( + pdfium::as_bytes(pdfium::make_span(input))); CFX_XMLParser parser(in_stream); std::unique_ptr<CFX_XMLDocument> doc = parser.Parse(); @@ -116,14 +116,13 @@ TEST(CFX_XMLInstructionTest, ParseAndReSave) { } TEST(CFX_XMLInstructionTest, ParseAndReSaveInnerInstruction) { - const char* input = + static const char input[] = "<node>\n" "<?acrobat http://www.xfa.org/schema/xfa-template/3.3/ Display:1 ?>\n" "</node>"; - auto in_stream = pdfium::MakeRetain<CFX_MemoryStream>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input), - false); + auto in_stream = pdfium::MakeRetain<CFX_BufferSeekableReadStream>( + pdfium::as_bytes(pdfium::make_span(input))); CFX_XMLParser parser(in_stream); std::unique_ptr<CFX_XMLDocument> 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 <memory> -#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<CFX_XMLDocument> Parse(const char* input) { - auto stream = pdfium::MakeRetain<CFX_MemoryStream>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input), - false); - - CFX_XMLParser parser(stream); + std::unique_ptr<CFX_XMLDocument> Parse(pdfium::span<const char> input) { + CFX_XMLParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>( + pdfium::as_bytes(input))); return parser.Parse(); } }; TEST_F(CFX_XMLParserTest, AttributesMustBeQuoted) { - const char* input = + static const char input[] = "<script display=1>\n" "</script>"; ASSERT_TRUE(Parse(input) == nullptr); } TEST_F(CFX_XMLParserTest, Attributes) { - const char* input = + static const char input[] = "<script contentType=\"application/x-javascript\" display=\"1\">\n" "</script>"; @@ -50,7 +47,7 @@ TEST_F(CFX_XMLParserTest, Attributes) { } TEST_F(CFX_XMLParserTest, CData) { - const char* input = + static const char input[] = "<script>\n" " <![CDATA[\n" " if (a[1] < 3)\n" @@ -58,7 +55,7 @@ TEST_F(CFX_XMLParserTest, CData) { " ]]>\n" "</script>"; - 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[] = "<script>\n" " <![CDATA[\n" " if (a[1] < 3)\n" @@ -82,7 +79,7 @@ TEST_F(CFX_XMLParserTest, CDataWithInnerScript) { " ]]>\n" "</script>"; - 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[] = "<script>\n" " <!>\n" "</script>"; @@ -112,7 +109,7 @@ TEST_F(CFX_XMLParserTest, ArrowBangArrow) { } TEST_F(CFX_XMLParserTest, ArrowBangBracketArrow) { - const char* input = + static const char input[] = "<script>\n" " <![>\n" "</script>"; @@ -126,7 +123,7 @@ TEST_F(CFX_XMLParserTest, ArrowBangBracketArrow) { } TEST_F(CFX_XMLParserTest, IncompleteCData) { - const char* input = + static const char input[] = "<script>\n" " <![CDATA>\n" "</script>"; @@ -140,7 +137,7 @@ TEST_F(CFX_XMLParserTest, IncompleteCData) { } TEST_F(CFX_XMLParserTest, UnClosedCData) { - const char* input = + static const char input[] = "<script>\n" " <![CDATA[\n" "</script>"; @@ -154,7 +151,7 @@ TEST_F(CFX_XMLParserTest, UnClosedCData) { } TEST_F(CFX_XMLParserTest, EmptyCData) { - const char* input = + static const char input[] = "<script>\n" " <![CDATA[]]>\n" "</script>"; @@ -168,7 +165,7 @@ TEST_F(CFX_XMLParserTest, EmptyCData) { } TEST_F(CFX_XMLParserTest, Comment) { - const char* input = + static const char input[] = "<script>\n" " <!-- A Comment -->\n" "</script>"; @@ -182,7 +179,7 @@ TEST_F(CFX_XMLParserTest, Comment) { } TEST_F(CFX_XMLParserTest, IncorrectCommentStart) { - const char* input = + static const char input[] = "<script>\n" " <!- A Comment -->\n" "</script>"; @@ -196,7 +193,7 @@ TEST_F(CFX_XMLParserTest, IncorrectCommentStart) { } TEST_F(CFX_XMLParserTest, CommentEmpty) { - const char* input = + static const char input[] = "<script>\n" " <!---->\n" "</script>"; @@ -210,7 +207,7 @@ TEST_F(CFX_XMLParserTest, CommentEmpty) { } TEST_F(CFX_XMLParserTest, CommentThreeDash) { - const char* input = + static const char input[] = "<script>\n" " <!--->\n" "</script>"; @@ -224,7 +221,7 @@ TEST_F(CFX_XMLParserTest, CommentThreeDash) { } TEST_F(CFX_XMLParserTest, CommentTwoDash) { - const char* input = + static const char input[] = "<script>\n" " <!-->\n" "</script>"; @@ -237,7 +234,7 @@ TEST_F(CFX_XMLParserTest, CommentTwoDash) { } TEST_F(CFX_XMLParserTest, Entities) { - const char* input = + static const char input[] = "<script>" "B" // B "T" // T @@ -262,7 +259,7 @@ TEST_F(CFX_XMLParserTest, Entities) { } TEST_F(CFX_XMLParserTest, EntityOverflowHex) { - const char* input = + static const char input[] = "<script>" "�" "�" @@ -277,7 +274,7 @@ TEST_F(CFX_XMLParserTest, EntityOverflowHex) { } TEST_F(CFX_XMLParserTest, EntityOverflowDecimal) { - const char* input = + static const char input[] = "<script>" "�" "�" @@ -317,7 +314,7 @@ TEST_F(CFX_XMLParserTest, DoubleElementClose) { } TEST_F(CFX_XMLParserTest, ParseInstruction) { - const char* input = + static const char input[] = "<?originalXFAVersion http://www.xfa.org/schema/xfa-template/3.3/ ?>" "<form></form>"; @@ -334,7 +331,7 @@ TEST_F(CFX_XMLParserTest, ParseInstruction) { } TEST_F(CFX_XMLParserTest, BadEntity) { - const char* input = + static const char input[] = "<script>" "Test &<p>; thing" "</script>"; 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(); |