Home | History | Annotate | Download | only in fpdfdoc
      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 
     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   auto dest = pdfium::MakeUnique<CPDF_Dest>();
     23   EXPECT_FALSE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom));
     24 
     25   auto array = pdfium::MakeUnique<CPDF_Array>();
     26   array->AddNew<CPDF_Number>(0);  // Page Index.
     27   array->AddNew<CPDF_Name>("XYZ");
     28   array->AddNew<CPDF_Number>(4);  // X
     29 
     30   // Not enough entries.
     31   dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
     32   EXPECT_FALSE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom));
     33 
     34   array->AddNew<CPDF_Number>(5);  // Y
     35   array->AddNew<CPDF_Number>(6);  // Zoom.
     36 
     37   dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
     38   EXPECT_TRUE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom));
     39   EXPECT_TRUE(hasX);
     40   EXPECT_TRUE(hasY);
     41   EXPECT_TRUE(hasZoom);
     42   EXPECT_EQ(4, x);
     43   EXPECT_EQ(5, y);
     44   EXPECT_EQ(6, zoom);
     45 
     46   // Set zoom to 0.
     47   array->SetNewAt<CPDF_Number>(4, 0);
     48   dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
     49   EXPECT_TRUE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom));
     50   EXPECT_FALSE(hasZoom);
     51 
     52   // Set values to null.
     53   array->SetNewAt<CPDF_Null>(2);
     54   array->SetNewAt<CPDF_Null>(3);
     55   array->SetNewAt<CPDF_Null>(4);
     56   dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
     57   EXPECT_TRUE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom));
     58   EXPECT_FALSE(hasX);
     59   EXPECT_FALSE(hasY);
     60   EXPECT_FALSE(hasZoom);
     61 }
     62