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

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

Issue 2355083002: Make CPDF_Array not do indirect object creation. (Closed)
Patch Set: Missed two references Created 4 years, 3 months 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/fpdf_parser/cpdf_array.cpp ('k') | core/fpdfapi/fpdf_parser/cpdf_dictionary.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/fpdf_parser/include/cpdf_array.h" 5 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
6 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" 6 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h"
7 #include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h"
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // Indirect references to indirect objects. 110 // Indirect references to indirect objects.
111 std::unique_ptr<CPDF_IndirectObjectHolder> obj_holder( 111 std::unique_ptr<CPDF_IndirectObjectHolder> obj_holder(
112 new CPDF_IndirectObjectHolder()); 112 new CPDF_IndirectObjectHolder());
113 for (size_t i = 0; i < kNumOfRows; ++i) { 113 for (size_t i = 0; i < kNumOfRows; ++i) {
114 CPDF_Array* arr_elem = new CPDF_Array; 114 CPDF_Array* arr_elem = new CPDF_Array;
115 for (size_t j = 0; j < kNumOfRowElems; ++j) { 115 for (size_t j = 0; j < kNumOfRowElems; ++j) {
116 CPDF_Number* obj = new CPDF_Number(elems[i][j]); 116 CPDF_Number* obj = new CPDF_Number(elems[i][j]);
117 // Starts object number from 1. 117 // Starts object number from 1.
118 int obj_num = i * kNumOfRowElems + j + 1; 118 int obj_num = i * kNumOfRowElems + j + 1;
119 obj_holder->ReplaceIndirectObjectIfHigherGeneration(obj_num, obj); 119 obj_holder->ReplaceIndirectObjectIfHigherGeneration(obj_num, obj);
120 arr_elem->InsertAt(j, new CPDF_Reference(obj_holder.get(), obj_num), 120 arr_elem->InsertAt(j, new CPDF_Reference(obj_holder.get(), obj_num));
121 obj_holder.get());
122 } 121 }
123 arr->InsertAt(i, arr_elem); 122 arr->InsertAt(i, arr_elem);
124 } 123 }
125 ASSERT_EQ(kNumOfRows, arr->GetCount()); 124 ASSERT_EQ(kNumOfRows, arr->GetCount());
126 // Not dereferencing reference objects means just creating new references 125 // Not dereferencing reference objects means just creating new references
127 // instead of new copies of direct objects. 126 // instead of new copies of direct objects.
128 ScopedArray arr1(arr->Clone()->AsArray()); 127 ScopedArray arr1(arr->Clone()->AsArray());
129 EXPECT_EQ(arr->GetCount(), arr1->GetCount()); 128 EXPECT_EQ(arr->GetCount(), arr1->GetCount());
130 // Dereferencing reference objects creates new copies of direct objects. 129 // Dereferencing reference objects creates new copies of direct objects.
131 ScopedArray arr2(arr->CloneDirectObject()->AsArray()); 130 ScopedArray arr2(arr->CloneDirectObject()->AsArray());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 TEST(cpdf_array, Iterator) { 171 TEST(cpdf_array, Iterator) {
173 int elems[] = {-23, -11, 3, 455, 2345877, 172 int elems[] = {-23, -11, 3, 455, 2345877,
174 0, 7895330, -12564334, 10000, -100000}; 173 0, 7895330, -12564334, 10000, -100000};
175 ScopedArray arr(new CPDF_Array); 174 ScopedArray arr(new CPDF_Array);
176 for (size_t i = 0; i < FX_ArraySize(elems); ++i) 175 for (size_t i = 0; i < FX_ArraySize(elems); ++i)
177 arr->InsertAt(i, new CPDF_Number(elems[i])); 176 arr->InsertAt(i, new CPDF_Number(elems[i]));
178 size_t index = 0; 177 size_t index = 0;
179 for (const auto& it : *arr) 178 for (const auto& it : *arr)
180 EXPECT_EQ(elems[index++], it->AsNumber()->GetInteger()); 179 EXPECT_EQ(elems[index++], it->AsNumber()->GetInteger());
181 } 180 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_parser/cpdf_array.cpp ('k') | core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698