Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / vcl / qa / cppunit / font.cxx
blobd496ebe418d352ec0f45be8b9cc482170598d464
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <test/bootstrapfixture.hxx>
11 #include <cppunit/TestAssert.h>
12 #include <cppunit/TestFixture.h>
14 #include <osl/file.hxx>
15 #include <osl/process.h>
17 #include <vcl/font.hxx>
19 class VclFontTest : public test::BootstrapFixture
21 public:
22 VclFontTest() : BootstrapFixture(true, false) {}
24 void testName();
25 void testWeight();
26 void testWidthType();
27 void testPitch();
28 void testItalic();
29 void testAlignment();
30 void testQuality();
31 void testBuiltInFontFlag();
32 void testEmbeddableFontFlag();
33 void testSubsettableFontFlag();
34 void testOrientationFlag();
35 void testSymbolFlagAndCharSet();
37 CPPUNIT_TEST_SUITE(VclFontTest);
38 CPPUNIT_TEST(testName);
39 CPPUNIT_TEST(testWeight);
40 CPPUNIT_TEST(testWidthType);
41 CPPUNIT_TEST(testPitch);
42 CPPUNIT_TEST(testItalic);
43 CPPUNIT_TEST(testAlignment);
44 CPPUNIT_TEST(testQuality);
45 CPPUNIT_TEST(testBuiltInFontFlag);
46 CPPUNIT_TEST(testEmbeddableFontFlag);
47 CPPUNIT_TEST(testSubsettableFontFlag);
48 CPPUNIT_TEST(testOrientationFlag);
49 CPPUNIT_TEST(testSymbolFlagAndCharSet);
50 CPPUNIT_TEST_SUITE_END();
53 void VclFontTest::testName()
55 vcl::Font aFont;
57 CPPUNIT_ASSERT_MESSAGE( "Family name should be empty", aFont.GetFamilyName().isEmpty());
58 CPPUNIT_ASSERT_MESSAGE( "Style name should be empty", aFont.GetStyleName().isEmpty());
59 aFont.SetFamilyName("Test family name");
60 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Family name should not be empty", OUString("Test family name"), aFont.GetFamilyName());
61 aFont.SetStyleName("Test style name");
62 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Style name should not be empty", OUString("Test style name"), aFont.GetStyleName());
65 void VclFontTest::testWeight()
67 vcl::Font aFont;
69 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Weight should be WEIGHT_DONTKNOW", FontWeight::WEIGHT_DONTKNOW, aFont.GetWeight());
71 aFont.SetWeight(FontWeight::WEIGHT_BLACK);
72 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Weight should be WEIGHT_BLACK", FontWeight::WEIGHT_BLACK, aFont.GetWeight());
75 void VclFontTest::testWidthType()
77 vcl::Font aFont;
79 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Font width should be WIDTH_DONTKNOW", FontWidth::WIDTH_DONTKNOW, aFont.GetWidthType());
81 aFont.SetWidthType(FontWidth::WIDTH_EXPANDED);
82 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Font width should be EXPANDED", FontWidth::WIDTH_EXPANDED, aFont.GetWidthType());
85 void VclFontTest::testItalic()
87 vcl::Font aFont;
89 // shouldn't this be set to ITALIC_DONTKNOW? currently it defaults to ITALIC_NONE
90 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Italic should be ITALIC_NONE", FontItalic::ITALIC_NONE, aFont.GetItalic());
92 aFont.SetItalic(FontItalic::ITALIC_NORMAL);
93 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Italic should be EXPANDED", FontItalic::ITALIC_NORMAL, aFont.GetItalic());
97 void VclFontTest::testAlignment()
99 vcl::Font aFont;
101 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Text alignment should be ALIGN_TOP", TextAlign::ALIGN_TOP, aFont.GetAlignment());
103 aFont.SetAlignment(TextAlign::ALIGN_BASELINE);
104 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Text alignment should be ALIGN_BASELINE", TextAlign::ALIGN_BASELINE, aFont.GetAlignment());
108 void VclFontTest::testPitch()
110 vcl::Font aFont;
112 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Pitch should be PITCH_DONTKNOW", FontPitch::PITCH_DONTKNOW, aFont.GetPitch());
114 aFont.SetPitch(FontPitch::PITCH_FIXED);
115 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Pitch should be PITCH_FIXED", FontPitch::PITCH_FIXED, aFont.GetPitch());
118 void VclFontTest::testQuality()
120 vcl::Font aFont;
122 CPPUNIT_ASSERT_EQUAL( (int)0, aFont.GetQuality() );
124 aFont.SetQuality( 100 );
125 CPPUNIT_ASSERT_EQUAL( (int)100, aFont.GetQuality() );
127 aFont.IncreaseQualityBy( 50 );
128 CPPUNIT_ASSERT_EQUAL( (int)150, aFont.GetQuality() );
130 aFont.DecreaseQualityBy( 100 );
131 CPPUNIT_ASSERT_EQUAL( (int)50, aFont.GetQuality() );
134 void VclFontTest::testBuiltInFontFlag()
136 vcl::Font aFont;
138 CPPUNIT_ASSERT_EQUAL( false, aFont.IsBuiltInFont() );
140 aFont.SetBuiltInFontFlag( true );
141 CPPUNIT_ASSERT_EQUAL( true, aFont.IsBuiltInFont() );
144 void VclFontTest::testEmbeddableFontFlag()
146 vcl::Font aFont;
148 CPPUNIT_ASSERT_EQUAL( false, aFont.CanEmbed() );
150 aFont.SetEmbeddableFlag( true );
151 CPPUNIT_ASSERT_EQUAL( true, aFont.CanEmbed() );
155 void VclFontTest::testSubsettableFontFlag()
157 vcl::Font aFont;
159 CPPUNIT_ASSERT_EQUAL( false, aFont.CanSubset() );
161 aFont.SetSubsettableFlag( true );
162 CPPUNIT_ASSERT_EQUAL( true, aFont.CanSubset() );
166 void VclFontTest::testOrientationFlag()
168 vcl::Font aFont;
170 CPPUNIT_ASSERT_EQUAL( false, aFont.CanRotate() );
172 aFont.SetOrientationFlag( true );
173 CPPUNIT_ASSERT_EQUAL( true, aFont.CanRotate() );
177 void VclFontTest::testSymbolFlagAndCharSet()
179 // default constructor should set scalable flag to false
180 vcl::Font aFont;
182 CPPUNIT_ASSERT_MESSAGE( "Should not be seen as a symbol font after default constructor called", !aFont.IsSymbolFont() );
183 CPPUNIT_ASSERT_MESSAGE( "Character set should be RTL_TEXTENCODING_DONTKNOW after default constructor called",
184 aFont.GetCharSet() == RTL_TEXTENCODING_DONTKNOW );
186 aFont.SetSymbolFlag(true);
188 CPPUNIT_ASSERT_MESSAGE( "Test 1: Symbol font flag should be on", aFont.IsSymbolFont() );
189 CPPUNIT_ASSERT_MESSAGE( "Test 1: Character set should be RTL_TEXTENCODING_SYMBOL",
190 aFont.GetCharSet() == RTL_TEXTENCODING_SYMBOL );
192 aFont.SetSymbolFlag(false);
194 CPPUNIT_ASSERT_MESSAGE( "Test 2: Symbol font flag should be off", !aFont.IsSymbolFont() );
195 CPPUNIT_ASSERT_MESSAGE( "Test 2: Character set should be RTL_TEXTENCODING_DONTKNOW",
196 aFont.GetCharSet() == RTL_TEXTENCODING_DONTKNOW );
198 aFont.SetCharSet( RTL_TEXTENCODING_SYMBOL );
200 CPPUNIT_ASSERT_MESSAGE( "Test 3: Symbol font flag should be on", aFont.IsSymbolFont() );
201 CPPUNIT_ASSERT_MESSAGE( "Test 3: Character set should be RTL_TEXTENCODING_SYMBOL",
202 aFont.GetCharSet() == RTL_TEXTENCODING_SYMBOL );
204 aFont.SetCharSet( RTL_TEXTENCODING_UNICODE );
206 CPPUNIT_ASSERT_MESSAGE( "Test 4: Symbol font flag should be off", !aFont.IsSymbolFont() );
207 CPPUNIT_ASSERT_MESSAGE( "Test 4: Character set should be RTL_TEXTENCODING_UNICODE",
208 aFont.GetCharSet() == RTL_TEXTENCODING_UNICODE );
211 CPPUNIT_TEST_SUITE_REGISTRATION(VclFontTest);
213 CPPUNIT_PLUGIN_IMPLEMENT();
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */