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

Side by Side Diff: core/fpdfdoc/cpdf_formfield_unittest.cpp

Issue 2353093002: Assert that dictionary can own the objects it is given. (Closed)
Patch Set: Created 4 years, 3 months 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/fpdf_parser/cpdf_dictionary.cpp ('k') | no next file » | 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/fpdf_parser/include/cpdf_dictionary.h" 5 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
6 #include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h" 6 #include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h"
7 #include "core/fpdfdoc/include/cpdf_formfield.h" 7 #include "core/fpdfdoc/include/cpdf_formfield.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 TEST(cpdf_formfield, FPDF_GetFullName) { 10 TEST(cpdf_formfield, FPDF_GetFullName) {
11 CFX_WideString name = FPDF_GetFullName(nullptr); 11 CFX_WideString name = FPDF_GetFullName(nullptr);
12 EXPECT_TRUE(name.IsEmpty()); 12 EXPECT_TRUE(name.IsEmpty());
13 13
14 CPDF_IndirectObjectHolder obj_holder; 14 CPDF_IndirectObjectHolder obj_holder;
15 CPDF_Dictionary* root = new CPDF_Dictionary; 15 CPDF_Dictionary* root = new CPDF_Dictionary;
16 obj_holder.AddIndirectObject(root); 16 obj_holder.AddIndirectObject(root);
17 root->SetNameFor("T", "foo"); 17 root->SetNameFor("T", "foo");
18 name = FPDF_GetFullName(root); 18 name = FPDF_GetFullName(root);
19 EXPECT_STREQ("foo", name.UTF8Encode().c_str()); 19 EXPECT_STREQ("foo", name.UTF8Encode().c_str());
20 20
21 CPDF_Dictionary* dict1 = new CPDF_Dictionary; 21 CPDF_Dictionary* dict1 = new CPDF_Dictionary;
22 obj_holder.AddIndirectObject(dict1); 22 obj_holder.AddIndirectObject(dict1);
23 dict1->SetNameFor("T", "bar"); 23 dict1->SetNameFor("T", "bar");
24 root->SetReferenceFor("Parent", &obj_holder, dict1); 24 root->SetReferenceFor("Parent", &obj_holder, dict1);
25 name = FPDF_GetFullName(root); 25 name = FPDF_GetFullName(root);
26 EXPECT_STREQ("bar.foo", name.UTF8Encode().c_str()); 26 EXPECT_STREQ("bar.foo", name.UTF8Encode().c_str());
27 27
28 CPDF_Dictionary* dict2 = new CPDF_Dictionary; 28 CPDF_Dictionary* dict2 = new CPDF_Dictionary;
29 obj_holder.AddIndirectObject(dict2);
30 dict1->SetFor("Parent", dict2); 29 dict1->SetFor("Parent", dict2);
31 name = FPDF_GetFullName(root); 30 name = FPDF_GetFullName(root);
32 EXPECT_STREQ("bar.foo", name.UTF8Encode().c_str()); 31 EXPECT_STREQ("bar.foo", name.UTF8Encode().c_str());
33 32
34 CPDF_Dictionary* dict3 = new CPDF_Dictionary; 33 CPDF_Dictionary* dict3 = new CPDF_Dictionary;
35 obj_holder.AddIndirectObject(dict3); 34 obj_holder.AddIndirectObject(dict3);
36 dict3->SetNameFor("T", "qux"); 35 dict3->SetNameFor("T", "qux");
37 dict2->SetReferenceFor("Parent", &obj_holder, dict3); 36 dict2->SetReferenceFor("Parent", &obj_holder, dict3);
38 name = FPDF_GetFullName(root); 37 name = FPDF_GetFullName(root);
39 EXPECT_STREQ("qux.bar.foo", name.UTF8Encode().c_str()); 38 EXPECT_STREQ("qux.bar.foo", name.UTF8Encode().c_str());
40 39
41 dict3->SetReferenceFor("Parent", &obj_holder, root); 40 dict3->SetReferenceFor("Parent", &obj_holder, root);
42 name = FPDF_GetFullName(root); 41 name = FPDF_GetFullName(root);
43 EXPECT_STREQ("qux.bar.foo", name.UTF8Encode().c_str()); 42 EXPECT_STREQ("qux.bar.foo", name.UTF8Encode().c_str());
44 name = FPDF_GetFullName(dict1); 43 name = FPDF_GetFullName(dict1);
45 EXPECT_STREQ("foo.qux.bar", name.UTF8Encode().c_str()); 44 EXPECT_STREQ("foo.qux.bar", name.UTF8Encode().c_str());
46 name = FPDF_GetFullName(dict2); 45 name = FPDF_GetFullName(dict2);
47 EXPECT_STREQ("bar.foo.qux", name.UTF8Encode().c_str()); 46 EXPECT_STREQ("bar.foo.qux", name.UTF8Encode().c_str());
48 name = FPDF_GetFullName(dict3); 47 name = FPDF_GetFullName(dict3);
49 EXPECT_STREQ("bar.foo.qux", name.UTF8Encode().c_str()); 48 EXPECT_STREQ("bar.foo.qux", name.UTF8Encode().c_str());
50 } 49 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698