OLD | NEW |
| (Empty) |
1 // Copyright 2015 PDFium Authors. All rights reserved. | |
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/fpdf_font/font_int.h" | |
6 #include "testing/gtest/include/gtest/gtest.h" | |
7 | |
8 namespace { | |
9 | |
10 bool uint_ranges_equal(uint8_t* a, uint8_t* b, size_t count) { | |
11 for (size_t i = 0; i < count; ++i) { | |
12 if (a[i] != b[i]) | |
13 return false; | |
14 } | |
15 return true; | |
16 } | |
17 | |
18 } // namespace | |
19 | |
20 TEST(fpdf_font_cid, CMap_GetCode) { | |
21 EXPECT_EQ(0u, CPDF_CMapParser::CMap_GetCode("")); | |
22 EXPECT_EQ(0u, CPDF_CMapParser::CMap_GetCode("<")); | |
23 EXPECT_EQ(194u, CPDF_CMapParser::CMap_GetCode("<c2")); | |
24 EXPECT_EQ(162u, CPDF_CMapParser::CMap_GetCode("<A2")); | |
25 EXPECT_EQ(2802u, CPDF_CMapParser::CMap_GetCode("<Af2")); | |
26 EXPECT_EQ(162u, CPDF_CMapParser::CMap_GetCode("<A2z")); | |
27 | |
28 EXPECT_EQ(12u, CPDF_CMapParser::CMap_GetCode("12")); | |
29 EXPECT_EQ(12u, CPDF_CMapParser::CMap_GetCode("12d")); | |
30 EXPECT_EQ(128u, CPDF_CMapParser::CMap_GetCode("128")); | |
31 | |
32 EXPECT_EQ(4294967295u, CPDF_CMapParser::CMap_GetCode("<FFFFFFFF")); | |
33 | |
34 // Overflow a uint32_t. | |
35 EXPECT_EQ(0u, CPDF_CMapParser::CMap_GetCode("<100000000")); | |
36 } | |
37 | |
38 TEST(fpdf_font_cid, CMap_GetCodeRange) { | |
39 CMap_CodeRange range; | |
40 | |
41 // Must start with a < | |
42 EXPECT_FALSE(CPDF_CMapParser::CMap_GetCodeRange(range, "", "")); | |
43 EXPECT_FALSE(CPDF_CMapParser::CMap_GetCodeRange(range, "A", "")); | |
44 | |
45 // m_CharSize must be <= 4 | |
46 EXPECT_FALSE(CPDF_CMapParser::CMap_GetCodeRange(range, "<aaaaaaaaaa>", "")); | |
47 EXPECT_EQ(5, range.m_CharSize); | |
48 | |
49 EXPECT_TRUE( | |
50 CPDF_CMapParser::CMap_GetCodeRange(range, "<12345678>", "<87654321>")); | |
51 EXPECT_EQ(4, range.m_CharSize); | |
52 { | |
53 uint8_t lower[4] = {18, 52, 86, 120}; | |
54 uint8_t upper[4] = {135, 101, 67, 33}; | |
55 EXPECT_TRUE(uint_ranges_equal(lower, range.m_Lower, range.m_CharSize)); | |
56 EXPECT_TRUE(uint_ranges_equal(upper, range.m_Upper, range.m_CharSize)); | |
57 } | |
58 | |
59 // Hex characters | |
60 EXPECT_TRUE(CPDF_CMapParser::CMap_GetCodeRange(range, "<a1>", "<F3>")); | |
61 EXPECT_EQ(1, range.m_CharSize); | |
62 EXPECT_EQ(161, range.m_Lower[0]); | |
63 EXPECT_EQ(243, range.m_Upper[0]); | |
64 | |
65 // The second string should return 0's if it is shorter | |
66 EXPECT_TRUE(CPDF_CMapParser::CMap_GetCodeRange(range, "<a1>", "")); | |
67 EXPECT_EQ(1, range.m_CharSize); | |
68 EXPECT_EQ(161, range.m_Lower[0]); | |
69 EXPECT_EQ(0, range.m_Upper[0]); | |
70 } | |
OLD | NEW |