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

Side by Side Diff: core/fpdfdoc/cpdf_dest_unittest.cpp

Issue 2498223005: Make CPDF_Array take unique_ptrs (Closed)
Patch Set: nits 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
« no previous file with comments | « core/fpdfapi/parser/cpdf_syntax_parser.cpp ('k') | core/fpdfdoc/cpdf_formfield.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/fpdfapi/parser/cpdf_array.h" 5 #include "core/fpdfapi/parser/cpdf_array.h"
6 #include "core/fpdfapi/parser/cpdf_null.h" 6 #include "core/fpdfapi/parser/cpdf_null.h"
7 #include "core/fpdfapi/parser/cpdf_name.h"
7 #include "core/fpdfapi/parser/cpdf_number.h" 8 #include "core/fpdfapi/parser/cpdf_number.h"
8 #include "core/fpdfdoc/cpdf_dest.h" 9 #include "core/fpdfdoc/cpdf_dest.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 #include "testing/test_support.h" 11 #include "testing/test_support.h"
11 #include "third_party/base/ptr_util.h" 12 #include "third_party/base/ptr_util.h"
12 13
13 TEST(cpdf_dest, GetXYZ) { 14 TEST(cpdf_dest, GetXYZ) {
14 bool hasX; 15 bool hasX;
15 bool hasY; 16 bool hasY;
16 bool hasZoom; 17 bool hasZoom;
17 float x; 18 float x;
18 float y; 19 float y;
19 float zoom; 20 float zoom;
20 21
21 auto dest = pdfium::MakeUnique<CPDF_Dest>(); 22 auto dest = pdfium::MakeUnique<CPDF_Dest>();
22 EXPECT_FALSE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom)); 23 EXPECT_FALSE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom));
23 24
24 auto array = pdfium::MakeUnique<CPDF_Array>(); 25 auto array = pdfium::MakeUnique<CPDF_Array>();
25 array->AddInteger(0); // Page Index. 26 array->AddNew<CPDF_Number>(0); // Page Index.
26 array->AddName("XYZ"); 27 array->AddNew<CPDF_Name>("XYZ");
27 array->AddNumber(4); // X 28 array->AddNew<CPDF_Number>(4); // X
28 29
29 // Not enough entries. 30 // Not enough entries.
30 dest = pdfium::MakeUnique<CPDF_Dest>(array.get()); 31 dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
31 EXPECT_FALSE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom)); 32 EXPECT_FALSE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom));
32 33
33 array->AddNumber(5); // Y 34 array->AddNew<CPDF_Number>(5); // Y
34 array->AddNumber(6); // Zoom. 35 array->AddNew<CPDF_Number>(6); // Zoom.
35 36
36 dest = pdfium::MakeUnique<CPDF_Dest>(array.get()); 37 dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
37 EXPECT_TRUE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom)); 38 EXPECT_TRUE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom));
38 EXPECT_TRUE(hasX); 39 EXPECT_TRUE(hasX);
39 EXPECT_TRUE(hasY); 40 EXPECT_TRUE(hasY);
40 EXPECT_TRUE(hasZoom); 41 EXPECT_TRUE(hasZoom);
41 EXPECT_EQ(4, x); 42 EXPECT_EQ(4, x);
42 EXPECT_EQ(5, y); 43 EXPECT_EQ(5, y);
43 EXPECT_EQ(6, zoom); 44 EXPECT_EQ(6, zoom);
44 45
45 // Set zoom to 0. 46 // Set zoom to 0.
46 array->SetAt(4, new CPDF_Number(0)); 47 array->SetNewAt<CPDF_Number>(4, 0);
47 dest = pdfium::MakeUnique<CPDF_Dest>(array.get()); 48 dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
48 EXPECT_TRUE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom)); 49 EXPECT_TRUE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom));
49 EXPECT_FALSE(hasZoom); 50 EXPECT_FALSE(hasZoom);
50 51
51 // Set values to null. 52 // Set values to null.
52 array->SetAt(2, new CPDF_Null); 53 array->SetNewAt<CPDF_Null>(2);
53 array->SetAt(3, new CPDF_Null); 54 array->SetNewAt<CPDF_Null>(3);
54 array->SetAt(4, new CPDF_Null); 55 array->SetNewAt<CPDF_Null>(4);
55 dest = pdfium::MakeUnique<CPDF_Dest>(array.get()); 56 dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
56 EXPECT_TRUE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom)); 57 EXPECT_TRUE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom));
57 EXPECT_FALSE(hasX); 58 EXPECT_FALSE(hasX);
58 EXPECT_FALSE(hasY); 59 EXPECT_FALSE(hasY);
59 EXPECT_FALSE(hasZoom); 60 EXPECT_FALSE(hasZoom);
60 } 61 }
OLDNEW
« no previous file with comments | « core/fpdfapi/parser/cpdf_syntax_parser.cpp ('k') | core/fpdfdoc/cpdf_formfield.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698