diff options
author | Ryan Harrison <rharrison@chromium.org> | 2017-09-28 17:12:31 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-09-29 14:26:15 +0000 |
commit | a5c32a120ae918ecebab4042b3e52278f7a24b51 (patch) | |
tree | 3400953772db763e32ade601170a46c00982e49f /testing/fx_string_testhelpers.h | |
parent | 10e1f05a9e644cd954792bcd40ef787551cbd209 (diff) | |
download | pdfium-a5c32a120ae918ecebab4042b3e52278f7a24b51.tar.xz |
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 <rharrison@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'testing/fx_string_testhelpers.h')
-rw-r--r-- | testing/fx_string_testhelpers.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/testing/fx_string_testhelpers.h b/testing/fx_string_testhelpers.h index 34ac69dab4..5a269a3cf6 100644 --- a/testing/fx_string_testhelpers.h +++ b/testing/fx_string_testhelpers.h @@ -8,8 +8,58 @@ #include <ostream> #include "core/fxcrt/cfx_datetime.h" +#include "core/fxcrt/fx_stream.h" // Output stream operator so GTEST macros work with CFX_DateTime objects. std::ostream& operator<<(std::ostream& os, const CFX_DateTime& dt); +class CFX_InvalidSeekableReadStream : public IFX_SeekableReadStream { + public: + template <typename T, typename... Args> + friend RetainPtr<T> pdfium::MakeRetain(Args&&... args); + + // IFX_SeekableReadStream overrides: + bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { + return false; + } + FX_FILESIZE GetSize() override { return data_size_; } + + private: + explicit CFX_InvalidSeekableReadStream(FX_FILESIZE data_size) + : data_size_(data_size) {} + + FX_FILESIZE data_size_; +}; + +class CFX_BufferSeekableReadStream : public IFX_SeekableReadStream { + public: + template <typename T, typename... Args> + friend RetainPtr<T> pdfium::MakeRetain(Args&&... args); + + // IFX_SeekableReadStream: + bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { + if (offset < 0 || static_cast<size_t>(offset) >= data_size_) + return false; + + if (static_cast<size_t>(offset) + size > data_size_) + size = data_size_ - static_cast<size_t>(offset); + if (size == 0) + return false; + + memcpy(buffer, data_ + offset, size); + return true; + } + + FX_FILESIZE GetSize() override { + return static_cast<FX_FILESIZE>(data_size_); + } + + private: + CFX_BufferSeekableReadStream(const unsigned char* src, size_t src_size) + : data_(src), data_size_(src_size) {} + + const unsigned char* data_; + size_t data_size_; +}; + #endif // TESTING_FX_STRING_TESTHELPERS_H_ |