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 <mitch.curtis@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
21e5da2fe0
commit
9760f881c5
@ -253,6 +253,22 @@ namespace QTest
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<typename F> // Output QFlags of registered enumerations
|
||||
inline typename std::enable_if<QtPrivate::IsQEnumHelper<F>::Value, char*>::type toString(QFlags<F> f)
|
||||
{
|
||||
const QMetaEnum me = QMetaEnum::fromType<F>();
|
||||
return qstrdup(me.valueToKeys(int(f)).constData());
|
||||
}
|
||||
|
||||
template <typename F> // Fallback: Output hex value
|
||||
inline typename std::enable_if<!QtPrivate::IsQEnumHelper<F>::Value, char*>::type toString(QFlags<F> f)
|
||||
{
|
||||
const size_t space = 3 + 2 * sizeof(unsigned); // 2 for 0x, two hex digits per byte, 1 for '\0'
|
||||
char *msg = new char[space];
|
||||
qsnprintf(msg, space, "0x%x", unsigned(f));
|
||||
return msg;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
template<typename T>
|
||||
|
@ -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<Qt::WindowFlags>("actualWindowFlags");
|
||||
QTest::addColumn<Qt::WindowFlags>("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<UnregisteredEnum> UnregisteredFlags;
|
||||
|
||||
Q_DECLARE_METATYPE(UnregisteredFlags);
|
||||
|
||||
void tst_Cmptest::test_unregistered_flags_data()
|
||||
{
|
||||
QTest::addColumn<UnregisteredFlags>("actualFlags");
|
||||
QTest::addColumn<UnregisteredFlags>("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; }
|
||||
|
||||
|
@ -29,6 +29,42 @@
|
||||
</Incident>
|
||||
<Duration msecs="0"/>
|
||||
</TestFunction>
|
||||
<TestFunction name="test_windowflags">
|
||||
<Incident type="pass" file="" line="0">
|
||||
<DataTag><![CDATA[pass]]></DataTag>
|
||||
</Incident>
|
||||
<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
|
||||
<DataTag><![CDATA[fail1]]></DataTag>
|
||||
<Description><![CDATA[Compared values are not the same
|
||||
Actual (actualWindowFlags) : Window|WindowSystemMenuHint|WindowStaysOnBottomHint
|
||||
Expected (expectedWindowFlags): Window|FramelessWindowHint|WindowSystemMenuHint|WindowStaysOnBottomHint]]></Description>
|
||||
</Incident>
|
||||
<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
|
||||
<DataTag><![CDATA[fail2]]></DataTag>
|
||||
<Description><![CDATA[Compared values are not the same
|
||||
Actual (actualWindowFlags) : Window
|
||||
Expected (expectedWindowFlags): Window|FramelessWindowHint]]></Description>
|
||||
</Incident>
|
||||
<Duration msecs="0"/>
|
||||
</TestFunction>
|
||||
<TestFunction name="test_unregistered_flags">
|
||||
<Incident type="pass" file="" line="0">
|
||||
<DataTag><![CDATA[pass]]></DataTag>
|
||||
</Incident>
|
||||
<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
|
||||
<DataTag><![CDATA[fail1]]></DataTag>
|
||||
<Description><![CDATA[Compared values are not the same
|
||||
Actual (actualFlags) : 0x3
|
||||
Expected (expectedFlags): 0x5]]></Description>
|
||||
</Incident>
|
||||
<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
|
||||
<DataTag><![CDATA[fail2]]></DataTag>
|
||||
<Description><![CDATA[Compared values are not the same
|
||||
Actual (actualFlags) : 0x1
|
||||
Expected (expectedFlags): 0x5]]></Description>
|
||||
</Incident>
|
||||
<Duration msecs="0"/>
|
||||
</TestFunction>
|
||||
<TestFunction name="compare_boolfuncs">
|
||||
<Incident type="pass" file="" line="0" />
|
||||
<Duration msecs="0"/>
|
||||
|
@ -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']
|
||||
|
@ -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 *********
|
||||
|
@ -31,6 +31,42 @@
|
||||
</Incident>
|
||||
<Duration msecs="0"/>
|
||||
</TestFunction>
|
||||
<TestFunction name="test_windowflags">
|
||||
<Incident type="pass" file="" line="0">
|
||||
<DataTag><![CDATA[pass]]></DataTag>
|
||||
</Incident>
|
||||
<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
|
||||
<DataTag><![CDATA[fail1]]></DataTag>
|
||||
<Description><![CDATA[Compared values are not the same
|
||||
Actual (actualWindowFlags) : Window|WindowSystemMenuHint|WindowStaysOnBottomHint
|
||||
Expected (expectedWindowFlags): Window|FramelessWindowHint|WindowSystemMenuHint|WindowStaysOnBottomHint]]></Description>
|
||||
</Incident>
|
||||
<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
|
||||
<DataTag><![CDATA[fail2]]></DataTag>
|
||||
<Description><![CDATA[Compared values are not the same
|
||||
Actual (actualWindowFlags) : Window
|
||||
Expected (expectedWindowFlags): Window|FramelessWindowHint]]></Description>
|
||||
</Incident>
|
||||
<Duration msecs="0"/>
|
||||
</TestFunction>
|
||||
<TestFunction name="test_unregistered_flags">
|
||||
<Incident type="pass" file="" line="0">
|
||||
<DataTag><![CDATA[pass]]></DataTag>
|
||||
</Incident>
|
||||
<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
|
||||
<DataTag><![CDATA[fail1]]></DataTag>
|
||||
<Description><![CDATA[Compared values are not the same
|
||||
Actual (actualFlags) : 0x3
|
||||
Expected (expectedFlags): 0x5]]></Description>
|
||||
</Incident>
|
||||
<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
|
||||
<DataTag><![CDATA[fail2]]></DataTag>
|
||||
<Description><![CDATA[Compared values are not the same
|
||||
Actual (actualFlags) : 0x1
|
||||
Expected (expectedFlags): 0x5]]></Description>
|
||||
</Incident>
|
||||
<Duration msecs="0"/>
|
||||
</TestFunction>
|
||||
<TestFunction name="compare_boolfuncs">
|
||||
<Incident type="pass" file="" line="0" />
|
||||
<Duration msecs="0"/>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<testsuite errors="0" failures="34" tests="24" name="tst_Cmptest">
|
||||
<testsuite errors="0" failures="38" tests="26" name="tst_Cmptest">
|
||||
<properties>
|
||||
<property value="@INSERT_QT_VERSION_HERE@" name="QTestVersion"/>
|
||||
<property value="@INSERT_QT_VERSION_HERE@" name="QtVersion"/>
|
||||
@ -19,6 +19,22 @@
|
||||
Actual (MyClassEnum::MyClassEnumValue1): MyClassEnumValue1
|
||||
Expected (MyClassEnum::MyClassEnumValue2): MyClassEnumValue2" result="fail"/>
|
||||
</testcase>
|
||||
<testcase result="fail" name="test_windowflags">
|
||||
<failure tag="fail1" message="Compared values are not the same
|
||||
Actual (actualWindowFlags) : Window|WindowSystemMenuHint|WindowStaysOnBottomHint
|
||||
Expected (expectedWindowFlags): Window|FramelessWindowHint|WindowSystemMenuHint|WindowStaysOnBottomHint" result="fail"/>
|
||||
<failure tag="fail2" message="Compared values are not the same
|
||||
Actual (actualWindowFlags) : Window
|
||||
Expected (expectedWindowFlags): Window|FramelessWindowHint" result="fail"/>
|
||||
</testcase>
|
||||
<testcase result="fail" name="test_unregistered_flags">
|
||||
<failure tag="fail1" message="Compared values are not the same
|
||||
Actual (actualFlags) : 0x3
|
||||
Expected (expectedFlags): 0x5" result="fail"/>
|
||||
<failure tag="fail2" message="Compared values are not the same
|
||||
Actual (actualFlags) : 0x1
|
||||
Expected (expectedFlags): 0x5" result="fail"/>
|
||||
</testcase>
|
||||
<testcase result="pass" name="compare_boolfuncs"/>
|
||||
<testcase result="pass" name="compare_to_nullptr"/>
|
||||
<testcase result="pass" name="compare_pointerfuncs"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user