QTest: Fix printing of values of Q_ENUMs
QMetaEnum::key(n) returns the n-th key, which is not necessarily the one of value n. For the key of value n, we want QMetaEnum::valueToKey(n). Change-Id: Ic90fe6b1cbe84978a02fffff141bf4a06074917a Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
parent
9ba296cc4c
commit
194a56ea79
@ -238,7 +238,7 @@ namespace QTest
|
||||
inline typename QtPrivate::QEnableIf<QtPrivate::IsQEnumHelper<T>::Value, char*>::Type toString(T e)
|
||||
{
|
||||
QMetaEnum me = QMetaEnum::fromType<T>();
|
||||
return qstrdup(me.key(int(e))); // int cast is necessary to support enum classes
|
||||
return qstrdup(me.valueToKey(int(e))); // int cast is necessary to support enum classes
|
||||
}
|
||||
|
||||
template <typename T> // Fallback
|
||||
|
@ -156,8 +156,9 @@ void tst_Cmptest::compare_unregistered_enums()
|
||||
|
||||
void tst_Cmptest::compare_registered_enums()
|
||||
{
|
||||
QCOMPARE(Qt::ArrowCursor, Qt::ArrowCursor);
|
||||
QCOMPARE(Qt::ArrowCursor, Qt::BusyCursor);
|
||||
// use an enum that doesn't start at 0
|
||||
QCOMPARE(Qt::Monday, Qt::Monday);
|
||||
QCOMPARE(Qt::Monday, Qt::Sunday);
|
||||
}
|
||||
|
||||
static bool boolfunc() { return true; }
|
||||
|
@ -16,8 +16,8 @@
|
||||
<TestFunction name="compare_registered_enums">
|
||||
<Incident type="fail" file="tst_cmptest.cpp" line="160">
|
||||
<Description><![CDATA[Compared values are not the same
|
||||
Actual (Qt::ArrowCursor): ArrowCursor
|
||||
Expected (Qt::BusyCursor) : BusyCursor]]></Description>
|
||||
Actual (Qt::Monday): Monday
|
||||
Expected (Qt::Sunday): Sunday]]></Description>
|
||||
</Incident>
|
||||
<Duration msecs="0"/>
|
||||
</TestFunction>
|
||||
|
@ -4,8 +4,8 @@ PASS : tst_Cmptest::initTestCase()
|
||||
FAIL! : tst_Cmptest::compare_unregistered_enums() Compared values are not the same
|
||||
Loc: [tst_cmptest.cpp(154)]
|
||||
FAIL! : tst_Cmptest::compare_registered_enums() Compared values are not the same
|
||||
Actual (Qt::ArrowCursor): ArrowCursor
|
||||
Expected (Qt::BusyCursor) : BusyCursor
|
||||
Actual (Qt::Monday): Monday
|
||||
Expected (Qt::Sunday): Sunday
|
||||
Loc: [tst_cmptest.cpp(160)]
|
||||
PASS : tst_Cmptest::compare_boolfuncs()
|
||||
PASS : tst_Cmptest::compare_pointerfuncs()
|
||||
|
@ -18,8 +18,8 @@
|
||||
<TestFunction name="compare_registered_enums">
|
||||
<Incident type="fail" file="tst_cmptest.cpp" line="160">
|
||||
<Description><![CDATA[Compared values are not the same
|
||||
Actual (Qt::ArrowCursor): ArrowCursor
|
||||
Expected (Qt::BusyCursor) : BusyCursor]]></Description>
|
||||
Actual (Qt::Monday): Monday
|
||||
Expected (Qt::Sunday): Sunday]]></Description>
|
||||
</Incident>
|
||||
<Duration msecs="0"/>
|
||||
</TestFunction>
|
||||
|
@ -11,8 +11,8 @@
|
||||
</testcase>
|
||||
<testcase result="fail" name="compare_registered_enums">
|
||||
<failure message="Compared values are not the same
|
||||
Actual (Qt::ArrowCursor): ArrowCursor
|
||||
Expected (Qt::BusyCursor) : BusyCursor" result="fail"/>
|
||||
Actual (Qt::Monday): Monday
|
||||
Expected (Qt::Sunday): Sunday" result="fail"/>
|
||||
</testcase>
|
||||
<testcase result="pass" name="compare_boolfuncs"/>
|
||||
<testcase result="pass" name="compare_pointerfuncs"/>
|
||||
|
Loading…
Reference in New Issue
Block a user