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
cpdf_metadata_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/fpdfdoc/cpdf_metadata.h"
6
7#include "core/fpdfapi/parser/cpdf_stream.h"
8#include "testing/gtest/include/gtest/gtest.h"
9
11 static const char data[] =
12 "<?xml charset=\"utf-8\"?>\n"
13 "<node xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
14 "<adhocwf:workflowType>0</adhocwf:workflowType>\n"
15 "<adhocwf:version>1.1</adhocwf:version>\n"
16 "</node>";
17
18 auto stream = pdfium::MakeRetain<CPDF_Stream>();
19 stream->SetData(ByteStringView(data).raw_span());
20 CPDF_Metadata metadata(stream);
21
22 auto results = metadata.CheckForSharedForm();
23 ASSERT_EQ(1U, results.size());
25}
26
28 static const char data[] =
29 "<?xml charset=\"utf-8\"?>\n"
30 "<node xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
31 "<adhocwf:workflowType>1</adhocwf:workflowType>\n"
32 "<adhocwf:version>1.1</adhocwf:version>\n"
33 "</node>";
34
35 auto stream = pdfium::MakeRetain<CPDF_Stream>();
36 stream->SetData(ByteStringView(data).raw_span());
37 CPDF_Metadata metadata(stream);
38
39 auto results = metadata.CheckForSharedForm();
40 ASSERT_EQ(1U, results.size());
42}
43
45 static const char data[] =
46 "<?xml charset=\"utf-8\"?>\n"
47 "<node xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
48 "<adhocwf:workflowType>2</adhocwf:workflowType>\n"
49 "<adhocwf:version>1.1</adhocwf:version>\n"
50 "</node>";
51
52 auto stream = pdfium::MakeRetain<CPDF_Stream>();
53 stream->SetData(ByteStringView(data).raw_span());
54 CPDF_Metadata metadata(stream);
55
56 auto results = metadata.CheckForSharedForm();
57 ASSERT_EQ(1U, results.size());
59}
60
62 static const char data[] =
63 "<?xml charset=\"utf-8\"?>\n"
64 "<node xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
65 "<adhocwf:state>2</adhocwf:state>\n"
66 "<adhocwf:version>1.1</adhocwf:version>\n"
67 "</node>";
68
69 auto stream = pdfium::MakeRetain<CPDF_Stream>();
70 stream->SetData(ByteStringView(data).raw_span());
71 CPDF_Metadata metadata(stream);
72
73 auto results = metadata.CheckForSharedForm();
74 EXPECT_EQ(0U, results.size());
75}
76
78 static const char data[] =
79 "<?xml charset=\"utf-8\"?>\n"
80 "<grandparent><parent>\n"
81 "<node xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
82 "<adhocwf:workflowType>0</adhocwf:workflowType>\n"
83 "<adhocwf:version>1.1</adhocwf:version>\n"
84 "</node>"
85 "</parent></grandparent>";
86
87 auto stream = pdfium::MakeRetain<CPDF_Stream>();
88 stream->SetData(ByteStringView(data).raw_span());
89 CPDF_Metadata metadata(stream);
90
91 auto results = metadata.CheckForSharedForm();
92 ASSERT_EQ(1U, results.size());
94}
95
97 static const char data[] =
98 "<?xml charset=\"utf-8\"?>\n"
99 "<node></node>";
100
101 auto stream = pdfium::MakeRetain<CPDF_Stream>();
102 stream->SetData(ByteStringView(data).raw_span());
103 CPDF_Metadata metadata(stream);
104
105 auto results = metadata.CheckForSharedForm();
106 EXPECT_EQ(0U, results.size());
107}
108
110 // Node <parent> has the depth of 130, which exceeds the maximum node depth of
111 // `kMaxMetaDataDepth`.
112 static const char kData[] =
113 "<?xml charset=\"utf-8\"?>\n"
114 "<node><node><node><node><node><node><node><node><node><node>\n"
115 "<node><node><node><node><node><node><node><node><node><node>\n"
116 "<node><node><node><node><node><node><node><node><node><node>\n"
117 "<node><node><node><node><node><node><node><node><node><node>\n"
118 "<node><node><node><node><node><node><node><node><node><node>\n"
119 "<node><node><node><node><node><node><node><node><node><node>\n"
120 "<node><node><node><node><node><node><node><node><node><node>\n"
121 "<node><node><node><node><node><node><node><node><node><node>\n"
122 "<node><node><node><node><node><node><node><node><node><node>\n"
123 "<node><node><node><node><node><node><node><node><node><node>\n"
124 "<node><node><node><node><node><node><node><node><node><node>\n"
125 "<node><node><node><node><node><node><node><node><node><node>\n"
126 "<node><node><node><node><node><node><node><node><node><node>\n"
127 "<parent>\n"
128 "<node xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
129 "<adhocwf:workflowType>0</adhocwf:workflowType>\n"
130 "<adhocwf:version>1.1</adhocwf:version>\n"
131 "</node>"
132 "</parent>";
133
134 auto stream = pdfium::MakeRetain<CPDF_Stream>();
135 stream->SetData(ByteStringView(kData).raw_span());
136 CPDF_Metadata metadata(stream);
137
138 auto results = metadata.CheckForSharedForm();
139 ASSERT_EQ(0U, results.size());
140}
141
143 static const char data[] =
144 "<?xml charset=\"utf-8\"?>\n"
145 "<node xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/2.0/\">\n"
146 "<adhocwf:workflowType>1</adhocwf:workflowType>\n"
147 "<adhocwf:version>1.1</adhocwf:version>\n"
148 "</node>";
149
150 auto stream = pdfium::MakeRetain<CPDF_Stream>();
151 stream->SetData(ByteStringView(data).raw_span());
152 CPDF_Metadata metadata(stream);
153
154 auto results = metadata.CheckForSharedForm();
155 EXPECT_EQ(0U, results.size());
156}
157
159 static const char data[] =
160 "<?xml charset=\"utf-8\"?>\n"
161 "<grandparent>"
162 "<parent>\n"
163 "<node xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
164 "<adhocwf:workflowType>0</adhocwf:workflowType>\n"
165 "<adhocwf:version>1.1</adhocwf:version>\n"
166 "</node>"
167 "</parent>"
168 "<node2 "
169 "xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
170 "<adhocwf:workflowType>2</adhocwf:workflowType>\n"
171 "<adhocwf:version>1.1</adhocwf:version>\n"
172 "</node2>"
173 "<node3 "
174 "xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
175 "<adhocwf:workflowType>1</adhocwf:workflowType>\n"
176 "<adhocwf:version>1.1</adhocwf:version>\n"
177 "</node3>"
178 "</grandparent>";
179
180 auto stream = pdfium::MakeRetain<CPDF_Stream>();
181 stream->SetData(ByteStringView(data).raw_span());
182 CPDF_Metadata metadata(stream);
183
184 auto results = metadata.CheckForSharedForm();
185 ASSERT_EQ(3U, results.size());
189}
UnsupportedFeature
TEST(FXCRYPT, MD5GenerateEmtpyData)