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

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

Issue 2509123002: Make CPDF_Object subclass constructors intern strings (Closed)
Patch Set: Nits Created 4 years, 1 month 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
« no previous file with comments | « core/fpdfapi/parser/cpdf_object.h ('k') | core/fpdfapi/parser/cpdf_string.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/parser/cpdf_array.h" 5 #include "core/fpdfapi/parser/cpdf_array.h"
6 #include "core/fpdfapi/parser/cpdf_boolean.h" 6 #include "core/fpdfapi/parser/cpdf_boolean.h"
7 #include "core/fpdfapi/parser/cpdf_dictionary.h" 7 #include "core/fpdfapi/parser/cpdf_dictionary.h"
8 #include "core/fpdfapi/parser/cpdf_name.h" 8 #include "core/fpdfapi/parser/cpdf_name.h"
9 #include "core/fpdfapi/parser/cpdf_null.h" 9 #include "core/fpdfapi/parser/cpdf_null.h"
10 #include "core/fpdfapi/parser/cpdf_number.h" 10 #include "core/fpdfapi/parser/cpdf_number.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // Boolean objects. 49 // Boolean objects.
50 CPDF_Boolean* boolean_false_obj = new CPDF_Boolean(false); 50 CPDF_Boolean* boolean_false_obj = new CPDF_Boolean(false);
51 CPDF_Boolean* boolean_true_obj = new CPDF_Boolean(true); 51 CPDF_Boolean* boolean_true_obj = new CPDF_Boolean(true);
52 // Number objects. 52 // Number objects.
53 CPDF_Number* number_int_obj = new CPDF_Number(1245); 53 CPDF_Number* number_int_obj = new CPDF_Number(1245);
54 CPDF_Number* number_float_obj = new CPDF_Number(9.00345f); 54 CPDF_Number* number_float_obj = new CPDF_Number(9.00345f);
55 // String objects. 55 // String objects.
56 CPDF_String* str_reg_obj = new CPDF_String(L"A simple test"); 56 CPDF_String* str_reg_obj = new CPDF_String(L"A simple test");
57 CPDF_String* str_spec_obj = new CPDF_String(L"\t\n"); 57 CPDF_String* str_spec_obj = new CPDF_String(L"\t\n");
58 // Name object. 58 // Name object.
59 CPDF_Name* name_obj = new CPDF_Name("space"); 59 CPDF_Name* name_obj = new CPDF_Name(nullptr, "space");
60 // Array object. 60 // Array object.
61 m_ArrayObj = new CPDF_Array; 61 m_ArrayObj = new CPDF_Array;
62 m_ArrayObj->InsertNewAt<CPDF_Number>(0, 8902); 62 m_ArrayObj->InsertNewAt<CPDF_Number>(0, 8902);
63 m_ArrayObj->InsertNewAt<CPDF_Name>(1, "address"); 63 m_ArrayObj->InsertNewAt<CPDF_Name>(1, "address");
64 // Dictionary object. 64 // Dictionary object.
65 m_DictObj = new CPDF_Dictionary(); 65 m_DictObj = new CPDF_Dictionary();
66 m_DictObj->SetFor("bool", new CPDF_Boolean(false)); 66 m_DictObj->SetFor("bool", new CPDF_Boolean(false));
67 m_DictObj->SetFor("num", new CPDF_Number(0.23f)); 67 m_DictObj->SetFor("num", new CPDF_Number(0.23f));
68 // Stream object. 68 // Stream object.
69 const char content[] = "abcdefghijklmnopqrstuvwxyz"; 69 const char content[] = "abcdefghijklmnopqrstuvwxyz";
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 arr->InsertNewAt<CPDF_String>(7, "It is a test!", false); 613 arr->InsertNewAt<CPDF_String>(7, "It is a test!", false);
614 arr->InsertNewAt<CPDF_Name>(8, "NAME"); 614 arr->InsertNewAt<CPDF_Name>(8, "NAME");
615 arr->InsertNewAt<CPDF_Name>(9, "test"); 615 arr->InsertNewAt<CPDF_Name>(9, "test");
616 arr->InsertNewAt<CPDF_Null>(10); 616 arr->InsertNewAt<CPDF_Null>(10);
617 617
618 CPDF_Array* arr_val = arr->InsertNewAt<CPDF_Array>(11); 618 CPDF_Array* arr_val = arr->InsertNewAt<CPDF_Array>(11);
619 arr_val->AddNew<CPDF_Number>(1); 619 arr_val->AddNew<CPDF_Number>(1);
620 arr_val->AddNew<CPDF_Number>(2); 620 arr_val->AddNew<CPDF_Number>(2);
621 621
622 CPDF_Dictionary* dict_val = arr->InsertNewAt<CPDF_Dictionary>(12); 622 CPDF_Dictionary* dict_val = arr->InsertNewAt<CPDF_Dictionary>(12);
623 dict_val->SetFor("key1", new CPDF_String("Linda", false)); 623 dict_val->SetFor("key1", new CPDF_String(nullptr, "Linda", false));
624 dict_val->SetFor("key2", new CPDF_String("Zoe", false)); 624 dict_val->SetFor("key2", new CPDF_String(nullptr, "Zoe", false));
625 625
626 CPDF_Dictionary* stream_dict = new CPDF_Dictionary(); 626 CPDF_Dictionary* stream_dict = new CPDF_Dictionary();
627 stream_dict->SetFor("key1", new CPDF_String("John", false)); 627 stream_dict->SetFor("key1", new CPDF_String(nullptr, "John", false));
628 stream_dict->SetFor("key2", new CPDF_String("King", false)); 628 stream_dict->SetFor("key2", new CPDF_String(nullptr, "King", false));
629 uint8_t data[] = "A stream for test"; 629 uint8_t data[] = "A stream for test";
630 // The data buffer will be owned by stream object, so it needs to be 630 // The data buffer will be owned by stream object, so it needs to be
631 // dynamically allocated. 631 // dynamically allocated.
632 size_t buf_size = sizeof(data); 632 size_t buf_size = sizeof(data);
633 uint8_t* buf = reinterpret_cast<uint8_t*>(malloc(buf_size)); 633 uint8_t* buf = reinterpret_cast<uint8_t*>(malloc(buf_size));
634 memcpy(buf, data, buf_size); 634 memcpy(buf, data, buf_size);
635 CPDF_Stream* stream_val = 635 CPDF_Stream* stream_val =
636 arr->InsertNewAt<CPDF_Stream>(13, buf, buf_size, stream_dict); 636 arr->InsertNewAt<CPDF_Stream>(13, buf, buf_size, stream_dict);
637 const char* const expected_str[] = { 637 const char* const expected_str[] = {
638 "true", "false", "0", "-1234", "2345", "0.05", "", 638 "true", "false", "0", "-1234", "2345", "0.05", "",
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 EXPECT_STREQ(vals[i], name_array->GetObjectAt(i)->GetString().c_str()); 703 EXPECT_STREQ(vals[i], name_array->GetObjectAt(i)->GetString().c_str());
704 } 704 }
705 } 705 }
706 706
707 TEST(PDFArrayTest, AddReferenceAndGetObjectAt) { 707 TEST(PDFArrayTest, AddReferenceAndGetObjectAt) {
708 std::unique_ptr<CPDF_IndirectObjectHolder> holder( 708 std::unique_ptr<CPDF_IndirectObjectHolder> holder(
709 new CPDF_IndirectObjectHolder()); 709 new CPDF_IndirectObjectHolder());
710 CPDF_Boolean* boolean_obj = new CPDF_Boolean(true); 710 CPDF_Boolean* boolean_obj = new CPDF_Boolean(true);
711 CPDF_Number* int_obj = new CPDF_Number(-1234); 711 CPDF_Number* int_obj = new CPDF_Number(-1234);
712 CPDF_Number* float_obj = new CPDF_Number(2345.089f); 712 CPDF_Number* float_obj = new CPDF_Number(2345.089f);
713 CPDF_String* str_obj = new CPDF_String("Adsfdsf 343434 %&&*\n", false); 713 CPDF_String* str_obj =
714 CPDF_Name* name_obj = new CPDF_Name("Title:"); 714 new CPDF_String(nullptr, "Adsfdsf 343434 %&&*\n", false);
715 CPDF_Name* name_obj = new CPDF_Name(nullptr, "Title:");
715 CPDF_Null* null_obj = new CPDF_Null(); 716 CPDF_Null* null_obj = new CPDF_Null();
716 CPDF_Object* indirect_objs[] = {boolean_obj, int_obj, float_obj, 717 CPDF_Object* indirect_objs[] = {boolean_obj, int_obj, float_obj,
717 str_obj, name_obj, null_obj}; 718 str_obj, name_obj, null_obj};
718 unsigned int obj_nums[] = {2, 4, 7, 2345, 799887, 1}; 719 unsigned int obj_nums[] = {2, 4, 7, 2345, 799887, 1};
719 auto arr = pdfium::MakeUnique<CPDF_Array>(); 720 auto arr = pdfium::MakeUnique<CPDF_Array>();
720 std::unique_ptr<CPDF_Array> arr1(new CPDF_Array); 721 std::unique_ptr<CPDF_Array> arr1(new CPDF_Array);
721 // Create two arrays of references by different AddReference() APIs. 722 // Create two arrays of references by different AddReference() APIs.
722 for (size_t i = 0; i < FX_ArraySize(indirect_objs); ++i) { 723 for (size_t i = 0; i < FX_ArraySize(indirect_objs); ++i) {
723 holder->ReplaceIndirectObjectIfHigherGeneration( 724 holder->ReplaceIndirectObjectIfHigherGeneration(
724 obj_nums[i], pdfium::WrapUnique<CPDF_Object>(indirect_objs[i])); 725 obj_nums[i], pdfium::WrapUnique<CPDF_Object>(indirect_objs[i]));
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 dict->SetFor("clams", pObj); 865 dict->SetFor("clams", pObj);
865 dict->ConvertToIndirectObjectFor("clams", &objects_holder); 866 dict->ConvertToIndirectObjectFor("clams", &objects_holder);
866 CPDF_Object* pRef = dict->GetObjectFor("clams"); 867 CPDF_Object* pRef = dict->GetObjectFor("clams");
867 CPDF_Object* pNum = dict->GetDirectObjectFor("clams"); 868 CPDF_Object* pNum = dict->GetDirectObjectFor("clams");
868 EXPECT_TRUE(pRef->IsReference()); 869 EXPECT_TRUE(pRef->IsReference());
869 EXPECT_TRUE(pNum->IsNumber()); 870 EXPECT_TRUE(pNum->IsNumber());
870 EXPECT_NE(pObj, pRef); 871 EXPECT_NE(pObj, pRef);
871 EXPECT_EQ(pObj, pNum); 872 EXPECT_EQ(pObj, pNum);
872 EXPECT_EQ(42, dict->GetIntegerFor("clams")); 873 EXPECT_EQ(42, dict->GetIntegerFor("clams"));
873 } 874 }
OLDNEW
« no previous file with comments | « core/fpdfapi/parser/cpdf_object.h ('k') | core/fpdfapi/parser/cpdf_string.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698