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

Side by Side Diff: core/fpdfapi/parser/cpdf_array_unittest.cpp

Issue 2477003002: Pass object to ReplaceIndirectObjectIfHigherGeneration() by unique_ptr. (Closed)
Patch Set: Fix issuse 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/cfdf_document.cpp ('k') | core/fpdfapi/parser/cpdf_data_avail.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_number.h"
7 #include "core/fpdfapi/parser/cpdf_reference.h"
8 6
9 #include <memory> 7 #include <memory>
10 8
9 #include "core/fpdfapi/parser/cpdf_number.h"
10 #include "core/fpdfapi/parser/cpdf_reference.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/base/ptr_util.h"
12 13
13 TEST(cpdf_array, RemoveAt) { 14 TEST(cpdf_array, RemoveAt) {
14 { 15 {
15 int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; 16 int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
16 std::unique_ptr<CPDF_Array> arr(new CPDF_Array); 17 std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
17 for (size_t i = 0; i < FX_ArraySize(elems); ++i) 18 for (size_t i = 0; i < FX_ArraySize(elems); ++i)
18 arr->AddInteger(elems[i]); 19 arr->AddInteger(elems[i]);
19 arr->RemoveAt(3, 3); 20 arr->RemoveAt(3, 3);
20 int expected[] = {1, 2, 3, 7, 8, 9, 10}; 21 int expected[] = {1, 2, 3, 7, 8, 9, 10};
21 EXPECT_EQ(FX_ArraySize(expected), arr->GetCount()); 22 EXPECT_EQ(FX_ArraySize(expected), arr->GetCount());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 static const size_t kNumOfRowElems = 5; 101 static const size_t kNumOfRowElems = 5;
101 int elems[kNumOfRows][kNumOfRowElems] = { 102 int elems[kNumOfRows][kNumOfRowElems] = {
102 {1, 2, 3, 4, 5}, {10, 9, 8, 7, 6}, {11, 12, 13, 14, 15}}; 103 {1, 2, 3, 4, 5}, {10, 9, 8, 7, 6}, {11, 12, 13, 14, 15}};
103 std::unique_ptr<CPDF_Array> arr(new CPDF_Array); 104 std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
104 // Indirect references to indirect objects. 105 // Indirect references to indirect objects.
105 std::unique_ptr<CPDF_IndirectObjectHolder> obj_holder( 106 std::unique_ptr<CPDF_IndirectObjectHolder> obj_holder(
106 new CPDF_IndirectObjectHolder()); 107 new CPDF_IndirectObjectHolder());
107 for (size_t i = 0; i < kNumOfRows; ++i) { 108 for (size_t i = 0; i < kNumOfRows; ++i) {
108 CPDF_Array* arr_elem = new CPDF_Array; 109 CPDF_Array* arr_elem = new CPDF_Array;
109 for (size_t j = 0; j < kNumOfRowElems; ++j) { 110 for (size_t j = 0; j < kNumOfRowElems; ++j) {
110 CPDF_Number* obj = new CPDF_Number(elems[i][j]); 111 std::unique_ptr<CPDF_Number> obj(new CPDF_Number(elems[i][j]));
111 // Starts object number from 1. 112 // Starts object number from 1.
112 int obj_num = i * kNumOfRowElems + j + 1; 113 int obj_num = i * kNumOfRowElems + j + 1;
113 obj_holder->ReplaceIndirectObjectIfHigherGeneration(obj_num, obj); 114 obj_holder->ReplaceIndirectObjectIfHigherGeneration(obj_num,
115 std::move(obj));
114 arr_elem->InsertAt(j, new CPDF_Reference(obj_holder.get(), obj_num)); 116 arr_elem->InsertAt(j, new CPDF_Reference(obj_holder.get(), obj_num));
115 } 117 }
116 arr->InsertAt(i, arr_elem); 118 arr->InsertAt(i, arr_elem);
117 } 119 }
118 ASSERT_EQ(kNumOfRows, arr->GetCount()); 120 ASSERT_EQ(kNumOfRows, arr->GetCount());
119 // Not dereferencing reference objects means just creating new references 121 // Not dereferencing reference objects means just creating new references
120 // instead of new copies of direct objects. 122 // instead of new copies of direct objects.
121 std::unique_ptr<CPDF_Array> arr1(arr->Clone()->AsArray()); 123 std::unique_ptr<CPDF_Array> arr1(arr->Clone()->AsArray());
122 EXPECT_EQ(arr->GetCount(), arr1->GetCount()); 124 EXPECT_EQ(arr->GetCount(), arr1->GetCount());
123 // Dereferencing reference objects creates new copies of direct objects. 125 // Dereferencing reference objects creates new copies of direct objects.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 TEST(cpdf_array, Iterator) { 167 TEST(cpdf_array, Iterator) {
166 int elems[] = {-23, -11, 3, 455, 2345877, 168 int elems[] = {-23, -11, 3, 455, 2345877,
167 0, 7895330, -12564334, 10000, -100000}; 169 0, 7895330, -12564334, 10000, -100000};
168 std::unique_ptr<CPDF_Array> arr(new CPDF_Array); 170 std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
169 for (size_t i = 0; i < FX_ArraySize(elems); ++i) 171 for (size_t i = 0; i < FX_ArraySize(elems); ++i)
170 arr->InsertAt(i, new CPDF_Number(elems[i])); 172 arr->InsertAt(i, new CPDF_Number(elems[i]));
171 size_t index = 0; 173 size_t index = 0;
172 for (const auto& it : *arr) 174 for (const auto& it : *arr)
173 EXPECT_EQ(elems[index++], it->AsNumber()->GetInteger()); 175 EXPECT_EQ(elems[index++], it->AsNumber()->GetInteger());
174 } 176 }
OLDNEW
« no previous file with comments | « core/fpdfapi/parser/cfdf_document.cpp ('k') | core/fpdfapi/parser/cpdf_data_avail.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698