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

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

Issue 2451493002: Refcount all the IFX_ stream classes all the time. (Closed)
Patch Set: Clean up cast expression 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 = std::unique_ptr<IFX_SeekableReadStream,
17 ReleaseDeleter<IFX_SeekableReadStream>>;
18
19 TEST(CXFAFileRead, NoStreams) { 16 TEST(CXFAFileRead, NoStreams) {
20 std::vector<CPDF_Stream*> streams; 17 std::vector<CPDF_Stream*> streams;
21 UniqueFileRead fileread(MakeSeekableReadStream(streams)); 18 CFX_RetainPtr<IFX_SeekableReadStream> fileread =
19 MakeSeekableReadStream(streams);
22 20
23 uint8_t output_buffer[16]; 21 uint8_t output_buffer[16];
24 memset(output_buffer, 0xbd, sizeof(output_buffer)); 22 memset(output_buffer, 0xbd, sizeof(output_buffer));
25 EXPECT_FALSE(fileread->ReadBlock(output_buffer, 0, 0)); 23 EXPECT_FALSE(fileread->ReadBlock(output_buffer, 0, 0));
26 EXPECT_EQ(0xbd, output_buffer[0]); 24 EXPECT_EQ(0xbd, output_buffer[0]);
27 } 25 }
28 26
29 TEST(CXFAFileRead, EmptyStreams) { 27 TEST(CXFAFileRead, EmptyStreams) {
30 std::vector<CPDF_Stream*> streams; 28 std::vector<CPDF_Stream*> streams;
31 std::unique_ptr<CPDF_Stream> stream1 = pdfium::MakeUnique<CPDF_Stream>(); 29 auto stream1 = pdfium::MakeUnique<CPDF_Stream>();
32 streams.push_back(stream1.get()); 30 streams.push_back(stream1.get());
33 UniqueFileRead fileread(MakeSeekableReadStream(streams)); 31 CFX_RetainPtr<IFX_SeekableReadStream> fileread =
32 MakeSeekableReadStream(streams);
34 33
35 uint8_t output_buffer[16]; 34 uint8_t output_buffer[16];
36 memset(output_buffer, 0xbd, sizeof(output_buffer)); 35 memset(output_buffer, 0xbd, sizeof(output_buffer));
37 EXPECT_FALSE(fileread->ReadBlock(output_buffer, 0, 0)); 36 EXPECT_FALSE(fileread->ReadBlock(output_buffer, 0, 0));
38 EXPECT_EQ(0xbd, output_buffer[0]); 37 EXPECT_EQ(0xbd, output_buffer[0]);
39 } 38 }
40 39
41 TEST(CXFAFileRead, NormalStreams) { 40 TEST(CXFAFileRead, NormalStreams) {
42 std::vector<CPDF_Stream*> streams; 41 std::vector<CPDF_Stream*> streams;
43 std::unique_ptr<CPDF_Stream> stream1 = pdfium::MakeUnique<CPDF_Stream>(); 42 auto stream1 = pdfium::MakeUnique<CPDF_Stream>();
44 std::unique_ptr<CPDF_Stream> stream2 = pdfium::MakeUnique<CPDF_Stream>(); 43 auto stream2 = pdfium::MakeUnique<CPDF_Stream>();
45 std::unique_ptr<CPDF_Stream> stream3 = pdfium::MakeUnique<CPDF_Stream>(); 44 auto stream3 = pdfium::MakeUnique<CPDF_Stream>();
46 45
47 // 16 chars total. 46 // 16 chars total.
48 stream1->InitStream(reinterpret_cast<const uint8_t*>("one t"), 5, 47 stream1->InitStream(reinterpret_cast<const uint8_t*>("one t"), 5,
49 pdfium::MakeUnique<CPDF_Dictionary>()); 48 pdfium::MakeUnique<CPDF_Dictionary>());
50 stream2->InitStream(reinterpret_cast<const uint8_t*>("wo "), 3, 49 stream2->InitStream(reinterpret_cast<const uint8_t*>("wo "), 3,
51 pdfium::MakeUnique<CPDF_Dictionary>()); 50 pdfium::MakeUnique<CPDF_Dictionary>());
52 stream3->InitStream(reinterpret_cast<const uint8_t*>("three!!!"), 8, 51 stream3->InitStream(reinterpret_cast<const uint8_t*>("three!!!"), 8,
53 pdfium::MakeUnique<CPDF_Dictionary>()); 52 pdfium::MakeUnique<CPDF_Dictionary>());
54 53
55 streams.push_back(stream1.get()); 54 streams.push_back(stream1.get());
56 streams.push_back(stream2.get()); 55 streams.push_back(stream2.get());
57 streams.push_back(stream3.get()); 56 streams.push_back(stream3.get());
58 UniqueFileRead fileread(MakeSeekableReadStream(streams)); 57 CFX_RetainPtr<IFX_SeekableReadStream> fileread =
58 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