From 294b795005e846047837fc8f93a8a0cdb02376d4 Mon Sep 17 00:00:00 2001 From: "Vogel, Rick" Date: Fri, 24 Mar 2023 11:30:31 +0100 Subject: [PATCH] move static assertions into tests --- features/qskconfig.pri | 1 - src/common/QskRgbValue.cpp | 25 ------------------------- src/src.pro | 1 - tests/test_QskRgbLiterals.cpp | 26 ++++++++++++++++++++++++++ 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/features/qskconfig.pri b/features/qskconfig.pri index b1c40d56..1b3f20fb 100644 --- a/features/qskconfig.pri +++ b/features/qskconfig.pri @@ -63,7 +63,6 @@ OBJECTS_DIR = obj RCC_DIR = rcc QSK_CONFIG += QskDll -QSK_CONFIG += QskRequireConstexprLiterals linux { diff --git a/src/common/QskRgbValue.cpp b/src/common/QskRgbValue.cpp index 886729a9..9a091b7a 100644 --- a/src/common/QskRgbValue.cpp +++ b/src/common/QskRgbValue.cpp @@ -12,31 +12,6 @@ QSK_QT_PRIVATE_BEGIN #include QSK_QT_PRIVATE_END -#ifdef QSK_REQUIRE_CONSTEXPR_LITERALS -namespace QskRgb::literals::integral -{ - // RGBA hex string to QRgb with defaulted alpha = 0xFF - static_assert( "#123456"_rgba == 0xFF123456, "invalid or not constexpr" ); - static_assert( "#123456"_argb == 0xFF123456, "invalid or not constexpr" ); - - // ARGB hex string to QRgb with defaulted alpha = 0xFF - static_assert( "#AA112233"_argb == 0xAA112233, "invalid or not constexpr" ); - static_assert( "#112233AA"_rgba == 0xAA112233, "invalid or not constexpr" ); - - // RGBA hex literal to QRgb with defaulted alpha = 0xFF - static_assert( 0x112233_rgba == 0xFF112233, "invalid or not constexpr" ); - static_assert( 0xaabbcc_rgba == 0xFFAABBCC, "invalid or not constexpr" ); - static_assert( 0xAABBCC_rgba == 0xFFAABBCC, "invalid or not constexpr" ); - static_assert( 0x112233aa_rgba == 0xaa112233, "invalid or not constexpr" ); - - // ARGB hex literal to QRgb with defaulted alpha = 0xFF - static_assert( 0x112233_argb == 0xFF112233, "invalid or not constexpr" ); - static_assert( 0xaabbcc_argb == 0xFFAABBCC, "invalid or not constexpr" ); - static_assert( 0xAABBCC_argb == 0xFFAABBCC, "invalid or not constexpr" ); - static_assert( 0x112233aa_argb == 0x112233aa, "invalid or not constexpr" ); -} -#endif - namespace { inline int value( int from, int to, qreal ratio ) diff --git a/src/src.pro b/src/src.pro index e0070a42..6cd9ba77 100644 --- a/src/src.pro +++ b/src/src.pro @@ -8,7 +8,6 @@ greaterThan( QT_MAJOR_VERSION, 5 ) { } contains(QSK_CONFIG, QskDll): DEFINES += QSK_MAKEDLL -contains(QSK_CONFIG, QskRequireConstexprLiterals): DEFINES += QSK_REQUIRE_CONSTEXPR_LITERALS QSK_SUBDIRS = common graphic nodes controls layouts dialogs inputpanel INCLUDEPATH *= $${QSK_SUBDIRS} diff --git a/tests/test_QskRgbLiterals.cpp b/tests/test_QskRgbLiterals.cpp index 486c2566..ec2afb7b 100644 --- a/tests/test_QskRgbLiterals.cpp +++ b/tests/test_QskRgbLiterals.cpp @@ -2,6 +2,32 @@ #include #include +#define QSK_REQUIRE_CONSTEXPR_LITERALS +#ifdef QSK_REQUIRE_CONSTEXPR_LITERALS +namespace QskRgb::literals::integral +{ +// RGBA hex string to QRgb with defaulted alpha = 0xFF +static_assert( "#123456"_rgba == 0xFF123456, "invalid or not constexpr" ); +static_assert( "#123456"_argb == 0xFF123456, "invalid or not constexpr" ); + +// ARGB hex string to QRgb with defaulted alpha = 0xFF +static_assert( "#AA112233"_argb == 0xAA112233, "invalid or not constexpr" ); +static_assert( "#112233AA"_rgba == 0xAA112233, "invalid or not constexpr" ); + +// RGBA hex literal to QRgb with defaulted alpha = 0xFF +static_assert( 0x112233_rgba == 0xFF112233, "invalid or not constexpr" ); +static_assert( 0xaabbcc_rgba == 0xFFAABBCC, "invalid or not constexpr" ); +static_assert( 0xAABBCC_rgba == 0xFFAABBCC, "invalid or not constexpr" ); +static_assert( 0x112233aa_rgba == 0xaa112233, "invalid or not constexpr" ); + +// ARGB hex literal to QRgb with defaulted alpha = 0xFF +static_assert( 0x112233_argb == 0xFF112233, "invalid or not constexpr" ); +static_assert( 0xaabbcc_argb == 0xFFAABBCC, "invalid or not constexpr" ); +static_assert( 0xAABBCC_argb == 0xFFAABBCC, "invalid or not constexpr" ); +static_assert( 0x112233aa_argb == 0x112233aa, "invalid or not constexpr" ); +} +#endif + void QskRgbLiterals::parsing_data() { QTest::addColumn< QString >( "text" );