1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10 #include <test/bootstrapfixture.hxx>
11 #include <cppunit/TestAssert.h>
12
13 #include <vcl/font.hxx>
14
15 class VclFontTest : public test::BootstrapFixture
16 {
17 public:
VclFontTest()18 VclFontTest() : BootstrapFixture(true, false) {}
19
20 void testName();
21 void testWeight();
22 void testWidthType();
23 void testPitch();
24 void testItalic();
25 void testAlignment();
26 void testQuality();
27 void testSymbolFlagAndCharSet();
28
29 CPPUNIT_TEST_SUITE(VclFontTest);
30 CPPUNIT_TEST(testName);
31 CPPUNIT_TEST(testWeight);
32 CPPUNIT_TEST(testWidthType);
33 CPPUNIT_TEST(testPitch);
34 CPPUNIT_TEST(testItalic);
35 CPPUNIT_TEST(testAlignment);
36 CPPUNIT_TEST(testQuality);
37 CPPUNIT_TEST(testSymbolFlagAndCharSet);
38 CPPUNIT_TEST_SUITE_END();
39 };
40
testName()41 void VclFontTest::testName()
42 {
43 vcl::Font aFont;
44
45 CPPUNIT_ASSERT_MESSAGE( "Family name should be empty", aFont.GetFamilyName().isEmpty());
46 CPPUNIT_ASSERT_MESSAGE( "Style name should be empty", aFont.GetStyleName().isEmpty());
47 aFont.SetFamilyName("Test family name");
48 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Family name should not be empty", OUString("Test family name"), aFont.GetFamilyName());
49 aFont.SetStyleName("Test style name");
50 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Style name should not be empty", OUString("Test style name"), aFont.GetStyleName());
51 }
52
testWeight()53 void VclFontTest::testWeight()
54 {
55 vcl::Font aFont;
56
57 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Weight should be WEIGHT_DONTKNOW", FontWeight::WEIGHT_DONTKNOW, aFont.GetWeight());
58
59 aFont.SetWeight(FontWeight::WEIGHT_BLACK);
60 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Weight should be WEIGHT_BLACK", FontWeight::WEIGHT_BLACK, aFont.GetWeight());
61 }
62
testWidthType()63 void VclFontTest::testWidthType()
64 {
65 vcl::Font aFont;
66
67 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Font width should be WIDTH_DONTKNOW", FontWidth::WIDTH_DONTKNOW, aFont.GetWidthType());
68
69 aFont.SetWidthType(FontWidth::WIDTH_EXPANDED);
70 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Font width should be EXPANDED", FontWidth::WIDTH_EXPANDED, aFont.GetWidthType());
71 }
72
testItalic()73 void VclFontTest::testItalic()
74 {
75 vcl::Font aFont;
76
77 // shouldn't this be set to ITALIC_DONTKNOW? currently it defaults to ITALIC_NONE
78 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Italic should be ITALIC_NONE", FontItalic::ITALIC_NONE, aFont.GetItalic());
79
80 aFont.SetItalic(FontItalic::ITALIC_NORMAL);
81 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Italic should be EXPANDED", FontItalic::ITALIC_NORMAL, aFont.GetItalic());
82 }
83
84
testAlignment()85 void VclFontTest::testAlignment()
86 {
87 vcl::Font aFont;
88
89 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Text alignment should be ALIGN_TOP", TextAlign::ALIGN_TOP, aFont.GetAlignment());
90
91 aFont.SetAlignment(TextAlign::ALIGN_BASELINE);
92 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Text alignment should be ALIGN_BASELINE", TextAlign::ALIGN_BASELINE, aFont.GetAlignment());
93 }
94
95
testPitch()96 void VclFontTest::testPitch()
97 {
98 vcl::Font aFont;
99
100 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Pitch should be PITCH_DONTKNOW", FontPitch::PITCH_DONTKNOW, aFont.GetPitch());
101
102 aFont.SetPitch(FontPitch::PITCH_FIXED);
103 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Pitch should be PITCH_FIXED", FontPitch::PITCH_FIXED, aFont.GetPitch());
104 }
105
testQuality()106 void VclFontTest::testQuality()
107 {
108 vcl::Font aFont;
109
110 CPPUNIT_ASSERT_EQUAL( int(0), aFont.GetQuality() );
111
112 aFont.SetQuality( 100 );
113 CPPUNIT_ASSERT_EQUAL( int(100), aFont.GetQuality() );
114
115 aFont.IncreaseQualityBy( 50 );
116 CPPUNIT_ASSERT_EQUAL( int(150), aFont.GetQuality() );
117
118 aFont.DecreaseQualityBy( 100 );
119 CPPUNIT_ASSERT_EQUAL( int(50), aFont.GetQuality() );
120 }
121
122
testSymbolFlagAndCharSet()123 void VclFontTest::testSymbolFlagAndCharSet()
124 {
125 // default constructor should set scalable flag to false
126 vcl::Font aFont;
127
128 CPPUNIT_ASSERT_MESSAGE( "Should not be seen as a symbol font after default constructor called", !aFont.IsSymbolFont() );
129 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Character set should be RTL_TEXTENCODING_DONTKNOW after default constructor called",
130 RTL_TEXTENCODING_DONTKNOW, aFont.GetCharSet() );
131
132 aFont.SetSymbolFlag(true);
133
134 CPPUNIT_ASSERT_MESSAGE( "Test 1: Symbol font flag should be on", aFont.IsSymbolFont() );
135 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Test 1: Character set should be RTL_TEXTENCODING_SYMBOL",
136 RTL_TEXTENCODING_SYMBOL, aFont.GetCharSet() );
137
138 aFont.SetSymbolFlag(false);
139
140 CPPUNIT_ASSERT_MESSAGE( "Test 2: Symbol font flag should be off", !aFont.IsSymbolFont() );
141 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Test 2: Character set should be RTL_TEXTENCODING_DONTKNOW",
142 RTL_TEXTENCODING_DONTKNOW, aFont.GetCharSet() );
143
144 aFont.SetCharSet( RTL_TEXTENCODING_SYMBOL );
145
146 CPPUNIT_ASSERT_MESSAGE( "Test 3: Symbol font flag should be on", aFont.IsSymbolFont() );
147 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Test 3: Character set should be RTL_TEXTENCODING_SYMBOL",
148 RTL_TEXTENCODING_SYMBOL, aFont.GetCharSet() );
149
150 aFont.SetCharSet( RTL_TEXTENCODING_UNICODE );
151
152 CPPUNIT_ASSERT_MESSAGE( "Test 4: Symbol font flag should be off", !aFont.IsSymbolFont() );
153 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Test 4: Character set should be RTL_TEXTENCODING_UNICODE",
154 RTL_TEXTENCODING_UNICODE, aFont.GetCharSet() );
155 }
156
157 CPPUNIT_TEST_SUITE_REGISTRATION(VclFontTest);
158
159 CPPUNIT_PLUGIN_IMPLEMENT();
160
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
162