18 auto arr = pdfium::MakeRetain<CPDF_Array>();
19 arr->AppendNew<CPDF_Boolean>(
true);
20 arr->AppendNew<CPDF_Boolean>(
false);
21 arr->AppendNew<CPDF_Number>(100);
22 arr->AppendNew<CPDF_Number>(0);
24 ASSERT_EQ(4u, arr->size());
25 EXPECT_TRUE(arr->GetBooleanAt(0,
true));
26 EXPECT_TRUE(arr->GetBooleanAt(0,
false));
27 EXPECT_FALSE(arr->GetBooleanAt(1,
true));
28 EXPECT_FALSE(arr->GetBooleanAt(1,
false));
29 EXPECT_TRUE(arr->GetBooleanAt(2,
true));
30 EXPECT_FALSE(arr->GetBooleanAt(2,
false));
31 EXPECT_TRUE(arr->GetBooleanAt(3,
true));
32 EXPECT_FALSE(arr->GetBooleanAt(3,
false));
33 EXPECT_TRUE(arr->GetBooleanAt(99,
true));
34 EXPECT_FALSE(arr->GetBooleanAt(99,
false));
39 const int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
40 auto arr = pdfium::MakeRetain<CPDF_Array>();
41 for (size_t i = 0; i <
std::size(elems); ++i)
42 arr->AppendNew<CPDF_Number>(elems[i]);
43 for (size_t i = 0; i < 3; ++i)
45 const int expected[] = {1, 2, 3, 7, 8, 9, 10};
46 ASSERT_EQ(
std::size(expected), arr->size());
47 for (size_t i = 0; i <
std::size(expected); ++i)
48 EXPECT_EQ(expected[i], arr->GetIntegerAt(i));
51 const int expected2[] = {1, 2, 3, 7, 10};
52 ASSERT_EQ(
std::size(expected2), arr->size());
53 for (size_t i = 0; i <
std::size(expected2); ++i)
54 EXPECT_EQ(expected2[i], arr->GetIntegerAt(i));
58 const int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
59 auto arr = pdfium::MakeRetain<CPDF_Array>();
60 for (size_t i = 0; i <
std::size(elems); ++i)
61 arr->AppendNew<CPDF_Number>(elems[i]);
63 EXPECT_EQ(
std::size(elems), arr->size());
86 const int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
87 auto arr = pdfium::MakeRetain<CPDF_Array>();
88 for (size_t i = 0; i <
std::size(elems); ++i)
89 arr->InsertNewAt<CPDF_Number>(i, elems[i]);
90 ASSERT_EQ(
std::size(elems), arr->size());
91 for (size_t i = 0; i <
std::size(elems); ++i)
92 EXPECT_EQ(elems[i], arr->GetIntegerAt(i));
93 arr->InsertNewAt<CPDF_Number>(3, 33);
94 arr->InsertNewAt<CPDF_Number>(6, 55);
95 arr->InsertNewAt<CPDF_Number>(12, 12);
96 const int expected[] = {1, 2, 3, 33, 4, 5, 55, 6, 7, 8, 9, 10, 12};
97 ASSERT_EQ(
std::size(expected), arr->size());
98 for (size_t i = 0; i <
std::size(expected); ++i)
99 EXPECT_EQ(expected[i], arr->GetIntegerAt(i));
112 const int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
113 auto arr = pdfium::MakeRetain<CPDF_Array>();
114 for (size_t i = 0; i <
std::size(elems); ++i)
115 arr->InsertNewAt<CPDF_Number>(i, elems[i]);
116 RetainPtr<CPDF_Array> arr2 = ToArray(arr->Clone());
117 ASSERT_EQ(arr->size(), arr2->size());
118 for (size_t i = 0; i <
std::size(elems); ++i) {
120 EXPECT_NE(arr->GetObjectAt(i), arr2->GetObjectAt(i));
121 EXPECT_EQ(arr->GetIntegerAt(i), arr2->GetIntegerAt(i));
126 static const size_t kNumOfRows = 3;
127 static const size_t kNumOfRowElems = 5;
128 const int elems[kNumOfRows][kNumOfRowElems] = {
129 {1, 2, 3, 4, 5}, {10, 9, 8, 7, 6}, {11, 12, 13, 14, 15}};
130 auto arr = pdfium::MakeRetain<CPDF_Array>();
133 for (size_t i = 0; i < kNumOfRows; ++i) {
134 auto arr_elem = pdfium::MakeRetain<CPDF_Array>();
135 for (size_t j = 0; j < kNumOfRowElems; ++j) {
136 auto obj = pdfium::MakeRetain<CPDF_Number>(elems[i][j]);
138 int obj_num = i * kNumOfRowElems + j + 1;
139 obj_holder->ReplaceIndirectObjectIfHigherGeneration(obj_num,
141 arr_elem->InsertNewAt<CPDF_Reference>(j, obj_holder.get(), obj_num);
143 arr->InsertAt(i,
std::move(arr_elem));
145 ASSERT_EQ(kNumOfRows, arr->size());
148 RetainPtr<CPDF_Array> arr1 = ToArray(arr->Clone());
149 ASSERT_EQ(arr->size(), arr1->size());
151 RetainPtr<CPDF_Array> arr2 = ToArray(arr->CloneDirectObject());
152 ASSERT_EQ(arr->size(), arr2->size());
153 for (size_t i = 0; i < kNumOfRows; ++i) {
154 const CPDF_Array* arr_elem = arr->GetObjectAt(i)->AsArray();
155 const CPDF_Array* arr1_elem = arr1->GetObjectAt(i)->AsArray();
156 const CPDF_Array* arr2_elem = arr2->GetObjectAt(i)->AsArray();
157 EXPECT_NE(arr_elem, arr1_elem);
158 EXPECT_NE(arr_elem, arr2_elem);
159 for (size_t j = 0; j < kNumOfRowElems; ++j) {
160 auto elem_obj = arr_elem->GetObjectAt(j);
161 auto elem_obj1 = arr1_elem->GetObjectAt(j);
162 auto elem_obj2 = arr2_elem->GetObjectAt(j);
164 EXPECT_NE(elem_obj, elem_obj1);
165 EXPECT_TRUE(elem_obj1->IsReference());
166 EXPECT_EQ(elem_obj->GetDirect(), elem_obj1->GetDirect());
167 EXPECT_EQ(elem_obj->GetInteger(), elem_obj1->GetInteger());
169 EXPECT_NE(elem_obj, elem_obj2);
170 EXPECT_TRUE(elem_obj2->IsNumber());
171 EXPECT_NE(elem_obj->GetDirect(), elem_obj2);
172 EXPECT_EQ(elem_obj->GetObjNum(), elem_obj2->GetObjNum());
173 EXPECT_EQ(elem_obj->GetInteger(), elem_obj2->GetInteger());
177 ASSERT_EQ(kNumOfRows, arr1->size());
178 for (size_t i = 0; i < kNumOfRows; ++i) {
179 for (size_t j = 0; j < kNumOfRowElems; ++j) {
181 auto elem_obj1 = arr1->GetObjectAt(i)->AsArray()->GetObjectAt(j);
182 EXPECT_TRUE(elem_obj1->IsReference());
183 EXPECT_EQ(elems[i][j], elem_obj1->GetInteger());
185 EXPECT_EQ(elems[i][j],
186 arr2->GetObjectAt(i)->AsArray()->GetIntegerAt(j));
193 auto arr = pdfium::MakeRetain<CPDF_Array>();
194 auto dict0 = pdfium::MakeRetain<CPDF_Dictionary>();
195 auto dict1 = pdfium::MakeRetain<CPDF_Dictionary>();
196 auto dict2 = pdfium::MakeRetain<CPDF_Dictionary>();
200 absl::optional<size_t> maybe_found = arr->Find(
nullptr);
201 EXPECT_FALSE(maybe_found.has_value());
203 maybe_found = arr->Find(dict0.Get());
204 ASSERT_TRUE(maybe_found.has_value());
205 EXPECT_EQ(0u, maybe_found.value());
207 maybe_found = arr->Find(dict1.Get());
208 ASSERT_TRUE(maybe_found.has_value());
209 EXPECT_EQ(1u, maybe_found.value());
211 maybe_found = arr->Find(dict2.Get());
212 EXPECT_FALSE(maybe_found.has_value());