summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/testlib/qtestcase.h16
-rw-r--r--tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp62
-rw-r--r--tests/auto/testlib/selftests/expected_cmptest.lightxml36
-rw-r--r--tests/auto/testlib/selftests/expected_cmptest.teamcity16
-rw-r--r--tests/auto/testlib/selftests/expected_cmptest.txt20
-rw-r--r--tests/auto/testlib/selftests/expected_cmptest.xml36
-rw-r--r--tests/auto/testlib/selftests/expected_cmptest.xunitxml18
7 files changed, 202 insertions, 2 deletions
diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h
index f38f7ed4df..2e50f4f44f 100644
--- a/src/testlib/qtestcase.h
+++ b/src/testlib/qtestcase.h
@@ -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>
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<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; }
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 @@
</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"/>
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 @@
</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"/>
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 @@
<?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"/>