move static assertions into tests

This commit is contained in:
Vogel, Rick 2023-03-24 11:30:31 +01:00
parent d228bcaca2
commit 294b795005
4 changed files with 26 additions and 27 deletions

View File

@ -63,7 +63,6 @@ OBJECTS_DIR = obj
RCC_DIR = rcc
QSK_CONFIG += QskDll
QSK_CONFIG += QskRequireConstexprLiterals
linux {

View File

@ -12,31 +12,6 @@ QSK_QT_PRIVATE_BEGIN
#include <private/qdrawhelper_p.h>
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 )

View File

@ -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}

View File

@ -2,6 +2,32 @@
#include <QTest>
#include <QskRgbValue.h>
#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" );