357 for (size_t i = 0; i < m_DirectObjs.size(); ++i) {
358 if (m_DirectObjTypes[i] == CPDF_Object::kArray) {
359 EXPECT_TRUE(m_DirectObjs[i]->IsArray());
360 EXPECT_EQ(m_DirectObjs[i].Get(), m_DirectObjs[i]->AsArray());
362 EXPECT_FALSE(m_DirectObjs[i]->IsArray());
363 EXPECT_FALSE(m_DirectObjs[i]->AsArray());
366 if (m_DirectObjTypes[i] == CPDF_Object::kBoolean) {
367 EXPECT_TRUE(m_DirectObjs[i]->IsBoolean());
368 EXPECT_EQ(m_DirectObjs[i].Get(), m_DirectObjs[i]->AsBoolean());
370 EXPECT_FALSE(m_DirectObjs[i]->IsBoolean());
371 EXPECT_FALSE(m_DirectObjs[i]->AsBoolean());
374 if (m_DirectObjTypes[i] == CPDF_Object::kName) {
375 EXPECT_TRUE(m_DirectObjs[i]->IsName());
376 EXPECT_EQ(m_DirectObjs[i].Get(), m_DirectObjs[i]->AsName());
378 EXPECT_FALSE(m_DirectObjs[i]->IsName());
379 EXPECT_FALSE(m_DirectObjs[i]->AsName());
382 if (m_DirectObjTypes[i] == CPDF_Object::kNumber) {
383 EXPECT_TRUE(m_DirectObjs[i]->IsNumber());
384 EXPECT_EQ(m_DirectObjs[i].Get(), m_DirectObjs[i]->AsNumber());
386 EXPECT_FALSE(m_DirectObjs[i]->IsNumber());
387 EXPECT_FALSE(m_DirectObjs[i]->AsNumber());
390 if (m_DirectObjTypes[i] == CPDF_Object::kString) {
391 EXPECT_TRUE(m_DirectObjs[i]->IsString());
392 EXPECT_EQ(m_DirectObjs[i].Get(), m_DirectObjs[i]->AsString());
394 EXPECT_FALSE(m_DirectObjs[i]->IsString());
395 EXPECT_FALSE(m_DirectObjs[i]->AsString());
398 if (m_DirectObjTypes[i] == CPDF_Object::kDictionary) {
399 EXPECT_TRUE(m_DirectObjs[i]->IsDictionary());
400 EXPECT_EQ(m_DirectObjs[i].Get(), m_DirectObjs[i]->AsDictionary());
402 EXPECT_FALSE(m_DirectObjs[i]->IsDictionary());
403 EXPECT_FALSE(m_DirectObjs[i]->AsDictionary());
406 if (m_DirectObjTypes[i] == CPDF_Object::kStream) {
407 EXPECT_TRUE(m_DirectObjs[i]->IsStream());
408 EXPECT_EQ(m_DirectObjs[i].Get(), m_DirectObjs[i]->AsStream());
410 EXPECT_FALSE(m_DirectObjs[i]->IsStream());
411 EXPECT_FALSE(m_DirectObjs[i]->AsStream());
414 EXPECT_FALSE(m_DirectObjs[i]->IsReference());
415 EXPECT_FALSE(m_DirectObjs[i]->AsReference());
418 for (size_t i = 0; i < m_RefObjs.size(); ++i) {
419 EXPECT_TRUE(m_RefObjs[i]->IsReference());
420 EXPECT_EQ(m_RefObjs[i].Get(), m_RefObjs[i]->AsReference());
494 const bool vals[] = {
true,
false,
false,
true,
true};
495 auto arr = pdfium::MakeRetain<CPDF_Array>();
496 for (size_t i = 0; i <
std::size(vals); ++i)
497 arr->InsertNewAt<CPDF_Boolean>(i, vals[i]);
498 for (size_t i = 0; i <
std::size(vals); ++i) {
499 TestArrayAccessors(arr.Get(), i,
500 vals[i] ?
"true" :
"false",
511 const int vals[] = {10, 0, -345, 2089345456, -1000000000, 567, 93658767};
512 auto arr = pdfium::MakeRetain<CPDF_Array>();
513 for (size_t i = 0; i <
std::size(vals); ++i)
514 arr->InsertNewAt<CPDF_Number>(i, vals[i]);
515 for (size_t i = 0; i <
std::size(vals); ++i) {
517 TestArrayAccessors(arr.Get(), i,
518 FXSYS_itoa(vals[i], buf, 10),
529 const float vals[] = {0.0f, 0, 10, 10.0f, 0.0345f,
530 897.34f, -2.5f, -1.0f, -345.0f, -0.0f};
531 const char*
const expected_str[] = {
532 "0",
"0",
"10",
"10",
"0.0345",
"897.34",
"-2.5",
"-1",
"-345",
"0"};
533 auto arr = pdfium::MakeRetain<CPDF_Array>();
534 for (size_t i = 0; i <
std::size(vals); ++i)
535 arr->InsertNewAt<CPDF_Number>(i, vals[i]);
536 for (size_t i = 0; i <
std::size(vals); ++i) {
537 TestArrayAccessors(arr.Get(), i,
549 const char*
const vals[] = {
"this",
"adsde$%^",
"\r\t",
"\"012",
550 ".",
"EYREW",
"It is a joke :)"};
551 auto string_array = pdfium::MakeRetain<CPDF_Array>();
552 auto name_array = pdfium::MakeRetain<CPDF_Array>();
553 for (size_t i = 0; i <
std::size(vals); ++i) {
554 string_array->InsertNewAt<CPDF_String>(i, vals[i],
false);
555 name_array->InsertNewAt<CPDF_Name>(i, vals[i]);
557 for (size_t i = 0; i <
std::size(vals); ++i) {
558 TestArrayAccessors(string_array.Get(), i,
566 TestArrayAccessors(name_array.Get(), i,
578 auto arr = pdfium::MakeRetain<CPDF_Array>();
579 for (size_t i = 0; i < 3; ++i)
580 arr->InsertNewAt<CPDF_Null>(i);
581 for (size_t i = 0; i < 3; ++i) {
582 TestArrayAccessors(arr.Get(), i,
595 auto arr = pdfium::MakeRetain<CPDF_Array>();
596 for (size_t i = 0; i < 3; ++i) {
597 vals[i] = arr->AppendNew<CPDF_Array>();
598 for (size_t j = 0; j < 3; ++j) {
600 vals[i]->InsertNewAt<CPDF_Number>(j, value);
603 for (size_t i = 0; i < 3; ++i) {
604 TestArrayAccessors(arr.Get(), i,
617 auto arr = pdfium::MakeRetain<CPDF_Array>();
618 for (size_t i = 0; i < 3; ++i) {
619 vals[i] = arr->AppendNew<CPDF_Dictionary>();
620 for (size_t j = 0; j < 3; ++j) {
621 std::string key(
"key");
623 key.append(FXSYS_itoa(j, buf, 10));
625 vals[i]->SetNewFor<CPDF_Number>(key.c_str(), value);
628 for (size_t i = 0; i < 3; ++i) {
629 TestArrayAccessors(arr.Get(), i,
643 auto arr = pdfium::MakeRetain<CPDF_Array>();
644 for (size_t i = 0; i < 3; ++i) {
645 vals[i] = pdfium::MakeRetain<CPDF_Dictionary>();
646 for (size_t j = 0; j < 3; ++j) {
647 std::string key(
"key");
649 key.append(FXSYS_itoa(j, buf, 10));
651 vals[i]->SetNewFor<CPDF_Number>(key.c_str(), value);
653 static constexpr uint8_t kContents[] =
"content: this is a stream";
654 stream_vals[i] = arr->AppendNew<CPDF_Stream>(
655 DataVector<uint8_t>(
std::begin(kContents),
std::end(kContents)),
658 for (size_t i = 0; i < 3; ++i) {
659 TestArrayAccessors(arr.Get(), i,
666 stream_vals[i].Get());
671 auto arr = pdfium::MakeRetain<CPDF_Array>();
672 arr->InsertNewAt<CPDF_Boolean>(0,
true);
673 arr->InsertNewAt<CPDF_Boolean>(1,
false);
674 arr->InsertNewAt<CPDF_Number>(2, 0);
675 arr->InsertNewAt<CPDF_Number>(3, -1234);
676 arr->InsertNewAt<CPDF_Number>(4, 2345.0f);
677 arr->InsertNewAt<CPDF_Number>(5, 0.05f);
678 arr->InsertNewAt<CPDF_String>(6,
"",
false);
679 arr->InsertNewAt<CPDF_String>(7,
"It is a test!",
false);
680 arr->InsertNewAt<CPDF_Name>(8,
"NAME");
681 arr->InsertNewAt<CPDF_Name>(9,
"test");
682 arr->InsertNewAt<CPDF_Null>(10);
684 auto arr_val = arr->InsertNewAt<CPDF_Array>(11);
685 arr_val->AppendNew<CPDF_Number>(1);
686 arr_val->AppendNew<CPDF_Number>(2);
688 auto dict_val = arr->InsertNewAt<CPDF_Dictionary>(12);
689 dict_val->SetNewFor<CPDF_String>(
"key1",
"Linda",
false);
690 dict_val->SetNewFor<CPDF_String>(
"key2",
"Zoe",
false);
692 auto stream_dict = pdfium::MakeRetain<CPDF_Dictionary>();
693 stream_dict->SetNewFor<CPDF_String>(
"key1",
"John",
false);
694 stream_dict->SetNewFor<CPDF_String>(
"key2",
"King",
false);
695 static constexpr uint8_t kData[] =
"A stream for test";
698 CPDF_Stream* stream_val = arr->InsertNewAt<CPDF_Stream>(
699 13, DataVector<uint8_t>(
std::begin(kData),
std::end(kData)),
701 const char*
const expected_str[] = {
702 "true",
"false",
"0",
"-1234",
"2345",
"0.05",
"",
703 "It is a test!",
"NAME",
"test",
"",
"",
"",
""};
704 const int expected_int[] = {1, 0, 0, -1234, 2345, 0, 0,
705 0, 0, 0, 0, 0, 0, 0};
706 const float expected_float[] = {0, 0, 0, -1234, 2345, 0.05f, 0,
707 0, 0, 0, 0, 0, 0, 0};
708 for (size_t i = 0; i < arr->size(); ++i) {
709 EXPECT_STREQ(expected_str[i], arr->GetByteStringAt(i).c_str());
710 EXPECT_EQ(expected_int[i], arr->GetIntegerAt(i));
711 EXPECT_EQ(expected_float[i], arr->GetFloatAt(i));
713 EXPECT_EQ(arr_val, arr->GetArrayAt(i));
715 EXPECT_FALSE(arr->GetArrayAt(i));
717 EXPECT_EQ(stream_dict, arr->GetDictAt(i));
718 EXPECT_EQ(stream_val, arr->GetStreamAt(i));
720 EXPECT_FALSE(arr->GetStreamAt(i));
722 EXPECT_EQ(dict_val, arr->GetDictAt(i));
724 EXPECT_FALSE(arr->GetDictAt(i));
773 auto boolean_obj = pdfium::MakeRetain<CPDF_Boolean>(
true);
774 auto int_obj = pdfium::MakeRetain<CPDF_Number>(-1234);
775 auto float_obj = pdfium::MakeRetain<CPDF_Number>(2345.089f);
777 pdfium::MakeRetain<CPDF_String>(
nullptr,
"Adsfdsf 343434 %&&*\n",
false);
778 auto name_obj = pdfium::MakeRetain<CPDF_Name>(
nullptr,
"Title:");
779 auto null_obj = pdfium::MakeRetain<CPDF_Null>();
781 str_obj, name_obj, null_obj};
782 unsigned int obj_nums[] = {2, 4, 7, 2345, 799887, 1};
783 auto arr = pdfium::MakeRetain<CPDF_Array>();
784 auto arr1 = pdfium::MakeRetain<CPDF_Array>();
786 for (size_t i = 0; i <
std::size(indirect_objs); ++i) {
787 holder->ReplaceIndirectObjectIfHigherGeneration(obj_nums[i],
789 arr->AppendNew<CPDF_Reference>(holder.get(), obj_nums[i]);
790 arr1->AppendNew<CPDF_Reference>(holder.get(),
791 indirect_objs[i]->GetObjNum());
794 for (size_t i = 0; i <
std::size(obj_nums); ++i)
795 EXPECT_EQ(indirect_objs[i], holder->GetOrParseIndirectObject(obj_nums[i]));
797 EXPECT_EQ(arr->size(), arr1->size());
798 for (size_t i = 0; i < arr->size(); ++i) {
800 EXPECT_EQ(indirect_objs[i], arr->GetObjectAt(i)->GetDirect());
801 EXPECT_EQ(indirect_objs[i], arr->GetDirectObjectAt(i));
803 EXPECT_EQ(indirect_objs[i], arr1->GetObjectAt(i)->GetDirect());
804 EXPECT_EQ(indirect_objs[i], arr1->GetDirectObjectAt(i));
933 auto arr_obj = pdfium::MakeRetain<CPDF_Array>();
934 auto dict_obj = arr_obj->InsertNewAt<CPDF_Dictionary>(0);
935 dict_obj->SetFor(
"arr", arr_obj);
937 RetainPtr<CPDF_Array> cloned_array = ToArray(arr_obj->Clone());
939 ASSERT_TRUE(cloned_array);
940 EXPECT_EQ(1u, cloned_array->size());
942 ASSERT_TRUE(cloned_dict);
943 ASSERT_TRUE(cloned_dict->IsDictionary());
945 EXPECT_FALSE(cloned_dict->AsDictionary()->GetObjectFor(
"arr"));
946 dict_obj->RemoveFor(
"arr");
951 auto dict_obj = objects_holder.NewIndirect<CPDF_Dictionary>();
952 auto arr_obj = pdfium::MakeRetain<CPDF_Array>();
953 arr_obj->InsertNewAt<CPDF_Reference>(0, &objects_holder,
954 dict_obj->GetObjNum());
956 dict_obj->SetFor(
"arr",
std::move(arr_obj));
957 EXPECT_EQ(1u, dict_obj->GetObjNum());
959 ASSERT_TRUE(elem0->IsReference());
960 EXPECT_EQ(1u, elem0->AsReference()->GetRefObjNum());
961 EXPECT_EQ(dict_obj, elem0->AsReference()->GetDirect());
965 ToDictionary(dict_obj->CloneDirectObject());
967 ASSERT_TRUE(cloned_dict);
969 ASSERT_TRUE(cloned_arr);
970 ASSERT_TRUE(cloned_arr->IsArray());
971 EXPECT_EQ(0U, cloned_arr->AsArray()->size());
973 EXPECT_FALSE(cloned_arr->AsArray()->GetObjectAt(0));
974 dict_obj->RemoveFor(
"arr");