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

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

Issue 2361713002: Remove some objnum locals with AddIndirectObject (Closed)
Patch Set: Same treatment for arrays Created 4 years, 3 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/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 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
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);
726 ScopedArray arr1(new CPDF_Array); 726 ScopedArray arr1(new CPDF_Array);
727 // Create two arrays of references by different AddReference() APIs. 727 // Create two arrays of references by different AddReference() APIs.
728 for (size_t i = 0; i < FX_ArraySize(indirect_objs); ++i) { 728 for (size_t i = 0; i < FX_ArraySize(indirect_objs); ++i) {
729 // All the indirect objects inserted will be owned by holder. 729 // All the indirect objects inserted will be owned by holder.
730 holder->ReplaceIndirectObjectIfHigherGeneration(obj_nums[i], 730 holder->ReplaceIndirectObjectIfHigherGeneration(obj_nums[i],
731 indirect_objs[i]); 731 indirect_objs[i]);
732 arr->AddReference(holder.get(), obj_nums[i]); 732 arr->AddReference(holder.get(), obj_nums[i]);
733 arr1->AddReference(holder.get(), indirect_objs[i]); 733 arr1->AddReference(holder.get(), indirect_objs[i]->GetObjNum());
734 } 734 }
735 // Check indirect objects. 735 // Check indirect objects.
736 for (size_t i = 0; i < FX_ArraySize(obj_nums); ++i) 736 for (size_t i = 0; i < FX_ArraySize(obj_nums); ++i)
737 EXPECT_EQ(indirect_objs[i], holder->GetOrParseIndirectObject(obj_nums[i])); 737 EXPECT_EQ(indirect_objs[i], holder->GetOrParseIndirectObject(obj_nums[i]));
738 // Check arrays. 738 // Check arrays.
739 EXPECT_EQ(arr->GetCount(), arr1->GetCount()); 739 EXPECT_EQ(arr->GetCount(), arr1->GetCount());
740 for (size_t i = 0; i < arr->GetCount(); ++i) { 740 for (size_t i = 0; i < arr->GetCount(); ++i) {
741 EXPECT_EQ(CPDF_Object::REFERENCE, arr->GetObjectAt(i)->GetType()); 741 EXPECT_EQ(CPDF_Object::REFERENCE, arr->GetObjectAt(i)->GetType());
742 EXPECT_EQ(indirect_objs[i], arr->GetObjectAt(i)->GetDirect()); 742 EXPECT_EQ(indirect_objs[i], arr->GetObjectAt(i)->GetDirect());
743 EXPECT_EQ(indirect_objs[i], arr->GetDirectObjectAt(i)); 743 EXPECT_EQ(indirect_objs[i], arr->GetDirectObjectAt(i));
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 // Cloned object should be the same as the original. 826 // Cloned object should be the same as the original.
827 ASSERT_TRUE(cloned_dict); 827 ASSERT_TRUE(cloned_dict);
828 CPDF_Object* cloned_arr = cloned_dict->GetObjectFor("arr"); 828 CPDF_Object* cloned_arr = cloned_dict->GetObjectFor("arr");
829 ASSERT_TRUE(cloned_arr); 829 ASSERT_TRUE(cloned_arr);
830 ASSERT_TRUE(cloned_arr->IsArray()); 830 ASSERT_TRUE(cloned_arr->IsArray());
831 EXPECT_EQ(1u, cloned_arr->AsArray()->GetCount()); 831 EXPECT_EQ(1u, cloned_arr->AsArray()->GetCount());
832 // Recursively referenced object is not cloned. 832 // Recursively referenced object is not cloned.
833 EXPECT_EQ(nullptr, cloned_arr->AsArray()->GetObjectAt(0)); 833 EXPECT_EQ(nullptr, cloned_arr->AsArray()->GetObjectAt(0));
834 } 834 }
835 } 835 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_parser/cpdf_document.cpp ('k') | core/fpdfapi/fpdf_parser/include/cpdf_array.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698