From 9760f881c54e601c56d606b6fe276def9531a43d Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 18 Jan 2018 17:10:03 +0100 Subject: QTestlib: Add formatting for QFlags<> Add formatting for registered enumerations based on QMetaEnum and unregistered enumerations as hex values. [ChangeLog][QtTest] QtTest now prints values of QFlags that failed to compare with QCOMPARE. Task-number: QTBUG-65845 Change-Id: I3eae6d20d3c0d72441ca6c4037d9a8dafa4b6357 Reviewed-by: Mitch Curtis Reviewed-by: Edward Welbourne --- .../auto/testlib/selftests/cmptest/tst_cmptest.cpp | 62 ++++++++++++++++++++++ .../testlib/selftests/expected_cmptest.lightxml | 36 +++++++++++++ .../testlib/selftests/expected_cmptest.teamcity | 16 ++++++ tests/auto/testlib/selftests/expected_cmptest.txt | 20 ++++++- tests/auto/testlib/selftests/expected_cmptest.xml | 36 +++++++++++++ .../testlib/selftests/expected_cmptest.xunitxml | 18 ++++++- 6 files changed, 186 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp index a662fea615..8e2c7694a5 100644 --- a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp +++ b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp @@ -130,6 +130,10 @@ private slots: void compare_unregistered_enums(); void compare_registered_enums(); void compare_class_enums(); + void test_windowflags_data(); + void test_windowflags(); + void test_unregistered_flags_data(); + void test_unregistered_flags(); void compare_boolfuncs(); void compare_to_nullptr(); void compare_pointerfuncs(); @@ -180,6 +184,64 @@ void tst_Cmptest::compare_class_enums() QCOMPARE(MyClassEnum::MyClassEnumValue1, MyClassEnum::MyClassEnumValue2); } +void tst_Cmptest::test_windowflags_data() +{ + QTest::addColumn("actualWindowFlags"); + QTest::addColumn("expectedWindowFlags"); + + const Qt::WindowFlags windowFlags = Qt::Window + | Qt::WindowSystemMenuHint | Qt::WindowStaysOnBottomHint; + QTest::newRow("pass") + << windowFlags + << windowFlags; + QTest::newRow("fail1") + << windowFlags + << (windowFlags | Qt::FramelessWindowHint); + QTest::newRow("fail2") + << Qt::WindowFlags(Qt::Window) + << Qt::WindowFlags(Qt::Window | Qt::FramelessWindowHint); +} + +void tst_Cmptest::test_windowflags() +{ + QFETCH(Qt::WindowFlags, actualWindowFlags); + QFETCH(Qt::WindowFlags, expectedWindowFlags); + QCOMPARE(actualWindowFlags, expectedWindowFlags); +} + +enum UnregisteredEnum { + UnregisteredEnumValue1 = 0x1, + UnregisteredEnumValue2 = 0x2, + UnregisteredEnumValue3 = 0x4 +}; + +typedef QFlags UnregisteredFlags; + +Q_DECLARE_METATYPE(UnregisteredFlags); + +void tst_Cmptest::test_unregistered_flags_data() +{ + QTest::addColumn("actualFlags"); + QTest::addColumn("expectedFlags"); + + QTest::newRow("pass") + << UnregisteredFlags(UnregisteredEnumValue1) + << UnregisteredFlags(UnregisteredEnumValue1); + QTest::newRow("fail1") + << UnregisteredFlags(UnregisteredEnumValue1 | UnregisteredEnumValue2) + << UnregisteredFlags(UnregisteredEnumValue1 | UnregisteredEnumValue3); + QTest::newRow("fail2") + << UnregisteredFlags(UnregisteredEnumValue1) + << UnregisteredFlags(UnregisteredEnumValue1 | UnregisteredEnumValue3); +} + +void tst_Cmptest::test_unregistered_flags() +{ + QFETCH(UnregisteredFlags, actualFlags); + QFETCH(UnregisteredFlags, expectedFlags); + QCOMPARE(actualFlags, expectedFlags); +} + static bool boolfunc() { return true; } static bool boolfunc2() { return true; } diff --git a/tests/auto/testlib/selftests/expected_cmptest.lightxml b/tests/auto/testlib/selftests/expected_cmptest.lightxml index d47967a445..58b5a5e530 100644 --- a/tests/auto/testlib/selftests/expected_cmptest.lightxml +++ b/tests/auto/testlib/selftests/expected_cmptest.lightxml @@ -29,6 +29,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/auto/testlib/selftests/expected_cmptest.teamcity b/tests/auto/testlib/selftests/expected_cmptest.teamcity index a0dc509279..422d0cbfdf 100644 --- a/tests/auto/testlib/selftests/expected_cmptest.teamcity +++ b/tests/auto/testlib/selftests/expected_cmptest.teamcity @@ -10,6 +10,22 @@ ##teamcity[testStarted name='compare_class_enums()' flowId='tst_Cmptest'] ##teamcity[testFailed name='compare_class_enums()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]' details='Compared values are not the same|n Actual (MyClassEnum::MyClassEnumValue1): MyClassEnumValue1|n Expected (MyClassEnum::MyClassEnumValue2): MyClassEnumValue2' flowId='tst_Cmptest'] ##teamcity[testFinished name='compare_class_enums()' flowId='tst_Cmptest'] +##teamcity[testStarted name='test_windowflags(pass)' flowId='tst_Cmptest'] +##teamcity[testFinished name='test_windowflags(pass)' flowId='tst_Cmptest'] +##teamcity[testStarted name='test_windowflags(fail1)' flowId='tst_Cmptest'] +##teamcity[testFailed name='test_windowflags(fail1)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]' details='Compared values are not the same|n Actual (actualWindowFlags) : Window||WindowSystemMenuHint||WindowStaysOnBottomHint|n Expected (expectedWindowFlags): Window||FramelessWindowHint||WindowSystemMenuHint||WindowStaysOnBottomHint' flowId='tst_Cmptest'] +##teamcity[testFinished name='test_windowflags(fail1)' flowId='tst_Cmptest'] +##teamcity[testStarted name='test_windowflags(fail2)' flowId='tst_Cmptest'] +##teamcity[testFailed name='test_windowflags(fail2)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]' details='Compared values are not the same|n Actual (actualWindowFlags) : Window|n Expected (expectedWindowFlags): Window||FramelessWindowHint' flowId='tst_Cmptest'] +##teamcity[testFinished name='test_windowflags(fail2)' flowId='tst_Cmptest'] +##teamcity[testStarted name='test_unregistered_flags(pass)' flowId='tst_Cmptest'] +##teamcity[testFinished name='test_unregistered_flags(pass)' flowId='tst_Cmptest'] +##teamcity[testStarted name='test_unregistered_flags(fail1)' flowId='tst_Cmptest'] +##teamcity[testFailed name='test_unregistered_flags(fail1)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]' details='Compared values are not the same|n Actual (actualFlags) : 0x3|n Expected (expectedFlags): 0x5' flowId='tst_Cmptest'] +##teamcity[testFinished name='test_unregistered_flags(fail1)' flowId='tst_Cmptest'] +##teamcity[testStarted name='test_unregistered_flags(fail2)' flowId='tst_Cmptest'] +##teamcity[testFailed name='test_unregistered_flags(fail2)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]' details='Compared values are not the same|n Actual (actualFlags) : 0x1|n Expected (expectedFlags): 0x5' flowId='tst_Cmptest'] +##teamcity[testFinished name='test_unregistered_flags(fail2)' flowId='tst_Cmptest'] ##teamcity[testStarted name='compare_boolfuncs()' flowId='tst_Cmptest'] ##teamcity[testFinished name='compare_boolfuncs()' flowId='tst_Cmptest'] ##teamcity[testStarted name='compare_to_nullptr()' flowId='tst_Cmptest'] diff --git a/tests/auto/testlib/selftests/expected_cmptest.txt b/tests/auto/testlib/selftests/expected_cmptest.txt index 78df990dea..e1aa81c1a1 100644 --- a/tests/auto/testlib/selftests/expected_cmptest.txt +++ b/tests/auto/testlib/selftests/expected_cmptest.txt @@ -11,6 +11,24 @@ FAIL! : tst_Cmptest::compare_class_enums() Compared values are not the same Actual (MyClassEnum::MyClassEnumValue1): MyClassEnumValue1 Expected (MyClassEnum::MyClassEnumValue2): MyClassEnumValue2 Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)] +PASS : tst_Cmptest::test_windowflags(pass) +FAIL! : tst_Cmptest::test_windowflags(fail1) Compared values are not the same + Actual (actualWindowFlags) : Window|WindowSystemMenuHint|WindowStaysOnBottomHint + Expected (expectedWindowFlags): Window|FramelessWindowHint|WindowSystemMenuHint|WindowStaysOnBottomHint + Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)] +FAIL! : tst_Cmptest::test_windowflags(fail2) Compared values are not the same + Actual (actualWindowFlags) : Window + Expected (expectedWindowFlags): Window|FramelessWindowHint + Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)] +PASS : tst_Cmptest::test_unregistered_flags(pass) +FAIL! : tst_Cmptest::test_unregistered_flags(fail1) Compared values are not the same + Actual (actualFlags) : 0x3 + Expected (expectedFlags): 0x5 + Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)] +FAIL! : tst_Cmptest::test_unregistered_flags(fail2) Compared values are not the same + Actual (actualFlags) : 0x1 + Expected (expectedFlags): 0x5 + Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)] PASS : tst_Cmptest::compare_boolfuncs() PASS : tst_Cmptest::compare_to_nullptr() PASS : tst_Cmptest::compare_pointerfuncs() @@ -138,5 +156,5 @@ FAIL! : tst_Cmptest::tryVerify2() 'opaqueFunc() < 2' returned FALSE. (42) Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)] PASS : tst_Cmptest::verifyExplicitOperatorBool() PASS : tst_Cmptest::cleanupTestCase() -Totals: 16 passed, 34 failed, 0 skipped, 0 blacklisted, 0ms +Totals: 18 passed, 38 failed, 0 skipped, 0 blacklisted, 0ms ********* Finished testing of tst_Cmptest ********* diff --git a/tests/auto/testlib/selftests/expected_cmptest.xml b/tests/auto/testlib/selftests/expected_cmptest.xml index 01b725f247..1c5a17631a 100644 --- a/tests/auto/testlib/selftests/expected_cmptest.xml +++ b/tests/auto/testlib/selftests/expected_cmptest.xml @@ -31,6 +31,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/auto/testlib/selftests/expected_cmptest.xunitxml b/tests/auto/testlib/selftests/expected_cmptest.xunitxml index 812696ffcf..99823d1c1c 100644 --- a/tests/auto/testlib/selftests/expected_cmptest.xunitxml +++ b/tests/auto/testlib/selftests/expected_cmptest.xunitxml @@ -1,5 +1,5 @@ - + @@ -19,6 +19,22 @@ Actual (MyClassEnum::MyClassEnumValue1): MyClassEnumValue1 Expected (MyClassEnum::MyClassEnumValue2): MyClassEnumValue2" result="fail"/> + + + + + + + + -- cgit v1.2.3