summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfdoc_unittest.cpp
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2016-11-08 06:55:40 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-08 06:55:40 -0800
commitc59fa8895fa6fa8428b9b278eee6f05478ab8f56 (patch)
tree3216ee06e894144d578c07e5c655b7637bb6c59c /fpdfsdk/fpdfdoc_unittest.cpp
parent3c669a7fb05dfb602992a5d2333081daef6f002f (diff)
downloadpdfium-c59fa8895fa6fa8428b9b278eee6f05478ab8f56.tar.xz
Add FPDFDest_GetLocationInPage API
Add an API to get the value of the /XYZ destination parameter. This CL was originally from https://codereview.chromium.org/1960193003/ by halcanary@. Review-Url: https://codereview.chromium.org/2481743004
Diffstat (limited to 'fpdfsdk/fpdfdoc_unittest.cpp')
-rw-r--r--fpdfsdk/fpdfdoc_unittest.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/fpdfsdk/fpdfdoc_unittest.cpp b/fpdfsdk/fpdfdoc_unittest.cpp
index 39e81d52e8..fc902570b4 100644
--- a/fpdfsdk/fpdfdoc_unittest.cpp
+++ b/fpdfsdk/fpdfdoc_unittest.cpp
@@ -8,12 +8,15 @@
#include <vector>
#include "core/fpdfapi/cpdf_modulemgr.h"
+#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_document.h"
#include "core/fpdfapi/parser/cpdf_name.h"
+#include "core/fpdfapi/parser/cpdf_null.h"
#include "core/fpdfapi/parser/cpdf_number.h"
#include "core/fpdfapi/parser/cpdf_parser.h"
#include "core/fpdfapi/parser/cpdf_reference.h"
#include "core/fpdfapi/parser/cpdf_string.h"
+#include "core/fpdfdoc/cpdf_dest.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/test_support.h"
#include "third_party/base/ptr_util.h"
@@ -230,3 +233,41 @@ TEST_F(PDFDocTest, FindBookmark) {
EXPECT_EQ(bookmarks[3].obj, FPDFBookmark_Find(m_pDoc.get(), title.get()));
}
}
+
+TEST_F(PDFDocTest, GetLocationInPage) {
+ auto array = pdfium::MakeUnique<CPDF_Array>();
+ array->AddInteger(0); // Page Index.
+ array->AddName("XYZ");
+ array->AddNumber(4); // X
+ array->AddNumber(5); // Y
+ array->AddNumber(6); // Zoom.
+
+ FPDF_BOOL hasX;
+ FPDF_BOOL hasY;
+ FPDF_BOOL hasZoom;
+ FS_FLOAT x;
+ FS_FLOAT y;
+ FS_FLOAT zoom;
+
+ EXPECT_TRUE(FPDFDest_GetLocationInPage(array.get(), &hasX, &hasY, &hasZoom,
+ &x, &y, &zoom));
+ EXPECT_TRUE(hasX);
+ EXPECT_TRUE(hasY);
+ EXPECT_TRUE(hasZoom);
+ EXPECT_EQ(4, x);
+ EXPECT_EQ(5, y);
+ EXPECT_EQ(6, zoom);
+
+ array->SetAt(2, new CPDF_Null);
+ array->SetAt(3, new CPDF_Null);
+ array->SetAt(4, new CPDF_Null);
+ EXPECT_TRUE(FPDFDest_GetLocationInPage(array.get(), &hasX, &hasY, &hasZoom,
+ &x, &y, &zoom));
+ EXPECT_FALSE(hasX);
+ EXPECT_FALSE(hasY);
+ EXPECT_FALSE(hasZoom);
+
+ array = pdfium::MakeUnique<CPDF_Array>();
+ EXPECT_FALSE(FPDFDest_GetLocationInPage(array.get(), &hasX, &hasY, &hasZoom,
+ &x, &y, &zoom));
+}