1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <test/bootstrapfixture.hxx>
11 #include <cppunit/TestAssert.h>
13 #include <vcl/font.hxx>
15 #include <font/EmphasisMark.hxx>
17 class VclFontTest
: public test::BootstrapFixture
20 VclFontTest() : BootstrapFixture(true, false) {}
29 void testEmphasisMarkShouldBePosAboveWhenSimplifiedChinese();
30 void testEmphasisMarkShouldBePosAboveWhenNotSimplifiedChinese();
31 void testEmphasisMarkInitAsNone();
32 void testEmphasisMarkInitAsDot();
33 void testEmphasisMarkInitAsDisc();
34 void testEmphasisMarkInitAsAccent();
35 void testEmphasisMarkInitAsStyle();
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(testEmphasisMarkShouldBePosAboveWhenSimplifiedChinese
);
46 CPPUNIT_TEST(testEmphasisMarkShouldBePosAboveWhenNotSimplifiedChinese
);
47 CPPUNIT_TEST(testEmphasisMarkInitAsNone
);
48 CPPUNIT_TEST(testEmphasisMarkInitAsDot
);
49 CPPUNIT_TEST(testEmphasisMarkInitAsDisc
);
50 CPPUNIT_TEST(testEmphasisMarkInitAsAccent
);
51 CPPUNIT_TEST(testEmphasisMarkInitAsStyle
);
52 CPPUNIT_TEST_SUITE_END();
55 void VclFontTest::testName()
59 CPPUNIT_ASSERT_MESSAGE( "Family name should be empty", aFont
.GetFamilyName().isEmpty());
60 CPPUNIT_ASSERT_MESSAGE( "Style name should be empty", aFont
.GetStyleName().isEmpty());
61 aFont
.SetFamilyName(u
"Test family name"_ustr
);
62 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Family name should not be empty", u
"Test family name"_ustr
, aFont
.GetFamilyName());
63 aFont
.SetStyleName(u
"Test style name"_ustr
);
64 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Style name should not be empty", u
"Test style name"_ustr
, aFont
.GetStyleName());
67 void VclFontTest::testWeight()
71 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Weight should be WEIGHT_DONTKNOW", FontWeight::WEIGHT_DONTKNOW
, aFont
.GetWeight());
73 aFont
.SetWeight(FontWeight::WEIGHT_BLACK
);
74 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Weight should be WEIGHT_BLACK", FontWeight::WEIGHT_BLACK
, aFont
.GetWeight());
77 void VclFontTest::testWidthType()
81 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Font width should be WIDTH_DONTKNOW", FontWidth::WIDTH_DONTKNOW
, aFont
.GetWidthType());
83 aFont
.SetWidthType(FontWidth::WIDTH_EXPANDED
);
84 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Font width should be EXPANDED", FontWidth::WIDTH_EXPANDED
, aFont
.GetWidthType());
87 void VclFontTest::testItalic()
91 // shouldn't this be set to ITALIC_DONTKNOW? currently it defaults to ITALIC_NONE
92 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Italic should be ITALIC_NONE", FontItalic::ITALIC_NONE
, aFont
.GetItalic());
94 aFont
.SetItalic(FontItalic::ITALIC_NORMAL
);
95 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Italic should be EXPANDED", FontItalic::ITALIC_NORMAL
, aFont
.GetItalic());
99 void VclFontTest::testAlignment()
103 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Text alignment should be ALIGN_TOP", TextAlign::ALIGN_TOP
, aFont
.GetAlignment());
105 aFont
.SetAlignment(TextAlign::ALIGN_BASELINE
);
106 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Text alignment should be ALIGN_BASELINE", TextAlign::ALIGN_BASELINE
, aFont
.GetAlignment());
110 void VclFontTest::testPitch()
114 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Pitch should be PITCH_DONTKNOW", FontPitch::PITCH_DONTKNOW
, aFont
.GetPitch());
116 aFont
.SetPitch(FontPitch::PITCH_FIXED
);
117 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Pitch should be PITCH_FIXED", FontPitch::PITCH_FIXED
, aFont
.GetPitch());
120 void VclFontTest::testQuality()
124 CPPUNIT_ASSERT_EQUAL( int(0), aFont
.GetQuality() );
126 aFont
.SetQuality( 100 );
127 CPPUNIT_ASSERT_EQUAL( int(100), aFont
.GetQuality() );
129 aFont
.IncreaseQualityBy( 50 );
130 CPPUNIT_ASSERT_EQUAL( int(150), aFont
.GetQuality() );
132 aFont
.DecreaseQualityBy( 100 );
133 CPPUNIT_ASSERT_EQUAL( int(50), aFont
.GetQuality() );
136 void VclFontTest::testEmphasisMarkShouldBePosAboveWhenSimplifiedChinese()
139 aFont
.SetLanguage(LANGUAGE_CHINESE_SIMPLIFIED
);
140 aFont
.SetEmphasisMark(FontEmphasisMark::Accent
);
142 CPPUNIT_ASSERT_MESSAGE("Emphasis not positioned below", (aFont
.GetEmphasisMarkStyle() & FontEmphasisMark::PosBelow
));
143 CPPUNIT_ASSERT_MESSAGE("Accent mark not kept", (aFont
.GetEmphasisMarkStyle() & FontEmphasisMark::Accent
));
146 void VclFontTest::testEmphasisMarkShouldBePosAboveWhenNotSimplifiedChinese()
149 aFont
.SetLanguage(LANGUAGE_ENGLISH
);
150 aFont
.SetEmphasisMark(FontEmphasisMark::Accent
);
152 CPPUNIT_ASSERT_MESSAGE("Emphasis not positioned above", (aFont
.GetEmphasisMarkStyle() & FontEmphasisMark::PosAbove
));
153 CPPUNIT_ASSERT_MESSAGE("Accent mark not kept", (aFont
.GetEmphasisMarkStyle() & FontEmphasisMark::Accent
));
156 void VclFontTest::testEmphasisMarkInitAsNone()
158 vcl::font::EmphasisMark
aEmphasisMark(FontEmphasisMark::NONE
, 5, 96);
160 CPPUNIT_ASSERT_MESSAGE("Shape not a polyline", !aEmphasisMark
.IsShapePolyLine());
161 CPPUNIT_ASSERT_EQUAL_MESSAGE("Shape wrong", tools::PolyPolygon(), aEmphasisMark
.GetShape());
162 CPPUNIT_ASSERT_EQUAL_MESSAGE("Rect1 not correct", tools::Rectangle(), aEmphasisMark
.GetRect1());
163 CPPUNIT_ASSERT_EQUAL_MESSAGE("Rect2 not correct", tools::Rectangle(), aEmphasisMark
.GetRect2());
164 CPPUNIT_ASSERT_EQUAL_MESSAGE("y offset wrong", tools::Long(1), aEmphasisMark
.GetYOffset());
165 CPPUNIT_ASSERT_EQUAL_MESSAGE("width wrong", tools::Long(0), aEmphasisMark
.GetWidth());
168 void VclFontTest::testEmphasisMarkInitAsDot()
170 vcl::font::EmphasisMark
aEmphasisMark(FontEmphasisMark::Dot
, 5, 96);
172 CPPUNIT_ASSERT_MESSAGE("Shape not a polyline", !aEmphasisMark
.IsShapePolyLine());
173 CPPUNIT_ASSERT_EQUAL_MESSAGE("Shape wrong", tools::PolyPolygon(), aEmphasisMark
.GetShape());
174 CPPUNIT_ASSERT_EQUAL_MESSAGE("Rect1 not correct", tools::Rectangle(Point(), Size(2, 2)), aEmphasisMark
.GetRect1());
175 CPPUNIT_ASSERT_EQUAL_MESSAGE("Rect2 not correct", tools::Rectangle(), aEmphasisMark
.GetRect2());
176 CPPUNIT_ASSERT_EQUAL_MESSAGE("y offset wrong", tools::Long(3), aEmphasisMark
.GetYOffset());
177 CPPUNIT_ASSERT_EQUAL_MESSAGE("width wrong", tools::Long(2), aEmphasisMark
.GetWidth());
180 void VclFontTest::testEmphasisMarkInitAsDisc()
182 vcl::font::EmphasisMark
aEmphasisMark(FontEmphasisMark::Disc
, 5, 96);
184 CPPUNIT_ASSERT_MESSAGE("Shape not a polyline", !aEmphasisMark
.IsShapePolyLine());
185 // something wrong with polypolygon equality checking!
186 // CPPUNIT_ASSERT_EQUAL_MESSAGE("Shape not disc with radius of 2", tools::PolyPolygon(tools::Polygon(Point(2, 2), 2, 2)), aEmphasisMark.GetShape());
187 CPPUNIT_ASSERT_EQUAL_MESSAGE("Rect1 not correct", tools::Rectangle(), aEmphasisMark
.GetRect1());
188 CPPUNIT_ASSERT_EQUAL_MESSAGE("Rect2 not correct", tools::Rectangle(), aEmphasisMark
.GetRect2());
189 CPPUNIT_ASSERT_EQUAL_MESSAGE("y offset wrong", tools::Long(4), aEmphasisMark
.GetYOffset());
190 CPPUNIT_ASSERT_EQUAL_MESSAGE("width wrong", tools::Long(4), aEmphasisMark
.GetWidth());
193 void VclFontTest::testEmphasisMarkInitAsAccent()
195 vcl::font::EmphasisMark
aEmphasisMark(FontEmphasisMark::Accent
, 5, 96);
197 CPPUNIT_ASSERT_MESSAGE("Shape not a polyline", !aEmphasisMark
.IsShapePolyLine());
198 CPPUNIT_ASSERT_EQUAL_MESSAGE("Rect1 not correct", tools::Rectangle(), aEmphasisMark
.GetRect1());
199 CPPUNIT_ASSERT_EQUAL_MESSAGE("Rect2 not correct", tools::Rectangle(), aEmphasisMark
.GetRect2());
200 CPPUNIT_ASSERT_EQUAL_MESSAGE("y offset wrong", tools::Long(4), aEmphasisMark
.GetYOffset());
201 CPPUNIT_ASSERT_EQUAL_MESSAGE("width wrong", tools::Long(4), aEmphasisMark
.GetWidth());
204 void VclFontTest::testEmphasisMarkInitAsStyle()
206 vcl::font::EmphasisMark
aEmphasisMark(FontEmphasisMark::Style
, 5, 96);
208 CPPUNIT_ASSERT_MESSAGE("Shape not a polyline", !aEmphasisMark
.IsShapePolyLine());
209 CPPUNIT_ASSERT_EQUAL_MESSAGE("Rect1 not correct", tools::Rectangle(), aEmphasisMark
.GetRect1());
210 CPPUNIT_ASSERT_EQUAL_MESSAGE("Rect2 not correct", tools::Rectangle(), aEmphasisMark
.GetRect2());
211 CPPUNIT_ASSERT_EQUAL_MESSAGE("y offset wrong", tools::Long(1), aEmphasisMark
.GetYOffset());
212 CPPUNIT_ASSERT_EQUAL_MESSAGE("width wrong", tools::Long(0), aEmphasisMark
.GetWidth());
215 CPPUNIT_TEST_SUITE_REGISTRATION(VclFontTest
);
217 CPPUNIT_PLUGIN_IMPLEMENT();
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */