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/cpdf_boolean.h" | 5 #include "core/fpdfapi/fpdf_parser/cpdf_boolean.h" |
6 #include "core/fpdfapi/fpdf_parser/cpdf_null.h" | 6 #include "core/fpdfapi/fpdf_parser/cpdf_null.h" |
7 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
8 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 8 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_name.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_name.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 stream_obj, null_obj}; | 87 stream_obj, null_obj}; |
88 m_DirectObjTypes = { | 88 m_DirectObjTypes = { |
89 CPDF_Object::BOOLEAN, CPDF_Object::BOOLEAN, CPDF_Object::NUMBER, | 89 CPDF_Object::BOOLEAN, CPDF_Object::BOOLEAN, CPDF_Object::NUMBER, |
90 CPDF_Object::NUMBER, CPDF_Object::STRING, CPDF_Object::STRING, | 90 CPDF_Object::NUMBER, CPDF_Object::STRING, CPDF_Object::STRING, |
91 CPDF_Object::NAME, CPDF_Object::ARRAY, CPDF_Object::DICTIONARY, | 91 CPDF_Object::NAME, CPDF_Object::ARRAY, CPDF_Object::DICTIONARY, |
92 CPDF_Object::STREAM, CPDF_Object::NULLOBJ}; | 92 CPDF_Object::STREAM, CPDF_Object::NULLOBJ}; |
93 for (size_t i = 0; i < FX_ArraySize(objs); ++i) | 93 for (size_t i = 0; i < FX_ArraySize(objs); ++i) |
94 m_DirectObjs.emplace_back(objs[i]); | 94 m_DirectObjs.emplace_back(objs[i]); |
95 | 95 |
96 // Indirect references to indirect objects. | 96 // Indirect references to indirect objects. |
97 m_ObjHolder.reset(new CPDF_IndirectObjectHolder(nullptr)); | 97 m_ObjHolder.reset(new CPDF_IndirectObjectHolder()); |
98 m_IndirectObjs = {boolean_true_obj, number_int_obj, str_spec_obj, name_obj, | 98 m_IndirectObjs = {boolean_true_obj, number_int_obj, str_spec_obj, name_obj, |
99 m_ArrayObj, m_DictObj, stream_obj}; | 99 m_ArrayObj, m_DictObj, stream_obj}; |
100 for (size_t i = 0; i < m_IndirectObjs.size(); ++i) { | 100 for (size_t i = 0; i < m_IndirectObjs.size(); ++i) { |
101 m_ObjHolder->AddIndirectObject(m_IndirectObjs[i]); | 101 m_ObjHolder->AddIndirectObject(m_IndirectObjs[i]); |
102 m_RefObjs.emplace_back(new CPDF_Reference( | 102 m_RefObjs.emplace_back(new CPDF_Reference( |
103 m_ObjHolder.get(), m_IndirectObjs[i]->GetObjNum())); | 103 m_ObjHolder.get(), m_IndirectObjs[i]->GetObjNum())); |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 bool Equal(CPDF_Object* obj1, CPDF_Object* obj2) { | 107 bool Equal(CPDF_Object* obj1, CPDF_Object* obj2) { |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 for (size_t i = 0; i < FX_ArraySize(vals); ++i) { | 705 for (size_t i = 0; i < FX_ArraySize(vals); ++i) { |
706 EXPECT_EQ(CPDF_Object::STRING, string_array->GetObjectAt(i)->GetType()); | 706 EXPECT_EQ(CPDF_Object::STRING, string_array->GetObjectAt(i)->GetType()); |
707 EXPECT_STREQ(vals[i], string_array->GetObjectAt(i)->GetString().c_str()); | 707 EXPECT_STREQ(vals[i], string_array->GetObjectAt(i)->GetString().c_str()); |
708 EXPECT_EQ(CPDF_Object::NAME, name_array->GetObjectAt(i)->GetType()); | 708 EXPECT_EQ(CPDF_Object::NAME, name_array->GetObjectAt(i)->GetType()); |
709 EXPECT_STREQ(vals[i], name_array->GetObjectAt(i)->GetString().c_str()); | 709 EXPECT_STREQ(vals[i], name_array->GetObjectAt(i)->GetString().c_str()); |
710 } | 710 } |
711 } | 711 } |
712 | 712 |
713 TEST(PDFArrayTest, AddReferenceAndGetObjectAt) { | 713 TEST(PDFArrayTest, AddReferenceAndGetObjectAt) { |
714 std::unique_ptr<CPDF_IndirectObjectHolder> holder( | 714 std::unique_ptr<CPDF_IndirectObjectHolder> holder( |
715 new CPDF_IndirectObjectHolder(nullptr)); | 715 new CPDF_IndirectObjectHolder()); |
716 CPDF_Boolean* boolean_obj = new CPDF_Boolean(true); | 716 CPDF_Boolean* boolean_obj = new CPDF_Boolean(true); |
717 CPDF_Number* int_obj = new CPDF_Number(-1234); | 717 CPDF_Number* int_obj = new CPDF_Number(-1234); |
718 CPDF_Number* float_obj = new CPDF_Number(2345.089f); | 718 CPDF_Number* float_obj = new CPDF_Number(2345.089f); |
719 CPDF_String* str_obj = new CPDF_String("Adsfdsf 343434 %&&*\n", false); | 719 CPDF_String* str_obj = new CPDF_String("Adsfdsf 343434 %&&*\n", false); |
720 CPDF_Name* name_obj = new CPDF_Name("Title:"); | 720 CPDF_Name* name_obj = new CPDF_Name("Title:"); |
721 CPDF_Null* null_obj = new CPDF_Null(); | 721 CPDF_Null* null_obj = new CPDF_Null(); |
722 CPDF_Object* indirect_objs[] = {boolean_obj, int_obj, float_obj, | 722 CPDF_Object* indirect_objs[] = {boolean_obj, int_obj, float_obj, |
723 str_obj, name_obj, null_obj}; | 723 str_obj, name_obj, null_obj}; |
724 unsigned int obj_nums[] = {2, 4, 7, 2345, 799887, 1}; | 724 unsigned int obj_nums[] = {2, 4, 7, 2345, 799887, 1}; |
725 ScopedArray arr(new CPDF_Array); | 725 ScopedArray arr(new CPDF_Array); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 ASSERT_TRUE(cloned_array); | 762 ASSERT_TRUE(cloned_array); |
763 EXPECT_EQ(1u, cloned_array->GetCount()); | 763 EXPECT_EQ(1u, cloned_array->GetCount()); |
764 CPDF_Object* cloned_dict = cloned_array->GetObjectAt(0); | 764 CPDF_Object* cloned_dict = cloned_array->GetObjectAt(0); |
765 ASSERT_TRUE(cloned_dict); | 765 ASSERT_TRUE(cloned_dict); |
766 ASSERT_TRUE(cloned_dict->IsDictionary()); | 766 ASSERT_TRUE(cloned_dict->IsDictionary()); |
767 // Recursively referenced object is not cloned. | 767 // Recursively referenced object is not cloned. |
768 EXPECT_EQ(nullptr, cloned_dict->AsDictionary()->GetObjectBy("arr")); | 768 EXPECT_EQ(nullptr, cloned_dict->AsDictionary()->GetObjectBy("arr")); |
769 } | 769 } |
770 { | 770 { |
771 std::unique_ptr<CPDF_IndirectObjectHolder> m_ObjHolder( | 771 std::unique_ptr<CPDF_IndirectObjectHolder> m_ObjHolder( |
772 new CPDF_IndirectObjectHolder(nullptr)); | 772 new CPDF_IndirectObjectHolder()); |
773 // Create an object with a reference loop. | 773 // Create an object with a reference loop. |
774 CPDF_Dictionary* dict_obj = new CPDF_Dictionary; | 774 CPDF_Dictionary* dict_obj = new CPDF_Dictionary; |
775 CPDF_Array* arr_obj = new CPDF_Array; | 775 CPDF_Array* arr_obj = new CPDF_Array; |
776 m_ObjHolder->AddIndirectObject(dict_obj); | 776 m_ObjHolder->AddIndirectObject(dict_obj); |
777 EXPECT_EQ(1u, dict_obj->GetObjNum()); | 777 EXPECT_EQ(1u, dict_obj->GetObjNum()); |
778 dict_obj->SetAt("arr", arr_obj); | 778 dict_obj->SetAt("arr", arr_obj); |
779 arr_obj->InsertAt(0, dict_obj, m_ObjHolder.get()); | 779 arr_obj->InsertAt(0, dict_obj, m_ObjHolder.get()); |
780 CPDF_Object* elem0 = arr_obj->GetObjectAt(0); | 780 CPDF_Object* elem0 = arr_obj->GetObjectAt(0); |
781 ASSERT_TRUE(elem0); | 781 ASSERT_TRUE(elem0); |
782 ASSERT_TRUE(elem0->IsReference()); | 782 ASSERT_TRUE(elem0->IsReference()); |
783 EXPECT_EQ(1u, elem0->AsReference()->GetRefObjNum()); | 783 EXPECT_EQ(1u, elem0->AsReference()->GetRefObjNum()); |
784 EXPECT_EQ(dict_obj, elem0->AsReference()->GetDirect()); | 784 EXPECT_EQ(dict_obj, elem0->AsReference()->GetDirect()); |
785 | 785 |
786 // Clone this object to see whether stack overflow will be triggered. | 786 // Clone this object to see whether stack overflow will be triggered. |
787 ScopedDict cloned_dict(ToDictionary(dict_obj->CloneDirectObject())); | 787 ScopedDict cloned_dict(ToDictionary(dict_obj->CloneDirectObject())); |
788 // Cloned object should be the same as the original. | 788 // Cloned object should be the same as the original. |
789 ASSERT_TRUE(cloned_dict); | 789 ASSERT_TRUE(cloned_dict); |
790 CPDF_Object* cloned_arr = cloned_dict->GetObjectBy("arr"); | 790 CPDF_Object* cloned_arr = cloned_dict->GetObjectBy("arr"); |
791 ASSERT_TRUE(cloned_arr); | 791 ASSERT_TRUE(cloned_arr); |
792 ASSERT_TRUE(cloned_arr->IsArray()); | 792 ASSERT_TRUE(cloned_arr->IsArray()); |
793 EXPECT_EQ(1u, cloned_arr->AsArray()->GetCount()); | 793 EXPECT_EQ(1u, cloned_arr->AsArray()->GetCount()); |
794 // Recursively referenced object is not cloned. | 794 // Recursively referenced object is not cloned. |
795 EXPECT_EQ(nullptr, cloned_arr->AsArray()->GetObjectAt(0)); | 795 EXPECT_EQ(nullptr, cloned_arr->AsArray()->GetObjectAt(0)); |
796 } | 796 } |
797 } | 797 } |
OLD | NEW |