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

Side by Side 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 unified diff | Download patch
OLDNEW
(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, hasXYZ) {
14 // Empty dest.
15 auto dest = pdfium::MakeUnique<CPDF_Dest>();
16 EXPECT_FALSE(dest->HasXYZ());
17
18 auto array = pdfium::MakeUnique<CPDF_Array>();
19 array->AddInteger(0); // Page Index.
20 array->AddName("XYZ");
21 array->AddNumber(4); // X
22
23 // Not enough entries.
24 dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
25 EXPECT_FALSE(dest->HasXYZ());
26
27 array->AddNumber(5); // Y
28 array->AddNumber(6); // Zoom.
29
30 dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
31 EXPECT_TRUE(dest->HasXYZ());
32 }
33
34 TEST(cpdf_dest, GetXYZ) {
35 auto array = pdfium::MakeUnique<CPDF_Array>();
36 array->AddInteger(0); // Page Index.
37 array->AddName("XYZ");
38 array->AddNumber(4); // X
39 array->AddNumber(5); // Y
40 array->AddNumber(6); // Zoom.
41
42 bool hasX;
43 bool hasY;
44 bool hasZoom;
45 float x;
46 float y;
47 float zoom;
48
49 auto dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
50 dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom);
51 EXPECT_TRUE(hasX);
52 EXPECT_TRUE(hasY);
53 EXPECT_TRUE(hasZoom);
54 EXPECT_EQ(4, x);
55 EXPECT_EQ(5, y);
56 EXPECT_EQ(6, zoom);
57
58 // Set zoom to 0.
59 array->SetAt(4, new CPDF_Number(0));
60 dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
61 dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom);
62 EXPECT_FALSE(hasZoom);
63
64 // Set values to null.
65 array->SetAt(2, new CPDF_Null);
66 array->SetAt(3, new CPDF_Null);
67 array->SetAt(4, new CPDF_Null);
68 dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
69 dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom);
70 EXPECT_FALSE(hasX);
71 EXPECT_FALSE(hasY);
72 EXPECT_FALSE(hasZoom);
73 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698