1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/fpdfdoc/cpdf_formfield.h"
6
7 #include "core/fpdfapi/parser/cpdf_dictionary.h"
8 #include "core/fpdfapi/parser/cpdf_indirect_object_holder.h"
9 #include "core/fpdfapi/parser/cpdf_name.h"
10 #include "core/fpdfapi/parser/cpdf_reference.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
TEST(cpdf_formfield,GetFullNameForDict)13 TEST(cpdf_formfield, GetFullNameForDict) {
14 WideString name = CPDF_FormField::GetFullNameForDict(nullptr);
15 EXPECT_TRUE(name.IsEmpty());
16
17 CPDF_IndirectObjectHolder obj_holder;
18 CPDF_Dictionary* root = obj_holder.NewIndirect<CPDF_Dictionary>();
19 root->SetNewFor<CPDF_Name>("T", "foo");
20 name = CPDF_FormField::GetFullNameForDict(root);
21 EXPECT_STREQ("foo", name.ToUTF8().c_str());
22
23 CPDF_Dictionary* dict1 = obj_holder.NewIndirect<CPDF_Dictionary>();
24 root->SetNewFor<CPDF_Reference>("Parent", &obj_holder, dict1->GetObjNum());
25 dict1->SetNewFor<CPDF_Name>("T", "bar");
26 name = CPDF_FormField::GetFullNameForDict(root);
27 EXPECT_STREQ("bar.foo", name.ToUTF8().c_str());
28
29 CPDF_Dictionary* dict2 = dict1->SetNewFor<CPDF_Dictionary>("Parent");
30 name = CPDF_FormField::GetFullNameForDict(root);
31 EXPECT_STREQ("bar.foo", name.ToUTF8().c_str());
32
33 CPDF_Dictionary* dict3 = obj_holder.NewIndirect<CPDF_Dictionary>();
34 dict2->SetNewFor<CPDF_Reference>("Parent", &obj_holder, dict3->GetObjNum());
35
36 dict3->SetNewFor<CPDF_Name>("T", "qux");
37 name = CPDF_FormField::GetFullNameForDict(root);
38 EXPECT_STREQ("qux.bar.foo", name.ToUTF8().c_str());
39
40 dict3->SetNewFor<CPDF_Reference>("Parent", &obj_holder, root->GetObjNum());
41 name = CPDF_FormField::GetFullNameForDict(root);
42 EXPECT_STREQ("qux.bar.foo", name.ToUTF8().c_str());
43 name = CPDF_FormField::GetFullNameForDict(dict1);
44 EXPECT_STREQ("foo.qux.bar", name.ToUTF8().c_str());
45 name = CPDF_FormField::GetFullNameForDict(dict2);
46 EXPECT_STREQ("bar.foo.qux", name.ToUTF8().c_str());
47 name = CPDF_FormField::GetFullNameForDict(dict3);
48 EXPECT_STREQ("bar.foo.qux", name.ToUTF8().c_str());
49 }
50