From fc41e77c97173592ea2abb88c3f6f4dc7c43349d Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 10 Oct 2018 22:41:42 +0000 Subject: Create embeddertests for other kinds of actions. Change-Id: Ia4619be65e2ab8ee4bf19ba9608c1cc94594ba89 Reviewed-on: https://pdfium-review.googlesource.com/c/43812 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- fpdfsdk/fpdf_doc_embeddertest.cpp | 86 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 3 deletions(-) (limited to 'fpdfsdk/fpdf_doc_embeddertest.cpp') diff --git a/fpdfsdk/fpdf_doc_embeddertest.cpp b/fpdfsdk/fpdf_doc_embeddertest.cpp index 91a2333241..a3d8b3a082 100644 --- a/fpdfsdk/fpdf_doc_embeddertest.cpp +++ b/fpdfsdk/fpdf_doc_embeddertest.cpp @@ -257,13 +257,93 @@ TEST_F(FPDFDocEmbeddertest, ActionLaunch) { unsigned long bufsize = FPDFAction_GetFilePath(action, nullptr, 0); EXPECT_EQ(kExpectedLength, bufsize); - char buf[kExpectedLength]; + char buf[1024]; EXPECT_EQ(bufsize, FPDFAction_GetFilePath(action, buf, bufsize)); EXPECT_STREQ(kExpectedResult, buf); - // Other public methods are not appropriate for this action type. + // Other public methods are not appropriate for launch actions. EXPECT_EQ(nullptr, FPDFAction_GetDest(document(), action)); - EXPECT_EQ(0u, FPDFAction_GetURIPath(document(), action, buf, bufsize)); + EXPECT_EQ(0u, FPDFAction_GetURIPath(document(), action, buf, sizeof(buf))); + + UnloadPage(page); +} + +TEST_F(FPDFDocEmbeddertest, ActionURI) { + EXPECT_TRUE(OpenDocument("uri_action.pdf")); + + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + // The target action is nearly the size of the whole page. + FPDF_LINK link = FPDFLink_GetLinkAtPoint(page, 100, 100); + ASSERT_TRUE(link); + + FPDF_ACTION action = FPDFLink_GetAction(link); + ASSERT_TRUE(action); + EXPECT_EQ(static_cast(PDFACTION_URI), + FPDFAction_GetType(action)); + + const char kExpectedResult[] = "https://example.com/page.html"; + const unsigned long kExpectedLength = sizeof(kExpectedResult); + unsigned long bufsize = FPDFAction_GetURIPath(document(), action, nullptr, 0); + ASSERT_EQ(kExpectedLength, bufsize); + + char buf[1024]; + EXPECT_EQ(bufsize, FPDFAction_GetURIPath(document(), action, buf, bufsize)); + EXPECT_STREQ(kExpectedResult, buf); + + // Other public methods are not appropriate for URI actions + EXPECT_EQ(nullptr, FPDFAction_GetDest(document(), action)); + EXPECT_EQ(0u, FPDFAction_GetFilePath(action, buf, sizeof(buf))); + + UnloadPage(page); +} + +TEST_F(FPDFDocEmbeddertest, ActionGoto) { + EXPECT_TRUE(OpenDocument("goto_action.pdf")); + + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + // The target action is nearly the size of the whole page. + FPDF_LINK link = FPDFLink_GetLinkAtPoint(page, 100, 100); + ASSERT_TRUE(link); + + FPDF_ACTION action = FPDFLink_GetAction(link); + ASSERT_TRUE(action); + EXPECT_EQ(static_cast(PDFACTION_GOTO), + FPDFAction_GetType(action)); + + EXPECT_TRUE(FPDFAction_GetDest(document(), action)); + + // Other public methods are not appropriate for GoTo actions. + char buf[1024]; + EXPECT_EQ(0u, FPDFAction_GetFilePath(action, buf, sizeof(buf))); + EXPECT_EQ(0u, FPDFAction_GetURIPath(document(), action, buf, sizeof(buf))); + + UnloadPage(page); +} + +TEST_F(FPDFDocEmbeddertest, ActionNonesuch) { + EXPECT_TRUE(OpenDocument("nonesuch_action.pdf")); + + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + // The target action is nearly the size of the whole page. + FPDF_LINK link = FPDFLink_GetLinkAtPoint(page, 100, 100); + ASSERT_TRUE(link); + + FPDF_ACTION action = FPDFLink_GetAction(link); + ASSERT_TRUE(action); + EXPECT_EQ(static_cast(PDFACTION_UNSUPPORTED), + FPDFAction_GetType(action)); + + // No public methods are appropriate for unsupported actions. + char buf[1024]; + EXPECT_FALSE(FPDFAction_GetDest(document(), action)); + EXPECT_EQ(0u, FPDFAction_GetFilePath(action, buf, sizeof(buf))); + EXPECT_EQ(0u, FPDFAction_GetURIPath(document(), action, buf, sizeof(buf))); UnloadPage(page); } -- cgit v1.2.3