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_array.h" | 5 #include "core/fpdfapi/fpdf_parser/cpdf_array.h" |
6 #include "core/fpdfapi/fpdf_parser/cpdf_boolean.h" | 6 #include "core/fpdfapi/fpdf_parser/cpdf_boolean.h" |
7 #include "core/fpdfapi/fpdf_parser/cpdf_dictionary.h" | 7 #include "core/fpdfapi/fpdf_parser/cpdf_dictionary.h" |
8 #include "core/fpdfapi/fpdf_parser/cpdf_name.h" | 8 #include "core/fpdfapi/fpdf_parser/cpdf_name.h" |
9 #include "core/fpdfapi/fpdf_parser/cpdf_null.h" | 9 #include "core/fpdfapi/fpdf_parser/cpdf_null.h" |
10 #include "core/fpdfapi/fpdf_parser/cpdf_number.h" | 10 #include "core/fpdfapi/fpdf_parser/cpdf_number.h" |
11 #include "core/fpdfapi/fpdf_parser/cpdf_reference.h" | 11 #include "core/fpdfapi/fpdf_parser/cpdf_reference.h" |
12 #include "core/fpdfapi/fpdf_parser/cpdf_stream.h" | 12 #include "core/fpdfapi/fpdf_parser/cpdf_stream.h" |
13 #include "core/fpdfapi/fpdf_parser/cpdf_string.h" | 13 #include "core/fpdfapi/fpdf_parser/cpdf_string.h" |
14 | 14 |
15 #include <memory> | 15 #include <memory> |
16 #include <string> | 16 #include <string> |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
19 #include "core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.h" | 19 #include "core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.h" |
20 #include "core/fxcrt/fx_basic.h" | 20 #include "core/fxcrt/fx_basic.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 using ScopedArray = std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>>; | 25 using ScopedArray = std::unique_ptr<CPDF_Array>; |
Lei Zhang
2016/10/03 21:18:30
We can also just get rid of these.
Tom Sepez
2016/10/03 21:41:31
Done.
| |
26 using ScopedDict = | 26 using ScopedDict = std::unique_ptr<CPDF_Dictionary>; |
27 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>>; | |
28 | 27 |
29 void TestArrayAccessors(const CPDF_Array* arr, | 28 void TestArrayAccessors(const CPDF_Array* arr, |
30 size_t index, | 29 size_t index, |
31 const char* str_val, | 30 const char* str_val, |
32 const char* const_str_val, | 31 const char* const_str_val, |
33 int int_val, | 32 int int_val, |
34 float float_val, | 33 float float_val, |
35 CPDF_Array* arr_val, | 34 CPDF_Array* arr_val, |
36 CPDF_Dictionary* dict_val, | 35 CPDF_Dictionary* dict_val, |
37 CPDF_Stream* stream_val) { | 36 CPDF_Stream* stream_val) { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 stream1->GetRawSize()) == 0; | 164 stream1->GetRawSize()) == 0; |
166 } | 165 } |
167 case CPDF_Object::REFERENCE: | 166 case CPDF_Object::REFERENCE: |
168 return obj1->AsReference()->GetRefObjNum() == | 167 return obj1->AsReference()->GetRefObjNum() == |
169 obj2->AsReference()->GetRefObjNum(); | 168 obj2->AsReference()->GetRefObjNum(); |
170 } | 169 } |
171 return false; | 170 return false; |
172 } | 171 } |
173 | 172 |
174 protected: | 173 protected: |
175 using ScopedObj = std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>>; | 174 using ScopedObj = std::unique_ptr<CPDF_Object>; |
176 | 175 |
177 // m_ObjHolder needs to be declared first and destructed last since it also | 176 // m_ObjHolder needs to be declared first and destructed last since it also |
178 // refers to some objects in m_DirectObjs. | 177 // refers to some objects in m_DirectObjs. |
179 std::unique_ptr<CPDF_IndirectObjectHolder> m_ObjHolder; | 178 std::unique_ptr<CPDF_IndirectObjectHolder> m_ObjHolder; |
180 std::vector<ScopedObj> m_DirectObjs; | 179 std::vector<ScopedObj> m_DirectObjs; |
181 std::vector<int> m_DirectObjTypes; | 180 std::vector<int> m_DirectObjTypes; |
182 std::vector<ScopedObj> m_RefObjs; | 181 std::vector<ScopedObj> m_RefObjs; |
183 CPDF_Dictionary* m_DictObj; | 182 CPDF_Dictionary* m_DictObj; |
184 CPDF_Dictionary* m_StreamDictObj; | 183 CPDF_Dictionary* m_StreamDictObj; |
185 CPDF_Array* m_ArrayObj; | 184 CPDF_Array* m_ArrayObj; |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
828 // Cloned object should be the same as the original. | 827 // Cloned object should be the same as the original. |
829 ASSERT_TRUE(cloned_dict); | 828 ASSERT_TRUE(cloned_dict); |
830 CPDF_Object* cloned_arr = cloned_dict->GetObjectFor("arr"); | 829 CPDF_Object* cloned_arr = cloned_dict->GetObjectFor("arr"); |
831 ASSERT_TRUE(cloned_arr); | 830 ASSERT_TRUE(cloned_arr); |
832 ASSERT_TRUE(cloned_arr->IsArray()); | 831 ASSERT_TRUE(cloned_arr->IsArray()); |
833 EXPECT_EQ(1u, cloned_arr->AsArray()->GetCount()); | 832 EXPECT_EQ(1u, cloned_arr->AsArray()->GetCount()); |
834 // Recursively referenced object is not cloned. | 833 // Recursively referenced object is not cloned. |
835 EXPECT_EQ(nullptr, cloned_arr->AsArray()->GetObjectAt(0)); | 834 EXPECT_EQ(nullptr, cloned_arr->AsArray()->GetObjectAt(0)); |
836 } | 835 } |
837 } | 836 } |
OLD | NEW |