1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/fpdfapi/parser/cpdf_array.h"
6 #include "core/fpdfapi/parser/cpdf_name.h"
7 #include "core/fpdfapi/parser/cpdf_null.h"
8 #include "core/fpdfapi/parser/cpdf_number.h"
9 #include "core/fpdfdoc/cpdf_dest.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/test_support.h"
12 #include "third_party/base/ptr_util.h"
13
TEST(cpdf_dest,GetXYZ)14 TEST(cpdf_dest, GetXYZ) {
15 bool hasX;
16 bool hasY;
17 bool hasZoom;
18 float x;
19 float y;
20 float zoom;
21
22 // |array| must outlive |dest|.
23 auto array = pdfium::MakeUnique<CPDF_Array>();
24 array->AddNew<CPDF_Number>(0); // Page Index.
25 array->AddNew<CPDF_Name>("XYZ");
26 array->AddNew<CPDF_Number>(4); // X
27 {
28 auto dest = pdfium::MakeUnique<CPDF_Dest>();
29 EXPECT_FALSE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom));
30 }
31 {
32 // Not enough entries.
33 auto dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
34 EXPECT_FALSE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom));
35 }
36 array->AddNew<CPDF_Number>(5); // Y
37 array->AddNew<CPDF_Number>(6); // Zoom.
38 {
39 auto dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
40 EXPECT_TRUE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom));
41 EXPECT_TRUE(hasX);
42 EXPECT_TRUE(hasY);
43 EXPECT_TRUE(hasZoom);
44 EXPECT_EQ(4, x);
45 EXPECT_EQ(5, y);
46 EXPECT_EQ(6, zoom);
47 }
48 // Set zoom to 0.
49 array->SetNewAt<CPDF_Number>(4, 0);
50 {
51 auto dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
52 EXPECT_TRUE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom));
53 EXPECT_FALSE(hasZoom);
54 }
55 // Set values to null.
56 array->SetNewAt<CPDF_Null>(2);
57 array->SetNewAt<CPDF_Null>(3);
58 array->SetNewAt<CPDF_Null>(4);
59 {
60 auto dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
61 EXPECT_TRUE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom));
62 EXPECT_FALSE(hasX);
63 EXPECT_FALSE(hasY);
64 EXPECT_FALSE(hasZoom);
65 }
66 }
67