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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 obj1->GetInteger() == obj2->GetInteger(); | 116 obj1->GetInteger() == obj2->GetInteger(); |
117 case CPDF_Object::STRING: | 117 case CPDF_Object::STRING: |
118 case CPDF_Object::NAME: | 118 case CPDF_Object::NAME: |
119 return obj1->GetString() == obj2->GetString(); | 119 return obj1->GetString() == obj2->GetString(); |
120 case CPDF_Object::ARRAY: { | 120 case CPDF_Object::ARRAY: { |
121 const CPDF_Array* array1 = obj1->AsArray(); | 121 const CPDF_Array* array1 = obj1->AsArray(); |
122 const CPDF_Array* array2 = obj2->AsArray(); | 122 const CPDF_Array* array2 = obj2->AsArray(); |
123 if (array1->GetCount() != array2->GetCount()) | 123 if (array1->GetCount() != array2->GetCount()) |
124 return false; | 124 return false; |
125 for (size_t i = 0; i < array1->GetCount(); ++i) { | 125 for (size_t i = 0; i < array1->GetCount(); ++i) { |
126 if (!Equal(array1->GetElement(i), array2->GetElement(i))) | 126 if (!Equal(array1->GetObjectAt(i), array2->GetObjectAt(i))) |
127 return false; | 127 return false; |
128 } | 128 } |
129 return true; | 129 return true; |
130 } | 130 } |
131 case CPDF_Object::DICTIONARY: { | 131 case CPDF_Object::DICTIONARY: { |
132 const CPDF_Dictionary* dict1 = obj1->AsDictionary(); | 132 const CPDF_Dictionary* dict1 = obj1->AsDictionary(); |
133 const CPDF_Dictionary* dict2 = obj2->AsDictionary(); | 133 const CPDF_Dictionary* dict2 = obj2->AsDictionary(); |
134 if (dict1->GetCount() != dict2->GetCount()) | 134 if (dict1->GetCount() != dict2->GetCount()) |
135 return false; | 135 return false; |
136 for (CPDF_Dictionary::const_iterator it = dict1->begin(); | 136 for (CPDF_Dictionary::const_iterator it = dict1->begin(); |
137 it != dict1->end(); ++it) { | 137 it != dict1->end(); ++it) { |
138 if (!Equal(it->second, dict2->GetElement(it->first))) | 138 if (!Equal(it->second, dict2->GetObjectBy(it->first))) |
139 return false; | 139 return false; |
140 } | 140 } |
141 return true; | 141 return true; |
142 } | 142 } |
143 case CPDF_Object::NULLOBJ: | 143 case CPDF_Object::NULLOBJ: |
144 return true; | 144 return true; |
145 case CPDF_Object::STREAM: { | 145 case CPDF_Object::STREAM: { |
146 const CPDF_Stream* stream1 = obj1->AsStream(); | 146 const CPDF_Stream* stream1 = obj1->AsStream(); |
147 const CPDF_Stream* stream2 = obj2->AsStream(); | 147 const CPDF_Stream* stream2 = obj2->AsStream(); |
148 if (!stream1->GetDict() && !stream2->GetDict()) | 148 if (!stream1->GetDict() && !stream2->GetDict()) |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 } | 699 } |
700 } | 700 } |
701 | 701 |
702 TEST(PDFArrayTest, AddNumber) { | 702 TEST(PDFArrayTest, AddNumber) { |
703 float vals[] = {1.0f, -1.0f, 0, 0.456734f, | 703 float vals[] = {1.0f, -1.0f, 0, 0.456734f, |
704 12345.54321f, 0.5f, 1000, 0.000045f}; | 704 12345.54321f, 0.5f, 1000, 0.000045f}; |
705 ScopedArray arr(new CPDF_Array); | 705 ScopedArray arr(new CPDF_Array); |
706 for (size_t i = 0; i < FX_ArraySize(vals); ++i) | 706 for (size_t i = 0; i < FX_ArraySize(vals); ++i) |
707 arr->AddNumber(vals[i]); | 707 arr->AddNumber(vals[i]); |
708 for (size_t i = 0; i < FX_ArraySize(vals); ++i) { | 708 for (size_t i = 0; i < FX_ArraySize(vals); ++i) { |
709 EXPECT_EQ(CPDF_Object::NUMBER, arr->GetElement(i)->GetType()); | 709 EXPECT_EQ(CPDF_Object::NUMBER, arr->GetObjectAt(i)->GetType()); |
710 EXPECT_EQ(vals[i], arr->GetElement(i)->GetNumber()); | 710 EXPECT_EQ(vals[i], arr->GetObjectAt(i)->GetNumber()); |
711 } | 711 } |
712 } | 712 } |
713 | 713 |
714 TEST(PDFArrayTest, AddInteger) { | 714 TEST(PDFArrayTest, AddInteger) { |
715 int vals[] = {0, 1, 934435456, 876, 10000, -1, -24354656, -100}; | 715 int vals[] = {0, 1, 934435456, 876, 10000, -1, -24354656, -100}; |
716 ScopedArray arr(new CPDF_Array); | 716 ScopedArray arr(new CPDF_Array); |
717 for (size_t i = 0; i < FX_ArraySize(vals); ++i) | 717 for (size_t i = 0; i < FX_ArraySize(vals); ++i) |
718 arr->AddInteger(vals[i]); | 718 arr->AddInteger(vals[i]); |
719 for (size_t i = 0; i < FX_ArraySize(vals); ++i) { | 719 for (size_t i = 0; i < FX_ArraySize(vals); ++i) { |
720 EXPECT_EQ(CPDF_Object::NUMBER, arr->GetElement(i)->GetType()); | 720 EXPECT_EQ(CPDF_Object::NUMBER, arr->GetObjectAt(i)->GetType()); |
721 EXPECT_EQ(vals[i], arr->GetElement(i)->GetNumber()); | 721 EXPECT_EQ(vals[i], arr->GetObjectAt(i)->GetNumber()); |
722 } | 722 } |
723 } | 723 } |
724 | 724 |
725 TEST(PDFArrayTest, AddStringAndName) { | 725 TEST(PDFArrayTest, AddStringAndName) { |
726 const char* vals[] = {"", "a", "ehjhRIOYTTFdfcdnv", "122323", | 726 const char* vals[] = {"", "a", "ehjhRIOYTTFdfcdnv", "122323", |
727 "$#%^&**", " ", "This is a test.\r\n"}; | 727 "$#%^&**", " ", "This is a test.\r\n"}; |
728 ScopedArray string_array(new CPDF_Array); | 728 ScopedArray string_array(new CPDF_Array); |
729 ScopedArray name_array(new CPDF_Array); | 729 ScopedArray name_array(new CPDF_Array); |
730 for (size_t i = 0; i < FX_ArraySize(vals); ++i) { | 730 for (size_t i = 0; i < FX_ArraySize(vals); ++i) { |
731 string_array->AddString(vals[i]); | 731 string_array->AddString(vals[i]); |
732 name_array->AddName(vals[i]); | 732 name_array->AddName(vals[i]); |
733 } | 733 } |
734 for (size_t i = 0; i < FX_ArraySize(vals); ++i) { | 734 for (size_t i = 0; i < FX_ArraySize(vals); ++i) { |
735 EXPECT_EQ(CPDF_Object::STRING, string_array->GetElement(i)->GetType()); | 735 EXPECT_EQ(CPDF_Object::STRING, string_array->GetObjectAt(i)->GetType()); |
736 EXPECT_STREQ(vals[i], string_array->GetElement(i)->GetString().c_str()); | 736 EXPECT_STREQ(vals[i], string_array->GetObjectAt(i)->GetString().c_str()); |
737 EXPECT_EQ(CPDF_Object::NAME, name_array->GetElement(i)->GetType()); | 737 EXPECT_EQ(CPDF_Object::NAME, name_array->GetObjectAt(i)->GetType()); |
738 EXPECT_STREQ(vals[i], name_array->GetElement(i)->GetString().c_str()); | 738 EXPECT_STREQ(vals[i], name_array->GetObjectAt(i)->GetString().c_str()); |
739 } | 739 } |
740 } | 740 } |
741 | 741 |
742 TEST(PDFArrayTest, AddReferenceAndGetElement) { | 742 TEST(PDFArrayTest, AddReferenceAndGetObjectAt) { |
743 std::unique_ptr<CPDF_IndirectObjectHolder> holder( | 743 std::unique_ptr<CPDF_IndirectObjectHolder> holder( |
744 new CPDF_IndirectObjectHolder(nullptr)); | 744 new CPDF_IndirectObjectHolder(nullptr)); |
745 CPDF_Boolean* boolean_obj = new CPDF_Boolean(true); | 745 CPDF_Boolean* boolean_obj = new CPDF_Boolean(true); |
746 CPDF_Number* int_obj = new CPDF_Number(-1234); | 746 CPDF_Number* int_obj = new CPDF_Number(-1234); |
747 CPDF_Number* float_obj = new CPDF_Number(2345.089f); | 747 CPDF_Number* float_obj = new CPDF_Number(2345.089f); |
748 CPDF_String* str_obj = new CPDF_String("Adsfdsf 343434 %&&*\n", false); | 748 CPDF_String* str_obj = new CPDF_String("Adsfdsf 343434 %&&*\n", false); |
749 CPDF_Name* name_obj = new CPDF_Name("Title:"); | 749 CPDF_Name* name_obj = new CPDF_Name("Title:"); |
750 CPDF_Null* null_obj = new CPDF_Null(); | 750 CPDF_Null* null_obj = new CPDF_Null(); |
751 CPDF_Object* indirect_objs[] = {boolean_obj, int_obj, float_obj, | 751 CPDF_Object* indirect_objs[] = {boolean_obj, int_obj, float_obj, |
752 str_obj, name_obj, null_obj}; | 752 str_obj, name_obj, null_obj}; |
753 unsigned int obj_nums[] = {2, 4, 7, 2345, 799887, 1}; | 753 unsigned int obj_nums[] = {2, 4, 7, 2345, 799887, 1}; |
754 ScopedArray arr(new CPDF_Array); | 754 ScopedArray arr(new CPDF_Array); |
755 ScopedArray arr1(new CPDF_Array); | 755 ScopedArray arr1(new CPDF_Array); |
756 // Create two arrays of references by different AddReference() APIs. | 756 // Create two arrays of references by different AddReference() APIs. |
757 for (size_t i = 0; i < FX_ArraySize(indirect_objs); ++i) { | 757 for (size_t i = 0; i < FX_ArraySize(indirect_objs); ++i) { |
758 // All the indirect objects inserted will be owned by holder. | 758 // All the indirect objects inserted will be owned by holder. |
759 holder->InsertIndirectObject(obj_nums[i], indirect_objs[i]); | 759 holder->InsertIndirectObject(obj_nums[i], indirect_objs[i]); |
760 arr->AddReference(holder.get(), obj_nums[i]); | 760 arr->AddReference(holder.get(), obj_nums[i]); |
761 arr1->AddReference(holder.get(), indirect_objs[i]); | 761 arr1->AddReference(holder.get(), indirect_objs[i]); |
762 } | 762 } |
763 // Check indirect objects. | 763 // Check indirect objects. |
764 for (size_t i = 0; i < FX_ArraySize(obj_nums); ++i) | 764 for (size_t i = 0; i < FX_ArraySize(obj_nums); ++i) |
765 EXPECT_EQ(indirect_objs[i], holder->GetIndirectObject(obj_nums[i])); | 765 EXPECT_EQ(indirect_objs[i], holder->GetIndirectObject(obj_nums[i])); |
766 // Check arrays. | 766 // Check arrays. |
767 EXPECT_EQ(arr->GetCount(), arr1->GetCount()); | 767 EXPECT_EQ(arr->GetCount(), arr1->GetCount()); |
768 for (size_t i = 0; i < arr->GetCount(); ++i) { | 768 for (size_t i = 0; i < arr->GetCount(); ++i) { |
769 EXPECT_EQ(CPDF_Object::REFERENCE, arr->GetElement(i)->GetType()); | 769 EXPECT_EQ(CPDF_Object::REFERENCE, arr->GetObjectAt(i)->GetType()); |
770 EXPECT_EQ(indirect_objs[i], arr->GetElement(i)->GetDirect()); | 770 EXPECT_EQ(indirect_objs[i], arr->GetObjectAt(i)->GetDirect()); |
771 EXPECT_EQ(indirect_objs[i], arr->GetElementValue(i)); | 771 EXPECT_EQ(indirect_objs[i], arr->GetDirectObjectAt(i)); |
772 EXPECT_EQ(CPDF_Object::REFERENCE, arr1->GetElement(i)->GetType()); | 772 EXPECT_EQ(CPDF_Object::REFERENCE, arr1->GetObjectAt(i)->GetType()); |
773 EXPECT_EQ(indirect_objs[i], arr1->GetElement(i)->GetDirect()); | 773 EXPECT_EQ(indirect_objs[i], arr1->GetObjectAt(i)->GetDirect()); |
774 EXPECT_EQ(indirect_objs[i], arr1->GetElementValue(i)); | 774 EXPECT_EQ(indirect_objs[i], arr1->GetDirectObjectAt(i)); |
775 } | 775 } |
776 } | 776 } |
OLD | NEW |