Kaydet (Commit) 60de1cb0 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Tomaž Vajngerl

Replace compile time test with a static_assert

There is no need to check this in a test when we can do it
directly in the header. static_assert will complain when compiling
something that uses the header file instead of waiting that it
finds a piece of code, where it is actually needed. The purpose of
the test was the same (fail early).

The main problem was that Color can be created and converted to
sal_uInt32 string completely in compile time, so it can be used for
"case" in a "switch" statement, which requires that in "case" it
uses a constant. Normally this isn't possible unless we resolve
and convert a Color to sal_uInt32 in compile time.
This use-case is used somewhere in the code, but it takes a lot
of (re)compiling to get to that piece of code, where it would
eventually fail.

Change-Id: I1f1f9b77c19a0e61f78ce703b380d98a569da833
Reviewed-on: https://gerrit.libreoffice.org/71060Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
Tested-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst bb6906b6
......@@ -243,6 +243,11 @@ namespace com { namespace sun { namespace star { namespace uno {
}
} } } }
// Test compile time conversion of Color to sal_uInt32
static_assert (sal_uInt32(Color(0x00, 0x12, 0x34, 0x56)) == 0x00123456);
static_assert (sal_uInt32(Color(0x12, 0x34, 0x56)) == 0x00123456);
// Color types
constexpr ::Color COL_BLACK ( 0x00, 0x00, 0x00 );
......
......@@ -21,7 +21,6 @@ namespace
class Test: public CppUnit::TestFixture
{
public:
void testConstruction();
void testVariables();
void test_asRGBColor();
void test_readAndWriteStream();
......@@ -31,7 +30,6 @@ public:
void testBColor();
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(testConstruction);
CPPUNIT_TEST(testVariables);
CPPUNIT_TEST(test_asRGBColor);
CPPUNIT_TEST(test_readAndWriteStream);
......@@ -42,24 +40,6 @@ public:
CPPUNIT_TEST_SUITE_END();
};
void Test::testConstruction()
{
// Compile time construction of the Color and representation as a sal_uInt32
Color aColor = Color(0xFF, 0xFF, 0x00);
switch (sal_uInt32(aColor))
{
case sal_uInt32(Color(0xFF, 0xFF, 0x00)):
break;
case sal_uInt32(Color(0x00, 0x00, 0xFF, 0xFF)):
break;
default:
CPPUNIT_ASSERT(false);
break;
}
}
void Test::testVariables()
{
Color aColor(0x44, 0x88, 0xAA);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment