| 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_dictionary.h" | 5 #include "core/fpdfapi/fpdf_parser/cpdf_dictionary.h" |
| 6 #include "core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.h" | 6 #include "core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.h" |
| 7 #include "core/fpdfdoc/cpdf_formfield.h" | 7 #include "core/fpdfdoc/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 = | 15 CPDF_Dictionary* root = new CPDF_Dictionary(); |
| 16 new CPDF_Dictionary(CFX_WeakPtr<CFX_ByteStringPool>()); | |
| 17 obj_holder.AddIndirectObject(root); | 16 obj_holder.AddIndirectObject(root); |
| 18 root->SetNameFor("T", "foo"); | 17 root->SetNameFor("T", "foo"); |
| 19 name = FPDF_GetFullName(root); | 18 name = FPDF_GetFullName(root); |
| 20 EXPECT_STREQ("foo", name.UTF8Encode().c_str()); | 19 EXPECT_STREQ("foo", name.UTF8Encode().c_str()); |
| 21 | 20 |
| 22 CPDF_Dictionary* dict1 = | 21 CPDF_Dictionary* dict1 = new CPDF_Dictionary(); |
| 23 new CPDF_Dictionary(CFX_WeakPtr<CFX_ByteStringPool>()); | |
| 24 root->SetReferenceFor("Parent", &obj_holder, | 22 root->SetReferenceFor("Parent", &obj_holder, |
| 25 obj_holder.AddIndirectObject(dict1)); | 23 obj_holder.AddIndirectObject(dict1)); |
| 26 dict1->SetNameFor("T", "bar"); | 24 dict1->SetNameFor("T", "bar"); |
| 27 name = FPDF_GetFullName(root); | 25 name = FPDF_GetFullName(root); |
| 28 EXPECT_STREQ("bar.foo", name.UTF8Encode().c_str()); | 26 EXPECT_STREQ("bar.foo", name.UTF8Encode().c_str()); |
| 29 | 27 |
| 30 CPDF_Dictionary* dict2 = | 28 CPDF_Dictionary* dict2 = new CPDF_Dictionary(); |
| 31 new CPDF_Dictionary(CFX_WeakPtr<CFX_ByteStringPool>()); | |
| 32 dict1->SetFor("Parent", dict2); | 29 dict1->SetFor("Parent", dict2); |
| 33 name = FPDF_GetFullName(root); | 30 name = FPDF_GetFullName(root); |
| 34 EXPECT_STREQ("bar.foo", name.UTF8Encode().c_str()); | 31 EXPECT_STREQ("bar.foo", name.UTF8Encode().c_str()); |
| 35 | 32 |
| 36 CPDF_Dictionary* dict3 = | 33 CPDF_Dictionary* dict3 = new CPDF_Dictionary(); |
| 37 new CPDF_Dictionary(CFX_WeakPtr<CFX_ByteStringPool>()); | |
| 38 dict2->SetReferenceFor("Parent", &obj_holder, | 34 dict2->SetReferenceFor("Parent", &obj_holder, |
| 39 obj_holder.AddIndirectObject(dict3)); | 35 obj_holder.AddIndirectObject(dict3)); |
| 40 dict3->SetNameFor("T", "qux"); | 36 dict3->SetNameFor("T", "qux"); |
| 41 name = FPDF_GetFullName(root); | 37 name = FPDF_GetFullName(root); |
| 42 EXPECT_STREQ("qux.bar.foo", name.UTF8Encode().c_str()); | 38 EXPECT_STREQ("qux.bar.foo", name.UTF8Encode().c_str()); |
| 43 | 39 |
| 44 dict3->SetReferenceFor("Parent", &obj_holder, root->GetObjNum()); | 40 dict3->SetReferenceFor("Parent", &obj_holder, root->GetObjNum()); |
| 45 name = FPDF_GetFullName(root); | 41 name = FPDF_GetFullName(root); |
| 46 EXPECT_STREQ("qux.bar.foo", name.UTF8Encode().c_str()); | 42 EXPECT_STREQ("qux.bar.foo", name.UTF8Encode().c_str()); |
| 47 name = FPDF_GetFullName(dict1); | 43 name = FPDF_GetFullName(dict1); |
| 48 EXPECT_STREQ("foo.qux.bar", name.UTF8Encode().c_str()); | 44 EXPECT_STREQ("foo.qux.bar", name.UTF8Encode().c_str()); |
| 49 name = FPDF_GetFullName(dict2); | 45 name = FPDF_GetFullName(dict2); |
| 50 EXPECT_STREQ("bar.foo.qux", name.UTF8Encode().c_str()); | 46 EXPECT_STREQ("bar.foo.qux", name.UTF8Encode().c_str()); |
| 51 name = FPDF_GetFullName(dict3); | 47 name = FPDF_GetFullName(dict3); |
| 52 EXPECT_STREQ("bar.foo.qux", name.UTF8Encode().c_str()); | 48 EXPECT_STREQ("bar.foo.qux", name.UTF8Encode().c_str()); |
| 53 } | 49 } |
| OLD | NEW |