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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/src/fpdfapi/fpdf_font/fpdf_font_cid_unittest.cpp
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font_cid_unittest.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font_cid_unittest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0a8086a19380790c65b8f4adb83aada31ac384b1
--- /dev/null
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font_cid_unittest.cpp
@@ -0,0 +1,66 @@
+// Copyright 2015 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+#include "font_int.h"
+
+namespace {
+
+bool uint_ranges_equal(uint8_t* a, uint8_t* b, size_t count) {
+ for (size_t i = 0; i < count; ++i) {
+ if (a[i] != b[i])
+ return false;
+ }
+ return true;
+}
+
+} // namespace
+
+TEST(fpdf_font_cid, CMap_GetCode) {
+ EXPECT_EQ(0, CPDF_CMapParser::CMap_GetCode(""));
+ EXPECT_EQ(0, CPDF_CMapParser::CMap_GetCode("<"));
+ EXPECT_EQ(194, CPDF_CMapParser::CMap_GetCode("<c2"));
+ EXPECT_EQ(162, CPDF_CMapParser::CMap_GetCode("<A2"));
+ EXPECT_EQ(2802, CPDF_CMapParser::CMap_GetCode("<Af2"));
+ EXPECT_EQ(162, CPDF_CMapParser::CMap_GetCode("<A2z"));
+
+ EXPECT_EQ(12, CPDF_CMapParser::CMap_GetCode("12"));
+ EXPECT_EQ(12, CPDF_CMapParser::CMap_GetCode("12d"));
+ EXPECT_EQ(128, CPDF_CMapParser::CMap_GetCode("128"));
+}
+
+TEST(fpdf_font_cid, CMap_GetCodeRange) {
+ CMap_CodeRange range;
+
+ // Must start with a <
+ EXPECT_FALSE(CPDF_CMapParser::CMap_GetCodeRange(range, "", ""));
+ EXPECT_FALSE(CPDF_CMapParser::CMap_GetCodeRange(range, "A", ""));
+
+ // m_CharSize must be <= 4
+ EXPECT_FALSE(CPDF_CMapParser::CMap_GetCodeRange(range, "<aaaaaaaaaa>", ""));
+ EXPECT_EQ(5, range.m_CharSize);
+
+ EXPECT_TRUE(
+ CPDF_CMapParser::CMap_GetCodeRange(range, "<12345678>", "<87654321>"));
+ EXPECT_EQ(4, range.m_CharSize);
+ {
+ uint8_t lower[4] = {18, 52, 86, 120};
+ uint8_t upper[4] = {135, 101, 67, 33};
+ EXPECT_TRUE(uint_ranges_equal(lower, range.m_Lower, range.m_CharSize));
+ EXPECT_TRUE(uint_ranges_equal(upper, range.m_Upper, range.m_CharSize));
+ }
+
+ // Hex characters
+ EXPECT_TRUE(CPDF_CMapParser::CMap_GetCodeRange(range, "<a1>", "<F3>"));
+ EXPECT_EQ(1, range.m_CharSize);
+ EXPECT_EQ(161, range.m_Lower[0]);
+ EXPECT_EQ(243, range.m_Upper[0]);
+
+ // The second string should return 0's if it is shorter
+ EXPECT_TRUE(CPDF_CMapParser::CMap_GetCodeRange(range, "<a1>", ""));
+ EXPECT_EQ(1, range.m_CharSize);
+ EXPECT_EQ(161, range.m_Lower[0]);
+ EXPECT_EQ(0, range.m_Upper[0]);
+}
« 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