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/parser/cpdf_dictionary.h" | 5 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
6 #include "core/fpdfapi/parser/cpdf_indirect_object_holder.h" | 6 #include "core/fpdfapi/parser/cpdf_indirect_object_holder.h" |
| 7 #include "core/fpdfapi/parser/cpdf_name.h" |
| 8 #include "core/fpdfapi/parser/cpdf_reference.h" |
7 #include "core/fpdfdoc/cpdf_formfield.h" | 9 #include "core/fpdfdoc/cpdf_formfield.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
9 | 11 |
10 TEST(cpdf_formfield, FPDF_GetFullName) { | 12 TEST(cpdf_formfield, FPDF_GetFullName) { |
11 CFX_WideString name = FPDF_GetFullName(nullptr); | 13 CFX_WideString name = FPDF_GetFullName(nullptr); |
12 EXPECT_TRUE(name.IsEmpty()); | 14 EXPECT_TRUE(name.IsEmpty()); |
13 | 15 |
14 CPDF_IndirectObjectHolder obj_holder; | 16 CPDF_IndirectObjectHolder obj_holder; |
15 CPDF_Dictionary* root = obj_holder.NewIndirect<CPDF_Dictionary>(); | 17 CPDF_Dictionary* root = obj_holder.NewIndirect<CPDF_Dictionary>(); |
16 root->SetNameFor("T", "foo"); | 18 root->SetNewFor<CPDF_Name>("T", "foo"); |
17 name = FPDF_GetFullName(root); | 19 name = FPDF_GetFullName(root); |
18 EXPECT_STREQ("foo", name.UTF8Encode().c_str()); | 20 EXPECT_STREQ("foo", name.UTF8Encode().c_str()); |
19 | 21 |
20 CPDF_Dictionary* dict1 = obj_holder.NewIndirect<CPDF_Dictionary>(); | 22 CPDF_Dictionary* dict1 = obj_holder.NewIndirect<CPDF_Dictionary>(); |
21 root->SetReferenceFor("Parent", &obj_holder, dict1); | 23 root->SetNewFor<CPDF_Reference>("Parent", &obj_holder, dict1->GetObjNum()); |
22 dict1->SetNameFor("T", "bar"); | 24 dict1->SetNewFor<CPDF_Name>("T", "bar"); |
23 name = FPDF_GetFullName(root); | 25 name = FPDF_GetFullName(root); |
24 EXPECT_STREQ("bar.foo", name.UTF8Encode().c_str()); | 26 EXPECT_STREQ("bar.foo", name.UTF8Encode().c_str()); |
25 | 27 |
26 CPDF_Dictionary* dict2 = new CPDF_Dictionary(); | 28 CPDF_Dictionary* dict2 = dict1->SetNewFor<CPDF_Dictionary>("Parent"); |
27 dict1->SetFor("Parent", dict2); | |
28 name = FPDF_GetFullName(root); | 29 name = FPDF_GetFullName(root); |
29 EXPECT_STREQ("bar.foo", name.UTF8Encode().c_str()); | 30 EXPECT_STREQ("bar.foo", name.UTF8Encode().c_str()); |
30 | 31 |
31 CPDF_Dictionary* dict3 = obj_holder.NewIndirect<CPDF_Dictionary>(); | 32 CPDF_Dictionary* dict3 = obj_holder.NewIndirect<CPDF_Dictionary>(); |
32 dict2->SetReferenceFor("Parent", &obj_holder, dict3); | 33 dict2->SetNewFor<CPDF_Reference>("Parent", &obj_holder, dict3->GetObjNum()); |
33 | 34 |
34 dict3->SetNameFor("T", "qux"); | 35 dict3->SetNewFor<CPDF_Name>("T", "qux"); |
35 name = FPDF_GetFullName(root); | 36 name = FPDF_GetFullName(root); |
36 EXPECT_STREQ("qux.bar.foo", name.UTF8Encode().c_str()); | 37 EXPECT_STREQ("qux.bar.foo", name.UTF8Encode().c_str()); |
37 | 38 |
38 dict3->SetReferenceFor("Parent", &obj_holder, root->GetObjNum()); | 39 dict3->SetNewFor<CPDF_Reference>("Parent", &obj_holder, root->GetObjNum()); |
39 name = FPDF_GetFullName(root); | 40 name = FPDF_GetFullName(root); |
40 EXPECT_STREQ("qux.bar.foo", name.UTF8Encode().c_str()); | 41 EXPECT_STREQ("qux.bar.foo", name.UTF8Encode().c_str()); |
41 name = FPDF_GetFullName(dict1); | 42 name = FPDF_GetFullName(dict1); |
42 EXPECT_STREQ("foo.qux.bar", name.UTF8Encode().c_str()); | 43 EXPECT_STREQ("foo.qux.bar", name.UTF8Encode().c_str()); |
43 name = FPDF_GetFullName(dict2); | 44 name = FPDF_GetFullName(dict2); |
44 EXPECT_STREQ("bar.foo.qux", name.UTF8Encode().c_str()); | 45 EXPECT_STREQ("bar.foo.qux", name.UTF8Encode().c_str()); |
45 name = FPDF_GetFullName(dict3); | 46 name = FPDF_GetFullName(dict3); |
46 EXPECT_STREQ("bar.foo.qux", name.UTF8Encode().c_str()); | 47 EXPECT_STREQ("bar.foo.qux", name.UTF8Encode().c_str()); |
47 } | 48 } |
OLD | NEW |