Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Side by Side Diff: core/fpdfapi/parser/cpdf_object_unittest.cpp

Issue 2419173002: Update CPDF_IndirectObjectHolder APIs for unique objects (Closed)
Patch Set: Fix issues Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/parser/cpdf_array.h" 5 #include "core/fpdfapi/parser/cpdf_array.h"
6 #include "core/fpdfapi/parser/cpdf_boolean.h" 6 #include "core/fpdfapi/parser/cpdf_boolean.h"
7 #include "core/fpdfapi/parser/cpdf_dictionary.h" 7 #include "core/fpdfapi/parser/cpdf_dictionary.h"
8 #include "core/fpdfapi/parser/cpdf_name.h" 8 #include "core/fpdfapi/parser/cpdf_name.h"
9 #include "core/fpdfapi/parser/cpdf_null.h" 9 #include "core/fpdfapi/parser/cpdf_null.h"
10 #include "core/fpdfapi/parser/cpdf_number.h" 10 #include "core/fpdfapi/parser/cpdf_number.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 for (size_t i = 0; i < FX_ArraySize(objs); ++i) 94 for (size_t i = 0; i < FX_ArraySize(objs); ++i)
95 m_DirectObjs.emplace_back(objs[i]); 95 m_DirectObjs.emplace_back(objs[i]);
96 96
97 // Indirect references to indirect objects. 97 // Indirect references to indirect objects.
98 m_ObjHolder.reset(new CPDF_IndirectObjectHolder()); 98 m_ObjHolder.reset(new CPDF_IndirectObjectHolder());
99 m_IndirectObjs = {boolean_true_obj->Clone(), number_int_obj->Clone(), 99 m_IndirectObjs = {boolean_true_obj->Clone(), number_int_obj->Clone(),
100 str_spec_obj->Clone(), name_obj->Clone(), 100 str_spec_obj->Clone(), name_obj->Clone(),
101 m_ArrayObj->Clone(), m_DictObj->Clone(), 101 m_ArrayObj->Clone(), m_DictObj->Clone(),
102 stream_obj->Clone()}; 102 stream_obj->Clone()};
103 for (size_t i = 0; i < m_IndirectObjs.size(); ++i) { 103 for (size_t i = 0; i < m_IndirectObjs.size(); ++i) {
104 m_ObjHolder->AddIndirectObject(m_IndirectObjs[i]); 104 m_ObjHolder->AddIndirectObject(UniqueObject(m_IndirectObjs[i]));
105 m_RefObjs.emplace_back(new CPDF_Reference( 105 m_RefObjs.emplace_back(new CPDF_Reference(
106 m_ObjHolder.get(), m_IndirectObjs[i]->GetObjNum())); 106 m_ObjHolder.get(), m_IndirectObjs[i]->GetObjNum()));
107 } 107 }
108 } 108 }
109 109
110 bool Equal(const CPDF_Object* obj1, const CPDF_Object* obj2) { 110 bool Equal(const CPDF_Object* obj1, const CPDF_Object* obj2) {
111 if (obj1 == obj2) 111 if (obj1 == obj2)
112 return true; 112 return true;
113 if (!obj1 || !obj2 || obj1->GetType() != obj2->GetType()) 113 if (!obj1 || !obj2 || obj1->GetType() != obj2->GetType())
114 return false; 114 return false;
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 CPDF_Name* name_obj = new CPDF_Name("Title:"); 723 CPDF_Name* name_obj = new CPDF_Name("Title:");
724 CPDF_Null* null_obj = new CPDF_Null(); 724 CPDF_Null* null_obj = new CPDF_Null();
725 CPDF_Object* indirect_objs[] = {boolean_obj, int_obj, float_obj, 725 CPDF_Object* indirect_objs[] = {boolean_obj, int_obj, float_obj,
726 str_obj, name_obj, null_obj}; 726 str_obj, name_obj, null_obj};
727 unsigned int obj_nums[] = {2, 4, 7, 2345, 799887, 1}; 727 unsigned int obj_nums[] = {2, 4, 7, 2345, 799887, 1};
728 ScopedArray arr(new CPDF_Array); 728 ScopedArray arr(new CPDF_Array);
729 ScopedArray arr1(new CPDF_Array); 729 ScopedArray arr1(new CPDF_Array);
730 // Create two arrays of references by different AddReference() APIs. 730 // Create two arrays of references by different AddReference() APIs.
731 for (size_t i = 0; i < FX_ArraySize(indirect_objs); ++i) { 731 for (size_t i = 0; i < FX_ArraySize(indirect_objs); ++i) {
732 // All the indirect objects inserted will be owned by holder. 732 // All the indirect objects inserted will be owned by holder.
733 holder->ReplaceIndirectObjectIfHigherGeneration(obj_nums[i], 733 holder->ReplaceIndirectObjectIfHigherGeneration(
734 indirect_objs[i]); 734 obj_nums[i], UniqueObject(indirect_objs[i]));
735 arr->AddReference(holder.get(), obj_nums[i]); 735 arr->AddReference(holder.get(), obj_nums[i]);
736 arr1->AddReference(holder.get(), indirect_objs[i]->GetObjNum()); 736 arr1->AddReference(holder.get(), indirect_objs[i]->GetObjNum());
737 } 737 }
738 // Check indirect objects. 738 // Check indirect objects.
739 for (size_t i = 0; i < FX_ArraySize(obj_nums); ++i) 739 for (size_t i = 0; i < FX_ArraySize(obj_nums); ++i)
740 EXPECT_EQ(indirect_objs[i], holder->GetOrParseIndirectObject(obj_nums[i])); 740 EXPECT_EQ(indirect_objs[i], holder->GetOrParseIndirectObject(obj_nums[i]));
741 // Check arrays. 741 // Check arrays.
742 EXPECT_EQ(arr->GetCount(), arr1->GetCount()); 742 EXPECT_EQ(arr->GetCount(), arr1->GetCount());
743 for (size_t i = 0; i < arr->GetCount(); ++i) { 743 for (size_t i = 0; i < arr->GetCount(); ++i) {
744 EXPECT_EQ(CPDF_Object::REFERENCE, arr->GetObjectAt(i)->GetType()); 744 EXPECT_EQ(CPDF_Object::REFERENCE, arr->GetObjectAt(i)->GetType());
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 ASSERT_TRUE(cloned_stream); 834 ASSERT_TRUE(cloned_stream);
835 CPDF_Object* cloned_dict = cloned_stream->GetDict(); 835 CPDF_Object* cloned_dict = cloned_stream->GetDict();
836 ASSERT_TRUE(cloned_dict); 836 ASSERT_TRUE(cloned_dict);
837 ASSERT_TRUE(cloned_dict->IsDictionary()); 837 ASSERT_TRUE(cloned_dict->IsDictionary());
838 // Recursively referenced object is not cloned. 838 // Recursively referenced object is not cloned.
839 EXPECT_EQ(nullptr, cloned_dict->AsDictionary()->GetObjectFor("stream")); 839 EXPECT_EQ(nullptr, cloned_dict->AsDictionary()->GetObjectFor("stream"));
840 } 840 }
841 { 841 {
842 CPDF_IndirectObjectHolder objects_holder; 842 CPDF_IndirectObjectHolder objects_holder;
843 // Create an object with a reference loop. 843 // Create an object with a reference loop.
844 CPDF_Dictionary* dict_obj = new CPDF_Dictionary(); 844 CPDF_Dictionary* dict_obj = objects_holder.AddIndirectDictionary();
845 CPDF_Array* arr_obj = new CPDF_Array; 845 CPDF_Array* arr_obj = new CPDF_Array;
846 objects_holder.AddIndirectObject(dict_obj);
847 EXPECT_EQ(1u, dict_obj->GetObjNum()); 846 EXPECT_EQ(1u, dict_obj->GetObjNum());
848 dict_obj->SetFor("arr", arr_obj); 847 dict_obj->SetFor("arr", arr_obj);
849 arr_obj->InsertAt( 848 arr_obj->InsertAt(
850 0, new CPDF_Reference(&objects_holder, dict_obj->GetObjNum())); 849 0, new CPDF_Reference(&objects_holder, dict_obj->GetObjNum()));
851 CPDF_Object* elem0 = arr_obj->GetObjectAt(0); 850 CPDF_Object* elem0 = arr_obj->GetObjectAt(0);
852 ASSERT_TRUE(elem0); 851 ASSERT_TRUE(elem0);
853 ASSERT_TRUE(elem0->IsReference()); 852 ASSERT_TRUE(elem0->IsReference());
854 EXPECT_EQ(1u, elem0->AsReference()->GetRefObjNum()); 853 EXPECT_EQ(1u, elem0->AsReference()->GetRefObjNum());
855 EXPECT_EQ(dict_obj, elem0->AsReference()->GetDirect()); 854 EXPECT_EQ(dict_obj, elem0->AsReference()->GetDirect());
856 855
(...skipping 17 matching lines...) Expand all
874 dict->SetFor("clams", pObj); 873 dict->SetFor("clams", pObj);
875 dict->ConvertToIndirectObjectFor("clams", &objects_holder); 874 dict->ConvertToIndirectObjectFor("clams", &objects_holder);
876 CPDF_Object* pRef = dict->GetObjectFor("clams"); 875 CPDF_Object* pRef = dict->GetObjectFor("clams");
877 CPDF_Object* pNum = dict->GetDirectObjectFor("clams"); 876 CPDF_Object* pNum = dict->GetDirectObjectFor("clams");
878 EXPECT_TRUE(pRef->IsReference()); 877 EXPECT_TRUE(pRef->IsReference());
879 EXPECT_TRUE(pNum->IsNumber()); 878 EXPECT_TRUE(pNum->IsNumber());
880 EXPECT_NE(pObj, pRef); 879 EXPECT_NE(pObj, pRef);
881 EXPECT_EQ(pObj, pNum); 880 EXPECT_EQ(pObj, pNum);
882 EXPECT_EQ(42, dict->GetIntegerFor("clams")); 881 EXPECT_EQ(42, dict->GetIntegerFor("clams"));
883 } 882 }
OLDNEW
« no previous file with comments | « core/fpdfapi/parser/cpdf_indirect_object_holder.cpp ('k') | core/fpdfapi/parser/cpdf_parser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698