Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: core/src/fpdfapi/fpdf_font/fpdf_font_cid_unittest.cpp

Issue 1414013005: Add tests for CMap_GetCode and CMap_GetCodeRange. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp ('k') | pdfium.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "testing/gtest/include/gtest/gtest.h"
6
7 #include "font_int.h"
8
9 namespace {
10
11 bool uint_ranges_equal(uint8_t* a, 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
21 TEST(fpdf_font_cid, CMap_GetCode) {
22 EXPECT_EQ(0, CPDF_CMapParser::CMap_GetCode(""));
23 EXPECT_EQ(0, CPDF_CMapParser::CMap_GetCode("<"));
24 EXPECT_EQ(194, CPDF_CMapParser::CMap_GetCode("<c2"));
25 EXPECT_EQ(162, CPDF_CMapParser::CMap_GetCode("<A2"));
26 EXPECT_EQ(2802, CPDF_CMapParser::CMap_GetCode("<Af2"));
27 EXPECT_EQ(162, CPDF_CMapParser::CMap_GetCode("<A2z"));
28
29 EXPECT_EQ(12, CPDF_CMapParser::CMap_GetCode("12"));
30 EXPECT_EQ(12, CPDF_CMapParser::CMap_GetCode("12d"));
31 EXPECT_EQ(128, CPDF_CMapParser::CMap_GetCode("128"));
32 }
33
34 TEST(fpdf_font_cid, CMap_GetCodeRange) {
35 CMap_CodeRange range;
36
37 // Must start with a <
38 EXPECT_FALSE(CPDF_CMapParser::CMap_GetCodeRange(range, "", ""));
39 EXPECT_FALSE(CPDF_CMapParser::CMap_GetCodeRange(range, "A", ""));
40
41 // m_CharSize must be <= 4
42 EXPECT_FALSE(CPDF_CMapParser::CMap_GetCodeRange(range, "<aaaaaaaaaa>", ""));
43 EXPECT_EQ(5, range.m_CharSize);
44
45 EXPECT_TRUE(
46 CPDF_CMapParser::CMap_GetCodeRange(range, "<12345678>", "<87654321>"));
47 EXPECT_EQ(4, range.m_CharSize);
48 {
49 uint8_t lower[4] = {18, 52, 86, 120};
50 uint8_t upper[4] = {135, 101, 67, 33};
51 EXPECT_TRUE(uint_ranges_equal(lower, range.m_Lower, range.m_CharSize));
52 EXPECT_TRUE(uint_ranges_equal(upper, range.m_Upper, range.m_CharSize));
53 }
54
55 // Hex characters
56 EXPECT_TRUE(CPDF_CMapParser::CMap_GetCodeRange(range, "<a1>", "<F3>"));
57 EXPECT_EQ(1, range.m_CharSize);
58 EXPECT_EQ(161, range.m_Lower[0]);
59 EXPECT_EQ(243, range.m_Upper[0]);
60
61 // The second string should return 0's if it is shorter
62 EXPECT_TRUE(CPDF_CMapParser::CMap_GetCodeRange(range, "<a1>", ""));
63 EXPECT_EQ(1, range.m_CharSize);
64 EXPECT_EQ(161, range.m_Lower[0]);
65 EXPECT_EQ(0, range.m_Upper[0]);
66 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp ('k') | pdfium.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698