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 "../../testing/embedder_test.h" | 5 #include "../../testing/embedder_test.h" |
6 #include "../../fpdfsdk/include/fpdfview.h" | 6 #include "../../fpdfsdk/include/fpdfview.h" |
7 #include "../../fpdfsdk/include/fpdftext.h" | 7 #include "../../fpdfsdk/include/fpdftext.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 12 matching lines...) Expand all Loading... |
23 return true; | 23 return true; |
24 } | 24 } |
25 | 25 |
26 } // namespace | 26 } // namespace |
27 | 27 |
28 class FPDFTextEmbeddertest : public EmbedderTest { | 28 class FPDFTextEmbeddertest : public EmbedderTest { |
29 }; | 29 }; |
30 | 30 |
31 TEST_F(FPDFTextEmbeddertest, Text) { | 31 TEST_F(FPDFTextEmbeddertest, Text) { |
32 EXPECT_TRUE(OpenDocument("testing/resources/hello_world.pdf")); | 32 EXPECT_TRUE(OpenDocument("testing/resources/hello_world.pdf")); |
33 FPDF_FORMHANDLE form_handle = SetFormFillEnvironment(); | 33 FPDF_PAGE page = LoadPage(0); |
34 FPDF_PAGE page = LoadPage(0, form_handle); | |
35 EXPECT_NE(nullptr, page); | 34 EXPECT_NE(nullptr, page); |
36 | 35 |
37 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); | 36 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); |
38 EXPECT_NE(nullptr, textpage); | 37 EXPECT_NE(nullptr, textpage); |
39 | 38 |
40 const char expected[] = "Hello, world!\r\nGoodbye, world!"; | 39 const char expected[] = "Hello, world!\r\nGoodbye, world!"; |
41 unsigned short fixed_buffer[128]; | 40 unsigned short fixed_buffer[128]; |
42 memset(fixed_buffer, 0xbd, sizeof(fixed_buffer)); | 41 memset(fixed_buffer, 0xbd, sizeof(fixed_buffer)); |
43 | 42 |
44 // Check includes the terminating NUL that is provided. | 43 // Check includes the terminating NUL that is provided. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 EXPECT_EQ(0xbdbd, fixed_buffer[9]); | 127 EXPECT_EQ(0xbdbd, fixed_buffer[9]); |
129 | 128 |
130 memset(fixed_buffer, 0xbd, sizeof(fixed_buffer)); | 129 memset(fixed_buffer, 0xbd, sizeof(fixed_buffer)); |
131 EXPECT_EQ(10, FPDFText_GetBoundedText( | 130 EXPECT_EQ(10, FPDFText_GetBoundedText( |
132 textpage, 41.0, 56.0, 82.0, 48.0, fixed_buffer, 128)); | 131 textpage, 41.0, 56.0, 82.0, 48.0, fixed_buffer, 128)); |
133 EXPECT_TRUE(check_unsigned_shorts(expected + 4, fixed_buffer, 9)); | 132 EXPECT_TRUE(check_unsigned_shorts(expected + 4, fixed_buffer, 9)); |
134 EXPECT_EQ(0u, fixed_buffer[9]); | 133 EXPECT_EQ(0u, fixed_buffer[9]); |
135 EXPECT_EQ(0xbdbd, fixed_buffer[10]); | 134 EXPECT_EQ(0xbdbd, fixed_buffer[10]); |
136 | 135 |
137 FPDFText_ClosePage(textpage); | 136 FPDFText_ClosePage(textpage); |
138 ClearFormFillEnvironment(form_handle); | |
139 } | 137 } |
140 | 138 |
141 TEST_F(FPDFTextEmbeddertest, TextSearch) { | 139 TEST_F(FPDFTextEmbeddertest, TextSearch) { |
142 EXPECT_TRUE(OpenDocument("testing/resources/hello_world.pdf")); | 140 EXPECT_TRUE(OpenDocument("testing/resources/hello_world.pdf")); |
143 FPDF_FORMHANDLE form_handle = SetFormFillEnvironment(); | 141 FPDF_PAGE page = LoadPage(0); |
144 FPDF_PAGE page = LoadPage(0, form_handle); | |
145 EXPECT_NE(nullptr, page); | 142 EXPECT_NE(nullptr, page); |
146 | 143 |
147 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); | 144 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); |
148 EXPECT_NE(nullptr, textpage); | 145 EXPECT_NE(nullptr, textpage); |
149 | 146 |
150 // Avoid issues with system wchar_t width vs. FPDF_WideString. | 147 // Avoid issues with system wchar_t width vs. FPDF_WideString. |
151 const unsigned short nope[] = { 'n', 'o', 'p', 'e', '\0' }; | 148 const unsigned short nope[] = { 'n', 'o', 'p', 'e', '\0' }; |
152 const unsigned short world[] = { 'w', 'o', 'r', 'l', 'd', '\0' }; | 149 const unsigned short world[] = { 'w', 'o', 'r', 'l', 'd', '\0' }; |
153 const unsigned short world_caps[] = { 'W', 'O', 'R', 'L', 'D', '\0' }; | 150 const unsigned short world_caps[] = { 'W', 'O', 'R', 'L', 'D', '\0' }; |
154 const unsigned short world_substr[] = { 'o', 'r', 'l', 'd', '\0' }; | 151 const unsigned short world_substr[] = { 'o', 'r', 'l', 'd', '\0' }; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 EXPECT_EQ(4, FPDFText_GetSchCount(search)); | 232 EXPECT_EQ(4, FPDFText_GetSchCount(search)); |
236 FPDFText_FindClose(search); | 233 FPDFText_FindClose(search); |
237 | 234 |
238 // But can be made to mach word boundaries, in which case this fails. | 235 // But can be made to mach word boundaries, in which case this fails. |
239 search = FPDFText_FindStart(textpage, world_substr, FPDF_MATCHWHOLEWORD, 0); | 236 search = FPDFText_FindStart(textpage, world_substr, FPDF_MATCHWHOLEWORD, 0); |
240 EXPECT_FALSE(FPDFText_FindNext(search)); | 237 EXPECT_FALSE(FPDFText_FindNext(search)); |
241 // TODO(tsepez): investigate strange index/count values in this state. | 238 // TODO(tsepez): investigate strange index/count values in this state. |
242 FPDFText_FindClose(search); | 239 FPDFText_FindClose(search); |
243 | 240 |
244 FPDFText_ClosePage(textpage); | 241 FPDFText_ClosePage(textpage); |
245 ClearFormFillEnvironment(form_handle); | |
246 } | 242 } |
247 | 243 |
248 // Test that the page has characters despite a bad stream length. | 244 // Test that the page has characters despite a bad stream length. |
249 TEST_F(FPDFTextEmbeddertest, StreamLengthPastEndOfFile) { | 245 TEST_F(FPDFTextEmbeddertest, StreamLengthPastEndOfFile) { |
250 EXPECT_TRUE(OpenDocument("testing/resources/bug_57.pdf")); | 246 EXPECT_TRUE(OpenDocument("testing/resources/bug_57.pdf")); |
251 FPDF_FORMHANDLE form_handle = SetFormFillEnvironment(); | 247 FPDF_PAGE page = LoadPage(0); |
252 FPDF_PAGE page = LoadPage(0, form_handle); | |
253 EXPECT_NE(nullptr, page); | 248 EXPECT_NE(nullptr, page); |
254 | 249 |
255 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); | 250 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); |
256 EXPECT_NE(nullptr, textpage); | 251 EXPECT_NE(nullptr, textpage); |
257 EXPECT_EQ(13, FPDFText_CountChars(textpage)); | 252 EXPECT_EQ(13, FPDFText_CountChars(textpage)); |
258 | 253 |
259 FPDFText_ClosePage(textpage); | 254 FPDFText_ClosePage(textpage); |
260 ClearFormFillEnvironment(form_handle); | |
261 } | 255 } |
262 | 256 |
263 TEST_F(FPDFTextEmbeddertest, WebLinks) { | 257 TEST_F(FPDFTextEmbeddertest, WebLinks) { |
264 EXPECT_TRUE(OpenDocument("testing/resources/weblinks.pdf")); | 258 EXPECT_TRUE(OpenDocument("testing/resources/weblinks.pdf")); |
265 FPDF_FORMHANDLE form_handle = SetFormFillEnvironment(); | 259 FPDF_PAGE page = LoadPage(0); |
266 FPDF_PAGE page = LoadPage(0, form_handle); | |
267 EXPECT_NE(nullptr, page); | 260 EXPECT_NE(nullptr, page); |
268 | 261 |
269 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); | 262 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); |
270 EXPECT_NE(nullptr, textpage); | 263 EXPECT_NE(nullptr, textpage); |
271 | 264 |
272 FPDF_PAGELINK pagelink = FPDFLink_LoadWebLinks(textpage); | 265 FPDF_PAGELINK pagelink = FPDFLink_LoadWebLinks(textpage); |
273 EXPECT_NE(nullptr, pagelink); | 266 EXPECT_NE(nullptr, pagelink); |
274 | 267 |
275 // Page contains two HTTP-style URLs. | 268 // Page contains two HTTP-style URLs. |
276 EXPECT_EQ(2, FPDFLink_CountWebLinks(pagelink)); | 269 EXPECT_EQ(2, FPDFLink_CountWebLinks(pagelink)); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 top = -2.0; | 351 top = -2.0; |
359 bottom = -2.0; | 352 bottom = -2.0; |
360 FPDFLink_GetRect(pagelink, -1, 0, &left, &top, &right, &bottom); | 353 FPDFLink_GetRect(pagelink, -1, 0, &left, &top, &right, &bottom); |
361 EXPECT_EQ(-2.0, left); | 354 EXPECT_EQ(-2.0, left); |
362 EXPECT_EQ(-2.0, right); | 355 EXPECT_EQ(-2.0, right); |
363 EXPECT_EQ(-2.0, bottom); | 356 EXPECT_EQ(-2.0, bottom); |
364 EXPECT_EQ(-2.0, top); | 357 EXPECT_EQ(-2.0, top); |
365 | 358 |
366 FPDFLink_CloseWebLinks(pagelink); | 359 FPDFLink_CloseWebLinks(pagelink); |
367 FPDFText_ClosePage(textpage); | 360 FPDFText_ClosePage(textpage); |
368 ClearFormFillEnvironment(form_handle); | |
369 } | 361 } |
OLD | NEW |