Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Unified Diff: core/fpdfdoc/cpdf_dest_unittest.cpp

Issue 2481743004: Add FPDFDest_GetLocationInPage API (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: core/fpdfdoc/cpdf_dest_unittest.cpp
diff --git a/core/fpdfdoc/cpdf_dest_unittest.cpp b/core/fpdfdoc/cpdf_dest_unittest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9214e57e8a393af150261cf15bb99410200f9638
--- /dev/null
+++ b/core/fpdfdoc/cpdf_dest_unittest.cpp
@@ -0,0 +1,73 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/fpdfapi/parser/cpdf_array.h"
+#include "core/fpdfapi/parser/cpdf_null.h"
+#include "core/fpdfapi/parser/cpdf_number.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"
+
+TEST(cpdf_dest, hasXYZ) {
+ // Empty dest.
+ auto dest = pdfium::MakeUnique<CPDF_Dest>();
+ EXPECT_FALSE(dest->HasXYZ());
+
+ auto array = pdfium::MakeUnique<CPDF_Array>();
+ array->AddInteger(0); // Page Index.
+ array->AddName("XYZ");
+ array->AddNumber(4); // X
+
+ // Not enough entries.
+ dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
+ EXPECT_FALSE(dest->HasXYZ());
+
+ array->AddNumber(5); // Y
+ array->AddNumber(6); // Zoom.
+
+ dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
+ EXPECT_TRUE(dest->HasXYZ());
+}
+
+TEST(cpdf_dest, GetXYZ) {
+ 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.
+
+ bool hasX;
+ bool hasY;
+ bool hasZoom;
+ float x;
+ float y;
+ float zoom;
+
+ auto dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
+ dest->GetXYZ(&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);
+
+ // Set zoom to 0.
+ array->SetAt(4, new CPDF_Number(0));
+ dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
+ dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom);
+ EXPECT_FALSE(hasZoom);
+
+ // Set values to null.
+ array->SetAt(2, new CPDF_Null);
+ array->SetAt(3, new CPDF_Null);
+ array->SetAt(4, new CPDF_Null);
+ dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
+ dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom);
+ EXPECT_FALSE(hasX);
+ EXPECT_FALSE(hasY);
+ EXPECT_FALSE(hasZoom);
+}

Powered by Google App Engine
This is Rietveld 408576698