Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
cfx_xmlinstruction_unittest.cpp
Go to the documentation of this file.
1
// Copyright 2018 The PDFium Authors
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/fxcrt/xml/cfx_xmlinstruction.h"
6
7
#
include
<
memory
>
8
9
#
include
"core/fxcrt/cfx_read_only_span_stream.h"
10
#
include
"core/fxcrt/xml/cfx_xmldocument.h"
11
#
include
"core/fxcrt/xml/cfx_xmlelement.h"
12
#
include
"core/fxcrt/xml/cfx_xmlparser.h"
13
#
include
"testing/gtest/include/gtest/gtest.h"
14
#
include
"testing/string_write_stream.h"
15
16
TEST
(
CFX_XMLInstructionTest
,
GetType
) {
17
CFX_XMLInstruction node
(
L"acrobat"
)
;
18
EXPECT_EQ(
CFX_XMLNode
::
Type
::
kInstruction
, node
.
GetType
(
)
);
19
}
20
21
TEST
(
CFX_XMLInstructionTest
,
AcrobatInstruction
) {
22
CFX_XMLInstruction node
(
L"acrobat"
)
;
23
EXPECT_TRUE(node
.
IsAcrobat
(
)
);
24
EXPECT_FALSE(node
.
IsOriginalXFAVersion
(
)
);
25
}
26
27
TEST
(
CFX_XMLInstructionTest
,
OriginalXFAInstruction
) {
28
CFX_XMLInstruction node
(
L"originalXFAVersion"
)
;
29
EXPECT_TRUE(node
.
IsOriginalXFAVersion
(
)
);
30
EXPECT_FALSE(node
.
IsAcrobat
(
)
);
31
}
32
33
TEST
(
CFX_XMLInstructionTest
,
TargetData
) {
34
CFX_XMLInstruction node
(
L"acrobat"
)
;
35
EXPECT_EQ(0U, node.GetTargetData().size());
36
37
node
.
AppendData
(
L"firstString"
)
;
38
node
.
AppendData
(
L"secondString"
)
;
39
40
auto
& data = node.GetTargetData();
41
ASSERT_EQ(2U, data.size());
42
EXPECT_EQ(L"firstString", data[0]);
43
EXPECT_EQ(L"secondString", data[1]);
44
}
45
46
TEST
(
CFX_XMLInstructionTest
,
Clone
) {
47
CFX_XMLDocument
doc;
48
49
CFX_XMLInstruction node
(
L"acrobat"
)
;
50
node
.
AppendData
(
L"firstString"
)
;
51
node
.
AppendData
(
L"secondString"
)
;
52
53
CFX_XMLNode
* clone = node
.
Clone
(
&doc
)
;
54
EXPECT_TRUE(clone !=
nullptr
);
55
56
ASSERT_EQ(
CFX_XMLNode
::
Type
::
kInstruction
, clone
->
GetType
(
)
);
57
CFX_XMLInstruction* inst =
ToXMLInstruction
(
clone
)
;
58
EXPECT_TRUE(inst
->
IsAcrobat
(
)
);
59
60
auto
& data = inst->GetTargetData();
61
ASSERT_EQ(2U, data.size());
62
EXPECT_EQ(L"firstString", data[0]);
63
EXPECT_EQ(L"secondString", data[1]);
64
}
65
66
TEST
(
CFX_XMLInstructionTest
,
SaveXML
) {
67
auto
stream =
pdfium
::MakeRetain<StringWriteStream>();
68
CFX_XMLInstruction node
(
L"xml"
)
;
69
node
.
Save
(
stream
)
;
70
EXPECT_EQ(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
, stream->ToString());
71
}
72
73
TEST
(
CFX_XMLInstructionTest
,
SaveAcrobat
) {
74
auto
stream =
pdfium
::MakeRetain<StringWriteStream>();
75
CFX_XMLInstruction node
(
L"acrobat"
)
;
76
node
.
AppendData
(
L"http://www.xfa.org/schema/xfa-template/3.3/"
)
;
77
node
.
AppendData
(
L"Display:1"
)
;
78
79
node
.
Save
(
stream
)
;
80
EXPECT_EQ(
81
"<?acrobat http://www.xfa.org/schema/xfa-template/3.3/ Display:1 ?>\n"
,
82
stream->ToString());
83
}
84
85
TEST
(
CFX_XMLInstructionTest
,
ParseAndReSave
) {
86
static
const
char
input[] =
87
"<?acrobat http://www.xfa.org/schema/xfa-template/3.3/ Display:1 ?>\n"
88
"<node></node>"
;
89
90
auto
in_stream =
91
pdfium
::MakeRetain<CFX_ReadOnlySpanStream>(
pdfium
::as_byte_span(input));
92
93
CFX_XMLParser parser(in_stream);
94
std::unique_ptr<CFX_XMLDocument> doc = parser.Parse();
95
ASSERT_TRUE(doc !=
nullptr
);
96
97
CFX_XMLElement* root = doc->GetRoot();
98
ASSERT_TRUE(root->GetFirstChild() !=
nullptr
);
99
ASSERT_EQ(
CFX_XMLNode
::
Type
::
kInstruction
, root->GetFirstChild()->GetType());
100
101
CFX_XMLInstruction* node = ToXMLInstruction(root->GetFirstChild());
102
ASSERT_TRUE(node !=
nullptr
);
103
EXPECT_TRUE(node
->
IsAcrobat
(
)
);
104
105
auto
& data = node->GetTargetData();
106
ASSERT_EQ(2U, data.size());
107
EXPECT_EQ(L"http://www.xfa.org/schema/xfa-template/3.3/", data[0]);
108
EXPECT_EQ(L"Display:1", data[1]);
109
110
auto
out_stream =
pdfium
::MakeRetain<StringWriteStream>();
111
node
->
Save
(
out_stream
)
;
112
EXPECT_EQ(
113
"<?acrobat http://www.xfa.org/schema/xfa-template/3.3/ Display:1 ?>\n"
,
114
out_stream->ToString());
115
}
116
117
TEST
(
CFX_XMLInstructionTest
,
ParseAndReSaveInnerInstruction
) {
118
static
const
char
input[] =
119
"<node>\n"
120
"<?acrobat http://www.xfa.org/schema/xfa-template/3.3/ Display:1 ?>\n"
121
"</node>"
;
122
123
auto
in_stream =
124
pdfium
::MakeRetain<CFX_ReadOnlySpanStream>(
pdfium
::as_byte_span(input));
125
126
CFX_XMLParser parser(in_stream);
127
std::unique_ptr<CFX_XMLDocument> doc = parser.Parse();
128
ASSERT_TRUE(doc !=
nullptr
);
129
130
CFX_XMLElement* root = doc->GetRoot();
131
ASSERT_TRUE(root->GetFirstChild() !=
nullptr
);
132
ASSERT_TRUE(root->GetFirstChild()->GetType() ==
CFX_XMLNode
::
Type
::
kElement
);
133
134
CFX_XMLElement* node = ToXMLElement(root->GetFirstChild());
135
EXPECT_EQ(L"node", node
->
GetName
(
)
);
136
137
CFX_XMLInstruction* instruction =
nullptr
;
138
for
(
auto
* elem = node->GetFirstChild(); elem && !instruction;
139
elem = elem->GetNextSibling()) {
140
instruction = ToXMLInstruction(elem);
141
}
142
ASSERT_TRUE(instruction !=
nullptr
);
143
EXPECT_TRUE(instruction
->
IsAcrobat
(
)
);
144
145
auto
& data = instruction->GetTargetData();
146
ASSERT_EQ(2U, data.size());
147
EXPECT_EQ(L"http://www.xfa.org/schema/xfa-template/3.3/", data[0]);
148
EXPECT_EQ(L"Display:1", data[1]);
149
150
auto
out_stream =
pdfium
::MakeRetain<StringWriteStream>();
151
node
->
Save
(
out_stream
)
;
152
EXPECT_EQ(
153
"<node>\n\n"
154
"<?acrobat http://www.xfa.org/schema/xfa-template/3.3/ Display:1 ?>\n\n"
155
"</node>\n"
,
156
out_stream->ToString());
157
}
ToXMLInstruction
CFX_XMLInstruction * ToXMLInstruction(CFX_XMLNode *pNode)
Definition
cfx_xmlinstruction.h:38
CFX_XMLDocument
Definition
cfx_xmldocument.h:17
CFX_XMLElement::Save
void Save(const RetainPtr< IFX_RetainableWriteStream > &pXMLStream) override
Definition
cfx_xmlelement.cpp:80
CFX_XMLElement::GetName
const WideString & GetName() const
Definition
cfx_xmlelement.h:27
CFX_XMLInstruction::AppendData
void AppendData(const WideString &wsData)
Definition
cfx_xmlinstruction.cpp:28
CFX_XMLInstruction::CFX_XMLInstruction
CFX_XMLInstruction(const WideString &wsTarget)
Definition
cfx_xmlinstruction.cpp:13
CFX_XMLInstruction::GetType
Type GetType() const override
Definition
cfx_xmlinstruction.cpp:18
CFX_XMLInstruction::IsAcrobat
bool IsAcrobat() const
Definition
cfx_xmlinstruction.cpp:36
CFX_XMLInstruction::IsOriginalXFAVersion
bool IsOriginalXFAVersion() const
Definition
cfx_xmlinstruction.cpp:32
CFX_XMLInstruction::Clone
CFX_XMLNode * Clone(CFX_XMLDocument *doc) override
Definition
cfx_xmlinstruction.cpp:22
CFX_XMLInstruction::Save
void Save(const RetainPtr< IFX_RetainableWriteStream > &pXMLStream) override
Definition
cfx_xmlinstruction.cpp:40
CFX_XMLNode
Definition
cfx_xmlnode.h:16
CFX_XMLNode::GetType
virtual Type GetType() const =0
CFX_XMLNode::Type
Type
Definition
cfx_xmlnode.h:18
CFX_XMLNode::Type::kInstruction
@ kInstruction
Definition
cfx_xmlnode.h:19
CFX_XMLNode::Type::kElement
@ kElement
Definition
cfx_xmlnode.h:20
pdfium::CFDETextOutLargeBitmapTest
Definition
cfde_textout_unittest.cpp:117
TEST
TEST(FXCRYPT, MD5GenerateEmtpyData)
Definition
fx_crypt_unittest.cpp:50
qtwebengine
src
3rdparty
chromium
third_party
pdfium
core
fxcrt
xml
cfx_xmlinstruction_unittest.cpp
Generated on
for Qt by
1.18.0