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 16 matching lines...) Expand all Loading... |
27 void TestArrayAccessors(const CPDF_Array* arr, | 27 void TestArrayAccessors(const CPDF_Array* arr, |
28 size_t index, | 28 size_t index, |
29 const char* str_val, | 29 const char* str_val, |
30 const char* const_str_val, | 30 const char* const_str_val, |
31 int int_val, | 31 int int_val, |
32 float float_val, | 32 float float_val, |
33 CPDF_Array* arr_val, | 33 CPDF_Array* arr_val, |
34 CPDF_Dictionary* dict_val, | 34 CPDF_Dictionary* dict_val, |
35 CPDF_Stream* stream_val) { | 35 CPDF_Stream* stream_val) { |
36 EXPECT_STREQ(str_val, arr->GetStringAt(index).c_str()); | 36 EXPECT_STREQ(str_val, arr->GetStringAt(index).c_str()); |
37 EXPECT_STREQ(const_str_val, arr->GetConstStringAt(index).GetCStr()); | 37 EXPECT_STREQ(const_str_val, arr->GetConstStringAt(index).c_str()); |
38 EXPECT_EQ(int_val, arr->GetIntegerAt(index)); | 38 EXPECT_EQ(int_val, arr->GetIntegerAt(index)); |
39 EXPECT_EQ(float_val, arr->GetNumberAt(index)); | 39 EXPECT_EQ(float_val, arr->GetNumberAt(index)); |
40 EXPECT_EQ(float_val, arr->GetFloatAt(index)); | 40 EXPECT_EQ(float_val, arr->GetFloatAt(index)); |
41 EXPECT_EQ(arr_val, arr->GetArrayAt(index)); | 41 EXPECT_EQ(arr_val, arr->GetArrayAt(index)); |
42 EXPECT_EQ(dict_val, arr->GetDictAt(index)); | 42 EXPECT_EQ(dict_val, arr->GetDictAt(index)); |
43 EXPECT_EQ(stream_val, arr->GetStreamAt(index)); | 43 EXPECT_EQ(stream_val, arr->GetStreamAt(index)); |
44 } | 44 } |
45 | 45 |
46 } // namespace | 46 } // namespace |
47 | 47 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 } | 200 } |
201 | 201 |
202 TEST_F(PDFObjectsTest, GetConstString) { | 202 TEST_F(PDFObjectsTest, GetConstString) { |
203 const char* direct_obj_results[] = { | 203 const char* direct_obj_results[] = { |
204 nullptr, nullptr, nullptr, nullptr, "A simple test", "\t\n", | 204 nullptr, nullptr, nullptr, nullptr, "A simple test", "\t\n", |
205 "space", nullptr, nullptr, nullptr, nullptr}; | 205 "space", nullptr, nullptr, nullptr, nullptr}; |
206 // Check for direct objects. | 206 // Check for direct objects. |
207 for (size_t i = 0; i < m_DirectObjs.size(); ++i) { | 207 for (size_t i = 0; i < m_DirectObjs.size(); ++i) { |
208 if (!direct_obj_results[i]) { | 208 if (!direct_obj_results[i]) { |
209 EXPECT_EQ(direct_obj_results[i], | 209 EXPECT_EQ(direct_obj_results[i], |
210 m_DirectObjs[i]->GetConstString().GetCStr()); | 210 m_DirectObjs[i]->GetConstString().c_str()); |
211 } else { | 211 } else { |
212 EXPECT_STREQ(direct_obj_results[i], | 212 EXPECT_STREQ(direct_obj_results[i], |
213 m_DirectObjs[i]->GetConstString().GetCStr()); | 213 m_DirectObjs[i]->GetConstString().c_str()); |
214 } | 214 } |
215 } | 215 } |
216 // Check indirect references. | 216 // Check indirect references. |
217 const char* indirect_obj_results[] = {nullptr, nullptr, "\t\n", "space", | 217 const char* indirect_obj_results[] = {nullptr, nullptr, "\t\n", "space", |
218 nullptr, nullptr, nullptr}; | 218 nullptr, nullptr, nullptr}; |
219 for (size_t i = 0; i < m_RefObjs.size(); ++i) { | 219 for (size_t i = 0; i < m_RefObjs.size(); ++i) { |
220 if (!indirect_obj_results[i]) { | 220 if (!indirect_obj_results[i]) { |
221 EXPECT_EQ(nullptr, m_RefObjs[i]->GetConstString().GetCStr()); | 221 EXPECT_EQ(nullptr, m_RefObjs[i]->GetConstString().c_str()); |
222 } else { | 222 } else { |
223 EXPECT_STREQ(indirect_obj_results[i], | 223 EXPECT_STREQ(indirect_obj_results[i], |
224 m_RefObjs[i]->GetConstString().GetCStr()); | 224 m_RefObjs[i]->GetConstString().c_str()); |
225 } | 225 } |
226 } | 226 } |
227 } | 227 } |
228 | 228 |
229 TEST_F(PDFObjectsTest, GetUnicodeText) { | 229 TEST_F(PDFObjectsTest, GetUnicodeText) { |
230 const wchar_t* direct_obj_results[] = { | 230 const wchar_t* direct_obj_results[] = { |
231 L"", L"", L"", L"", L"A simple test", | 231 L"", L"", L"", L"", L"A simple test", |
232 L"\t\n", L"space", L"", L"", L"abcdefghijklmnopqrstuvwxyz", | 232 L"\t\n", L"space", L"", L"", L"abcdefghijklmnopqrstuvwxyz", |
233 L""}; | 233 L""}; |
234 // Check for direct objects. | 234 // Check for direct objects. |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 "It is a test!", "NAME", "test", "", "", "", ""}; | 670 "It is a test!", "NAME", "test", "", "", "", ""}; |
671 const char* const expected_cstr[] = { | 671 const char* const expected_cstr[] = { |
672 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, | 672 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, |
673 "It is a test!", "NAME", "test", nullptr, nullptr, nullptr, nullptr}; | 673 "It is a test!", "NAME", "test", nullptr, nullptr, nullptr, nullptr}; |
674 const int expected_int[] = {1, 0, 0, -1234, 2345, 0, 0, | 674 const int expected_int[] = {1, 0, 0, -1234, 2345, 0, 0, |
675 0, 0, 0, 0, 0, 0, 0}; | 675 0, 0, 0, 0, 0, 0, 0}; |
676 const float expected_float[] = {0, 0, 0, -1234, 2345, 0.05f, 0, | 676 const float expected_float[] = {0, 0, 0, -1234, 2345, 0.05f, 0, |
677 0, 0, 0, 0, 0, 0, 0}; | 677 0, 0, 0, 0, 0, 0, 0}; |
678 for (size_t i = 0; i < arr->GetCount(); ++i) { | 678 for (size_t i = 0; i < arr->GetCount(); ++i) { |
679 EXPECT_STREQ(expected_str[i], arr->GetStringAt(i).c_str()); | 679 EXPECT_STREQ(expected_str[i], arr->GetStringAt(i).c_str()); |
680 EXPECT_STREQ(expected_cstr[i], arr->GetConstStringAt(i).GetCStr()); | 680 EXPECT_STREQ(expected_cstr[i], arr->GetConstStringAt(i).c_str()); |
681 EXPECT_EQ(expected_int[i], arr->GetIntegerAt(i)); | 681 EXPECT_EQ(expected_int[i], arr->GetIntegerAt(i)); |
682 EXPECT_EQ(expected_float[i], arr->GetNumberAt(i)); | 682 EXPECT_EQ(expected_float[i], arr->GetNumberAt(i)); |
683 EXPECT_EQ(expected_float[i], arr->GetFloatAt(i)); | 683 EXPECT_EQ(expected_float[i], arr->GetFloatAt(i)); |
684 if (i == 11) | 684 if (i == 11) |
685 EXPECT_EQ(arr_val, arr->GetArrayAt(i)); | 685 EXPECT_EQ(arr_val, arr->GetArrayAt(i)); |
686 else | 686 else |
687 EXPECT_EQ(nullptr, arr->GetArrayAt(i)); | 687 EXPECT_EQ(nullptr, arr->GetArrayAt(i)); |
688 if (i == 13) { | 688 if (i == 13) { |
689 EXPECT_EQ(stream_dict, arr->GetDictAt(i)); | 689 EXPECT_EQ(stream_dict, arr->GetDictAt(i)); |
690 EXPECT_EQ(stream_val, arr->GetStreamAt(i)); | 690 EXPECT_EQ(stream_val, arr->GetStreamAt(i)); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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->GetObjectAt(i)->GetType()); | 769 EXPECT_EQ(CPDF_Object::REFERENCE, arr->GetObjectAt(i)->GetType()); |
770 EXPECT_EQ(indirect_objs[i], arr->GetObjectAt(i)->GetDirect()); | 770 EXPECT_EQ(indirect_objs[i], arr->GetObjectAt(i)->GetDirect()); |
771 EXPECT_EQ(indirect_objs[i], arr->GetDirectObjectAt(i)); | 771 EXPECT_EQ(indirect_objs[i], arr->GetDirectObjectAt(i)); |
772 EXPECT_EQ(CPDF_Object::REFERENCE, arr1->GetObjectAt(i)->GetType()); | 772 EXPECT_EQ(CPDF_Object::REFERENCE, arr1->GetObjectAt(i)->GetType()); |
773 EXPECT_EQ(indirect_objs[i], arr1->GetObjectAt(i)->GetDirect()); | 773 EXPECT_EQ(indirect_objs[i], arr1->GetObjectAt(i)->GetDirect()); |
774 EXPECT_EQ(indirect_objs[i], arr1->GetDirectObjectAt(i)); | 774 EXPECT_EQ(indirect_objs[i], arr1->GetDirectObjectAt(i)); |
775 } | 775 } |
776 } | 776 } |
OLD | NEW |