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

Side by Side Diff: fpdfsdk/fpdfview_embeddertest.cpp

Issue 1986533002: Fix the code that causes warnings (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 7 months 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 | « core/fxge/win32/fx_win32_gdipext.cpp ('k') | xfa/fgas/localization/fgas_locale.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 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 "fpdfsdk/fpdfview_c_api_test.h" 8 #include "fpdfsdk/fpdfview_c_api_test.h"
9 #include "public/fpdfview.h" 9 #include "public/fpdfview.h"
10 #include "testing/embedder_test.h" 10 #include "testing/embedder_test.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } 49 }
50 50
51 EXPECT_EQ(-1, FPDF_GetSecurityHandlerRevision(document())); 51 EXPECT_EQ(-1, FPDF_GetSecurityHandlerRevision(document()));
52 52
53 EXPECT_EQ(0, FPDF_GetPageCount(document())); 53 EXPECT_EQ(0, FPDF_GetPageCount(document()));
54 54
55 EXPECT_TRUE(FPDF_VIEWERREF_GetPrintScaling(document())); 55 EXPECT_TRUE(FPDF_VIEWERREF_GetPrintScaling(document()));
56 EXPECT_EQ(1, FPDF_VIEWERREF_GetNumCopies(document())); 56 EXPECT_EQ(1, FPDF_VIEWERREF_GetNumCopies(document()));
57 EXPECT_EQ(DuplexUndefined, FPDF_VIEWERREF_GetDuplex(document())); 57 EXPECT_EQ(DuplexUndefined, FPDF_VIEWERREF_GetDuplex(document()));
58 58
59 EXPECT_EQ(0, FPDF_CountNamedDests(document())); 59 EXPECT_EQ(0u, FPDF_CountNamedDests(document()));
60 } 60 }
61 61
62 TEST_F(FPDFViewEmbeddertest, Page) { 62 TEST_F(FPDFViewEmbeddertest, Page) {
63 EXPECT_TRUE(OpenDocument("about_blank.pdf")); 63 EXPECT_TRUE(OpenDocument("about_blank.pdf"));
64 FPDF_PAGE page = LoadPage(0); 64 FPDF_PAGE page = LoadPage(0);
65 EXPECT_NE(nullptr, page); 65 EXPECT_NE(nullptr, page);
66 EXPECT_EQ(612.0, FPDF_GetPageWidth(page)); 66 EXPECT_EQ(612.0, FPDF_GetPageWidth(page));
67 EXPECT_EQ(792.0, FPDF_GetPageHeight(page)); 67 EXPECT_EQ(792.0, FPDF_GetPageHeight(page));
68 UnloadPage(page); 68 UnloadPage(page);
69 EXPECT_EQ(nullptr, LoadPage(1)); 69 EXPECT_EQ(nullptr, LoadPage(1));
70 } 70 }
71 71
72 TEST_F(FPDFViewEmbeddertest, ViewerRef) { 72 TEST_F(FPDFViewEmbeddertest, ViewerRef) {
73 EXPECT_TRUE(OpenDocument("about_blank.pdf")); 73 EXPECT_TRUE(OpenDocument("about_blank.pdf"));
74 EXPECT_TRUE(FPDF_VIEWERREF_GetPrintScaling(document())); 74 EXPECT_TRUE(FPDF_VIEWERREF_GetPrintScaling(document()));
75 EXPECT_EQ(1, FPDF_VIEWERREF_GetNumCopies(document())); 75 EXPECT_EQ(1, FPDF_VIEWERREF_GetNumCopies(document()));
76 EXPECT_EQ(DuplexUndefined, FPDF_VIEWERREF_GetDuplex(document())); 76 EXPECT_EQ(DuplexUndefined, FPDF_VIEWERREF_GetDuplex(document()));
77 } 77 }
78 78
79 TEST_F(FPDFViewEmbeddertest, NamedDests) { 79 TEST_F(FPDFViewEmbeddertest, NamedDests) {
80 EXPECT_TRUE(OpenDocument("named_dests.pdf")); 80 EXPECT_TRUE(OpenDocument("named_dests.pdf"));
81 long buffer_size; 81 long buffer_size;
82 char fixed_buffer[512]; 82 char fixed_buffer[512];
83 FPDF_DEST dest; 83 FPDF_DEST dest;
84 84
85 // Query the size of the first item. 85 // Query the size of the first item.
86 buffer_size = 2000000; // Absurdly large, check not used for this case. 86 buffer_size = 2000000; // Absurdly large, check not used for this case.
87 dest = FPDF_GetNamedDest(document(), 0, nullptr, &buffer_size); 87 dest = FPDF_GetNamedDest(document(), 0, nullptr, &buffer_size);
88 EXPECT_NE(nullptr, dest); 88 EXPECT_NE(nullptr, dest);
89 EXPECT_EQ(12u, buffer_size); 89 EXPECT_EQ(12, buffer_size);
90 90
91 // Try to retrieve the first item with too small a buffer. 91 // Try to retrieve the first item with too small a buffer.
92 buffer_size = 10; 92 buffer_size = 10;
93 dest = FPDF_GetNamedDest(document(), 0, fixed_buffer, &buffer_size); 93 dest = FPDF_GetNamedDest(document(), 0, fixed_buffer, &buffer_size);
94 EXPECT_NE(nullptr, dest); 94 EXPECT_NE(nullptr, dest);
95 EXPECT_EQ(-1, buffer_size); 95 EXPECT_EQ(-1, buffer_size);
96 96
97 // Try to retrieve the first item with correctly sized buffer. Item is 97 // Try to retrieve the first item with correctly sized buffer. Item is
98 // taken from Dests NameTree in named_dests.pdf. 98 // taken from Dests NameTree in named_dests.pdf.
99 buffer_size = 12; 99 buffer_size = 12;
100 dest = FPDF_GetNamedDest(document(), 0, fixed_buffer, &buffer_size); 100 dest = FPDF_GetNamedDest(document(), 0, fixed_buffer, &buffer_size);
101 EXPECT_NE(nullptr, dest); 101 EXPECT_NE(nullptr, dest);
102 EXPECT_EQ(12u, buffer_size); 102 EXPECT_EQ(12, buffer_size);
103 EXPECT_EQ(std::string("F\0i\0r\0s\0t\0\0\0", 12), 103 EXPECT_EQ(std::string("F\0i\0r\0s\0t\0\0\0", 12),
104 std::string(fixed_buffer, buffer_size)); 104 std::string(fixed_buffer, buffer_size));
105 105
106 // Try to retrieve the second item with ample buffer. Item is taken 106 // Try to retrieve the second item with ample buffer. Item is taken
107 // from Dests NameTree but has a sub-dictionary in named_dests.pdf. 107 // from Dests NameTree but has a sub-dictionary in named_dests.pdf.
108 buffer_size = sizeof(fixed_buffer); 108 buffer_size = sizeof(fixed_buffer);
109 dest = FPDF_GetNamedDest(document(), 1, fixed_buffer, &buffer_size); 109 dest = FPDF_GetNamedDest(document(), 1, fixed_buffer, &buffer_size);
110 EXPECT_NE(nullptr, dest); 110 EXPECT_NE(nullptr, dest);
111 EXPECT_EQ(10u, buffer_size); 111 EXPECT_EQ(10, buffer_size);
112 EXPECT_EQ(std::string("N\0e\0x\0t\0\0\0", 10), 112 EXPECT_EQ(std::string("N\0e\0x\0t\0\0\0", 10),
113 std::string(fixed_buffer, buffer_size)); 113 std::string(fixed_buffer, buffer_size));
114 114
115 // Try to retrieve third item with ample buffer. Item is taken 115 // Try to retrieve third item with ample buffer. Item is taken
116 // from Dests NameTree but has a bad sub-dictionary in named_dests.pdf. 116 // from Dests NameTree but has a bad sub-dictionary in named_dests.pdf.
117 // in named_dests.pdf). 117 // in named_dests.pdf).
118 buffer_size = sizeof(fixed_buffer); 118 buffer_size = sizeof(fixed_buffer);
119 dest = FPDF_GetNamedDest(document(), 2, fixed_buffer, &buffer_size); 119 dest = FPDF_GetNamedDest(document(), 2, fixed_buffer, &buffer_size);
120 EXPECT_EQ(nullptr, dest); 120 EXPECT_EQ(nullptr, dest);
121 EXPECT_EQ(sizeof(fixed_buffer), 121 EXPECT_EQ(sizeof(fixed_buffer),
122 static_cast<size_t>(buffer_size)); // unmodified. 122 static_cast<size_t>(buffer_size)); // unmodified.
123 123
124 // Try to retrieve the forth item with ample buffer. Item is taken 124 // Try to retrieve the forth item with ample buffer. Item is taken
125 // from Dests NameTree but has a vale of the wrong type in named_dests.pdf. 125 // from Dests NameTree but has a vale of the wrong type in named_dests.pdf.
126 buffer_size = sizeof(fixed_buffer); 126 buffer_size = sizeof(fixed_buffer);
127 dest = FPDF_GetNamedDest(document(), 3, fixed_buffer, &buffer_size); 127 dest = FPDF_GetNamedDest(document(), 3, fixed_buffer, &buffer_size);
128 EXPECT_EQ(nullptr, dest); 128 EXPECT_EQ(nullptr, dest);
129 EXPECT_EQ(sizeof(fixed_buffer), 129 EXPECT_EQ(sizeof(fixed_buffer),
130 static_cast<size_t>(buffer_size)); // unmodified. 130 static_cast<size_t>(buffer_size)); // unmodified.
131 131
132 // Try to retrieve fifth item with ample buffer. Item taken from the 132 // Try to retrieve fifth item with ample buffer. Item taken from the
133 // old-style Dests dictionary object in named_dests.pdf. 133 // old-style Dests dictionary object in named_dests.pdf.
134 buffer_size = sizeof(fixed_buffer); 134 buffer_size = sizeof(fixed_buffer);
135 dest = FPDF_GetNamedDest(document(), 4, fixed_buffer, &buffer_size); 135 dest = FPDF_GetNamedDest(document(), 4, fixed_buffer, &buffer_size);
136 EXPECT_NE(nullptr, dest); 136 EXPECT_NE(nullptr, dest);
137 EXPECT_EQ(30u, buffer_size); 137 EXPECT_EQ(30, buffer_size);
138 EXPECT_EQ(std::string("F\0i\0r\0s\0t\0A\0l\0t\0e\0r\0n\0a\0t\0e\0\0\0", 30), 138 EXPECT_EQ(std::string("F\0i\0r\0s\0t\0A\0l\0t\0e\0r\0n\0a\0t\0e\0\0\0", 30),
139 std::string(fixed_buffer, buffer_size)); 139 std::string(fixed_buffer, buffer_size));
140 140
141 // Try to retrieve sixth item with ample buffer. Item istaken from the 141 // Try to retrieve sixth item with ample buffer. Item istaken from the
142 // old-style Dests dictionary object but has a sub-dictionary in 142 // old-style Dests dictionary object but has a sub-dictionary in
143 // named_dests.pdf. 143 // named_dests.pdf.
144 buffer_size = sizeof(fixed_buffer); 144 buffer_size = sizeof(fixed_buffer);
145 dest = FPDF_GetNamedDest(document(), 5, fixed_buffer, &buffer_size); 145 dest = FPDF_GetNamedDest(document(), 5, fixed_buffer, &buffer_size);
146 EXPECT_NE(nullptr, dest); 146 EXPECT_NE(nullptr, dest);
147 EXPECT_EQ(28u, buffer_size); 147 EXPECT_EQ(28, buffer_size);
148 EXPECT_EQ(std::string("L\0a\0s\0t\0A\0l\0t\0e\0r\0n\0a\0t\0e\0\0\0", 28), 148 EXPECT_EQ(std::string("L\0a\0s\0t\0A\0l\0t\0e\0r\0n\0a\0t\0e\0\0\0", 28),
149 std::string(fixed_buffer, buffer_size)); 149 std::string(fixed_buffer, buffer_size));
150 150
151 // Try to retrieve non-existent item with ample buffer. 151 // Try to retrieve non-existent item with ample buffer.
152 buffer_size = sizeof(fixed_buffer); 152 buffer_size = sizeof(fixed_buffer);
153 dest = FPDF_GetNamedDest(document(), 6, fixed_buffer, &buffer_size); 153 dest = FPDF_GetNamedDest(document(), 6, fixed_buffer, &buffer_size);
154 EXPECT_EQ(nullptr, dest); 154 EXPECT_EQ(nullptr, dest);
155 EXPECT_EQ(sizeof(fixed_buffer), 155 EXPECT_EQ(sizeof(fixed_buffer),
156 static_cast<size_t>(buffer_size)); // unmodified. 156 static_cast<size_t>(buffer_size)); // unmodified.
157 157
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 273
274 // The test should pass when there is no infinite recursion in 274 // The test should pass when there is no infinite recursion in
275 // CPDF_SyntaxParser::GetString(). 275 // CPDF_SyntaxParser::GetString().
276 TEST_F(FPDFViewEmbeddertest, Hang_355) { 276 TEST_F(FPDFViewEmbeddertest, Hang_355) {
277 EXPECT_FALSE(OpenDocument("bug_355.pdf")); 277 EXPECT_FALSE(OpenDocument("bug_355.pdf"));
278 } 278 }
279 // The test should pass even when the file has circular references to pages. 279 // The test should pass even when the file has circular references to pages.
280 TEST_F(FPDFViewEmbeddertest, Hang_360) { 280 TEST_F(FPDFViewEmbeddertest, Hang_360) {
281 EXPECT_FALSE(OpenDocument("bug_360.pdf")); 281 EXPECT_FALSE(OpenDocument("bug_360.pdf"));
282 } 282 }
OLDNEW
« no previous file with comments | « core/fxge/win32/fx_win32_gdipext.cpp ('k') | xfa/fgas/localization/fgas_locale.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698