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 --- .../parser/cpdf_read_validator_unittest.cpp | 14 +--- .../fpdfapi/parser/cpdf_syntax_parser_unittest.cpp | 91 +++++++++++----------- 2 files changed, 49 insertions(+), 56 deletions(-) (limited to 'core/fpdfapi/parser') 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 #include -#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 test_data(kTestDataSize); - auto file = pdfium::MakeRetain(test_data.data(), - test_data.size(), false); + auto file = pdfium::MakeRetain(test_data); MockFileAvail file_avail; auto validator = pdfium::MakeRetain(file, &file_avail); @@ -91,8 +88,7 @@ TEST(CPDF_ReadValidatorTest, UnavailableData) { TEST(CPDF_ReadValidatorTest, UnavailableDataWithHints) { std::vector test_data(kTestDataSize); - auto file = pdfium::MakeRetain(test_data.data(), - test_data.size(), false); + auto file = pdfium::MakeRetain(test_data); MockFileAvail file_avail; auto validator = pdfium::MakeRetain(file, &file_avail); @@ -147,8 +143,7 @@ TEST(CPDF_ReadValidatorTest, ReadError) { TEST(CPDF_ReadValidatorTest, IntOverflow) { std::vector test_data(kTestDataSize); - auto file = pdfium::MakeRetain(test_data.data(), - test_data.size(), false); + auto file = pdfium::MakeRetain(test_data); MockFileAvail file_avail; auto validator = pdfium::MakeRetain(file, &file_avail); @@ -246,8 +241,7 @@ TEST(CPDF_ReadValidatorTest, SessionReset) { TEST(CPDF_ReadValidatorTest, CheckDataRangeAndRequestIfUnavailable) { std::vector test_data(kTestDataSize); - auto file = pdfium::MakeRetain(test_data.data(), - test_data.size(), false); + auto file = pdfium::MakeRetain(test_data); MockFileAvail file_avail; auto validator = pdfium::MakeRetain(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(data, 0, false)); + static const uint8_t data[] = ""; + CPDF_SyntaxParser parser(pdfium::MakeRetain( + pdfium::make_span(data, 0))); EXPECT_EQ("", parser.ReadHexString()); EXPECT_EQ(0, parser.GetPos()); } { // Blank string. - uint8_t data[] = " "; - CPDF_SyntaxParser parser( - pdfium::MakeRetain(data, 2, false)); + static const uint8_t data[] = " "; + CPDF_SyntaxParser parser(pdfium::MakeRetain( + 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(data, 4, false)); + static const uint8_t data[] = "z12b"; + CPDF_SyntaxParser parser(pdfium::MakeRetain( + 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(data, 10, false)); + static const uint8_t data[] = "*<&*#$^&@1"; + CPDF_SyntaxParser parser(pdfium::MakeRetain( + 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(data, 4, false)); + static const uint8_t data[] = "\x80zab"; + CPDF_SyntaxParser parser(pdfium::MakeRetain( + 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(data, 4, false)); + static const uint8_t data[] = "\xffzab"; + CPDF_SyntaxParser parser(pdfium::MakeRetain( + 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(data, 9, false)); + static const uint8_t data[] = "1A2b>abcd"; + CPDF_SyntaxParser parser(pdfium::MakeRetain( + 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(data, 5, false)); + static const uint8_t data[] = "12ab>"; + CPDF_SyntaxParser parser(pdfium::MakeRetain( + 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(data, 4, false)); + static const uint8_t data[] = "1A2b"; + CPDF_SyntaxParser parser(pdfium::MakeRetain( + 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(data, 5, false)); + static const uint8_t data[] = "12abz"; + CPDF_SyntaxParser parser(pdfium::MakeRetain( + 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(data, 8, false)); + static const uint8_t data[] = "1A2>asdf"; + CPDF_SyntaxParser parser(pdfium::MakeRetain( + 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(data, 8, false)); + static const uint8_t data[] = "1A2zasdf"; + CPDF_SyntaxParser parser(pdfium::MakeRetain( + 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(data, 1, false)); + static const uint8_t data[] = ">"; + CPDF_SyntaxParser parser(pdfium::MakeRetain( + 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(data, 14, false)); + static const uint8_t data[] = "4294967295 0 R"; + CPDF_SyntaxParser parser(pdfium::MakeRetain( + pdfium::make_span(data, 14))); std::unique_ptr 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(data, sizeof(data), false)); + pdfium::MakeRetain(data)); EXPECT_EQ("WORD", parser.PeekNextWord(nullptr)); EXPECT_EQ("WORD", parser.GetNextWord(nullptr)); } -- cgit v1.2.3