xref: /aosp_15_r20/external/pdfium/xfa/fgas/font/fgas_fontutils_unittest.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2021 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 "xfa/fgas/font/fgas_fontutils.h"
6 
7 #include "core/fxcrt/fx_codepage.h"
8 #include "core/fxcrt/widestring.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 
TEST(FGAS,GetUnicodeBitField)11 TEST(FGAS, GetUnicodeBitField) {
12   const auto* pResult = FGAS_GetUnicodeBitField(0);
13   ASSERT_TRUE(pResult);
14   EXPECT_EQ(0u, pResult->wBitField);
15   EXPECT_EQ(FX_CodePage::kMSWin_WesternEuropean, pResult->wCodePage);
16 
17   pResult = FGAS_GetUnicodeBitField(65535);
18   EXPECT_FALSE(pResult);
19 
20   // Try arbitrary values.
21   pResult = FGAS_GetUnicodeBitField(1313);
22   ASSERT_TRUE(pResult);
23   EXPECT_EQ(9u, pResult->wBitField);
24   EXPECT_EQ(FX_CodePage::kFailure, pResult->wCodePage);
25 
26   pResult = FGAS_GetUnicodeBitField(14321);
27   ASSERT_TRUE(pResult);
28   EXPECT_EQ(59u, pResult->wBitField);
29   EXPECT_EQ(FX_CodePage::kFailure, pResult->wCodePage);
30 }
31 
TEST(FGAS,FontNameToEnglishName)32 TEST(FGAS, FontNameToEnglishName) {
33   // These aren't found with spaces.
34   WideString result = FGAS_FontNameToEnglishName(L"Myriad Pro");
35   EXPECT_EQ(L"Myriad Pro", result);
36 
37   result = FGAS_FontNameToEnglishName(L"mYriad pRo");
38   EXPECT_EQ(L"mYriad pRo", result);
39 
40   result = FGAS_FontNameToEnglishName(L"MyriadPro");
41   EXPECT_EQ(L"MyriadPro", result);
42 
43   result = FGAS_FontNameToEnglishName(L"mYriadpRo");
44   EXPECT_EQ(L"MyriadPro", result);
45 }
46 
TEST(FGAS,FontInfoByFontName)47 TEST(FGAS, FontInfoByFontName) {
48   // And yet, these are found despite spaces.
49   const auto* result = FGAS_FontInfoByFontName(L"Myriad Pro");
50   EXPECT_TRUE(result);
51 
52   result = FGAS_FontInfoByFontName(L"mYriad pRo");
53   EXPECT_TRUE(result);
54 
55   result = FGAS_FontInfoByFontName(L"MyriadPro");
56   EXPECT_TRUE(result);
57 
58   result = FGAS_FontInfoByFontName(L"mYriadpRo");
59   EXPECT_TRUE(result);
60 }
61