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).c_str()); | |
38 EXPECT_EQ(int_val, arr->GetIntegerAt(index)); | 37 EXPECT_EQ(int_val, arr->GetIntegerAt(index)); |
39 EXPECT_EQ(float_val, arr->GetNumberAt(index)); | 38 EXPECT_EQ(float_val, arr->GetNumberAt(index)); |
40 EXPECT_EQ(float_val, arr->GetFloatAt(index)); | 39 EXPECT_EQ(float_val, arr->GetFloatAt(index)); |
41 EXPECT_EQ(arr_val, arr->GetArrayAt(index)); | 40 EXPECT_EQ(arr_val, arr->GetArrayAt(index)); |
42 EXPECT_EQ(dict_val, arr->GetDictAt(index)); | 41 EXPECT_EQ(dict_val, arr->GetDictAt(index)); |
43 EXPECT_EQ(stream_val, arr->GetStreamAt(index)); | 42 EXPECT_EQ(stream_val, arr->GetStreamAt(index)); |
44 } | 43 } |
45 | 44 |
46 } // namespace | 45 } // namespace |
47 | 46 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 EXPECT_STREQ(direct_obj_results[i], m_DirectObjs[i]->GetString().c_str()); | 191 EXPECT_STREQ(direct_obj_results[i], m_DirectObjs[i]->GetString().c_str()); |
193 | 192 |
194 // Check indirect references. | 193 // Check indirect references. |
195 const char* indirect_obj_results[] = {"true", "1245", "\t\n", "space", | 194 const char* indirect_obj_results[] = {"true", "1245", "\t\n", "space", |
196 "", "", ""}; | 195 "", "", ""}; |
197 for (size_t i = 0; i < m_RefObjs.size(); ++i) { | 196 for (size_t i = 0; i < m_RefObjs.size(); ++i) { |
198 EXPECT_STREQ(indirect_obj_results[i], m_RefObjs[i]->GetString().c_str()); | 197 EXPECT_STREQ(indirect_obj_results[i], m_RefObjs[i]->GetString().c_str()); |
199 } | 198 } |
200 } | 199 } |
201 | 200 |
202 TEST_F(PDFObjectsTest, GetConstString) { | |
203 const char* direct_obj_results[] = { | |
204 nullptr, nullptr, nullptr, nullptr, "A simple test", "\t\n", | |
205 "space", nullptr, nullptr, nullptr, nullptr}; | |
206 // Check for direct objects. | |
207 for (size_t i = 0; i < m_DirectObjs.size(); ++i) { | |
208 if (!direct_obj_results[i]) { | |
209 EXPECT_EQ(direct_obj_results[i], | |
210 m_DirectObjs[i]->GetConstString().c_str()); | |
211 } else { | |
212 EXPECT_STREQ(direct_obj_results[i], | |
213 m_DirectObjs[i]->GetConstString().c_str()); | |
214 } | |
215 } | |
216 // Check indirect references. | |
217 const char* indirect_obj_results[] = {nullptr, nullptr, "\t\n", "space", | |
218 nullptr, nullptr, nullptr}; | |
219 for (size_t i = 0; i < m_RefObjs.size(); ++i) { | |
220 if (!indirect_obj_results[i]) { | |
221 EXPECT_EQ(nullptr, m_RefObjs[i]->GetConstString().c_str()); | |
222 } else { | |
223 EXPECT_STREQ(indirect_obj_results[i], | |
224 m_RefObjs[i]->GetConstString().c_str()); | |
225 } | |
226 } | |
227 } | |
228 | |
229 TEST_F(PDFObjectsTest, GetUnicodeText) { | 201 TEST_F(PDFObjectsTest, GetUnicodeText) { |
230 const wchar_t* direct_obj_results[] = { | 202 const wchar_t* direct_obj_results[] = { |
231 L"", L"", L"", L"", L"A simple test", | 203 L"", L"", L"", L"", L"A simple test", |
232 L"\t\n", L"space", L"", L"", L"abcdefghijklmnopqrstuvwxyz", | 204 L"\t\n", L"space", L"", L"", L"abcdefghijklmnopqrstuvwxyz", |
233 L""}; | 205 L""}; |
234 // Check for direct objects. | 206 // Check for direct objects. |
235 for (size_t i = 0; i < m_DirectObjs.size(); ++i) | 207 for (size_t i = 0; i < m_DirectObjs.size(); ++i) |
236 EXPECT_STREQ(direct_obj_results[i], | 208 EXPECT_STREQ(direct_obj_results[i], |
237 m_DirectObjs[i]->GetUnicodeText().c_str()); | 209 m_DirectObjs[i]->GetUnicodeText().c_str()); |
238 | 210 |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 // The data buffer will be owned by stream object, so it needs to be | 633 // The data buffer will be owned by stream object, so it needs to be |
662 // dynamically allocated. | 634 // dynamically allocated. |
663 size_t buf_size = sizeof(data); | 635 size_t buf_size = sizeof(data); |
664 uint8_t* buf = reinterpret_cast<uint8_t*>(malloc(buf_size)); | 636 uint8_t* buf = reinterpret_cast<uint8_t*>(malloc(buf_size)); |
665 memcpy(buf, data, buf_size); | 637 memcpy(buf, data, buf_size); |
666 CPDF_Stream* stream_val = new CPDF_Stream(buf, buf_size, stream_dict); | 638 CPDF_Stream* stream_val = new CPDF_Stream(buf, buf_size, stream_dict); |
667 arr->InsertAt(13, stream_val); | 639 arr->InsertAt(13, stream_val); |
668 const char* const expected_str[] = { | 640 const char* const expected_str[] = { |
669 "true", "false", "0", "-1234", "2345", "0.05", "", | 641 "true", "false", "0", "-1234", "2345", "0.05", "", |
670 "It is a test!", "NAME", "test", "", "", "", ""}; | 642 "It is a test!", "NAME", "test", "", "", "", ""}; |
671 const char* const expected_cstr[] = { | |
672 nullptr, nullptr, nullptr, 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, | 643 const int expected_int[] = {1, 0, 0, -1234, 2345, 0, 0, |
675 0, 0, 0, 0, 0, 0, 0}; | 644 0, 0, 0, 0, 0, 0, 0}; |
676 const float expected_float[] = {0, 0, 0, -1234, 2345, 0.05f, 0, | 645 const float expected_float[] = {0, 0, 0, -1234, 2345, 0.05f, 0, |
677 0, 0, 0, 0, 0, 0, 0}; | 646 0, 0, 0, 0, 0, 0, 0}; |
678 for (size_t i = 0; i < arr->GetCount(); ++i) { | 647 for (size_t i = 0; i < arr->GetCount(); ++i) { |
679 EXPECT_STREQ(expected_str[i], arr->GetStringAt(i).c_str()); | 648 EXPECT_STREQ(expected_str[i], arr->GetStringAt(i).c_str()); |
680 EXPECT_STREQ(expected_cstr[i], arr->GetConstStringAt(i).c_str()); | |
681 EXPECT_EQ(expected_int[i], arr->GetIntegerAt(i)); | 649 EXPECT_EQ(expected_int[i], arr->GetIntegerAt(i)); |
682 EXPECT_EQ(expected_float[i], arr->GetNumberAt(i)); | 650 EXPECT_EQ(expected_float[i], arr->GetNumberAt(i)); |
683 EXPECT_EQ(expected_float[i], arr->GetFloatAt(i)); | 651 EXPECT_EQ(expected_float[i], arr->GetFloatAt(i)); |
684 if (i == 11) | 652 if (i == 11) |
685 EXPECT_EQ(arr_val, arr->GetArrayAt(i)); | 653 EXPECT_EQ(arr_val, arr->GetArrayAt(i)); |
686 else | 654 else |
687 EXPECT_EQ(nullptr, arr->GetArrayAt(i)); | 655 EXPECT_EQ(nullptr, arr->GetArrayAt(i)); |
688 if (i == 13) { | 656 if (i == 13) { |
689 EXPECT_EQ(stream_dict, arr->GetDictAt(i)); | 657 EXPECT_EQ(stream_dict, arr->GetDictAt(i)); |
690 EXPECT_EQ(stream_val, arr->GetStreamAt(i)); | 658 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()); | 735 EXPECT_EQ(arr->GetCount(), arr1->GetCount()); |
768 for (size_t i = 0; i < arr->GetCount(); ++i) { | 736 for (size_t i = 0; i < arr->GetCount(); ++i) { |
769 EXPECT_EQ(CPDF_Object::REFERENCE, arr->GetObjectAt(i)->GetType()); | 737 EXPECT_EQ(CPDF_Object::REFERENCE, arr->GetObjectAt(i)->GetType()); |
770 EXPECT_EQ(indirect_objs[i], arr->GetObjectAt(i)->GetDirect()); | 738 EXPECT_EQ(indirect_objs[i], arr->GetObjectAt(i)->GetDirect()); |
771 EXPECT_EQ(indirect_objs[i], arr->GetDirectObjectAt(i)); | 739 EXPECT_EQ(indirect_objs[i], arr->GetDirectObjectAt(i)); |
772 EXPECT_EQ(CPDF_Object::REFERENCE, arr1->GetObjectAt(i)->GetType()); | 740 EXPECT_EQ(CPDF_Object::REFERENCE, arr1->GetObjectAt(i)->GetType()); |
773 EXPECT_EQ(indirect_objs[i], arr1->GetObjectAt(i)->GetDirect()); | 741 EXPECT_EQ(indirect_objs[i], arr1->GetObjectAt(i)->GetDirect()); |
774 EXPECT_EQ(indirect_objs[i], arr1->GetDirectObjectAt(i)); | 742 EXPECT_EQ(indirect_objs[i], arr1->GetDirectObjectAt(i)); |
775 } | 743 } |
776 } | 744 } |
OLD | NEW |