blob: dc81ca8ca4d10a7aa933b07518808e1740580d02 [file] [log] [blame]
[email protected]7f4bfe12008-12-12 01:52:251// 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
[email protected]82522512009-05-15 07:37:295#include "app/gfx/font.h"
[email protected]7f4bfe12008-12-12 01:52:256
7#include "testing/gtest/include/gtest/gtest.h"
8
9namespace {
10
[email protected]7322c4402009-05-15 02:16:1011using gfx::Font;
12
13class FontTest : public testing::Test {
[email protected]7f4bfe12008-12-12 01:52:2514};
15
[email protected]7322c4402009-05-15 02:16:1016TEST_F(FontTest, LoadArial) {
17 Font cf(Font::CreateFont(L"Arial", 16));
[email protected]7f4bfe12008-12-12 01:52:2518 ASSERT_TRUE(cf.nativeFont());
[email protected]7322c4402009-05-15 02:16:1019 ASSERT_EQ(cf.style(), Font::NORMAL);
[email protected]7f4bfe12008-12-12 01:52:2520 ASSERT_EQ(cf.FontSize(), 16);
21 ASSERT_EQ(cf.FontName(), L"Arial");
22}
23
[email protected]7322c4402009-05-15 02:16:1024TEST_F(FontTest, LoadArialBold) {
25 Font cf(Font::CreateFont(L"Arial", 16));
26 Font bold(cf.DeriveFont(0, Font::BOLD));
[email protected]7f4bfe12008-12-12 01:52:2527 ASSERT_TRUE(bold.nativeFont());
[email protected]7322c4402009-05-15 02:16:1028 ASSERT_EQ(bold.style(), Font::BOLD);
[email protected]7f4bfe12008-12-12 01:52:2529}
30
[email protected]7322c4402009-05-15 02:16:1031TEST_F(FontTest, Ascent) {
32 Font cf(Font::CreateFont(L"Arial", 16));
[email protected]7f4bfe12008-12-12 01:52:2533 ASSERT_GT(cf.baseline(), 2);
34 ASSERT_LT(cf.baseline(), 20);
35}
36
[email protected]7322c4402009-05-15 02:16:1037TEST_F(FontTest, Height) {
38 Font cf(Font::CreateFont(L"Arial", 16));
[email protected]7f4bfe12008-12-12 01:52:2539 ASSERT_GT(cf.baseline(), 2);
40 ASSERT_LT(cf.baseline(), 20);
41}
42
[email protected]7322c4402009-05-15 02:16:1043TEST_F(FontTest, AvgWidths) {
44 Font cf(Font::CreateFont(L"Arial", 16));
[email protected]7f4bfe12008-12-12 01:52:2545 ASSERT_EQ(cf.GetExpectedTextWidth(0), 0);
46 ASSERT_GT(cf.GetExpectedTextWidth(1), cf.GetExpectedTextWidth(0));
47 ASSERT_GT(cf.GetExpectedTextWidth(2), cf.GetExpectedTextWidth(1));
48 ASSERT_GT(cf.GetExpectedTextWidth(3), cf.GetExpectedTextWidth(2));
49}
50
[email protected]7322c4402009-05-15 02:16:1051TEST_F(FontTest, Widths) {
52 Font cf(Font::CreateFont(L"Arial", 16));
[email protected]7f4bfe12008-12-12 01:52:2553 ASSERT_EQ(cf.GetStringWidth(L""), 0);
54 ASSERT_GT(cf.GetStringWidth(L"a"), cf.GetStringWidth(L""));
55 ASSERT_GT(cf.GetStringWidth(L"ab"), cf.GetStringWidth(L"a"));
56 ASSERT_GT(cf.GetStringWidth(L"abc"), cf.GetStringWidth(L"ab"));
57}
58
[email protected]f80821f2009-06-16 23:10:2959#if defined(OS_WIN)
60TEST_F(FontTest, DeriveFontResizesIfSizeTooSmall) {
61 // This creates font of height -8.
62 Font cf(Font::CreateFont(L"Arial", 6));
63 Font derived_font = cf.DeriveFont(-4);
64 LOGFONT font_info;
65 GetObject(derived_font.hfont(), sizeof(LOGFONT), &font_info);
66 EXPECT_EQ(-5, font_info.lfHeight);
67}
68
69TEST_F(FontTest, DeriveFontKeepsOriginalSizeIfHeightOk) {
70 // This creates font of height -8.
71 Font cf(Font::CreateFont(L"Arial", 6));
72 Font derived_font = cf.DeriveFont(-2);
73 LOGFONT font_info;
74 GetObject(derived_font.hfont(), sizeof(LOGFONT), &font_info);
75 EXPECT_EQ(-6, font_info.lfHeight);
76}
77#endif
[email protected]7f4bfe12008-12-12 01:52:2578} // anonymous namespace