blob: 1d94b7255332c11d3371b564a4438490da0a472e [file] [log] [blame]
Tom Sepez96d13342015-01-16 14:59:26 -08001// Copyright 2015 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Tom Sepezc8f6ab62015-01-22 11:20:06 -08005#include <limits>
6#include <string>
7
Dan Sinclairf766ad22016-03-14 13:51:24 -04008#include "fpdfsdk/fpdfview_c_api_test.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -08009#include "public/fpdfview.h"
Wei Li091f7a02015-11-09 12:09:55 -080010#include "testing/embedder_test.h"
Tom Sepez96d13342015-01-16 14:59:26 -080011#include "testing/gtest/include/gtest/gtest.h"
12
Tom Sepezcf22eb82015-05-12 17:28:08 -070013TEST(fpdf, CApiTest) {
14 EXPECT_TRUE(CheckPDFiumCApi());
15}
16
Nico Weber9d8ec5a2015-08-04 13:00:21 -070017class FPDFViewEmbeddertest : public EmbedderTest {};
Tom Sepez96d13342015-01-16 14:59:26 -080018
19TEST_F(FPDFViewEmbeddertest, Document) {
Wei Li091f7a02015-11-09 12:09:55 -080020 EXPECT_TRUE(OpenDocument("about_blank.pdf"));
Tom Sepez96d13342015-01-16 14:59:26 -080021 EXPECT_EQ(1, GetPageCount());
22 EXPECT_EQ(0, GetFirstPageNum());
23
24 int version;
25 EXPECT_TRUE(FPDF_GetFileVersion(document(), &version));
26 EXPECT_EQ(14, version);
27
28 EXPECT_EQ(0xFFFFFFFF, FPDF_GetDocPermissions(document()));
29 EXPECT_EQ(-1, FPDF_GetSecurityHandlerRevision(document()));
30}
31
thestigb8db5112016-04-06 12:12:52 -070032// See bug 465.
33TEST_F(FPDFViewEmbeddertest, EmptyDocument) {
34 EXPECT_TRUE(CreateEmptyDocument());
35
36 {
37 int version = 42;
38 EXPECT_FALSE(FPDF_GetFileVersion(document(), &version));
39 EXPECT_EQ(0, version);
40 }
41
42 {
43#ifndef PDF_ENABLE_XFA
44 const unsigned long kExpected = 0;
45#else
46 const unsigned long kExpected = static_cast<uint32_t>(-1);
47#endif
48 EXPECT_EQ(kExpected, FPDF_GetDocPermissions(document()));
49 }
50
51 EXPECT_EQ(-1, FPDF_GetSecurityHandlerRevision(document()));
52
53 EXPECT_EQ(0, FPDF_GetPageCount(document()));
54
55 EXPECT_TRUE(FPDF_VIEWERREF_GetPrintScaling(document()));
56 EXPECT_EQ(1, FPDF_VIEWERREF_GetNumCopies(document()));
57 EXPECT_EQ(DuplexUndefined, FPDF_VIEWERREF_GetDuplex(document()));
58
thestig04bebfe2016-11-04 16:07:25 -070059 char buf[100];
60 EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "foo", nullptr, 0));
61 EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "foo", buf, sizeof(buf)));
62
weili3cc01f22016-05-16 13:53:42 -070063 EXPECT_EQ(0u, FPDF_CountNamedDests(document()));
thestigb8db5112016-04-06 12:12:52 -070064}
65
Tom Sepez96d13342015-01-16 14:59:26 -080066TEST_F(FPDFViewEmbeddertest, Page) {
Wei Li091f7a02015-11-09 12:09:55 -080067 EXPECT_TRUE(OpenDocument("about_blank.pdf"));
Tom Sepezda8189e2015-01-30 14:41:50 -080068 FPDF_PAGE page = LoadPage(0);
Tom Sepez96d13342015-01-16 14:59:26 -080069 EXPECT_NE(nullptr, page);
70 EXPECT_EQ(612.0, FPDF_GetPageWidth(page));
71 EXPECT_EQ(792.0, FPDF_GetPageHeight(page));
Tom Sepezda8189e2015-01-30 14:41:50 -080072 UnloadPage(page);
73 EXPECT_EQ(nullptr, LoadPage(1));
Tom Sepez96d13342015-01-16 14:59:26 -080074}
75
thestig04bebfe2016-11-04 16:07:25 -070076TEST_F(FPDFViewEmbeddertest, ViewerRefDummy) {
Wei Li091f7a02015-11-09 12:09:55 -080077 EXPECT_TRUE(OpenDocument("about_blank.pdf"));
Tom Sepez96d13342015-01-16 14:59:26 -080078 EXPECT_TRUE(FPDF_VIEWERREF_GetPrintScaling(document()));
79 EXPECT_EQ(1, FPDF_VIEWERREF_GetNumCopies(document()));
80 EXPECT_EQ(DuplexUndefined, FPDF_VIEWERREF_GetDuplex(document()));
thestig04bebfe2016-11-04 16:07:25 -070081
82 char buf[100];
83 EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "foo", nullptr, 0));
84 EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "foo", buf, sizeof(buf)));
85}
86
87TEST_F(FPDFViewEmbeddertest, ViewerRef) {
88 EXPECT_TRUE(OpenDocument("viewer_ref.pdf"));
89 EXPECT_TRUE(FPDF_VIEWERREF_GetPrintScaling(document()));
90 EXPECT_EQ(5, FPDF_VIEWERREF_GetNumCopies(document()));
91 EXPECT_EQ(DuplexUndefined, FPDF_VIEWERREF_GetDuplex(document()));
92
93 // Test some corner cases.
94 char buf[100];
95 EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "", buf, sizeof(buf)));
96 EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "foo", nullptr, 0));
97 EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "foo", buf, sizeof(buf)));
98
99 // Make sure |buf| does not get written into when it appears to be too small.
Dan Sinclair85c8e7f2016-11-21 13:50:32 -0500100 // NOLINTNEXTLINE(runtime/printf)
thestig04bebfe2016-11-04 16:07:25 -0700101 strcpy(buf, "ABCD");
102 EXPECT_EQ(4U, FPDF_VIEWERREF_GetName(document(), "Foo", buf, 1));
103 EXPECT_STREQ("ABCD", buf);
104
105 // Note "Foo" is a different key from "foo".
106 EXPECT_EQ(4U,
107 FPDF_VIEWERREF_GetName(document(), "Foo", nullptr, sizeof(buf)));
108 ASSERT_EQ(4U, FPDF_VIEWERREF_GetName(document(), "Foo", buf, sizeof(buf)));
109 EXPECT_STREQ("foo", buf);
110
111 // Try to retrieve a boolean and an integer.
112 EXPECT_EQ(
113 0U, FPDF_VIEWERREF_GetName(document(), "HideToolbar", buf, sizeof(buf)));
114 EXPECT_EQ(0U,
115 FPDF_VIEWERREF_GetName(document(), "NumCopies", buf, sizeof(buf)));
116
117 // Try more valid cases.
118 ASSERT_EQ(4U,
119 FPDF_VIEWERREF_GetName(document(), "Direction", buf, sizeof(buf)));
120 EXPECT_STREQ("R2L", buf);
121 ASSERT_EQ(8U,
122 FPDF_VIEWERREF_GetName(document(), "ViewArea", buf, sizeof(buf)));
123 EXPECT_STREQ("CropBox", buf);
Tom Sepez96d13342015-01-16 14:59:26 -0800124}
125
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800126TEST_F(FPDFViewEmbeddertest, NamedDests) {
Wei Li091f7a02015-11-09 12:09:55 -0800127 EXPECT_TRUE(OpenDocument("named_dests.pdf"));
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800128 long buffer_size;
129 char fixed_buffer[512];
130 FPDF_DEST dest;
131
132 // Query the size of the first item.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133 buffer_size = 2000000; // Absurdly large, check not used for this case.
Tom Sepezcf22eb82015-05-12 17:28:08 -0700134 dest = FPDF_GetNamedDest(document(), 0, nullptr, &buffer_size);
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800135 EXPECT_NE(nullptr, dest);
weili3cc01f22016-05-16 13:53:42 -0700136 EXPECT_EQ(12, buffer_size);
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800137
138 // Try to retrieve the first item with too small a buffer.
Oliver Chang35e68a52015-12-09 12:44:33 -0800139 buffer_size = 10;
Tom Sepezcf22eb82015-05-12 17:28:08 -0700140 dest = FPDF_GetNamedDest(document(), 0, fixed_buffer, &buffer_size);
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800141 EXPECT_NE(nullptr, dest);
142 EXPECT_EQ(-1, buffer_size);
143
144 // Try to retrieve the first item with correctly sized buffer. Item is
145 // taken from Dests NameTree in named_dests.pdf.
146 buffer_size = 12;
Tom Sepezcf22eb82015-05-12 17:28:08 -0700147 dest = FPDF_GetNamedDest(document(), 0, fixed_buffer, &buffer_size);
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800148 EXPECT_NE(nullptr, dest);
weili3cc01f22016-05-16 13:53:42 -0700149 EXPECT_EQ(12, buffer_size);
Oliver Chang35e68a52015-12-09 12:44:33 -0800150 EXPECT_EQ(std::string("F\0i\0r\0s\0t\0\0\0", 12),
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800151 std::string(fixed_buffer, buffer_size));
152
153 // Try to retrieve the second item with ample buffer. Item is taken
154 // from Dests NameTree but has a sub-dictionary in named_dests.pdf.
155 buffer_size = sizeof(fixed_buffer);
Tom Sepezcf22eb82015-05-12 17:28:08 -0700156 dest = FPDF_GetNamedDest(document(), 1, fixed_buffer, &buffer_size);
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800157 EXPECT_NE(nullptr, dest);
weili3cc01f22016-05-16 13:53:42 -0700158 EXPECT_EQ(10, buffer_size);
Oliver Chang35e68a52015-12-09 12:44:33 -0800159 EXPECT_EQ(std::string("N\0e\0x\0t\0\0\0", 10),
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800160 std::string(fixed_buffer, buffer_size));
161
162 // Try to retrieve third item with ample buffer. Item is taken
163 // from Dests NameTree but has a bad sub-dictionary in named_dests.pdf.
164 // in named_dests.pdf).
165 buffer_size = sizeof(fixed_buffer);
Tom Sepezcf22eb82015-05-12 17:28:08 -0700166 dest = FPDF_GetNamedDest(document(), 2, fixed_buffer, &buffer_size);
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800167 EXPECT_EQ(nullptr, dest);
Wei Li05d53f02016-03-29 16:42:53 -0700168 EXPECT_EQ(sizeof(fixed_buffer),
169 static_cast<size_t>(buffer_size)); // unmodified.
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800170
171 // Try to retrieve the forth item with ample buffer. Item is taken
172 // from Dests NameTree but has a vale of the wrong type in named_dests.pdf.
173 buffer_size = sizeof(fixed_buffer);
Tom Sepezcf22eb82015-05-12 17:28:08 -0700174 dest = FPDF_GetNamedDest(document(), 3, fixed_buffer, &buffer_size);
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800175 EXPECT_EQ(nullptr, dest);
Wei Li05d53f02016-03-29 16:42:53 -0700176 EXPECT_EQ(sizeof(fixed_buffer),
177 static_cast<size_t>(buffer_size)); // unmodified.
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800178
179 // Try to retrieve fifth item with ample buffer. Item taken from the
180 // old-style Dests dictionary object in named_dests.pdf.
181 buffer_size = sizeof(fixed_buffer);
Tom Sepezcf22eb82015-05-12 17:28:08 -0700182 dest = FPDF_GetNamedDest(document(), 4, fixed_buffer, &buffer_size);
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800183 EXPECT_NE(nullptr, dest);
weili3cc01f22016-05-16 13:53:42 -0700184 EXPECT_EQ(30, buffer_size);
Oliver Chang35e68a52015-12-09 12:44:33 -0800185 EXPECT_EQ(std::string("F\0i\0r\0s\0t\0A\0l\0t\0e\0r\0n\0a\0t\0e\0\0\0", 30),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700186 std::string(fixed_buffer, buffer_size));
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800187
188 // Try to retrieve sixth item with ample buffer. Item istaken from the
189 // old-style Dests dictionary object but has a sub-dictionary in
190 // named_dests.pdf.
191 buffer_size = sizeof(fixed_buffer);
Tom Sepezcf22eb82015-05-12 17:28:08 -0700192 dest = FPDF_GetNamedDest(document(), 5, fixed_buffer, &buffer_size);
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800193 EXPECT_NE(nullptr, dest);
weili3cc01f22016-05-16 13:53:42 -0700194 EXPECT_EQ(28, buffer_size);
Oliver Chang35e68a52015-12-09 12:44:33 -0800195 EXPECT_EQ(std::string("L\0a\0s\0t\0A\0l\0t\0e\0r\0n\0a\0t\0e\0\0\0", 28),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700196 std::string(fixed_buffer, buffer_size));
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800197
198 // Try to retrieve non-existent item with ample buffer.
199 buffer_size = sizeof(fixed_buffer);
Tom Sepezcf22eb82015-05-12 17:28:08 -0700200 dest = FPDF_GetNamedDest(document(), 6, fixed_buffer, &buffer_size);
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800201 EXPECT_EQ(nullptr, dest);
Wei Li05d53f02016-03-29 16:42:53 -0700202 EXPECT_EQ(sizeof(fixed_buffer),
203 static_cast<size_t>(buffer_size)); // unmodified.
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800204
205 // Try to underflow/overflow the integer index.
206 buffer_size = sizeof(fixed_buffer);
207 dest = FPDF_GetNamedDest(document(), std::numeric_limits<int>::max(),
Tom Sepezcf22eb82015-05-12 17:28:08 -0700208 fixed_buffer, &buffer_size);
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800209 EXPECT_EQ(nullptr, dest);
Wei Li05d53f02016-03-29 16:42:53 -0700210 EXPECT_EQ(sizeof(fixed_buffer),
211 static_cast<size_t>(buffer_size)); // unmodified.
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800212
213 buffer_size = sizeof(fixed_buffer);
214 dest = FPDF_GetNamedDest(document(), std::numeric_limits<int>::min(),
Tom Sepezcf22eb82015-05-12 17:28:08 -0700215 fixed_buffer, &buffer_size);
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800216 EXPECT_EQ(nullptr, dest);
Wei Li05d53f02016-03-29 16:42:53 -0700217 EXPECT_EQ(sizeof(fixed_buffer),
218 static_cast<size_t>(buffer_size)); // unmodified.
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800219
220 buffer_size = sizeof(fixed_buffer);
Tom Sepezcf22eb82015-05-12 17:28:08 -0700221 dest = FPDF_GetNamedDest(document(), -1, fixed_buffer, &buffer_size);
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800222 EXPECT_EQ(nullptr, dest);
Wei Li05d53f02016-03-29 16:42:53 -0700223 EXPECT_EQ(sizeof(fixed_buffer),
224 static_cast<size_t>(buffer_size)); // unmodified.
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800225}
226
227TEST_F(FPDFViewEmbeddertest, NamedDestsByName) {
Wei Li091f7a02015-11-09 12:09:55 -0800228 EXPECT_TRUE(OpenDocument("named_dests.pdf"));
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800229
thestig1cd352e2016-06-07 17:53:06 -0700230 // Null pointer returns nullptr.
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800231 FPDF_DEST dest = FPDF_GetNamedDestByName(document(), nullptr);
232 EXPECT_EQ(nullptr, dest);
233
thestig1cd352e2016-06-07 17:53:06 -0700234 // Empty string returns nullptr.
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800235 dest = FPDF_GetNamedDestByName(document(), "");
236 EXPECT_EQ(nullptr, dest);
237
238 // Item from Dests NameTree.
239 dest = FPDF_GetNamedDestByName(document(), "First");
240 EXPECT_NE(nullptr, dest);
241
242 long ignore_len = 0;
243 FPDF_DEST dest_by_index =
Tom Sepezcf22eb82015-05-12 17:28:08 -0700244 FPDF_GetNamedDest(document(), 0, nullptr, &ignore_len);
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800245 EXPECT_EQ(dest_by_index, dest);
246
247 // Item from Dests dictionary.
248 dest = FPDF_GetNamedDestByName(document(), "FirstAlternate");
249 EXPECT_NE(nullptr, dest);
250
251 ignore_len = 0;
Tom Sepezcf22eb82015-05-12 17:28:08 -0700252 dest_by_index = FPDF_GetNamedDest(document(), 4, nullptr, &ignore_len);
Tom Sepezc8f6ab62015-01-22 11:20:06 -0800253 EXPECT_EQ(dest_by_index, dest);
254
255 // Bad value type for item from Dests NameTree array.
256 dest = FPDF_GetNamedDestByName(document(), "WrongType");
257 EXPECT_EQ(nullptr, dest);
258
259 // No such destination in either Dest NameTree or dictionary.
260 dest = FPDF_GetNamedDestByName(document(), "Bogus");
261 EXPECT_EQ(nullptr, dest);
262}
Tom Sepeze80685c2015-01-26 16:59:09 -0800263
264// The following tests pass if the document opens without crashing.
Tom Sepez4dcf74d2015-02-03 16:24:43 -0800265TEST_F(FPDFViewEmbeddertest, Crasher_113) {
Wei Li091f7a02015-11-09 12:09:55 -0800266 EXPECT_TRUE(OpenDocument("bug_113.pdf"));
Tom Sepez4dcf74d2015-02-03 16:24:43 -0800267}
268
269TEST_F(FPDFViewEmbeddertest, Crasher_451830) {
Dan Sinclair6be2aab2015-10-28 13:58:49 -0400270 // Document is damaged and can't be opened.
Wei Li091f7a02015-11-09 12:09:55 -0800271 EXPECT_FALSE(OpenDocument("bug_451830.pdf"));
Tom Sepeze80685c2015-01-26 16:59:09 -0800272}
Tom Sepez3795a742015-02-02 11:22:42 -0800273
Tom Sepez4dcf74d2015-02-03 16:24:43 -0800274TEST_F(FPDFViewEmbeddertest, Crasher_452455) {
Wei Li091f7a02015-11-09 12:09:55 -0800275 EXPECT_TRUE(OpenDocument("bug_452455.pdf"));
Tom Sepez3795a742015-02-02 11:22:42 -0800276 FPDF_PAGE page = LoadPage(0);
277 EXPECT_NE(nullptr, page);
Lei Zhangd27acae2015-05-15 15:36:02 -0700278 UnloadPage(page);
Tom Sepez3795a742015-02-02 11:22:42 -0800279}
Tom Sepez93daa3c2015-02-05 10:51:54 -0800280
281TEST_F(FPDFViewEmbeddertest, Crasher_454695) {
Lei Zhangab5537d2016-01-06 14:58:14 -0800282 // Document is damaged and can't be opened.
Wei Li091f7a02015-11-09 12:09:55 -0800283 EXPECT_FALSE(OpenDocument("bug_454695.pdf"));
Tom Sepez93daa3c2015-02-05 10:51:54 -0800284}
Lei Zhang5fae9722015-12-09 23:56:51 -0800285
Lei Zhangab5537d2016-01-06 14:58:14 -0800286TEST_F(FPDFViewEmbeddertest, Crasher_572871) {
287 EXPECT_TRUE(OpenDocument("bug_572871.pdf"));
288}
289
Wei Li07fb4cf2016-01-14 15:15:14 -0800290// It tests that document can still be loaded even the trailer has no 'Size'
291// field if other information is right.
292TEST_F(FPDFViewEmbeddertest, Failed_213) {
293 EXPECT_TRUE(OpenDocument("bug_213.pdf"));
294}
295
Lei Zhang5fae9722015-12-09 23:56:51 -0800296// The following tests pass if the document opens without infinite looping.
297TEST_F(FPDFViewEmbeddertest, Hang_298) {
298 EXPECT_FALSE(OpenDocument("bug_298.pdf"));
299}
Wei Lic009e8e2016-01-05 12:51:32 -0800300
301// Test if the document opens without infinite looping.
302// Previously this test will hang in a loop inside LoadAllCrossRefV4. After
303// the fix, LoadAllCrossRefV4 will return false after detecting a cross
304// reference loop. Cross references will be rebuilt successfully.
305TEST_F(FPDFViewEmbeddertest, CrossRefV4Loop) {
306 EXPECT_TRUE(OpenDocument("bug_xrefv4_loop.pdf"));
307}
Wei Li8e3f8932016-01-08 14:36:59 -0800308
309// The test should pass when circular references to ParseIndirectObject will not
310// cause infinite loop.
311TEST_F(FPDFViewEmbeddertest, Hang_343) {
312 EXPECT_FALSE(OpenDocument("bug_343.pdf"));
Wei Lif2b300a2016-01-11 14:16:10 -0800313}
314
315// The test should pass when the absence of 'Contents' field in a signature
316// dictionary will not cause an infinite loop in CPDF_SyntaxParser::GetObject().
317TEST_F(FPDFViewEmbeddertest, Hang_344) {
318 EXPECT_FALSE(OpenDocument("bug_344.pdf"));
Wei Li215816b2016-01-14 12:29:02 -0800319}
320
Wei Li6bc997a2016-01-19 12:35:03 -0800321// The test should pass when there is no infinite recursion in
322// CPDF_SyntaxParser::GetString().
323TEST_F(FPDFViewEmbeddertest, Hang_355) {
324 EXPECT_FALSE(OpenDocument("bug_355.pdf"));
325}
Wei Li215816b2016-01-14 12:29:02 -0800326// The test should pass even when the file has circular references to pages.
327TEST_F(FPDFViewEmbeddertest, Hang_360) {
328 EXPECT_FALSE(OpenDocument("bug_360.pdf"));
Wei Li07fb4cf2016-01-14 15:15:14 -0800329}
thestiga78ba602016-11-23 15:25:48 -0800330
331TEST_F(FPDFViewEmbeddertest, FPDF_RenderPageBitmapWithMatrix) {
332 const char kAllBlackMd5sum[] = "5708fc5c4a8bd0abde99c8e8f0390615";
333 const char kTopLeftQuarterBlackMd5sum[] = "24e4d1ec06fa0258af758cfc8b2ad50a";
334
335 EXPECT_TRUE(OpenDocument("black.pdf"));
336 FPDF_PAGE page = LoadPage(0);
337 EXPECT_NE(nullptr, page);
338 const int width = static_cast<int>(FPDF_GetPageWidth(page));
339 const int height = static_cast<int>(FPDF_GetPageHeight(page));
340 EXPECT_EQ(612, width);
341 EXPECT_EQ(792, height);
342
343 FPDF_BITMAP bitmap = RenderPage(page);
344 CompareBitmap(bitmap, width, height, kAllBlackMd5sum);
345 FPDFBitmap_Destroy(bitmap);
346
347 // Try rendering with an identity matrix. The output should be the same as
348 // the RenderPage() output.
349 FS_MATRIX matrix;
350 matrix.a = 1;
351 matrix.b = 0;
352 matrix.c = 0;
353 matrix.d = 1;
354 matrix.e = 0;
355 matrix.f = 0;
356
357 FS_RECTF rect;
358 rect.left = 0;
359 rect.top = 0;
360 rect.right = width;
361 rect.bottom = height;
362
363 bitmap = FPDFBitmap_Create(width, height, 0);
364 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF);
365 FPDF_RenderPageBitmapWithMatrix(bitmap, page, &matrix, &rect, 0);
366 CompareBitmap(bitmap, width, height, kAllBlackMd5sum);
367 FPDFBitmap_Destroy(bitmap);
368
369 // Now render again with the image scaled.
370 matrix.a = 0.5;
371 matrix.d = 0.5;
372
373 bitmap = FPDFBitmap_Create(width, height, 0);
374 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF);
375 FPDF_RenderPageBitmapWithMatrix(bitmap, page, &matrix, &rect, 0);
376 CompareBitmap(bitmap, width, height, kTopLeftQuarterBlackMd5sum);
377 FPDFBitmap_Destroy(bitmap);
378
379 UnloadPage(page);
380}