1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
// Copyright (c) 2012 The Chromium 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 "ui/gfx/font_fallback_win.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace gfx {
namespace {
// Subclass of LinkedFontsIterator for testing that allows mocking the linked
// fonts vector.
class TestLinkedFontsIterator : public LinkedFontsIterator {
public:
explicit TestLinkedFontsIterator(Font font) : LinkedFontsIterator(font) {
}
virtual ~TestLinkedFontsIterator() {
}
// Add a linked font to the mocked vector of linked fonts.
void AddLinkedFontForTesting(Font font) {
test_linked_fonts.push_back(font);
}
virtual const std::vector<Font>* GetLinkedFonts() const OVERRIDE {
return &test_linked_fonts;
}
private:
std::vector<Font> test_linked_fonts;
DISALLOW_COPY_AND_ASSIGN(TestLinkedFontsIterator);
};
} // namespace
TEST(FontFallbackWinTest, ParseFontLinkEntry) {
std::string file;
std::string font;
internal::ParseFontLinkEntry("TAHOMA.TTF", &file, &font);
EXPECT_EQ("TAHOMA.TTF", file);
EXPECT_EQ("", font);
internal::ParseFontLinkEntry("MSGOTHIC.TTC,MS UI Gothic", &file, &font);
EXPECT_EQ("MSGOTHIC.TTC", file);
EXPECT_EQ("MS UI Gothic", font);
internal::ParseFontLinkEntry("MALGUN.TTF,128,96", &file, &font);
EXPECT_EQ("MALGUN.TTF", file);
EXPECT_EQ("", font);
internal::ParseFontLinkEntry("MEIRYO.TTC,Meiryo,128,85", &file, &font);
EXPECT_EQ("MEIRYO.TTC", file);
EXPECT_EQ("Meiryo", font);
}
TEST(FontFallbackWinTest, ParseFontFamilyString) {
std::vector<std::string> font_names;
internal::ParseFontFamilyString("Times New Roman (TrueType)", &font_names);
ASSERT_EQ(1U, font_names.size());
EXPECT_EQ("Times New Roman", font_names[0]);
font_names.clear();
internal::ParseFontFamilyString("Cambria & Cambria Math (TrueType)",
&font_names);
ASSERT_EQ(2U, font_names.size());
EXPECT_EQ("Cambria", font_names[0]);
EXPECT_EQ("Cambria Math", font_names[1]);
font_names.clear();
internal::ParseFontFamilyString(
"Meiryo & Meiryo Italic & Meiryo UI & Meiryo UI Italic (TrueType)",
&font_names);
ASSERT_EQ(4U, font_names.size());
EXPECT_EQ("Meiryo", font_names[0]);
EXPECT_EQ("Meiryo Italic", font_names[1]);
EXPECT_EQ("Meiryo UI", font_names[2]);
EXPECT_EQ("Meiryo UI Italic", font_names[3]);
}
TEST(FontFallbackWinTest, LinkedFontsIterator) {
TestLinkedFontsIterator iterator(Font("Arial", 16));
iterator.AddLinkedFontForTesting(Font("Times New Roman", 16));
Font font;
EXPECT_TRUE(iterator.NextFont(&font));
ASSERT_EQ("Arial", font.GetFontName());
EXPECT_TRUE(iterator.NextFont(&font));
ASSERT_EQ("Times New Roman", font.GetFontName());
EXPECT_FALSE(iterator.NextFont(&font));
}
TEST(FontFallbackWinTest, LinkedFontsIteratorSetNextFont) {
TestLinkedFontsIterator iterator(Font("Arial", 16));
iterator.AddLinkedFontForTesting(Font("Times New Roman", 16));
Font font;
EXPECT_TRUE(iterator.NextFont(&font));
ASSERT_EQ("Arial", font.GetFontName());
iterator.SetNextFont(Font("Tahoma", 16));
EXPECT_TRUE(iterator.NextFont(&font));
ASSERT_EQ("Tahoma", font.GetFontName());
EXPECT_TRUE(iterator.NextFont(&font));
ASSERT_EQ("Times New Roman", font.GetFontName());
EXPECT_FALSE(iterator.NextFont(&font));
}
} // namespace gfx
|