OLD | NEW |
---|---|
1 // Copyright 2015 PDFium Authors. All rights reserved. | 1 // Copyright 2015 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <limits> | 5 #include <limits> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h" | 8 #include "core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h" |
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" |
10 #include "core/fxcrt/include/fx_ext.h" | 10 #include "core/fxcrt/include/fx_ext.h" |
11 #include "core/fxcrt/include/fx_stream.h" | 11 #include "core/fxcrt/include/fx_stream.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "testing/utils/path_service.h" | 13 #include "testing/utils/path_service.h" |
14 | 14 |
15 // Provide a way to read test data from a buffer instead of a file. | 15 // Provide a way to read test data from a buffer instead of a file. |
16 class CFX_TestBufferRead : public IFX_FileRead { | 16 class CFX_TestBufferRead : public IFX_FileRead { |
17 public: | 17 public: |
18 CFX_TestBufferRead(const unsigned char* buffer_in, size_t buf_size) | 18 CFX_TestBufferRead(const unsigned char* buffer_in, size_t buf_size) |
19 : buffer_(buffer_in), total_size_(buf_size) {} | 19 : buffer_(buffer_in), total_size_(buf_size), m_nCurPos(0) {} |
20 | 20 |
21 // IFX_Stream | 21 // IFX_Stream |
22 void Release() override { delete this; } | 22 void Release() override { delete this; } |
23 | 23 |
24 // IFX_FileRead | 24 // IFX_FileRead |
25 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { | 25 FX_BOOL IsEOF() override { return m_nCurPos >= total_size_; } |
Tom Sepez
2016/10/19 23:12:47
nit: can we make this just a |bool|, we've been tr
Tom Sepez
2016/10/19 23:12:48
We may get a signed vs unsigned comparison error o
| |
26 | |
27 size_t ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { | |
26 if (offset < 0 || offset + size > total_size_) { | 28 if (offset < 0 || offset + size > total_size_) { |
27 return FALSE; | 29 return 0; |
28 } | 30 } |
29 | |
30 memcpy(buffer, buffer_ + offset, size); | 31 memcpy(buffer, buffer_ + offset, size); |
31 return TRUE; | 32 m_nCurPos = offset + size; |
33 return size; | |
32 } | 34 } |
33 FX_FILESIZE GetSize() override { return (FX_FILESIZE)total_size_; }; | 35 FX_FILESIZE GetSize() override { return (FX_FILESIZE)total_size_; }; |
34 | 36 |
35 protected: | 37 protected: |
36 const unsigned char* buffer_; | 38 const unsigned char* buffer_; |
37 size_t total_size_; | 39 size_t total_size_; |
Tom Sepez
2016/10/19 23:12:47
|total_size_| probably needs to be a FX_FILESIZE a
| |
40 FX_FILESIZE m_nCurPos; | |
Tom Sepez
2016/10/19 23:12:47
nit: use pre-existing convention, eg. current_pos_
| |
38 }; | 41 }; |
39 | 42 |
40 // A wrapper class to help test member functions of CPDF_Parser. | 43 // A wrapper class to help test member functions of CPDF_Parser. |
41 class CPDF_TestParser : public CPDF_Parser { | 44 class CPDF_TestParser : public CPDF_Parser { |
42 public: | 45 public: |
43 CPDF_TestParser() {} | 46 CPDF_TestParser() {} |
44 ~CPDF_TestParser() {} | 47 ~CPDF_TestParser() {} |
45 | 48 |
46 // Setup reading from a file and initial states. | 49 // Setup reading from a file and initial states. |
47 bool InitTestFromFile(const FX_CHAR* path) { | 50 bool InitTestFromFile(const FX_CHAR* path) { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 | 196 |
194 ASSERT_TRUE(parser.LoadCrossRefV4(0, 0, FALSE)); | 197 ASSERT_TRUE(parser.LoadCrossRefV4(0, 0, FALSE)); |
195 const FX_FILESIZE offsets[] = {0, 23, 0, 0, 0, 45, 179}; | 198 const FX_FILESIZE offsets[] = {0, 23, 0, 0, 0, 45, 179}; |
196 const uint8_t types[] = {0, 1, 0, 0, 0, 1, 1}; | 199 const uint8_t types[] = {0, 1, 0, 0, 0, 1, 1}; |
197 for (size_t i = 0; i < FX_ArraySize(offsets); ++i) { | 200 for (size_t i = 0; i < FX_ArraySize(offsets); ++i) { |
198 EXPECT_EQ(offsets[i], parser.m_ObjectInfo[i].pos); | 201 EXPECT_EQ(offsets[i], parser.m_ObjectInfo[i].pos); |
199 EXPECT_EQ(types[i], parser.m_ObjectInfo[i].type); | 202 EXPECT_EQ(types[i], parser.m_ObjectInfo[i].type); |
200 } | 203 } |
201 } | 204 } |
202 } | 205 } |
OLD | NEW |