OLD | NEW |
(Empty) | |
| 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_null.h" |
| 7 #include "core/fpdfapi/parser/cpdf_number.h" |
| 8 #include "core/fpdfdoc/cpdf_dest.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "testing/test_support.h" |
| 11 #include "third_party/base/ptr_util.h" |
| 12 |
| 13 TEST(cpdf_dest, GetXYZ) { |
| 14 bool hasX; |
| 15 bool hasY; |
| 16 bool hasZoom; |
| 17 float x; |
| 18 float y; |
| 19 float zoom; |
| 20 |
| 21 auto dest = pdfium::MakeUnique<CPDF_Dest>(); |
| 22 EXPECT_FALSE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom)); |
| 23 |
| 24 auto array = pdfium::MakeUnique<CPDF_Array>(); |
| 25 array->AddInteger(0); // Page Index. |
| 26 array->AddName("XYZ"); |
| 27 array->AddNumber(4); // X |
| 28 |
| 29 // Not enough entries. |
| 30 dest = pdfium::MakeUnique<CPDF_Dest>(array.get()); |
| 31 EXPECT_FALSE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom)); |
| 32 |
| 33 array->AddNumber(5); // Y |
| 34 array->AddNumber(6); // Zoom. |
| 35 |
| 36 dest = pdfium::MakeUnique<CPDF_Dest>(array.get()); |
| 37 EXPECT_TRUE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom)); |
| 38 EXPECT_TRUE(hasX); |
| 39 EXPECT_TRUE(hasY); |
| 40 EXPECT_TRUE(hasZoom); |
| 41 EXPECT_EQ(4, x); |
| 42 EXPECT_EQ(5, y); |
| 43 EXPECT_EQ(6, zoom); |
| 44 |
| 45 // Set zoom to 0. |
| 46 array->SetAt(4, new CPDF_Number(0)); |
| 47 dest = pdfium::MakeUnique<CPDF_Dest>(array.get()); |
| 48 EXPECT_TRUE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom)); |
| 49 EXPECT_FALSE(hasZoom); |
| 50 |
| 51 // Set values to null. |
| 52 array->SetAt(2, new CPDF_Null); |
| 53 array->SetAt(3, new CPDF_Null); |
| 54 array->SetAt(4, new CPDF_Null); |
| 55 dest = pdfium::MakeUnique<CPDF_Dest>(array.get()); |
| 56 EXPECT_TRUE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom)); |
| 57 EXPECT_FALSE(hasX); |
| 58 EXPECT_FALSE(hasY); |
| 59 EXPECT_FALSE(hasZoom); |
| 60 } |
OLD | NEW |