From 69c3285d3a4d6bb60c8d3b88b289873371ca91f9 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 9 Oct 2018 21:42:39 +0000 Subject: Add two NULL argument FPDFDest_* test cases Change-Id: I4b811bb28f9af5fd4a907a9a9eb29b05a8dc4b6a Reviewed-on: https://pdfium-review.googlesource.com/c/43731 Commit-Queue: Tom Sepez Reviewed-by: Lei Zhang --- fpdfsdk/fpdf_doc.cpp | 6 +++--- fpdfsdk/fpdf_doc_embeddertest.cpp | 24 ++++++++++++++---------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/fpdfsdk/fpdf_doc.cpp b/fpdfsdk/fpdf_doc.cpp index b8f50c7ccb..614462fa47 100644 --- a/fpdfsdk/fpdf_doc.cpp +++ b/fpdfsdk/fpdf_doc.cpp @@ -207,13 +207,13 @@ FPDFAction_GetURIPath(FPDF_DOCUMENT document, FPDF_EXPORT int FPDF_CALLCONV FPDFDest_GetDestPageIndex(FPDF_DOCUMENT document, FPDF_DEST dest) { - if (!dest) - return -1; - CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); if (!pDoc) return -1; + if (!dest) + return -1; + CPDF_Dest destination(CPDFArrayFromFPDFDest(dest)); return destination.GetDestPageIndex(pDoc); } diff --git a/fpdfsdk/fpdf_doc_embeddertest.cpp b/fpdfsdk/fpdf_doc_embeddertest.cpp index d90cc370e3..3d582bcca0 100644 --- a/fpdfsdk/fpdf_doc_embeddertest.cpp +++ b/fpdfsdk/fpdf_doc_embeddertest.cpp @@ -42,7 +42,8 @@ TEST_F(FPDFDocEmbeddertest, MultipleSamePage) { TEST_F(FPDFDocEmbeddertest, DestGetPageIndex) { EXPECT_TRUE(OpenDocument("named_dests.pdf")); - // NULL FPDF_DEST case. + // NULL argument cases. + EXPECT_EQ(-1, FPDFDest_GetDestPageIndex(nullptr, nullptr)); EXPECT_EQ(-1, FPDFDest_GetDestPageIndex(document(), nullptr)); // Page number directly in item from Dests NameTree. @@ -128,18 +129,21 @@ TEST_F(FPDFDocEmbeddertest, DestGetView) { TEST_F(FPDFDocEmbeddertest, DestGetLocationInPage) { EXPECT_TRUE(OpenDocument("named_dests.pdf")); - // NULL FPDF_DEST case. - EXPECT_EQ(-1, FPDFDest_GetDestPageIndex(document(), nullptr)); - FPDF_DEST dest = FPDF_GetNamedDestByName(document(), "First"); EXPECT_TRUE(dest); - FPDF_BOOL hasX; - FPDF_BOOL hasY; - FPDF_BOOL hasZoom; - FS_FLOAT x; - FS_FLOAT y; - FS_FLOAT zoom; + FPDF_BOOL hasX = 0; + FPDF_BOOL hasY = 0; + FPDF_BOOL hasZoom = 0; + FS_FLOAT x = -1.0f; + FS_FLOAT y = -1.0f; + FS_FLOAT zoom = -1.0f; + + // NULL argument case + EXPECT_FALSE(FPDFDest_GetLocationInPage(nullptr, &hasX, &hasY, &hasZoom, &x, + &y, &zoom)); + + // Actual argument case. EXPECT_TRUE( FPDFDest_GetLocationInPage(dest, &hasX, &hasY, &hasZoom, &x, &y, &zoom)); EXPECT_TRUE(hasX); -- cgit v1.2.3