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 | |
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')
-rw-r--r-- | tools/CppunitTest_tools_test.mk | 1 | ||||
-rw-r--r-- | tools/qa/cppunit/test_color.cxx | 61 | ||||
-rw-r--r-- | tools/source/generic/color.cxx | 7 |
3 files changed, 69 insertions, 0 deletions
diff --git a/tools/CppunitTest_tools_test.mk b/tools/CppunitTest_tools_test.mk index 959df078a49e..48324de54c3c 100644 --- a/tools/CppunitTest_tools_test.mk +++ b/tools/CppunitTest_tools_test.mk @@ -19,6 +19,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,tools_test, \ tools/qa/cppunit/test_reversemap \ tools/qa/cppunit/test_stream \ tools/qa/cppunit/test_urlobj \ + tools/qa/cppunit/test_color \ )) $(eval $(call gb_CppunitTest_use_api,tools_test, \ 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: */ diff --git a/tools/source/generic/color.cxx b/tools/source/generic/color.cxx index 909a4e82470f..64cc6c44e3fa 100644 --- a/tools/source/generic/color.cxx +++ b/tools/source/generic/color.cxx @@ -232,6 +232,13 @@ SvStream& Color::Write( SvStream& rOStm, bool bNewFormat ) return rOStm; } +OUString Color::AsRGBHexString() +{ + std::stringstream ss; + ss << std::hex << std::setfill ('0') << std::setw(6) << GetRGBColor(); + return OUString::createFromAscii(ss.str().c_str()); +} + #define COL_NAME_USER ((sal_uInt16)0x8000) SvStream& ReadColor( SvStream& rIStream, Color& rColor ) |