summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser/cpdf_parser_unittest.cpp
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-12-07 09:21:17 -0800
committerCommit bot <commit-bot@chromium.org>2016-12-07 09:21:18 -0800
commit833619b4441915c7c55085d44b3221eaef0d9800 (patch)
tree68bf76e83078223ba03f490c2c13f484e40154d4 /core/fpdfapi/parser/cpdf_parser_unittest.cpp
parent8f875507a986d10335e40a5f7c1679aff9770d0a (diff)
downloadpdfium-833619b4441915c7c55085d44b3221eaef0d9800.tar.xz
Refcount all the IFX_ stream classes all the time.
We can remove a lot of "bOwnsStream" logic in the process. Always pass these by const reference, in case the called method wants to hang on to the stream (one exception is where we stick a raw pointer into a void* slot in a context from another layer). Review-Url: https://codereview.chromium.org/2451493002
Diffstat (limited to 'core/fpdfapi/parser/cpdf_parser_unittest.cpp')
-rw-r--r--core/fpdfapi/parser/cpdf_parser_unittest.cpp20
1 files changed, 13 insertions, 7 deletions
diff --git a/core/fpdfapi/parser/cpdf_parser_unittest.cpp b/core/fpdfapi/parser/cpdf_parser_unittest.cpp
index 61496a1562..3518f7d16b 100644
--- a/core/fpdfapi/parser/cpdf_parser_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_parser_unittest.cpp
@@ -7,6 +7,7 @@
#include "core/fpdfapi/parser/cpdf_parser.h"
#include "core/fpdfapi/parser/cpdf_syntax_parser.h"
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_ext.h"
#include "core/fxcrt/fx_stream.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -15,11 +16,12 @@
// Provide a way to read test data from a buffer instead of a file.
class CFX_TestBufferRead : public IFX_SeekableReadStream {
public:
- CFX_TestBufferRead(const unsigned char* buffer_in, size_t buf_size)
- : buffer_(buffer_in), total_size_(buf_size) {}
-
- // IFX_ReadStream:
- void Release() override { delete this; }
+ static CFX_RetainPtr<CFX_TestBufferRead> Create(
+ const unsigned char* buffer_in,
+ size_t buf_size) {
+ return CFX_RetainPtr<CFX_TestBufferRead>(
+ new CFX_TestBufferRead(buffer_in, buf_size));
+ }
// IFX_SeekableReadStream:
bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override {
@@ -33,6 +35,9 @@ class CFX_TestBufferRead : public IFX_SeekableReadStream {
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_;
};
@@ -45,7 +50,7 @@ class CPDF_TestParser : public CPDF_Parser {
// Setup reading from a file and initial states.
bool InitTestFromFile(const FX_CHAR* path) {
- IFX_SeekableReadStream* pFileAccess =
+ CFX_RetainPtr<IFX_SeekableReadStream> pFileAccess =
IFX_SeekableReadStream::CreateFromFilename(path);
if (!pFileAccess)
return false;
@@ -57,7 +62,8 @@ class CPDF_TestParser : public CPDF_Parser {
// Setup reading from a buffer and initial states.
bool InitTestFromBuffer(const unsigned char* buffer, size_t len) {
- CFX_TestBufferRead* buffer_reader = new CFX_TestBufferRead(buffer, len);
+ CFX_RetainPtr<CFX_TestBufferRead> buffer_reader =
+ CFX_TestBufferRead::Create(buffer, len);
// For the test file, the header is set at the beginning.
m_pSyntax->InitParser(buffer_reader, 0);