summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/CppunitTest_tools_test.mk1
-rw-r--r--tools/qa/cppunit/test_color.cxx61
-rw-r--r--tools/source/generic/color.cxx7
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 )