OLD | NEW |
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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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()); | 121 obj_holder.get()); |
122 } | 122 } |
123 arr->InsertAt(i, arr_elem); | 123 arr->InsertAt(i, arr_elem); |
124 } | 124 } |
125 ASSERT_EQ(kNumOfRows, arr->GetCount()); | 125 ASSERT_EQ(kNumOfRows, arr->GetCount()); |
126 // Not dereferencing reference objects means just creating new references | 126 // Not dereferencing reference objects means just creating new references |
127 // instead of new copies of direct objects. | 127 // instead of new copies of direct objects. |
128 ScopedArray arr1(arr->Clone(FALSE)->AsArray()); | 128 ScopedArray arr1(arr->Clone()->AsArray()); |
129 EXPECT_EQ(arr->GetCount(), arr1->GetCount()); | 129 EXPECT_EQ(arr->GetCount(), arr1->GetCount()); |
130 // Dereferencing reference objects creates new copies of direct objects. | 130 // Dereferencing reference objects creates new copies of direct objects. |
131 ScopedArray arr2(arr->Clone(TRUE)->AsArray()); | 131 ScopedArray arr2(arr->CloneDirectObject()->AsArray()); |
132 EXPECT_EQ(arr->GetCount(), arr2->GetCount()); | 132 EXPECT_EQ(arr->GetCount(), arr2->GetCount()); |
133 for (size_t i = 0; i < kNumOfRows; ++i) { | 133 for (size_t i = 0; i < kNumOfRows; ++i) { |
134 CPDF_Array* arr_elem = arr->GetObjectAt(i)->AsArray(); | 134 CPDF_Array* arr_elem = arr->GetObjectAt(i)->AsArray(); |
135 CPDF_Array* arr1_elem = arr1->GetObjectAt(i)->AsArray(); | 135 CPDF_Array* arr1_elem = arr1->GetObjectAt(i)->AsArray(); |
136 CPDF_Array* arr2_elem = arr2->GetObjectAt(i)->AsArray(); | 136 CPDF_Array* arr2_elem = arr2->GetObjectAt(i)->AsArray(); |
137 EXPECT_NE(arr_elem, arr1_elem); | 137 EXPECT_NE(arr_elem, arr1_elem); |
138 EXPECT_NE(arr_elem, arr2_elem); | 138 EXPECT_NE(arr_elem, arr2_elem); |
139 for (size_t j = 0; j < kNumOfRowElems; ++j) { | 139 for (size_t j = 0; j < kNumOfRowElems; ++j) { |
140 auto elem_obj = arr_elem->GetObjectAt(j); | 140 auto elem_obj = arr_elem->GetObjectAt(j); |
141 auto elem_obj1 = arr1_elem->GetObjectAt(j); | 141 auto elem_obj1 = arr1_elem->GetObjectAt(j); |
(...skipping 30 matching lines...) Expand all Loading... |
172 TEST(cpdf_array, Iterator) { | 172 TEST(cpdf_array, Iterator) { |
173 int elems[] = {-23, -11, 3, 455, 2345877, | 173 int elems[] = {-23, -11, 3, 455, 2345877, |
174 0, 7895330, -12564334, 10000, -100000}; | 174 0, 7895330, -12564334, 10000, -100000}; |
175 ScopedArray arr(new CPDF_Array); | 175 ScopedArray arr(new CPDF_Array); |
176 for (size_t i = 0; i < FX_ArraySize(elems); ++i) | 176 for (size_t i = 0; i < FX_ArraySize(elems); ++i) |
177 arr->InsertAt(i, new CPDF_Number(elems[i])); | 177 arr->InsertAt(i, new CPDF_Number(elems[i])); |
178 size_t index = 0; | 178 size_t index = 0; |
179 for (const auto& it : *arr) | 179 for (const auto& it : *arr) |
180 EXPECT_EQ(elems[index++], it->AsNumber()->GetInteger()); | 180 EXPECT_EQ(elems[index++], it->AsNumber()->GetInteger()); |
181 } | 181 } |
OLD | NEW |