From a5c32a120ae918ecebab4042b3e52278f7a24b51 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Thu, 28 Sep 2017 17:12:31 -0400 Subject: Extract test subclasses of IFX_SeekableReadStream There are multiple instances of subclasses that either act as an invalid stream or one backed by a memory buffer. Merging all of these into two shared stream classes and removing the others. BUG=pdfium:911 Change-Id: I264602808c6dc0e5c878da462a5e00883fe43e51 Reviewed-on: https://pdfium-review.googlesource.com/15093 Commit-Queue: Ryan Harrison Reviewed-by: Henrique Nakashima --- core/fpdfapi/parser/cpdf_parser_unittest.cpp | 30 +++------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) (limited to 'core/fpdfapi/parser/cpdf_parser_unittest.cpp') diff --git a/core/fpdfapi/parser/cpdf_parser_unittest.cpp b/core/fpdfapi/parser/cpdf_parser_unittest.cpp index b3352975a9..53e1434141 100644 --- a/core/fpdfapi/parser/cpdf_parser_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_parser_unittest.cpp @@ -10,34 +10,10 @@ #include "core/fxcrt/fx_extension.h" #include "core/fxcrt/fx_stream.h" #include "core/fxcrt/retain_ptr.h" +#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/utils/path_service.h" -// Provide a way to read test data from a buffer instead of a file. -class CFX_TestBufferRead : public IFX_SeekableReadStream { - public: - template - friend RetainPtr pdfium::MakeRetain(Args&&... args); - - // IFX_SeekableReadStream: - bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { - if (offset < 0 || offset + size > total_size_) - return false; - - memcpy(buffer, buffer_ + offset, size); - return true; - } - - FX_FILESIZE GetSize() override { return (FX_FILESIZE)total_size_; }; - - protected: - CFX_TestBufferRead(const unsigned char* buffer_in, size_t buf_size) - : buffer_(buffer_in), total_size_(buf_size) {} - - const unsigned char* buffer_; - size_t total_size_; -}; - // A wrapper class to help test member functions of CPDF_Parser. class CPDF_TestParser : public CPDF_Parser { public: @@ -59,8 +35,8 @@ class CPDF_TestParser : public CPDF_Parser { // Setup reading from a buffer and initial states. bool InitTestFromBuffer(const unsigned char* buffer, size_t len) { // For the test file, the header is set at the beginning. - m_pSyntax->InitParser(pdfium::MakeRetain(buffer, len), - 0); + m_pSyntax->InitParser( + pdfium::MakeRetain(buffer, len), 0); return true; } -- cgit v1.2.3