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" | |
6 #include "public/fpdf_text.h" | 5 #include "public/fpdf_text.h" |
7 #include "public/fpdfview.h" | 6 #include "public/fpdfview.h" |
| 7 #include "testing/embedder_test.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace { | 10 namespace { |
11 | 11 |
12 static bool check_unsigned_shorts(const char* expected, | 12 static bool check_unsigned_shorts(const char* expected, |
13 const unsigned short* actual, | 13 const unsigned short* actual, |
14 size_t length) { | 14 size_t length) { |
15 if (length > strlen(expected) + 1) { | 15 if (length > strlen(expected) + 1) { |
16 return false; | 16 return false; |
17 } | 17 } |
18 for (size_t i = 0; i < length; ++i) { | 18 for (size_t i = 0; i < length; ++i) { |
19 if (actual[i] != static_cast<unsigned short>(expected[i])) { | 19 if (actual[i] != static_cast<unsigned short>(expected[i])) { |
20 return false; | 20 return false; |
21 } | 21 } |
22 } | 22 } |
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 TEST_F(FPDFTextEmbeddertest, Text) { | 30 TEST_F(FPDFTextEmbeddertest, Text) { |
31 EXPECT_TRUE(OpenDocument("testing/resources/hello_world.pdf")); | 31 EXPECT_TRUE(OpenDocument("hello_world.pdf")); |
32 FPDF_PAGE page = LoadPage(0); | 32 FPDF_PAGE page = LoadPage(0); |
33 EXPECT_NE(nullptr, page); | 33 EXPECT_NE(nullptr, page); |
34 | 34 |
35 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); | 35 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); |
36 EXPECT_NE(nullptr, textpage); | 36 EXPECT_NE(nullptr, textpage); |
37 | 37 |
38 static const char expected[] = "Hello, world!\r\nGoodbye, world!"; | 38 static const char expected[] = "Hello, world!\r\nGoodbye, world!"; |
39 unsigned short fixed_buffer[128]; | 39 unsigned short fixed_buffer[128]; |
40 memset(fixed_buffer, 0xbd, sizeof(fixed_buffer)); | 40 memset(fixed_buffer, 0xbd, sizeof(fixed_buffer)); |
41 | 41 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 fixed_buffer, 128)); | 129 fixed_buffer, 128)); |
130 EXPECT_TRUE(check_unsigned_shorts(expected + 4, fixed_buffer, 9)); | 130 EXPECT_TRUE(check_unsigned_shorts(expected + 4, fixed_buffer, 9)); |
131 EXPECT_EQ(0u, fixed_buffer[9]); | 131 EXPECT_EQ(0u, fixed_buffer[9]); |
132 EXPECT_EQ(0xbdbd, fixed_buffer[10]); | 132 EXPECT_EQ(0xbdbd, fixed_buffer[10]); |
133 | 133 |
134 FPDFText_ClosePage(textpage); | 134 FPDFText_ClosePage(textpage); |
135 UnloadPage(page); | 135 UnloadPage(page); |
136 } | 136 } |
137 | 137 |
138 TEST_F(FPDFTextEmbeddertest, TextSearch) { | 138 TEST_F(FPDFTextEmbeddertest, TextSearch) { |
139 EXPECT_TRUE(OpenDocument("testing/resources/hello_world.pdf")); | 139 EXPECT_TRUE(OpenDocument("hello_world.pdf")); |
140 FPDF_PAGE page = LoadPage(0); | 140 FPDF_PAGE page = LoadPage(0); |
141 EXPECT_NE(nullptr, page); | 141 EXPECT_NE(nullptr, page); |
142 | 142 |
143 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); | 143 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); |
144 EXPECT_NE(nullptr, textpage); | 144 EXPECT_NE(nullptr, textpage); |
145 | 145 |
146 // Avoid issues with system wchar_t width vs. FPDF_WideString. | 146 // Avoid issues with system wchar_t width vs. FPDF_WideString. |
147 const unsigned short nope[] = {'n', 'o', 'p', 'e', '\0'}; | 147 const unsigned short nope[] = {'n', 'o', 'p', 'e', '\0'}; |
148 const unsigned short world[] = {'w', 'o', 'r', 'l', 'd', '\0'}; | 148 const unsigned short world[] = {'w', 'o', 'r', 'l', 'd', '\0'}; |
149 const unsigned short world_caps[] = {'W', 'O', 'R', 'L', 'D', '\0'}; | 149 const unsigned short world_caps[] = {'W', 'O', 'R', 'L', 'D', '\0'}; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 EXPECT_FALSE(FPDFText_FindNext(search)); | 236 EXPECT_FALSE(FPDFText_FindNext(search)); |
237 // TODO(tsepez): investigate strange index/count values in this state. | 237 // TODO(tsepez): investigate strange index/count values in this state. |
238 FPDFText_FindClose(search); | 238 FPDFText_FindClose(search); |
239 | 239 |
240 FPDFText_ClosePage(textpage); | 240 FPDFText_ClosePage(textpage); |
241 UnloadPage(page); | 241 UnloadPage(page); |
242 } | 242 } |
243 | 243 |
244 // Test that the page has characters despite a bad stream length. | 244 // Test that the page has characters despite a bad stream length. |
245 TEST_F(FPDFTextEmbeddertest, StreamLengthPastEndOfFile) { | 245 TEST_F(FPDFTextEmbeddertest, StreamLengthPastEndOfFile) { |
246 EXPECT_TRUE(OpenDocument("testing/resources/bug_57.pdf")); | 246 EXPECT_TRUE(OpenDocument("bug_57.pdf")); |
247 FPDF_PAGE page = LoadPage(0); | 247 FPDF_PAGE page = LoadPage(0); |
248 EXPECT_NE(nullptr, page); | 248 EXPECT_NE(nullptr, page); |
249 | 249 |
250 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); | 250 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); |
251 EXPECT_NE(nullptr, textpage); | 251 EXPECT_NE(nullptr, textpage); |
252 EXPECT_EQ(13, FPDFText_CountChars(textpage)); | 252 EXPECT_EQ(13, FPDFText_CountChars(textpage)); |
253 | 253 |
254 FPDFText_ClosePage(textpage); | 254 FPDFText_ClosePage(textpage); |
255 UnloadPage(page); | 255 UnloadPage(page); |
256 } | 256 } |
257 | 257 |
258 TEST_F(FPDFTextEmbeddertest, WebLinks) { | 258 TEST_F(FPDFTextEmbeddertest, WebLinks) { |
259 EXPECT_TRUE(OpenDocument("testing/resources/weblinks.pdf")); | 259 EXPECT_TRUE(OpenDocument("weblinks.pdf")); |
260 FPDF_PAGE page = LoadPage(0); | 260 FPDF_PAGE page = LoadPage(0); |
261 EXPECT_NE(nullptr, page); | 261 EXPECT_NE(nullptr, page); |
262 | 262 |
263 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); | 263 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); |
264 EXPECT_NE(nullptr, textpage); | 264 EXPECT_NE(nullptr, textpage); |
265 | 265 |
266 FPDF_PAGELINK pagelink = FPDFLink_LoadWebLinks(textpage); | 266 FPDF_PAGELINK pagelink = FPDFLink_LoadWebLinks(textpage); |
267 EXPECT_NE(nullptr, pagelink); | 267 EXPECT_NE(nullptr, pagelink); |
268 | 268 |
269 // Page contains two HTTP-style URLs. | 269 // Page contains two HTTP-style URLs. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 FPDFLink_GetRect(pagelink, -1, 0, &left, &top, &right, &bottom); | 355 FPDFLink_GetRect(pagelink, -1, 0, &left, &top, &right, &bottom); |
356 EXPECT_EQ(-2.0, left); | 356 EXPECT_EQ(-2.0, left); |
357 EXPECT_EQ(-2.0, right); | 357 EXPECT_EQ(-2.0, right); |
358 EXPECT_EQ(-2.0, bottom); | 358 EXPECT_EQ(-2.0, bottom); |
359 EXPECT_EQ(-2.0, top); | 359 EXPECT_EQ(-2.0, top); |
360 | 360 |
361 FPDFLink_CloseWebLinks(pagelink); | 361 FPDFLink_CloseWebLinks(pagelink); |
362 FPDFText_ClosePage(textpage); | 362 FPDFText_ClosePage(textpage); |
363 UnloadPage(page); | 363 UnloadPage(page); |
364 } | 364 } |
OLD | NEW |