diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-05-12 12:29:20 +0200 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-05-15 19:51:06 +0200 |
commit | 599328b0a9f50f65d8ad1efea8b72ac604153c56 (patch) | |
tree | a3a8192e2c03a0c3c7d44708ff1fe7b3f429b97e /tools/qa | |
parent | 1c77fcacbd07b077412048a0647271fad16ff461 (diff) |
tools: add AsRGBHexString to Color + unit test
AsRGBHexString returns the Color as a RGB hex string. For example
"00ff00" for green color.
Change-Id: Ia95c7f9eb6d9aefc3ca989046fa8d76b7b7f9e8f
Diffstat (limited to 'tools/qa')
-rw-r--r-- | tools/qa/cppunit/test_color.cxx | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tools/qa/cppunit/test_color.cxx b/tools/qa/cppunit/test_color.cxx new file mode 100644 index 000000000000..6846fada04a4 --- /dev/null +++ b/tools/qa/cppunit/test_color.cxx @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <sal/types.h> +#include "cppunit/TestAssert.h" +#include "cppunit/TestFixture.h" +#include "cppunit/extensions/HelperMacros.h" +#include "cppunit/plugin/TestPlugIn.h" +#include <tools/color.hxx> + +namespace +{ + +class Test: public CppUnit::TestFixture +{ +public: + void test_asRGBColor(); + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(test_asRGBColor); + CPPUNIT_TEST_SUITE_END(); +}; + +void Test::test_asRGBColor() +{ + Color aColor; + aColor = COL_BLACK; + CPPUNIT_ASSERT_EQUAL(aColor.AsRGBHexString(), OUString("000000")); + + aColor = COL_WHITE; + CPPUNIT_ASSERT_EQUAL(aColor.AsRGBHexString(), OUString("ffffff")); + + aColor = COL_RED; + CPPUNIT_ASSERT_EQUAL(aColor.AsRGBHexString(), OUString("800000")); + + aColor = COL_TRANSPARENT; + CPPUNIT_ASSERT_EQUAL(aColor.AsRGBHexString(), OUString("ffffff")); + + aColor = COL_BLUE; + CPPUNIT_ASSERT_EQUAL(aColor.AsRGBHexString(), OUString("000080")); + + aColor.SetRed(0x12); + aColor.SetGreen(0x34); + aColor.SetBlue(0x56); + CPPUNIT_ASSERT_EQUAL(aColor.AsRGBHexString(), OUString("123456")); + + aColor = COL_AUTO; + CPPUNIT_ASSERT_EQUAL(aColor.AsRGBHexString(), OUString("ffffff")); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |