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 "public/fpdf_text.h" | 5 #include "public/fpdf_text.h" |
6 #include "public/fpdfview.h" | 6 #include "public/fpdfview.h" |
7 #include "testing/embedder_test.h" | 7 #include "testing/embedder_test.h" |
| 8 #include "testing/test_support.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
9 | 10 |
10 namespace { | 11 namespace { |
11 | 12 |
12 static bool check_unsigned_shorts(const char* expected, | 13 static bool check_unsigned_shorts(const char* expected, |
13 const unsigned short* actual, | 14 const unsigned short* actual, |
14 size_t length) { | 15 size_t length) { |
15 if (length > strlen(expected) + 1) { | 16 if (length > strlen(expected) + 1) { |
16 return false; | 17 return false; |
17 } | 18 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } | 137 } |
137 | 138 |
138 TEST_F(FPDFTextEmbeddertest, TextSearch) { | 139 TEST_F(FPDFTextEmbeddertest, TextSearch) { |
139 EXPECT_TRUE(OpenDocument("hello_world.pdf")); | 140 EXPECT_TRUE(OpenDocument("hello_world.pdf")); |
140 FPDF_PAGE page = LoadPage(0); | 141 FPDF_PAGE page = LoadPage(0); |
141 EXPECT_NE(nullptr, page); | 142 EXPECT_NE(nullptr, page); |
142 | 143 |
143 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); | 144 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); |
144 EXPECT_NE(nullptr, textpage); | 145 EXPECT_NE(nullptr, textpage); |
145 | 146 |
146 // Avoid issues with system wchar_t width vs. FPDF_WideString. | 147 FPDF_WIDESTRING nope = GetFPDFWideString(L"nope"); |
147 const unsigned short nope[] = {'n', 'o', 'p', 'e', '\0'}; | 148 FPDF_WIDESTRING world = GetFPDFWideString(L"world"); |
148 const unsigned short world[] = {'w', 'o', 'r', 'l', 'd', '\0'}; | 149 FPDF_WIDESTRING world_caps = GetFPDFWideString(L"WORLD"); |
149 const unsigned short world_caps[] = {'W', 'O', 'R', 'L', 'D', '\0'}; | 150 FPDF_WIDESTRING world_substr = GetFPDFWideString(L"orld"); |
150 const unsigned short world_substr[] = {'o', 'r', 'l', 'd', '\0'}; | |
151 | 151 |
152 // No occurences of "nope" in test page. | 152 // No occurences of "nope" in test page. |
153 FPDF_SCHHANDLE search = FPDFText_FindStart(textpage, nope, 0, 0); | 153 FPDF_SCHHANDLE search = FPDFText_FindStart(textpage, nope, 0, 0); |
154 EXPECT_NE(nullptr, search); | 154 EXPECT_NE(nullptr, search); |
155 EXPECT_EQ(0, FPDFText_GetSchResultIndex(search)); | 155 EXPECT_EQ(0, FPDFText_GetSchResultIndex(search)); |
156 EXPECT_EQ(0, FPDFText_GetSchCount(search)); | 156 EXPECT_EQ(0, FPDFText_GetSchCount(search)); |
157 | 157 |
158 // Advancing finds nothing. | 158 // Advancing finds nothing. |
159 EXPECT_FALSE(FPDFText_FindNext(search)); | 159 EXPECT_FALSE(FPDFText_FindNext(search)); |
160 EXPECT_EQ(0, FPDFText_GetSchResultIndex(search)); | 160 EXPECT_EQ(0, FPDFText_GetSchResultIndex(search)); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 FPDFText_FindClose(search); | 232 FPDFText_FindClose(search); |
233 | 233 |
234 // But can be made to mach word boundaries, in which case this fails. | 234 // But can be made to mach word boundaries, in which case this fails. |
235 search = FPDFText_FindStart(textpage, world_substr, FPDF_MATCHWHOLEWORD, 0); | 235 search = FPDFText_FindStart(textpage, world_substr, FPDF_MATCHWHOLEWORD, 0); |
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 |
| 243 // Alas, the typedef includes the "const". |
| 244 free(const_cast<unsigned short*>(nope)); |
| 245 free(const_cast<unsigned short*>(world)); |
| 246 free(const_cast<unsigned short*>(world_caps)); |
| 247 free(const_cast<unsigned short*>(world_substr)); |
242 } | 248 } |
243 | 249 |
244 // Test that the page has characters despite a bad stream length. | 250 // Test that the page has characters despite a bad stream length. |
245 TEST_F(FPDFTextEmbeddertest, StreamLengthPastEndOfFile) { | 251 TEST_F(FPDFTextEmbeddertest, StreamLengthPastEndOfFile) { |
246 EXPECT_TRUE(OpenDocument("bug_57.pdf")); | 252 EXPECT_TRUE(OpenDocument("bug_57.pdf")); |
247 FPDF_PAGE page = LoadPage(0); | 253 FPDF_PAGE page = LoadPage(0); |
248 EXPECT_NE(nullptr, page); | 254 EXPECT_NE(nullptr, page); |
249 | 255 |
250 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); | 256 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); |
251 EXPECT_NE(nullptr, textpage); | 257 EXPECT_NE(nullptr, textpage); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 FPDFLink_GetRect(pagelink, -1, 0, &left, &top, &right, &bottom); | 361 FPDFLink_GetRect(pagelink, -1, 0, &left, &top, &right, &bottom); |
356 EXPECT_EQ(-2.0, left); | 362 EXPECT_EQ(-2.0, left); |
357 EXPECT_EQ(-2.0, right); | 363 EXPECT_EQ(-2.0, right); |
358 EXPECT_EQ(-2.0, bottom); | 364 EXPECT_EQ(-2.0, bottom); |
359 EXPECT_EQ(-2.0, top); | 365 EXPECT_EQ(-2.0, top); |
360 | 366 |
361 FPDFLink_CloseWebLinks(pagelink); | 367 FPDFLink_CloseWebLinks(pagelink); |
362 FPDFText_ClosePage(textpage); | 368 FPDFText_ClosePage(textpage); |
363 UnloadPage(page); | 369 UnloadPage(page); |
364 } | 370 } |
OLD | NEW |