summaryrefslogtreecommitdiffstats
path: root/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp')
-rw-r--r--tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
index 3586b7f420..97eb19599b 100644
--- a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
+++ b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
@@ -128,6 +128,7 @@ private slots:
void compare_registered_enums();
void compare_class_enums();
void compare_boolfuncs();
+ void compare_to_nullptr();
void compare_pointerfuncs();
void compare_tostring();
void compare_tostring_data();
@@ -148,6 +149,7 @@ private slots:
void verify2();
void tryVerify();
void tryVerify2();
+ void verifyExplicitOperatorBool();
};
enum MyUnregisteredEnum { MyUnregisteredEnumValue1, MyUnregisteredEnumValue2 };
@@ -183,6 +185,24 @@ void tst_Cmptest::compare_boolfuncs()
QCOMPARE(!boolfunc(), false);
}
+namespace {
+template <typename T>
+T *null() Q_DECL_NOTHROW { return nullptr; }
+}
+
+void tst_Cmptest::compare_to_nullptr()
+{
+ QCOMPARE(null<int>(), nullptr);
+ QCOMPARE(null<const int>(), nullptr);
+ QCOMPARE(null<volatile int>(), nullptr);
+ QCOMPARE(null<const volatile int>(), nullptr);
+
+ QCOMPARE(nullptr, null<int>());
+ QCOMPARE(nullptr, null<const int>());
+ QCOMPARE(nullptr, null<volatile int>());
+ QCOMPARE(nullptr, null<const volatile int>());
+}
+
static int i = 0;
static int *intptr() { return &i; }
@@ -465,5 +485,21 @@ void tst_Cmptest::tryVerify2()
QTRY_VERIFY2_WITH_TIMEOUT(opaqueFunc() < 2, QByteArray::number(opaqueFunc()).constData(), 1);
}
+void tst_Cmptest::verifyExplicitOperatorBool()
+{
+ struct ExplicitOperatorBool {
+ int m_i;
+ explicit ExplicitOperatorBool(int i) : m_i(i) {}
+ explicit operator bool() const { return m_i > 0; }
+ bool operator !() const { return !bool(*this); }
+ };
+
+ ExplicitOperatorBool val1(42);
+ QVERIFY(val1);
+
+ ExplicitOperatorBool val2(-273);
+ QVERIFY(!val2);
+}
+
QTEST_MAIN(tst_Cmptest)
#include "tst_cmptest.moc"