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
cpdf_cmapparser_unittest.cpp
Go to the documentation of this file.
1
// Copyright 2015 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/fpdfapi/font/cpdf_cmapparser.h"
6
7
#
include
"core/fxcrt/span.h"
8
#
include
"core/fxcrt/span_util.h"
9
#
include
"testing/gtest/include/gtest/gtest.h"
10
11
namespace
{
12
13
// Helps with default construction of the appropriate span rather than
14
// writing make_span() and using span_equal() directly.
15
bool
uint_ranges_equal(pdfium::span<
const
uint8_t> a,
16
pdfium::span<
const
uint8_t> b) {
17
return
fxcrt
::span_equals(a, b);
18
}
19
20
}
// namespace
21
22
TEST
(
cpdf_cmapparser
,
GetCode
) {
23
EXPECT_EQ(0u,
CPDF_CMapParser
::GetCode(
""
));
24
EXPECT_EQ(0u,
CPDF_CMapParser
::GetCode(
"<"
));
25
EXPECT_EQ(194u,
CPDF_CMapParser
::GetCode(
"<c2"
));
26
EXPECT_EQ(162u,
CPDF_CMapParser
::GetCode(
"<A2"
));
27
EXPECT_EQ(2802u,
CPDF_CMapParser
::GetCode(
"<Af2"
));
28
EXPECT_EQ(162u,
CPDF_CMapParser
::GetCode(
"<A2z"
));
29
30
EXPECT_EQ(12u,
CPDF_CMapParser
::GetCode(
"12"
));
31
EXPECT_EQ(12u,
CPDF_CMapParser
::GetCode(
"12d"
));
32
EXPECT_EQ(128u,
CPDF_CMapParser
::GetCode(
"128"
));
33
34
EXPECT_EQ(4294967295u,
CPDF_CMapParser
::GetCode(
"<FFFFFFFF"
));
35
36
// Overflow a uint32_t.
37
EXPECT_EQ(0u,
CPDF_CMapParser
::GetCode(
"<100000000"
));
38
}
39
40
TEST
(
cpdf_cmapparser
,
GetCodeRange
) {
41
std
::optional<CPDF_CMap::
CodeRange
> range;
42
43
// Must start with a <
44
range =
CPDF_CMapParser
::GetCodeRange(
""
,
""
);
45
EXPECT_FALSE(range.has_value());
46
range =
CPDF_CMapParser
::GetCodeRange(
"A"
,
""
);
47
EXPECT_FALSE(range.has_value());
48
49
// m_CharSize must be <= 4
50
range =
CPDF_CMapParser
::GetCodeRange(
"<aaaaaaaaaa>"
,
""
);
51
EXPECT_FALSE(range.has_value());
52
53
range =
CPDF_CMapParser
::GetCodeRange(
"<12345678>"
,
"<87654321>"
);
54
ASSERT_TRUE(range.has_value());
55
ASSERT_EQ(4u, range.value().m_CharSize);
56
{
57
constexpr
uint8_t kLower[4] = {18, 52, 86, 120};
58
constexpr
uint8_t kUpper[4] = {135, 101, 67, 33};
59
EXPECT_TRUE(uint_ranges_equal(kLower, range.value().m_Lower));
60
EXPECT_TRUE(uint_ranges_equal(kUpper, range.value().m_Upper));
61
}
62
63
// Hex characters
64
range =
CPDF_CMapParser
::GetCodeRange(
"<a1>"
,
"<F3>"
);
65
ASSERT_TRUE(range.has_value());
66
ASSERT_EQ(1u, range.value().m_CharSize);
67
EXPECT_EQ(161, range.value().m_Lower[0]);
68
EXPECT_EQ(243, range.value().m_Upper[0]);
69
70
// The second string should return 0's if it is shorter
71
range =
CPDF_CMapParser
::GetCodeRange(
"<a1>"
,
""
);
72
ASSERT_TRUE(range.has_value());
73
ASSERT_EQ(1u, range.value().m_CharSize);
74
EXPECT_EQ(161, range.value().m_Lower[0]);
75
EXPECT_EQ(0, range.value().m_Upper[0]);
76
}
CPDF_CMapParser
Definition
cpdf_cmapparser.h:19
TEST
TEST(FXCRYPT, MD5GenerateEmtpyData)
Definition
fx_crypt_unittest.cpp:50
fxcrt
Definition
stl_util.h:17
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
CPDF_CMap::CodeRange
Definition
cpdf_cmap.h:47
qtwebengine
src
3rdparty
chromium
third_party
pdfium
core
fpdfapi
font
cpdf_cmapparser_unittest.cpp
Generated on
for Qt by
1.18.0