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