diff options
author | thestig <thestig@chromium.org> | 2016-08-25 11:14:21 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-25 11:14:21 -0700 |
commit | 22b176d0ee7f1dcbc7bca6e5eef65c19fa10f726 (patch) | |
tree | 7de5141f0e33e65930b252773cbf242441fb7b5f /core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp | |
parent | 695aac5f1f53088659f9b525a692002044e3b098 (diff) | |
download | pdfium-22b176d0ee7f1dcbc7bca6e5eef65c19fa10f726.tar.xz |
Check for nullptrs in CPDF_Dictionary dtor.
BUG=597440
Review-Url: https://codereview.chromium.org/2273293003
Diffstat (limited to 'core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp')
-rw-r--r-- | core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp b/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp index 02e50bcfec..ec982ab58a 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp @@ -747,6 +747,44 @@ TEST(PDFArrayTest, AddReferenceAndGetObjectAt) { } } +TEST(PDFArrayTest, CloneDirectObject) { + CPDF_IndirectObjectHolder objects_holder; + ScopedArray array(new CPDF_Array); + array->AddReference(&objects_holder, 1234); + ASSERT_EQ(1U, array->GetCount()); + CPDF_Object* obj = array->GetObjectAt(0); + ASSERT_TRUE(obj); + EXPECT_TRUE(obj->IsReference()); + + CPDF_Object* cloned_array_object = array->CloneDirectObject(); + ASSERT_TRUE(cloned_array_object); + ASSERT_TRUE(cloned_array_object->IsArray()); + + ScopedArray cloned_array(cloned_array_object->AsArray()); + ASSERT_EQ(1U, cloned_array->GetCount()); + CPDF_Object* cloned_obj = cloned_array->GetObjectAt(0); + EXPECT_FALSE(cloned_obj); +} + +TEST(PDFDictionaryTest, CloneDirectObject) { + CPDF_IndirectObjectHolder objects_holder; + ScopedDict dict(new CPDF_Dictionary); + dict->SetAtReference("foo", &objects_holder, 1234); + ASSERT_EQ(1U, dict->GetCount()); + CPDF_Object* obj = dict->GetObjectBy("foo"); + ASSERT_TRUE(obj); + EXPECT_TRUE(obj->IsReference()); + + CPDF_Object* cloned_dict_object = dict->CloneDirectObject(); + ASSERT_TRUE(cloned_dict_object); + ASSERT_TRUE(cloned_dict_object->IsDictionary()); + + ScopedDict cloned_dict(cloned_dict_object->AsDictionary()); + ASSERT_EQ(1U, cloned_dict->GetCount()); + CPDF_Object* cloned_obj = cloned_dict->GetObjectBy("foo"); + EXPECT_FALSE(cloned_obj); +} + TEST(PDFObjectTest, CloneCheckLoop) { { // Create an object with a reference loop. @@ -768,15 +806,14 @@ TEST(PDFObjectTest, CloneCheckLoop) { EXPECT_EQ(nullptr, cloned_dict->AsDictionary()->GetObjectBy("arr")); } { - std::unique_ptr<CPDF_IndirectObjectHolder> m_ObjHolder( - new CPDF_IndirectObjectHolder()); + CPDF_IndirectObjectHolder objects_holder; // Create an object with a reference loop. CPDF_Dictionary* dict_obj = new CPDF_Dictionary; CPDF_Array* arr_obj = new CPDF_Array; - m_ObjHolder->AddIndirectObject(dict_obj); + objects_holder.AddIndirectObject(dict_obj); EXPECT_EQ(1u, dict_obj->GetObjNum()); dict_obj->SetAt("arr", arr_obj); - arr_obj->InsertAt(0, dict_obj, m_ObjHolder.get()); + arr_obj->InsertAt(0, dict_obj, &objects_holder); CPDF_Object* elem0 = arr_obj->GetObjectAt(0); ASSERT_TRUE(elem0); ASSERT_TRUE(elem0->IsReference()); |