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
span_util_unittest.cpp
Go to the documentation of this file.
1
// Copyright 2021 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/span_util.h"
6
7
#
include
<
vector
>
8
9
#
include
"testing/gmock/include/gmock/gmock.h"
10
#
include
"testing/gtest/include/gtest/gtest.h"
11
12
TEST
(
Spancpy
,
FitsEntirely
) {
13
std::vector<
char
> src(4,
'A'
);
14
std::vector<
char
> dst(4,
'B'
);
15
auto
remain =
fxcrt
::spancpy(
pdfium
::make_span(dst),
pdfium
::make_span(src));
16
EXPECT_EQ(dst[0],
'A'
);
17
EXPECT_EQ(dst[1],
'A'
);
18
EXPECT_EQ(dst[2],
'A'
);
19
EXPECT_EQ(dst[3],
'A'
);
20
EXPECT_TRUE(remain.empty());
21
}
22
23
TEST
(
Spancpy
,
FitsWithin
) {
24
std::vector<
char
> src(2,
'A'
);
25
std::vector<
char
> dst(4,
'B'
);
26
// Also show that a const src argument is acceptable.
27
auto
remain =
fxcrt
::spancpy(
pdfium
::make_span(dst).subspan(1),
28
pdfium::span<
const
char
>(src));
29
EXPECT_EQ(dst[0],
'B'
);
30
EXPECT_EQ(dst[1],
'A'
);
31
EXPECT_EQ(dst[2],
'A'
);
32
EXPECT_EQ(dst[3],
'B'
);
33
EXPECT_EQ(remain.size(), 1u);
34
EXPECT_EQ(remain.data(), &dst[3]);
35
}
36
37
TEST
(
Spancpy
,
EmptyCopyWithin
) {
38
std::vector<
char
> src(2,
'A'
);
39
std::vector<
char
> dst(4,
'B'
);
40
auto
remain =
fxcrt
::spancpy(
pdfium
::make_span(dst).subspan(1),
41
pdfium
::make_span(src).subspan(2));
42
EXPECT_EQ(dst[0],
'B'
);
43
EXPECT_EQ(dst[1],
'B'
);
44
EXPECT_EQ(dst[2],
'B'
);
45
EXPECT_EQ(dst[3],
'B'
);
46
EXPECT_EQ(remain.size(), 3u);
47
EXPECT_EQ(remain.data(), &dst[1]);
48
}
49
50
TEST
(
Spancpy
,
EmptyCopyToEmpty
) {
51
std::vector<
char
> src(2,
'A'
);
52
std::vector<
char
> dst(4,
'B'
);
53
auto
remain =
fxcrt
::spancpy(
pdfium
::make_span(dst).subspan(4),
54
pdfium
::make_span(src).subspan(2));
55
EXPECT_EQ(dst[0],
'B'
);
56
EXPECT_EQ(dst[1],
'B'
);
57
EXPECT_EQ(dst[2],
'B'
);
58
EXPECT_EQ(dst[3],
'B'
);
59
EXPECT_TRUE(remain.empty());
60
}
61
62
TEST
(
Spancpy
,
TryFitsEntirely
) {
63
std::vector<
char
> src(4,
'A'
);
64
std::vector<
char
> dst(4,
'B'
);
65
EXPECT_TRUE(
66
fxcrt
::try_spancpy(
pdfium
::make_span(dst),
pdfium
::make_span(src)));
67
EXPECT_EQ(dst[0],
'A'
);
68
EXPECT_EQ(dst[1],
'A'
);
69
EXPECT_EQ(dst[2],
'A'
);
70
EXPECT_EQ(dst[3],
'A'
);
71
}
72
73
TEST
(
Spancpy
,
TryDoesNotFit
) {
74
std::vector<
char
> src(4,
'A'
);
75
std::vector<
char
> dst(3,
'B'
);
76
EXPECT_FALSE(
77
fxcrt
::try_spancpy(
pdfium
::make_span(dst),
pdfium
::make_span(src)));
78
EXPECT_EQ(dst[0],
'B'
);
79
EXPECT_EQ(dst[1],
'B'
);
80
EXPECT_EQ(dst[2],
'B'
);
81
}
82
83
TEST
(
Spanmove
,
FitsWithin
) {
84
std::vector<
char
> src(2,
'A'
);
85
std::vector<
char
> dst(4,
'B'
);
86
// Also show that a const src argument is acceptable.
87
auto
remain =
fxcrt
::spanmove(
pdfium
::make_span(dst).subspan(1),
88
pdfium::span<
const
char
>(src));
89
EXPECT_EQ(dst[0],
'B'
);
90
EXPECT_EQ(dst[1],
'A'
);
91
EXPECT_EQ(dst[2],
'A'
);
92
EXPECT_EQ(dst[3],
'B'
);
93
EXPECT_EQ(remain.size(), 1u);
94
EXPECT_EQ(remain.data(), &dst[3]);
95
}
96
97
TEST
(
Spanmove
,
TryFitsEntirely
) {
98
std::vector<
char
> src(4,
'A'
);
99
std::vector<
char
> dst(4,
'B'
);
100
EXPECT_TRUE(
101
fxcrt
::try_spanmove(
pdfium
::make_span(dst),
pdfium
::make_span(src)));
102
EXPECT_EQ(dst[0],
'A'
);
103
EXPECT_EQ(dst[1],
'A'
);
104
EXPECT_EQ(dst[2],
'A'
);
105
EXPECT_EQ(dst[3],
'A'
);
106
}
107
108
TEST
(
Spanmove
,
TrySelfIntersect
) {
109
{
110
std::vector<
char
> vec = {
'A'
,
'B'
,
'C'
,
'D'
};
111
EXPECT_TRUE(
fxcrt
::try_spanmove(
pdfium
::make_span(vec).first(3),
112
pdfium
::make_span(vec).last(3)));
113
EXPECT_EQ(vec[0],
'B'
);
114
EXPECT_EQ(vec[1],
'C'
);
115
EXPECT_EQ(vec[2],
'D'
);
116
EXPECT_EQ(vec[3],
'D'
);
117
}
118
{
119
std::vector<
char
> vec = {
'A'
,
'B'
,
'C'
,
'D'
};
120
EXPECT_TRUE(
fxcrt
::try_spanmove(
pdfium
::make_span(vec).last(3),
121
pdfium
::make_span(vec).first(3)));
122
EXPECT_EQ(vec[0],
'A'
);
123
EXPECT_EQ(vec[1],
'A'
);
124
EXPECT_EQ(vec[2],
'B'
);
125
EXPECT_EQ(vec[3],
'C'
);
126
}
127
}
128
129
TEST
(
Spanmove
,
TryDoesNotFit
) {
130
std::vector<
char
> src(4,
'A'
);
131
std::vector<
char
> dst(3,
'B'
);
132
EXPECT_FALSE(
133
fxcrt
::try_spanmove(
pdfium
::make_span(dst),
pdfium
::make_span(src)));
134
EXPECT_EQ(dst[0],
'B'
);
135
EXPECT_EQ(dst[1],
'B'
);
136
EXPECT_EQ(dst[2],
'B'
);
137
}
138
139
TEST
(
SpanEquals
,
Empty
) {
140
std::vector<
int
> vec = {1, 2};
141
std::vector<
int
> vec2 = {3, 4};
142
pdfium::span<
int
> empty;
143
pdfium::span<
int
> some =
pdfium
::make_span(vec);
144
pdfium::span<
int
> some2 =
pdfium
::make_span(vec2);
145
EXPECT_FALSE(
fxcrt
::span_equals(empty, some));
146
EXPECT_FALSE(
fxcrt
::span_equals(some, empty));
147
EXPECT_TRUE(
fxcrt
::span_equals(empty, empty));
148
EXPECT_TRUE(
fxcrt
::span_equals(empty, some.first(0)));
149
EXPECT_TRUE(
fxcrt
::span_equals(some.first(0), empty));
150
EXPECT_TRUE(
fxcrt
::span_equals(some2.first(0), some.first(0)));
151
EXPECT_TRUE(
fxcrt
::span_equals(some.first(0), some2.first(0)));
152
}
153
154
TEST
(
SpanEquals
,
NonEmpty
) {
155
std::vector<
int
> vec = {1, 2, 3};
156
std::vector<
int
> vec2 = {1, 2, 4};
157
pdfium::span<
int
> some =
pdfium
::make_span(vec);
158
pdfium::span<
int
> some2 =
pdfium
::make_span(vec2);
159
EXPECT_FALSE(
fxcrt
::span_equals(some, some2));
160
EXPECT_FALSE(
fxcrt
::span_equals(some.first(2), some2));
161
EXPECT_FALSE(
fxcrt
::span_equals(some, some2.first(2)));
162
EXPECT_TRUE(
fxcrt
::span_equals(some.first(2), some2.first(2)));
163
}
164
165
TEST
(
Span
,
AssignOverOnePastEnd
) {
166
std::vector<
char
> src(2,
'A'
);
167
pdfium::span<
char
> span =
pdfium
::make_span(src);
168
span = span.subspan(2);
169
span =
pdfium
::make_span(src);
170
EXPECT_EQ(span.size(), 2u);
171
}
172
173
TEST
(
ReinterpretSpan
,
Empty
) {
174
pdfium::span<uint8_t> empty;
175
pdfium::span<uint32_t> converted =
fxcrt
::reinterpret_span<uint32_t>(empty);
176
EXPECT_EQ(converted.data(),
nullptr
);
177
EXPECT_EQ(converted.size(), 0u);
178
}
179
180
TEST
(
ReinterpretSpan
,
LegalConversions
) {
181
uint8_t aaaabbbb[8] = {0x61, 0x61, 0x61, 0x61, 0x62, 0x62, 0x62, 0x62};
182
pdfium::span<uint8_t> original =
pdfium
::make_span(aaaabbbb);
183
pdfium::span<uint32_t> converted =
184
fxcrt
::reinterpret_span<uint32_t>(original);
185
ASSERT_NE(converted.data(),
nullptr
);
186
ASSERT_EQ(converted.size(), 2u);
187
EXPECT_EQ(converted[0], 0x61616161u);
188
EXPECT_EQ(converted[1], 0x62626262u);
189
}
190
191
TEST
(
ReinterpretSpan
,
BadAlignment
) {
192
uint8_t abcabc[6] = {0x61, 0x62, 0x63, 0x61, 0x62, 0x63};
193
EXPECT_DEATH(
fxcrt
::reinterpret_span<uint32_t>(
194
pdfium
::make_span(abcabc).subspan(1, 4)),
195
""
);
196
}
197
198
TEST
(
Spanpos
,
Empty
) {
199
pdfium::span<
const
uint32_t> kEmpty;
200
const
uint32_t kHaystack[] = {0, 1, 2, 3, 4, 5};
201
const
uint32_t kNeedle[] = {1, 2};
202
EXPECT_FALSE(
fxcrt
::spanpos(kEmpty, kEmpty));
203
EXPECT_FALSE(
fxcrt
::spanpos(
pdfium
::make_span(kHaystack), kEmpty));
204
EXPECT_FALSE(
fxcrt
::spanpos(kEmpty,
pdfium
::make_span(kNeedle)));
205
}
206
207
TEST
(
Spanpos
,
NotEmpty
) {
208
const
uint32_t kHaystack[] = {0, 1, 2, 3, 4, 5};
209
const
uint32_t kStartMatch[] = {0, 1};
210
const
uint32_t kEndMatch[] = {4, 5};
211
const
uint32_t kNotFound[] = {256, 512};
// test byte-shifted {1,2}.
212
const
uint32_t kTooLong[] = {0, 1, 2, 3, 4, 5, 6};
213
EXPECT_THAT(
fxcrt
::spanpos(
pdfium
::make_span(kHaystack),
214
pdfium
::make_span(kStartMatch)),
215
testing::Optional(0u));
216
EXPECT_THAT(
fxcrt
::spanpos(
pdfium
::make_span(kHaystack),
217
pdfium
::make_span(kEndMatch)),
218
testing::Optional(4u));
219
EXPECT_FALSE(
fxcrt
::spanpos(
pdfium
::make_span(kHaystack),
220
pdfium
::make_span(kNotFound)));
221
EXPECT_FALSE(
fxcrt
::spanpos(
pdfium
::make_span(kHaystack),
222
pdfium
::make_span(kTooLong)));
223
}
pdfium::CFDETextOutLargeBitmapTest
Definition
cfde_textout_unittest.cpp:117
TEST
TEST(FXCRYPT, MD5GenerateEmtpyData)
Definition
fx_crypt_unittest.cpp:50
fxcrt
Definition
stl_util.h:17
qtwebengine
src
3rdparty
chromium
third_party
pdfium
core
fxcrt
span_util_unittest.cpp
Generated on
for Qt by
1.18.0