Add unit tests for fgas_fontutils.cpp
These tests show some inconsistent behaviour with spaces in font names
that was noticed while working on other issues.
Change-Id: I0689275e5fa96dfd90ce4cadd1f998dac2ee5b32
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/87593
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/BUILD.gn b/BUILD.gn
index bdb5dae..717c8c3 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -445,6 +445,7 @@
"fxbarcode:unittests",
"xfa/fde:unittests",
"xfa/fgas/crt:unittests",
+ "xfa/fgas/font:unittests",
"xfa/fgas/layout:unittests",
"xfa/fxfa:unittests",
"xfa/fxfa/fm2js:unittests",
diff --git a/xfa/fgas/font/BUILD.gn b/xfa/fgas/font/BUILD.gn
index 82abd28..423e4cf 100644
--- a/xfa/fgas/font/BUILD.gn
+++ b/xfa/fgas/font/BUILD.gn
@@ -35,3 +35,12 @@
]
visibility = [ "../../../*" ]
}
+
+pdfium_unittest_source_set("unittests") {
+ sources = [ "fgas_fontutils_unittest.cpp" ]
+ deps = [
+ ":font",
+ "../../../core/fxcrt",
+ ]
+ pdfium_root_dir = "../../../"
+}
diff --git a/xfa/fgas/font/fgas_fontutils_unittest.cpp b/xfa/fgas/font/fgas_fontutils_unittest.cpp
new file mode 100644
index 0000000..e52f040
--- /dev/null
+++ b/xfa/fgas/font/fgas_fontutils_unittest.cpp
@@ -0,0 +1,60 @@
+// Copyright 2021 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 "xfa/fgas/font/fgas_fontutils.h"
+
+#include "core/fxcrt/fx_codepage.h"
+#include "core/fxcrt/widestring.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+TEST(FGAS, GetUnicodeBitField) {
+ const auto* pResult = FGAS_GetUnicodeBitField(0);
+ ASSERT_TRUE(pResult);
+ EXPECT_EQ(0u, pResult->wBitField);
+ EXPECT_EQ(FX_CodePage::kMSWin_WesternEuropean, pResult->wCodePage);
+
+ pResult = FGAS_GetUnicodeBitField(65535);
+ EXPECT_FALSE(pResult);
+
+ // Try arbitrary values.
+ pResult = FGAS_GetUnicodeBitField(1313);
+ ASSERT_TRUE(pResult);
+ EXPECT_EQ(9u, pResult->wBitField);
+ EXPECT_EQ(FX_CodePage::kFailure, pResult->wCodePage);
+
+ pResult = FGAS_GetUnicodeBitField(14321);
+ ASSERT_TRUE(pResult);
+ EXPECT_EQ(59u, pResult->wBitField);
+ EXPECT_EQ(FX_CodePage::kFailure, pResult->wCodePage);
+}
+
+TEST(FGAS, FontNameToEnglishName) {
+ // These aren't found with spaces.
+ WideString result = FGAS_FontNameToEnglishName(L"Myriad Pro");
+ EXPECT_EQ(L"Myriad Pro", result);
+
+ result = FGAS_FontNameToEnglishName(L"mYriad pRo");
+ EXPECT_EQ(L"mYriad pRo", result);
+
+ result = FGAS_FontNameToEnglishName(L"MyriadPro");
+ EXPECT_EQ(L"MyriadPro", result);
+
+ result = FGAS_FontNameToEnglishName(L"mYriadpRo");
+ EXPECT_EQ(L"MyriadPro", result);
+}
+
+TEST(FGAS, FontInfoByFontName) {
+ // And yet, these are found despite spaces.
+ const auto* result = FGAS_FontInfoByFontName(L"Myriad Pro");
+ EXPECT_TRUE(result);
+
+ result = FGAS_FontInfoByFontName(L"mYriad pRo");
+ EXPECT_TRUE(result);
+
+ result = FGAS_FontInfoByFontName(L"MyriadPro");
+ EXPECT_TRUE(result);
+
+ result = FGAS_FontInfoByFontName(L"mYriadpRo");
+ EXPECT_TRUE(result);
+}