Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: xfa/fxfa/app/xfa_ffapp_unittest.cpp

Issue 2545953002: Make concrete stream classes private to .cpp, part 3 (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fxfa/app/xfa_ffapp.cpp ('k') | xfa/fxfa/app/xfa_ffdoc.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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 "xfa/fxfa/xfa_ffapp.h" 5 #include "xfa/fxfa/xfa_ffapp.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "core/fpdfapi/parser/cpdf_dictionary.h" 10 #include "core/fpdfapi/parser/cpdf_dictionary.h"
11 #include "core/fpdfapi/parser/cpdf_stream.h" 11 #include "core/fpdfapi/parser/cpdf_stream.h"
12 #include "core/fxcrt/fx_memory.h" 12 #include "core/fxcrt/fx_memory.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/base/ptr_util.h" 14 #include "third_party/base/ptr_util.h"
15 15
16 using UniqueFileRead = 16 using UniqueFileRead = std::unique_ptr<IFX_SeekableReadStream,
17 std::unique_ptr<CXFA_FileRead, ReleaseDeleter<CXFA_FileRead>>; 17 ReleaseDeleter<IFX_SeekableReadStream>>;
18 18
19 TEST(CXFAFileRead, NoStreams) { 19 TEST(CXFAFileRead, NoStreams) {
20 std::vector<CPDF_Stream*> streams; 20 std::vector<CPDF_Stream*> streams;
21 UniqueFileRead fileread(new CXFA_FileRead(streams)); 21 UniqueFileRead fileread(MakeSeekableReadStream(streams));
22 22
23 uint8_t output_buffer[16]; 23 uint8_t output_buffer[16];
24 memset(output_buffer, 0xbd, sizeof(output_buffer)); 24 memset(output_buffer, 0xbd, sizeof(output_buffer));
25 EXPECT_FALSE(fileread->ReadBlock(output_buffer, 0, 0)); 25 EXPECT_FALSE(fileread->ReadBlock(output_buffer, 0, 0));
26 EXPECT_EQ(0xbd, output_buffer[0]); 26 EXPECT_EQ(0xbd, output_buffer[0]);
27 } 27 }
28 28
29 TEST(CXFAFileRead, EmptyStreams) { 29 TEST(CXFAFileRead, EmptyStreams) {
30 std::vector<CPDF_Stream*> streams; 30 std::vector<CPDF_Stream*> streams;
31 std::unique_ptr<CPDF_Stream> stream1 = pdfium::MakeUnique<CPDF_Stream>(); 31 std::unique_ptr<CPDF_Stream> stream1 = pdfium::MakeUnique<CPDF_Stream>();
32 streams.push_back(stream1.get()); 32 streams.push_back(stream1.get());
33 UniqueFileRead fileread(new CXFA_FileRead(streams)); 33 UniqueFileRead fileread(MakeSeekableReadStream(streams));
34 34
35 uint8_t output_buffer[16]; 35 uint8_t output_buffer[16];
36 memset(output_buffer, 0xbd, sizeof(output_buffer)); 36 memset(output_buffer, 0xbd, sizeof(output_buffer));
37 EXPECT_FALSE(fileread->ReadBlock(output_buffer, 0, 0)); 37 EXPECT_FALSE(fileread->ReadBlock(output_buffer, 0, 0));
38 EXPECT_EQ(0xbd, output_buffer[0]); 38 EXPECT_EQ(0xbd, output_buffer[0]);
39 } 39 }
40 40
41 TEST(CXFAFileRead, NormalStreams) { 41 TEST(CXFAFileRead, NormalStreams) {
42 std::vector<CPDF_Stream*> streams; 42 std::vector<CPDF_Stream*> streams;
43 std::unique_ptr<CPDF_Stream> stream1 = pdfium::MakeUnique<CPDF_Stream>(); 43 std::unique_ptr<CPDF_Stream> stream1 = pdfium::MakeUnique<CPDF_Stream>();
44 std::unique_ptr<CPDF_Stream> stream2 = pdfium::MakeUnique<CPDF_Stream>(); 44 std::unique_ptr<CPDF_Stream> stream2 = pdfium::MakeUnique<CPDF_Stream>();
45 std::unique_ptr<CPDF_Stream> stream3 = pdfium::MakeUnique<CPDF_Stream>(); 45 std::unique_ptr<CPDF_Stream> stream3 = pdfium::MakeUnique<CPDF_Stream>();
46 46
47 // 16 chars total. 47 // 16 chars total.
48 stream1->InitStream(reinterpret_cast<const uint8_t*>("one t"), 5, 48 stream1->InitStream(reinterpret_cast<const uint8_t*>("one t"), 5,
49 pdfium::MakeUnique<CPDF_Dictionary>()); 49 pdfium::MakeUnique<CPDF_Dictionary>());
50 stream2->InitStream(reinterpret_cast<const uint8_t*>("wo "), 3, 50 stream2->InitStream(reinterpret_cast<const uint8_t*>("wo "), 3,
51 pdfium::MakeUnique<CPDF_Dictionary>()); 51 pdfium::MakeUnique<CPDF_Dictionary>());
52 stream3->InitStream(reinterpret_cast<const uint8_t*>("three!!!"), 8, 52 stream3->InitStream(reinterpret_cast<const uint8_t*>("three!!!"), 8,
53 pdfium::MakeUnique<CPDF_Dictionary>()); 53 pdfium::MakeUnique<CPDF_Dictionary>());
54 54
55 streams.push_back(stream1.get()); 55 streams.push_back(stream1.get());
56 streams.push_back(stream2.get()); 56 streams.push_back(stream2.get());
57 streams.push_back(stream3.get()); 57 streams.push_back(stream3.get());
58 UniqueFileRead fileread(new CXFA_FileRead(streams)); 58 UniqueFileRead fileread(MakeSeekableReadStream(streams));
59 59
60 uint8_t output_buffer[16]; 60 uint8_t output_buffer[16];
61 memset(output_buffer, 0xbd, sizeof(output_buffer)); 61 memset(output_buffer, 0xbd, sizeof(output_buffer));
62 EXPECT_TRUE(fileread->ReadBlock(output_buffer, 0, 0)); 62 EXPECT_TRUE(fileread->ReadBlock(output_buffer, 0, 0));
63 EXPECT_EQ(0xbd, output_buffer[0]); 63 EXPECT_EQ(0xbd, output_buffer[0]);
64 64
65 memset(output_buffer, 0xbd, sizeof(output_buffer)); 65 memset(output_buffer, 0xbd, sizeof(output_buffer));
66 EXPECT_TRUE(fileread->ReadBlock(output_buffer, 1, 0)); 66 EXPECT_TRUE(fileread->ReadBlock(output_buffer, 1, 0));
67 EXPECT_EQ(0xbd, output_buffer[0]); 67 EXPECT_EQ(0xbd, output_buffer[0]);
68 68
69 memset(output_buffer, 0xbd, sizeof(output_buffer)); 69 memset(output_buffer, 0xbd, sizeof(output_buffer));
70 EXPECT_TRUE(fileread->ReadBlock(output_buffer, 0, 1)); 70 EXPECT_TRUE(fileread->ReadBlock(output_buffer, 0, 1));
71 EXPECT_EQ(0, memcmp(output_buffer, "o", 1)); 71 EXPECT_EQ(0, memcmp(output_buffer, "o", 1));
72 EXPECT_EQ(0xbd, output_buffer[1]); 72 EXPECT_EQ(0xbd, output_buffer[1]);
73 73
74 memset(output_buffer, 0xbd, sizeof(output_buffer)); 74 memset(output_buffer, 0xbd, sizeof(output_buffer));
75 EXPECT_TRUE(fileread->ReadBlock(output_buffer, 0, sizeof(output_buffer))); 75 EXPECT_TRUE(fileread->ReadBlock(output_buffer, 0, sizeof(output_buffer)));
76 EXPECT_EQ(0, memcmp(output_buffer, "one two three!!!", 16)); 76 EXPECT_EQ(0, memcmp(output_buffer, "one two three!!!", 16));
77 77
78 memset(output_buffer, 0xbd, sizeof(output_buffer)); 78 memset(output_buffer, 0xbd, sizeof(output_buffer));
79 EXPECT_TRUE(fileread->ReadBlock(output_buffer, 2, 10)); 79 EXPECT_TRUE(fileread->ReadBlock(output_buffer, 2, 10));
80 EXPECT_EQ(0, memcmp(output_buffer, "e two thre", 10)); 80 EXPECT_EQ(0, memcmp(output_buffer, "e two thre", 10));
81 EXPECT_EQ(0xbd, output_buffer[11]); 81 EXPECT_EQ(0xbd, output_buffer[11]);
82 82
83 memset(output_buffer, 0xbd, sizeof(output_buffer)); 83 memset(output_buffer, 0xbd, sizeof(output_buffer));
84 EXPECT_FALSE(fileread->ReadBlock(output_buffer, 1, sizeof(output_buffer))); 84 EXPECT_FALSE(fileread->ReadBlock(output_buffer, 1, sizeof(output_buffer)));
85 EXPECT_EQ(0, memcmp(output_buffer, "ne two three!!!", 15)); 85 EXPECT_EQ(0, memcmp(output_buffer, "ne two three!!!", 15));
86 EXPECT_EQ(0xbd, output_buffer[15]); 86 EXPECT_EQ(0xbd, output_buffer[15]);
87 } 87 }
OLDNEW
« no previous file with comments | « xfa/fxfa/app/xfa_ffapp.cpp ('k') | xfa/fxfa/app/xfa_ffdoc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698