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 <tools/color.hxx>
22 #include <test/bootstrapfixture.hxx>
24 #include <vcl/BitmapColor.hxx>
28 class BitmapColorTest
: public test::BootstrapFixture
32 : BootstrapFixture(true, false)
36 void defaultConstructor();
37 void colorValueConstructor();
38 void colorClassConstructor();
43 CPPUNIT_TEST_SUITE(BitmapColorTest
);
44 CPPUNIT_TEST(defaultConstructor
);
45 CPPUNIT_TEST(colorValueConstructor
);
46 CPPUNIT_TEST(colorClassConstructor
);
47 CPPUNIT_TEST(setValue
);
49 CPPUNIT_TEST(getLuminance
);
50 CPPUNIT_TEST_SUITE_END();
53 void BitmapColorTest::defaultConstructor()
55 BitmapColor aBmpColor
;
57 CPPUNIT_ASSERT_EQUAL_MESSAGE("Red wrong", static_cast<sal_uInt8
>(0), aBmpColor
.GetRed());
58 CPPUNIT_ASSERT_EQUAL_MESSAGE("Green wrong", static_cast<sal_uInt8
>(0), aBmpColor
.GetGreen());
59 CPPUNIT_ASSERT_EQUAL_MESSAGE("Blue wrong", static_cast<sal_uInt8
>(0), aBmpColor
.GetBlue());
60 CPPUNIT_ASSERT_EQUAL_MESSAGE("Transparency wrong", static_cast<sal_uInt8
>(255),
61 aBmpColor
.GetAlpha());
64 void BitmapColorTest::colorValueConstructor()
67 BitmapColor
aBmpColor(0, 0, 0);
69 CPPUNIT_ASSERT_EQUAL_MESSAGE("Red wrong", static_cast<sal_uInt8
>(0), aBmpColor
.GetRed());
70 CPPUNIT_ASSERT_EQUAL_MESSAGE("Green wrong", static_cast<sal_uInt8
>(0),
71 aBmpColor
.GetGreen());
72 CPPUNIT_ASSERT_EQUAL_MESSAGE("Blue wrong", static_cast<sal_uInt8
>(0), aBmpColor
.GetBlue());
73 CPPUNIT_ASSERT_EQUAL_MESSAGE("Transparency wrong", static_cast<sal_uInt8
>(255),
74 aBmpColor
.GetAlpha());
78 BitmapColor
aBmpColor(128, 128, 128);
80 CPPUNIT_ASSERT_EQUAL_MESSAGE("Red wrong", static_cast<sal_uInt8
>(128), aBmpColor
.GetRed());
81 CPPUNIT_ASSERT_EQUAL_MESSAGE("Green wrong", static_cast<sal_uInt8
>(128),
82 aBmpColor
.GetGreen());
83 CPPUNIT_ASSERT_EQUAL_MESSAGE("Blue wrong", static_cast<sal_uInt8
>(128),
85 CPPUNIT_ASSERT_EQUAL_MESSAGE("Transparency wrong", static_cast<sal_uInt8
>(255),
86 aBmpColor
.GetAlpha());
90 BitmapColor
aBmpColor(255, 255, 255);
92 CPPUNIT_ASSERT_EQUAL_MESSAGE("Red wrong", static_cast<sal_uInt8
>(255), aBmpColor
.GetRed());
93 CPPUNIT_ASSERT_EQUAL_MESSAGE("Green wrong", static_cast<sal_uInt8
>(255),
94 aBmpColor
.GetGreen());
95 CPPUNIT_ASSERT_EQUAL_MESSAGE("Blue wrong", static_cast<sal_uInt8
>(255),
97 CPPUNIT_ASSERT_EQUAL_MESSAGE("Transparency wrong", static_cast<sal_uInt8
>(255),
98 aBmpColor
.GetAlpha());
102 void BitmapColorTest::colorClassConstructor()
105 BitmapColor
aBmpColor(COL_BLACK
);
107 CPPUNIT_ASSERT_EQUAL_MESSAGE("Red wrong", static_cast<sal_uInt8
>(0), aBmpColor
.GetRed());
108 CPPUNIT_ASSERT_EQUAL_MESSAGE("Green wrong", static_cast<sal_uInt8
>(0),
109 aBmpColor
.GetGreen());
110 CPPUNIT_ASSERT_EQUAL_MESSAGE("Blue wrong", static_cast<sal_uInt8
>(0), aBmpColor
.GetBlue());
111 CPPUNIT_ASSERT_EQUAL_MESSAGE("Transparency wrong", static_cast<sal_uInt8
>(255),
112 aBmpColor
.GetAlpha());
116 BitmapColor
aBmpColor(Color(127, 127, 127));
118 CPPUNIT_ASSERT_EQUAL_MESSAGE("Red wrong", static_cast<sal_uInt8
>(127), aBmpColor
.GetRed());
119 CPPUNIT_ASSERT_EQUAL_MESSAGE("Green wrong", static_cast<sal_uInt8
>(127),
120 aBmpColor
.GetGreen());
121 CPPUNIT_ASSERT_EQUAL_MESSAGE("Blue wrong", static_cast<sal_uInt8
>(127),
122 aBmpColor
.GetBlue());
123 CPPUNIT_ASSERT_EQUAL_MESSAGE("Transparency wrong", static_cast<sal_uInt8
>(255),
124 aBmpColor
.GetAlpha());
128 BitmapColor
aBmpColor(COL_WHITE
);
130 CPPUNIT_ASSERT_EQUAL_MESSAGE("Red wrong", static_cast<sal_uInt8
>(255), aBmpColor
.GetRed());
131 CPPUNIT_ASSERT_EQUAL_MESSAGE("Green wrong", static_cast<sal_uInt8
>(255),
132 aBmpColor
.GetGreen());
133 CPPUNIT_ASSERT_EQUAL_MESSAGE("Blue wrong", static_cast<sal_uInt8
>(255),
134 aBmpColor
.GetBlue());
135 CPPUNIT_ASSERT_EQUAL_MESSAGE("Transparency wrong", static_cast<sal_uInt8
>(255),
136 aBmpColor
.GetAlpha());
139 // Transparency / Alpha
141 BitmapColor
aBmpColor(Color(ColorTransparency
, 255, 128, 64, 0));
143 CPPUNIT_ASSERT_EQUAL_MESSAGE("Red wrong", static_cast<sal_uInt8
>(128), aBmpColor
.GetRed());
144 CPPUNIT_ASSERT_EQUAL_MESSAGE("Green wrong", static_cast<sal_uInt8
>(64),
145 aBmpColor
.GetGreen());
146 CPPUNIT_ASSERT_EQUAL_MESSAGE("Blue wrong", static_cast<sal_uInt8
>(0), aBmpColor
.GetBlue());
147 CPPUNIT_ASSERT_EQUAL_MESSAGE("Transparency wrong", static_cast<sal_uInt8
>(0),
148 aBmpColor
.GetAlpha());
152 void BitmapColorTest::setValue()
154 BitmapColor aBmpColor
;
156 aBmpColor
.SetRed(127);
157 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(127), aBmpColor
.GetRed());
159 aBmpColor
.SetGreen(127);
160 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(127), aBmpColor
.GetGreen());
162 aBmpColor
.SetBlue(127);
163 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(127), aBmpColor
.GetBlue());
166 void BitmapColorTest::invert()
168 BitmapColor
aBmpColor(255, 255, 255);
169 BitmapColor
aInvertedColor(aBmpColor
);
170 aInvertedColor
.Invert();
172 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(0), aInvertedColor
.GetRed());
173 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(0), aInvertedColor
.GetGreen());
174 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(0), aInvertedColor
.GetBlue());
177 void BitmapColorTest::getLuminance()
180 BitmapColor
aBmpColor(COL_BLACK
);
181 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(0), aBmpColor
.GetLuminance());
185 BitmapColor
aBmpColor(COL_BLUE
);
186 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(14), aBmpColor
.GetLuminance());
190 BitmapColor
aBmpColor(COL_GREEN
);
191 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(75), aBmpColor
.GetLuminance());
195 BitmapColor
aBmpColor(COL_CYAN
);
196 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(90), aBmpColor
.GetLuminance());
200 BitmapColor
aBmpColor(COL_RED
);
201 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(38), aBmpColor
.GetLuminance());
205 BitmapColor
aBmpColor(COL_MAGENTA
);
206 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(52), aBmpColor
.GetLuminance());
210 BitmapColor
aBmpColor(COL_BROWN
);
211 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(113), aBmpColor
.GetLuminance());
215 BitmapColor
aBmpColor(COL_GRAY
);
216 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(128), aBmpColor
.GetLuminance());
220 BitmapColor
aBmpColor(COL_LIGHTGRAY
);
221 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(192), aBmpColor
.GetLuminance());
225 BitmapColor
aBmpColor(COL_LIGHTBLUE
);
226 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(28), aBmpColor
.GetLuminance());
230 BitmapColor
aBmpColor(COL_LIGHTGREEN
);
231 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(150), aBmpColor
.GetLuminance());
235 BitmapColor
aBmpColor(COL_LIGHTCYAN
);
236 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(179), aBmpColor
.GetLuminance());
240 BitmapColor
aBmpColor(COL_LIGHTRED
);
241 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(75), aBmpColor
.GetLuminance());
245 BitmapColor
aBmpColor(COL_LIGHTMAGENTA
);
246 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(104), aBmpColor
.GetLuminance());
250 BitmapColor
aBmpColor(COL_YELLOW
);
251 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(226), aBmpColor
.GetLuminance());
255 BitmapColor
aBmpColor(COL_WHITE
);
256 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>(255), aBmpColor
.GetLuminance());
262 CPPUNIT_TEST_SUITE_REGISTRATION(BitmapColorTest
);
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */