Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cxfa_document_builder_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 "xfa/fxfa/parser/cxfa_document_builder.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_xmlparser.h"
12#include "testing/fxgc_unittest.h"
13#include "testing/gtest/include/gtest/gtest.h"
14#include "v8/include/cppgc/allocation.h"
15#include "v8/include/cppgc/persistent.h"
16#include "xfa/fxfa/parser/cxfa_document.h"
17
19 public:
20 void SetUp() override {
22 doc_ = cppgc::MakeGarbageCollected<CXFA_Document>(
23 heap()->GetAllocationHandle(), nullptr, heap(), nullptr);
24 }
25
27 doc_ = nullptr;
29 }
30
31 CXFA_Document* GetDoc() const { return doc_; }
32
33 CXFA_Node* ParseAndBuild(const RetainPtr<CFX_ReadOnlySpanStream>& stream) {
34 xml_ = CFX_XMLParser(stream).Parse();
35 if (!xml_)
36 return nullptr;
37
38 CXFA_DocumentBuilder builder(doc_);
39 if (!builder.BuildDocument(xml_.get(), XFA_PacketType::Config))
40 return nullptr;
41 return builder.GetRootNode();
42 }
43
44 private:
45 std::unique_ptr<CFX_XMLDocument> xml_;
46 cppgc::Persistent<CXFA_Document> doc_;
47};
48
50 static const char kInput[] = "";
51 auto stream =
52 pdfium::MakeRetain<CFX_ReadOnlySpanStream>(pdfium::as_byte_span(kInput));
53 EXPECT_FALSE(ParseAndBuild(stream));
54}
55
57 static const char kInput[] = "<<<>bar?>>>>>>>";
58 auto stream =
59 pdfium::MakeRetain<CFX_ReadOnlySpanStream>(pdfium::as_byte_span(kInput));
60 EXPECT_FALSE(ParseAndBuild(stream));
61}
62
64 static const char kInput[] =
65 "<config>\n"
66 "<?originalXFAVersion http://www.xfa.org/schema/xfa-template/2.7 "
67 "v2.7-scripting:0 ?>\n"
68 "</config>";
69 EXPECT_FALSE(GetDoc()->is_scripting());
70
71 auto stream =
72 pdfium::MakeRetain<CFX_ReadOnlySpanStream>(pdfium::as_byte_span(kInput));
73
74 CXFA_Node* root = ParseAndBuild(stream);
75 ASSERT_TRUE(root);
76 EXPECT_FALSE(GetDoc()->is_scripting());
77}
78
80 static const char kInput[] =
81 "<config>\n"
82 "<?originalXFAVersion http://www.xfa.org/schema/xfa-template/2.7 "
83 "v2.7-scripting:1 ?>\n"
84 "</config>";
85
86 EXPECT_FALSE(GetDoc()->is_scripting());
87
88 auto stream =
89 pdfium::MakeRetain<CFX_ReadOnlySpanStream>(pdfium::as_byte_span(kInput));
90
91 CXFA_Node* root = ParseAndBuild(stream);
92 ASSERT_TRUE(root);
93 EXPECT_TRUE(GetDoc()->is_scripting());
94}
95
97 static const char kInput[] =
98 "<config>"
99 "<?acrobat JavaScript strictScoping ?>\n"
100 "</config>";
101
102 EXPECT_FALSE(GetDoc()->is_strict_scoping());
103
104 auto stream =
105 pdfium::MakeRetain<CFX_ReadOnlySpanStream>(pdfium::as_byte_span(kInput));
106
107 CXFA_Node* root = ParseAndBuild(stream);
108 ASSERT_TRUE(root);
109 EXPECT_TRUE(GetDoc()->is_strict_scoping());
110}
111
113 static const char kInput[] =
114 "<config>"
115 "<?acrobat JavaScript otherScoping ?>\n"
116 "</config>";
117
118 EXPECT_FALSE(GetDoc()->is_strict_scoping());
119
120 auto stream =
121 pdfium::MakeRetain<CFX_ReadOnlySpanStream>(pdfium::as_byte_span(kInput));
122
123 CXFA_Node* root = ParseAndBuild(stream);
124 ASSERT_TRUE(root);
125 EXPECT_FALSE(GetDoc()->is_strict_scoping());
126}
127
129 static const char kInput[] =
130 "<config>"
131 "<?originalXFAVersion http://www.xfa.org/schema/xfa-template/2.7 "
132 "v2.7-scripting:1 ?>\n"
133 "<?acrobat JavaScript strictScoping ?>\n"
134 "</config>";
135
136 EXPECT_FALSE(GetDoc()->is_scripting());
137 EXPECT_FALSE(GetDoc()->is_strict_scoping());
138
139 auto stream =
140 pdfium::MakeRetain<CFX_ReadOnlySpanStream>(pdfium::as_byte_span(kInput));
141
142 CXFA_Node* root = ParseAndBuild(stream);
143 ASSERT_TRUE(root);
144 EXPECT_TRUE(GetDoc()->is_scripting());
145 EXPECT_TRUE(GetDoc()->is_strict_scoping());
146}
CXFA_Node * ParseAndBuild(const RetainPtr< CFX_ReadOnlySpanStream > &stream)
CXFA_Node * GetRootNode() const
void SetUp() override
void TearDown() override
TEST_F(CXFA_DocumentBuilderTest, EmptyInput)