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