summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdftext_embeddertest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/fpdftext_embeddertest.cpp')
-rw-r--r--fpdfsdk/fpdftext_embeddertest.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/fpdfsdk/fpdftext_embeddertest.cpp b/fpdfsdk/fpdftext_embeddertest.cpp
index 198ef8a7f2..3d496bc06f 100644
--- a/fpdfsdk/fpdftext_embeddertest.cpp
+++ b/fpdfsdk/fpdftext_embeddertest.cpp
@@ -370,6 +370,74 @@ TEST_F(FPDFTextEmbeddertest, WebLinks) {
UnloadPage(page);
}
+TEST_F(FPDFTextEmbeddertest, WebLinksAcrossLines) {
+ EXPECT_TRUE(OpenDocument("weblinks_across_lines.pdf"));
+ FPDF_PAGE page = LoadPage(0);
+ EXPECT_TRUE(page);
+
+ FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
+ EXPECT_TRUE(textpage);
+
+ FPDF_PAGELINK pagelink = FPDFLink_LoadWebLinks(textpage);
+ EXPECT_TRUE(pagelink);
+
+ static const char* const kExpectedUrls[] = {
+ "http://example.com?", // from "http://www.example.com?\r\nfoo"
+ "http://example.com/", // from "http://www.example.com/\r\nfoo"
+ "http://example.com/test-foo", // from "http://example.com/test-\r\nfoo"
+ "http://abc.com/test-foo", // from "http://abc.com/test-\r\n\r\nfoo"
+ // Next two links from "http://www.example.com/\r\nhttp://www.abc.com/"
+ "http://example.com/", "http://www.abc.com",
+ };
+ static const int kNumLinks = static_cast<int>(FX_ArraySize(kExpectedUrls));
+
+ EXPECT_EQ(kNumLinks, FPDFLink_CountWebLinks(pagelink));
+
+ unsigned short fixed_buffer[128];
+ for (int i = 0; i < kNumLinks; i++) {
+ const size_t expected_len = strlen(kExpectedUrls[i]) + 1;
+ memset(fixed_buffer, 0, FX_ArraySize(fixed_buffer));
+ EXPECT_EQ(static_cast<int>(expected_len),
+ FPDFLink_GetURL(pagelink, i, nullptr, 0));
+ EXPECT_EQ(
+ static_cast<int>(expected_len),
+ FPDFLink_GetURL(pagelink, i, fixed_buffer, FX_ArraySize(fixed_buffer)));
+ EXPECT_TRUE(
+ check_unsigned_shorts(kExpectedUrls[i], fixed_buffer, expected_len));
+ }
+
+ FPDFLink_CloseWebLinks(pagelink);
+ FPDFText_ClosePage(textpage);
+ UnloadPage(page);
+}
+
+TEST_F(FPDFTextEmbeddertest, WebLinksAcrossLinesBug) {
+ EXPECT_TRUE(OpenDocument("bug_650.pdf"));
+ FPDF_PAGE page = LoadPage(0);
+ EXPECT_TRUE(page);
+
+ FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
+ EXPECT_TRUE(textpage);
+
+ FPDF_PAGELINK pagelink = FPDFLink_LoadWebLinks(textpage);
+ EXPECT_TRUE(pagelink);
+
+ EXPECT_EQ(2, FPDFLink_CountWebLinks(pagelink));
+ unsigned short fixed_buffer[128] = {0};
+ static const char kExpectedUrl[] =
+ "http://tutorial45.com/learn-autocad-basics-day-166/";
+ static const int kUrlSize = static_cast<int>(sizeof(kExpectedUrl));
+
+ EXPECT_EQ(kUrlSize, FPDFLink_GetURL(pagelink, 1, nullptr, 0));
+ EXPECT_EQ(kUrlSize, FPDFLink_GetURL(pagelink, 1, fixed_buffer,
+ FX_ArraySize(fixed_buffer)));
+ EXPECT_TRUE(check_unsigned_shorts(kExpectedUrl, fixed_buffer, kUrlSize));
+
+ FPDFLink_CloseWebLinks(pagelink);
+ FPDFText_ClosePage(textpage);
+ UnloadPage(page);
+}
+
TEST_F(FPDFTextEmbeddertest, GetFontSize) {
EXPECT_TRUE(OpenDocument("hello_world.pdf"));
FPDF_PAGE page = LoadPage(0);