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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <test/bootstrapfixture.hxx>
23 #include <vcl/BitmapColor.hxx>
27 class BitmapColorTest
: public test::BootstrapFixture
31 : BootstrapFixture(true, false)
35 void defaultConstructor();
36 void colorValueConstructor();
37 void colorClassConstructor();
42 CPPUNIT_TEST_SUITE(BitmapColorTest
);
43 CPPUNIT_TEST(defaultConstructor
);
44 CPPUNIT_TEST(colorValueConstructor
);
45 CPPUNIT_TEST(colorClassConstructor
);
46 CPPUNIT_TEST(setValue
);
48 CPPUNIT_TEST(getLuminance
);
49 CPPUNIT_TEST_SUITE_END();
52 void BitmapColorTest::defaultConstructor()
54 BitmapColor aBmpColor
;
56 CPPUNIT_ASSERT_EQUAL_MESSAGE("Red wrong", static_cast<sal_uInt8
>(0), aBmpColor
.GetRed());
57 CPPUNIT_ASSERT_EQUAL_MESSAGE("Green wrong", static_cast<sal_uInt8
>(0), aBmpColor
.GetGreen());
58 CPPUNIT_ASSERT_EQUAL_MESSAGE("Blue wrong", static_cast<sal_uInt8
>(0), aBmpColor
.GetBlue());
59 CPPUNIT_ASSERT_EQUAL_MESSAGE("Alpha wrong", static_cast<sal_uInt8
>(0), aBmpColor
.GetAlpha());
62 void BitmapColorTest::colorValueConstructor()
65 BitmapColor
aBmpColor(0, 0, 0);
67 CPPUNIT_ASSERT_EQUAL_MESSAGE("Red wrong", static_cast<sal_uInt8
>(0), aBmpColor
.GetRed());
68 CPPUNIT_ASSERT_EQUAL_MESSAGE("Green wrong", static_cast<sal_uInt8
>(0),
69 aBmpColor
.GetGreen());
70 CPPUNIT_ASSERT_EQUAL_MESSAGE("Blue wrong", static_cast<sal_uInt8
>(0), aBmpColor
.GetBlue());
71 CPPUNIT_ASSERT_EQUAL_MESSAGE("Alpha wrong", static_cast<sal_uInt8
>(0),
72 aBmpColor
.GetAlpha());
76 BitmapColor
aBmpColor(128, 128, 128);
78 CPPUNIT_ASSERT_EQUAL_MESSAGE("Red wrong", static_cast<sal_uInt8
>(128), aBmpColor
.GetRed());
79 CPPUNIT_ASSERT_EQUAL_MESSAGE("Green wrong", static_cast<sal_uInt8
>(128),
80 aBmpColor
.GetGreen());
81 CPPUNIT_ASSERT_EQUAL_MESSAGE("Blue wrong", static_cast<sal_uInt8
>(128),
83 CPPUNIT_ASSERT_EQUAL_MESSAGE("Alpha wrong", static_cast<sal_uInt8
>(0),
84 aBmpColor
.GetAlpha());
88 BitmapColor
aBmpColor(255, 255, 255);
90 CPPUNIT_ASSERT_EQUAL_MESSAGE("Red wrong", static_cast<sal_uInt8
>(255), aBmpColor
.GetRed());
91 CPPUNIT_ASSERT_EQUAL_MESSAGE("Green wrong", static_cast<sal_uInt8
>(255),
92 aBmpColor
.GetGreen());
93 CPPUNIT_ASSERT_EQUAL_MESSAGE("Blue wrong", static_cast<sal_uInt8
>(255),
95 CPPUNIT_ASSERT_EQUAL_MESSAGE("Alpha wrong", static_cast<sal_uInt8
>(0),
96 aBmpColor
.GetAlpha());
100 void BitmapColorTest::colorClassConstructor()
103 BitmapColor
aBmpColor(Color(0, 0, 0));
105 CPPUNIT_ASSERT_EQUAL_MESSAGE("Red wrong", static_cast<sal_uInt8
>(0), aBmpColor
.GetRed());
106 CPPUNIT_ASSERT_EQUAL_MESSAGE("Green wrong", static_cast<sal_uInt8
>(0),
107 aBmpColor
.GetGreen());
108 CPPUNIT_ASSERT_EQUAL_MESSAGE("Blue wrong", static_cast<sal_uInt8
>(0), aBmpColor
.GetBlue());
109 CPPUNIT_ASSERT_EQUAL_MESSAGE("Alpha wrong", static_cast<sal_uInt8
>(0),
110 aBmpColor
.GetAlpha());
114 BitmapColor
aBmpColor(Color(127, 127, 127));
116 CPPUNIT_ASSERT_EQUAL_MESSAGE("Red wrong", static_cast<sal_uInt8
>(127), aBmpColor
.GetRed());
117 CPPUNIT_ASSERT_EQUAL_MESSAGE("Green wrong", static_cast<sal_uInt8
>(127),
118 aBmpColor
.GetGreen());
119 CPPUNIT_ASSERT_EQUAL_MESSAGE("Blue wrong", static_cast<sal_uInt8
>(127),
120 aBmpColor
.GetBlue());
121 CPPUNIT_ASSERT_EQUAL_MESSAGE("Alpha wrong", static_cast<sal_uInt8
>(0),
122 aBmpColor
.GetAlpha());
126 BitmapColor
aBmpColor(Color(255, 255, 255));
128 CPPUNIT_ASSERT_EQUAL_MESSAGE("Red wrong", static_cast<sal_uInt8
>(255), aBmpColor
.GetRed());
129 CPPUNIT_ASSERT_EQUAL_MESSAGE("Green wrong", static_cast<sal_uInt8
>(255),
130 aBmpColor
.GetGreen());
131 CPPUNIT_ASSERT_EQUAL_MESSAGE("Blue wrong", static_cast<sal_uInt8
>(255),
132 aBmpColor
.GetBlue());
133 CPPUNIT_ASSERT_EQUAL_MESSAGE("Alpha wrong", static_cast<sal_uInt8
>(0),
134 aBmpColor
.GetAlpha());
137 // Transparency / Alpha
139 BitmapColor
aBmpColor(Color(255, 128, 64, 0));
141 CPPUNIT_ASSERT_EQUAL_MESSAGE("Red wrong", static_cast<sal_uInt8
>(128), aBmpColor
.GetRed());
142 CPPUNIT_ASSERT_EQUAL_MESSAGE("Green wrong", static_cast<sal_uInt8
>(64),
143 aBmpColor
.GetGreen());
144 CPPUNIT_ASSERT_EQUAL_MESSAGE("Blue wrong", static_cast<sal_uInt8
>(0), aBmpColor
.GetBlue());
145 CPPUNIT_ASSERT_EQUAL_MESSAGE("Alpha wrong", static_cast<sal_uInt8
>(255),
146 aBmpColor
.GetAlpha());
150 void BitmapColorTest::setValue()
152 BitmapColor aBmpColor
;
154 aBmpColor
.SetRed(127);
155 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(127), aBmpColor
.GetRed());
157 aBmpColor
.SetGreen(127);
158 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(127), aBmpColor
.GetGreen());
160 aBmpColor
.SetBlue(127);
161 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(127), aBmpColor
.GetBlue());
164 void BitmapColorTest::invert()
166 BitmapColor
aBmpColor(255, 255, 255);
167 BitmapColor
aInvertedColor(aBmpColor
);
168 aInvertedColor
.Invert();
170 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(0), aInvertedColor
.GetRed());
171 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(0), aInvertedColor
.GetGreen());
172 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(0), aInvertedColor
.GetBlue());
175 void BitmapColorTest::getLuminance()
178 BitmapColor
aBmpColor(COL_BLACK
);
179 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(0), aBmpColor
.GetLuminance());
183 BitmapColor
aBmpColor(COL_BLUE
);
184 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(14), aBmpColor
.GetLuminance());
188 BitmapColor
aBmpColor(COL_GREEN
);
189 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(75), aBmpColor
.GetLuminance());
193 BitmapColor
aBmpColor(COL_CYAN
);
194 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(90), aBmpColor
.GetLuminance());
198 BitmapColor
aBmpColor(COL_RED
);
199 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(38), aBmpColor
.GetLuminance());
203 BitmapColor
aBmpColor(COL_MAGENTA
);
204 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(52), aBmpColor
.GetLuminance());
208 BitmapColor
aBmpColor(COL_BROWN
);
209 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(113), aBmpColor
.GetLuminance());
213 BitmapColor
aBmpColor(COL_GRAY
);
214 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(128), aBmpColor
.GetLuminance());
218 BitmapColor
aBmpColor(COL_LIGHTGRAY
);
219 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(192), aBmpColor
.GetLuminance());
223 BitmapColor
aBmpColor(COL_LIGHTBLUE
);
224 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(28), aBmpColor
.GetLuminance());
228 BitmapColor
aBmpColor(COL_LIGHTGREEN
);
229 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(150), aBmpColor
.GetLuminance());
233 BitmapColor
aBmpColor(COL_LIGHTCYAN
);
234 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(179), aBmpColor
.GetLuminance());
238 BitmapColor
aBmpColor(COL_LIGHTRED
);
239 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(75), aBmpColor
.GetLuminance());
243 BitmapColor
aBmpColor(COL_LIGHTMAGENTA
);
244 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(104), aBmpColor
.GetLuminance());
248 BitmapColor
aBmpColor(COL_YELLOW
);
249 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(226), aBmpColor
.GetLuminance());
253 BitmapColor
aBmpColor(COL_WHITE
);
254 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(255), aBmpColor
.GetLuminance());
260 CPPUNIT_TEST_SUITE_REGISTRATION(BitmapColorTest
);
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */