130 auto pRootDict = pdfium::MakeRetain<CPDF_Dictionary>();
131 FillNameTreeDict(pRootDict.Get());
133 pRootDict->GetMutableArrayFor(
"Kids")->GetMutableDictAt(0);
135 pKid1->GetMutableArrayFor(
"Kids")->GetMutableDictAt(1);
136 RetainPtr<CPDF_Array> pLimits = pGrandKid3->GetMutableArrayFor(
"Limits");
137 ASSERT_EQ(2u, pLimits->size());
138 pLimits->AppendNew<CPDF_Number>(5);
139 pLimits->AppendNew<CPDF_Number>(6);
140 ASSERT_EQ(4u, pLimits->size());
141 std::unique_ptr<CPDF_NameTree> name_tree =
142 CPDF_NameTree::CreateForTesting(pRootDict.Get());
145 ToNumber(name_tree->LookupValue(L"9.txt"));
146 ASSERT_TRUE(pNumber);
147 EXPECT_EQ(999, pNumber->GetInteger());
148 CheckLimitsArray(pKid1.Get(),
"1.txt",
"9.txt");
149 CheckLimitsArray(pGrandKid3.Get(),
"9.txt",
"9.txt");
154 auto pRootDict = pdfium::MakeRetain<CPDF_Dictionary>();
155 auto pNames = pRootDict->SetNewFor<CPDF_Array>(
"Names");
156 AddNameKeyValue(pNames.Get(),
"2.txt", 222);
157 AddNameKeyValue(pNames.Get(),
"7.txt", 777);
159 std::unique_ptr<CPDF_NameTree> name_tree =
160 CPDF_NameTree::CreateForTesting(pRootDict.Get());
163 EXPECT_FALSE(name_tree->AddValueAndName(pdfium::MakeRetain<CPDF_Number>(111),
167 EXPECT_TRUE(name_tree->AddValueAndName(pdfium::MakeRetain<CPDF_Number>(111),
171 EXPECT_TRUE(name_tree->AddValueAndName(pdfium::MakeRetain<CPDF_Number>(555),
175 EXPECT_TRUE(name_tree->AddValueAndName(pdfium::MakeRetain<CPDF_Number>(999),
179 CheckNameKeyValue(pNames.Get(), 0,
"1.txt", 111);
180 CheckNameKeyValue(pNames.Get(), 1,
"2.txt", 222);
181 CheckNameKeyValue(pNames.Get(), 2,
"5.txt", 555);
182 CheckNameKeyValue(pNames.Get(), 3,
"7.txt", 777);
183 CheckNameKeyValue(pNames.Get(), 4,
"9.txt", 999);
188 auto pRootDict = pdfium::MakeRetain<CPDF_Dictionary>();
189 auto pNames = pRootDict->SetNewFor<CPDF_Array>(
"Names");
191 std::unique_ptr<CPDF_NameTree> name_tree =
192 CPDF_NameTree::CreateForTesting(pRootDict.Get());
195 EXPECT_TRUE(name_tree->AddValueAndName(pdfium::MakeRetain<CPDF_Number>(111),
199 EXPECT_FALSE(name_tree->AddValueAndName(pdfium::MakeRetain<CPDF_Number>(111),
203 EXPECT_TRUE(name_tree->AddValueAndName(pdfium::MakeRetain<CPDF_Number>(111),
207 EXPECT_TRUE(name_tree->AddValueAndName(pdfium::MakeRetain<CPDF_Number>(555),
211 EXPECT_TRUE(name_tree->AddValueAndName(pdfium::MakeRetain<CPDF_Number>(999),
215 CheckNameKeyValue(pNames.Get(), 0,
"1.txt", 111);
216 CheckNameKeyValue(pNames.Get(), 1,
"2.txt", 111);
217 CheckNameKeyValue(pNames.Get(), 2,
"5.txt", 555);
218 CheckNameKeyValue(pNames.Get(), 3,
"9.txt", 999);
222 auto pRootDict = pdfium::MakeRetain<CPDF_Dictionary>();
223 FillNameTreeDict(pRootDict.Get());
224 std::unique_ptr<CPDF_NameTree> name_tree =
225 CPDF_NameTree::CreateForTesting(pRootDict.Get());
228 EXPECT_FALSE(name_tree->AddValueAndName(pdfium::MakeRetain<CPDF_Number>(444),
232 EXPECT_TRUE(name_tree->AddValueAndName(pdfium::MakeRetain<CPDF_Number>(444),
234 ASSERT_TRUE(name_tree->LookupValue(L"4.txt"));
235 EXPECT_EQ(444, name_tree->LookupValue(L"4.txt")->GetInteger());
238 EXPECT_TRUE(name_tree->AddValueAndName(pdfium::MakeRetain<CPDF_Number>(666),
240 ASSERT_TRUE(name_tree->LookupValue(L"6.txt"));
241 EXPECT_EQ(666, name_tree->LookupValue(L"6.txt")->GetInteger());
244 EXPECT_TRUE(name_tree->AddValueAndName(pdfium::MakeRetain<CPDF_Number>(99),
246 ASSERT_TRUE(name_tree->LookupValue(L"99.txt"));
247 EXPECT_EQ(99, name_tree->LookupValue(L"99.txt")->GetInteger());
250 EXPECT_TRUE(name_tree->AddValueAndName(pdfium::MakeRetain<CPDF_Number>(-5),
252 ASSERT_TRUE(name_tree->LookupValue(L"0.txt"));
253 EXPECT_EQ(-5, name_tree->LookupValue(L"0.txt")->GetInteger());
257 name_tree->GetRootForTesting()->GetArrayFor(
"Kids")->GetDictAt(0);
259 CheckLimitsArray(pKid1.Get(),
"0.txt",
"99.txt");
262 RetainPtr<
const CPDF_Dictionary> pGrandKid2 =
263 pKid1->GetArrayFor(
"Kids")->GetDictAt(0);
264 ASSERT_TRUE(pGrandKid2);
265 CheckLimitsArray(pGrandKid2.Get(),
"0.txt",
"6.txt");
267 RetainPtr<
const CPDF_Dictionary> pGrandKid3 =
268 pKid1->GetArrayFor(
"Kids")->GetDictAt(1);
269 ASSERT_TRUE(pGrandKid3);
270 CheckLimitsArray(pGrandKid3.Get(),
"9.txt",
"99.txt");
271 RetainPtr<
const CPDF_Array> pNames = pGrandKid3->GetArrayFor(
"Names");
272 CheckNameKeyValue(pNames.Get(), 0,
"9.txt", 999);
273 CheckNameKeyValue(pNames.Get(), 1,
"99.txt", 99);
276 RetainPtr<
const CPDF_Dictionary> pGreatGrandKid4 =
277 pGrandKid2->GetArrayFor(
"Kids")->GetDictAt(0);
278 ASSERT_TRUE(pGreatGrandKid4);
279 CheckLimitsArray(pGreatGrandKid4.Get(),
"0.txt",
"2.txt");
280 pNames = pGreatGrandKid4->GetArrayFor(
"Names");
281 CheckNameKeyValue(pNames.Get(), 0,
"0.txt", -5);
282 CheckNameKeyValue(pNames.Get(), 1,
"1.txt", 111);
283 CheckNameKeyValue(pNames.Get(), 2,
"2.txt", 222);
285 RetainPtr<
const CPDF_Dictionary> pGreatGrandKid5 =
286 pGrandKid2->GetArrayFor(
"Kids")->GetDictAt(1);
287 ASSERT_TRUE(pGreatGrandKid5);
288 CheckLimitsArray(pGreatGrandKid5.Get(),
"3.txt",
"6.txt");
289 pNames = pGreatGrandKid5->GetArrayFor(
"Names");
290 CheckNameKeyValue(pNames.Get(), 0,
"3.txt", 333);
291 CheckNameKeyValue(pNames.Get(), 1,
"4.txt", 444);
292 CheckNameKeyValue(pNames.Get(), 2,
"5.txt", 555);
293 CheckNameKeyValue(pNames.Get(), 3,
"6.txt", 666);
297 auto pRootDict = pdfium::MakeRetain<CPDF_Dictionary>();
298 FillNameTreeDict(pRootDict.Get());
299 std::unique_ptr<CPDF_NameTree> name_tree =
300 CPDF_NameTree::CreateForTesting(pRootDict.Get());
304 name_tree->GetRootForTesting()->GetArrayFor(
"Kids")->GetDictAt(0);
306 RetainPtr<
const CPDF_Dictionary> pGrandKid2 =
307 pKid1->GetArrayFor(
"Kids")->GetDictAt(0);
308 ASSERT_TRUE(pGrandKid2);
309 RetainPtr<
const CPDF_Dictionary> pGrandKid3 =
310 pKid1->GetArrayFor(
"Kids")->GetDictAt(1);
311 ASSERT_TRUE(pGrandKid3);
312 RetainPtr<
const CPDF_Dictionary> pGreatGrandKid4 =
313 pGrandKid2->GetArrayFor(
"Kids")->GetDictAt(0);
314 ASSERT_TRUE(pGreatGrandKid4);
315 RetainPtr<
const CPDF_Dictionary> pGreatGrandKid5 =
316 pGrandKid2->GetArrayFor(
"Kids")->GetDictAt(1);
317 ASSERT_TRUE(pGreatGrandKid5);
320 EXPECT_FALSE(name_tree->DeleteValueAndName(5));
325 ASSERT_TRUE(name_tree->LookupValue(L"9.txt"));
326 EXPECT_EQ(999, name_tree->LookupValue(L"9.txt")->GetInteger());
327 EXPECT_TRUE(name_tree->LookupValueAndName(4, &csName));
328 EXPECT_STREQ(L"9.txt", csName
.c_str());
329 EXPECT_EQ(2u, pKid1->GetArrayFor(
"Kids")->size());
330 EXPECT_TRUE(name_tree->DeleteValueAndName(4));
331 EXPECT_EQ(1u, pKid1->GetArrayFor(
"Kids")->size());
332 CheckLimitsArray(pKid1.Get(),
"1.txt",
"5.txt");
336 ASSERT_TRUE(name_tree->LookupValue(L"2.txt"));
337 EXPECT_EQ(222, name_tree->LookupValue(L"2.txt")->GetInteger());
338 EXPECT_TRUE(name_tree->LookupValueAndName(1, &csName));
339 EXPECT_STREQ(L"2.txt", csName
.c_str());
340 EXPECT_EQ(4u, pGreatGrandKid4->GetArrayFor(
"Names")->size());
341 EXPECT_TRUE(name_tree->DeleteValueAndName(1));
342 EXPECT_EQ(2u, pGreatGrandKid4->GetArrayFor(
"Names")->size());
343 CheckLimitsArray(pGreatGrandKid4.Get(),
"1.txt",
"1.txt");
344 CheckLimitsArray(pGrandKid2.Get(),
"1.txt",
"5.txt");
345 CheckLimitsArray(pKid1.Get(),
"1.txt",
"5.txt");
349 ASSERT_TRUE(name_tree->LookupValue(L"1.txt"));
350 EXPECT_EQ(111, name_tree->LookupValue(L"1.txt")->GetInteger());
351 EXPECT_TRUE(name_tree->LookupValueAndName(0, &csName));
352 EXPECT_STREQ(L"1.txt", csName
.c_str());
353 EXPECT_EQ(2u, pGrandKid2->GetArrayFor(
"Kids")->size());
354 EXPECT_TRUE(name_tree->DeleteValueAndName(0));
355 EXPECT_EQ(1u, pGrandKid2->GetArrayFor(
"Kids")->size());
356 CheckLimitsArray(pGrandKid2.Get(),
"3.txt",
"5.txt");
357 CheckLimitsArray(pKid1.Get(),
"3.txt",
"5.txt");
361 ASSERT_TRUE(name_tree->LookupValue(L"3.txt"));
362 EXPECT_EQ(333, name_tree->LookupValue(L"3.txt")->GetInteger());
363 EXPECT_TRUE(name_tree->LookupValueAndName(0, &csName));
364 EXPECT_STREQ(L"3.txt", csName
.c_str());
365 EXPECT_EQ(4u, pGreatGrandKid5->GetArrayFor(
"Names")->size());
366 EXPECT_TRUE(name_tree->DeleteValueAndName(0));
367 EXPECT_EQ(2u, pGreatGrandKid5->GetArrayFor(
"Names")->size());
368 CheckLimitsArray(pGreatGrandKid5.Get(),
"5.txt",
"5.txt");
369 CheckLimitsArray(pGrandKid2.Get(),
"5.txt",
"5.txt");
370 CheckLimitsArray(pKid1.Get(),
"5.txt",
"5.txt");
374 ASSERT_TRUE(name_tree->LookupValue(L"5.txt"));
375 EXPECT_EQ(555, name_tree->LookupValue(L"5.txt")->GetInteger());
376 EXPECT_TRUE(name_tree->LookupValueAndName(0, &csName));
377 EXPECT_STREQ(L"5.txt", csName
.c_str());
378 EXPECT_EQ(1u, name_tree->GetRootForTesting()->GetArrayFor(
"Kids")->size());
379 EXPECT_TRUE(name_tree->DeleteValueAndName(0));
380 EXPECT_EQ(0u, name_tree->GetRootForTesting()->GetArrayFor(
"Kids")->size());
383 EXPECT_EQ(0u, name_tree->GetCount());
384 EXPECT_FALSE(name_tree->LookupValueAndName(0, &csName));
385 EXPECT_FALSE(name_tree->DeleteValueAndName(0));