diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2016-05-03 23:04:28 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2016-05-04 11:29:08 +0000 |
commit | 3489ab60a992f060c3e737838cc78ac79f79cc31 (patch) | |
tree | bfb796d4a9a35edd3c494cad05a7dcb5a852dda2 /tests/auto/testlib/selftests/cmptest | |
parent | 494376f980e96339b6f1eff7c41336ca4d853065 (diff) |
QTestLib: support explicit bool conversions in QVERIFY
[ChangeLog][QTestLib] It is now possible to use variables of
types with an explicit operator bool in the QVERIFY macro.
Change-Id: I2685df164a616f6a065d689867daa9ea1de78e08
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'tests/auto/testlib/selftests/cmptest')
-rw-r--r-- | tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp index 9ada718682..3a8d27631e 100644 --- a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp +++ b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp @@ -147,6 +147,7 @@ private slots: void verify2(); void tryVerify(); void tryVerify2(); + void verifyExplicitOperatorBool(); }; enum MyUnregisteredEnum { MyUnregisteredEnumValue1, MyUnregisteredEnumValue2 }; @@ -458,5 +459,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" |