From c988a8a28214914d20f4b8858e7f314a51b27507 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 3 Oct 2017 10:10:46 +0200 Subject: Make QCOMPARE print QColor alpha values on failure Currently, when two colors are equal except for their alpha values, QCOMPARE produces the following failure message: FAIL! : tst_Test::test() Compared values are not the same Actual (colorA): #ff0000 Expected (colorB): #ff0000 By using the HexArgb format instead of the default HexRgb, we can see the full hex string, with alpha values included: FAIL! : tst_Test::test() Compared values are not the same Actual (colorA): #88ff0000 Expected (colorB): #ffff0000 Task-number: QTBUG-55574 Change-Id: Id82c60a1b473ac6025a6f6ac560fce95a910d782 Reviewed-by: Friedemann Kleint Reviewed-by: Edward Welbourne --- tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp') diff --git a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp index 2cfe987f7d..a662fea615 100644 --- a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp +++ b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp @@ -140,6 +140,7 @@ private slots: void compareQListInt(); void compareQListDouble(); #ifdef QT_GUI_LIB + void compareQColor_data(); void compareQColor(); void compareQPixmaps(); void compareQPixmaps_data(); @@ -377,13 +378,22 @@ void tst_Cmptest::compareQListDouble() } #ifdef QT_GUI_LIB +void tst_Cmptest::compareQColor_data() +{ + QTest::addColumn("colorA"); + QTest::addColumn("colorB"); + + QTest::newRow("Qt::yellow vs \"yellow\"") << QColor(Qt::yellow) << QColor(QStringLiteral("yellow")); + QTest::newRow("Qt::yellow vs Qt::green") << QColor(Qt::yellow) << QColor(Qt::green); + QTest::newRow("0x88ff0000 vs 0xffff0000") << QColor::fromRgba(0x88ff0000) << QColor::fromRgba(0xffff0000); +} + void tst_Cmptest::compareQColor() { - const QColor yellow(Qt::yellow); - const QColor yellowFromName(QStringLiteral("yellow")); - const QColor green(Qt::green); - QCOMPARE(yellow, yellowFromName); - QCOMPARE(yellow, green); + QFETCH(QColor, colorA); + QFETCH(QColor, colorB); + + QCOMPARE(colorA, colorB); } void tst_Cmptest::compareQPixmaps_data() -- cgit v1.2.3