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_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 "testing/gtest/include/gtest/gtest.h"
8
9namespace {
10
11bool uint_ranges_equal(const uint8_t* a, const uint8_t* b, size_t count) {
12 for (size_t i = 0; i < count; ++i) {
13 if (a[i] != b[i])
14 return false;
15 }
16 return true;
17}
18
19} // namespace
20
22 EXPECT_EQ(0u, CPDF_CMapParser::GetCode(""));
23 EXPECT_EQ(0u, CPDF_CMapParser::GetCode("<"));
24 EXPECT_EQ(194u, CPDF_CMapParser::GetCode("<c2"));
25 EXPECT_EQ(162u, CPDF_CMapParser::GetCode("<A2"));
26 EXPECT_EQ(2802u, CPDF_CMapParser::GetCode("<Af2"));
27 EXPECT_EQ(162u, CPDF_CMapParser::GetCode("<A2z"));
28
29 EXPECT_EQ(12u, CPDF_CMapParser::GetCode("12"));
30 EXPECT_EQ(12u, CPDF_CMapParser::GetCode("12d"));
31 EXPECT_EQ(128u, CPDF_CMapParser::GetCode("128"));
32
33 EXPECT_EQ(4294967295u, CPDF_CMapParser::GetCode("<FFFFFFFF"));
34
35 // Overflow a uint32_t.
36 EXPECT_EQ(0u, CPDF_CMapParser::GetCode("<100000000"));
37}
38
40 absl::optional<CPDF_CMap::CodeRange> range;
41
42 // Must start with a <
43 range = CPDF_CMapParser::GetCodeRange("", "");
44 EXPECT_FALSE(range.has_value());
45 range = CPDF_CMapParser::GetCodeRange("A", "");
46 EXPECT_FALSE(range.has_value());
47
48 // m_CharSize must be <= 4
49 range = CPDF_CMapParser::GetCodeRange("<aaaaaaaaaa>", "");
50 EXPECT_FALSE(range.has_value());
51
52 range = CPDF_CMapParser::GetCodeRange("<12345678>", "<87654321>");
53 ASSERT_TRUE(range.has_value());
54 ASSERT_EQ(4u, range.value().m_CharSize);
55 {
56 constexpr uint8_t kLower[4] = {18, 52, 86, 120};
57 constexpr uint8_t kUpper[4] = {135, 101, 67, 33};
58 EXPECT_TRUE(uint_ranges_equal(kLower, range.value().m_Lower, 4));
59 EXPECT_TRUE(uint_ranges_equal(kUpper, range.value().m_Upper, 4));
60 }
61
62 // Hex characters
63 range = CPDF_CMapParser::GetCodeRange("<a1>", "<F3>");
64 ASSERT_TRUE(range.has_value());
65 ASSERT_EQ(1u, range.value().m_CharSize);
66 EXPECT_EQ(161, range.value().m_Lower[0]);
67 EXPECT_EQ(243, range.value().m_Upper[0]);
68
69 // The second string should return 0's if it is shorter
70 range = CPDF_CMapParser::GetCodeRange("<a1>", "");
71 ASSERT_TRUE(range.has_value());
72 ASSERT_EQ(1u, range.value().m_CharSize);
73 EXPECT_EQ(161, range.value().m_Lower[0]);
74 EXPECT_EQ(0, range.value().m_Upper[0]);
75}
TEST(FXCRYPT, MD5GenerateEmtpyData)