OLD | NEW |
| (Empty) |
1 // Copyright (c) 2006-2008 The Chromium 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 "app/gfx/font.h" | |
6 | |
7 #include "testing/gtest/include/gtest/gtest.h" | |
8 | |
9 namespace { | |
10 | |
11 using gfx::Font; | |
12 | |
13 class FontTest : public testing::Test { | |
14 }; | |
15 | |
16 TEST_F(FontTest, LoadArial) { | |
17 Font cf(Font::CreateFont(L"Arial", 16)); | |
18 ASSERT_TRUE(cf.nativeFont()); | |
19 ASSERT_EQ(cf.style(), Font::NORMAL); | |
20 ASSERT_EQ(cf.FontSize(), 16); | |
21 ASSERT_EQ(cf.FontName(), L"Arial"); | |
22 } | |
23 | |
24 TEST_F(FontTest, LoadArialBold) { | |
25 Font cf(Font::CreateFont(L"Arial", 16)); | |
26 Font bold(cf.DeriveFont(0, Font::BOLD)); | |
27 ASSERT_TRUE(bold.nativeFont()); | |
28 ASSERT_EQ(bold.style(), Font::BOLD); | |
29 } | |
30 | |
31 TEST_F(FontTest, Ascent) { | |
32 Font cf(Font::CreateFont(L"Arial", 16)); | |
33 ASSERT_GT(cf.baseline(), 2); | |
34 ASSERT_LE(cf.baseline(), 22); | |
35 } | |
36 | |
37 TEST_F(FontTest, Height) { | |
38 Font cf(Font::CreateFont(L"Arial", 16)); | |
39 ASSERT_GE(cf.height(), 16); | |
40 // TODO(akalin): Figure out why height is so large on Linux. | |
41 ASSERT_LE(cf.height(), 26); | |
42 } | |
43 | |
44 TEST_F(FontTest, AvgWidths) { | |
45 Font cf(Font::CreateFont(L"Arial", 16)); | |
46 ASSERT_EQ(cf.GetExpectedTextWidth(0), 0); | |
47 ASSERT_GT(cf.GetExpectedTextWidth(1), cf.GetExpectedTextWidth(0)); | |
48 ASSERT_GT(cf.GetExpectedTextWidth(2), cf.GetExpectedTextWidth(1)); | |
49 ASSERT_GT(cf.GetExpectedTextWidth(3), cf.GetExpectedTextWidth(2)); | |
50 } | |
51 | |
52 TEST_F(FontTest, Widths) { | |
53 Font cf(Font::CreateFont(L"Arial", 16)); | |
54 ASSERT_EQ(cf.GetStringWidth(L""), 0); | |
55 ASSERT_GT(cf.GetStringWidth(L"a"), cf.GetStringWidth(L"")); | |
56 ASSERT_GT(cf.GetStringWidth(L"ab"), cf.GetStringWidth(L"a")); | |
57 ASSERT_GT(cf.GetStringWidth(L"abc"), cf.GetStringWidth(L"ab")); | |
58 } | |
59 | |
60 #if defined(OS_WIN) | |
61 // TODO(beng): re-enable evening of 3/22. | |
62 TEST_F(FontTest, DISABLED_DeriveFontResizesIfSizeTooSmall) { | |
63 // This creates font of height -8. | |
64 Font cf(Font::CreateFont(L"Arial", 6)); | |
65 Font derived_font = cf.DeriveFont(-4); | |
66 LOGFONT font_info; | |
67 GetObject(derived_font.hfont(), sizeof(LOGFONT), &font_info); | |
68 EXPECT_EQ(-5, font_info.lfHeight); | |
69 } | |
70 | |
71 TEST_F(FontTest, DISABLED_DeriveFontKeepsOriginalSizeIfHeightOk) { | |
72 // This creates font of height -8. | |
73 Font cf(Font::CreateFont(L"Arial", 6)); | |
74 Font derived_font = cf.DeriveFont(-2); | |
75 LOGFONT font_info; | |
76 GetObject(derived_font.hfont(), sizeof(LOGFONT), &font_info); | |
77 EXPECT_EQ(-6, font_info.lfHeight); | |
78 } | |
79 #endif | |
80 } // anonymous namespace | |
OLD | NEW |