From 5f5db1c38b288441d02a68f1a095850b42585e04 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 21 Jul 2015 10:55:17 +0200 Subject: QTestLib: Add macros QTRY_VERIFY2_WITH_TIMEOUT(), QTRY_VERIFY2(). Add QTRY_VERIFY2_WITH_TIMEOUT() similar to QTRY_VERIFY_WITH_TIMEOUT() except that QTRY_VERIFY2() is used below the loop and QTRY_VERIFY2() based on it. Add tests to cmptest. [ChangeLog][QtTest] Added macros QTRY_VERIFY2_WITH_TIMEOUT(), QTRY_VERIFY2() making it possible to output a message after the timeout has expired. Change-Id: I587e24f3aeb73542dbf3ccb936a16f2e0806555f Reviewed-by: Mitch Curtis --- .../auto/testlib/selftests/cmptest/tst_cmptest.cpp | 35 +++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp') diff --git a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp index 1ee78960ab..6446fec510 100644 --- a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp +++ b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp @@ -140,6 +140,10 @@ private slots: void compareQImages(); void compareQImages_data(); #endif + void verify(); + void verify2(); + void tryVerify(); + void tryVerify2(); }; enum MyUnregisteredEnum { MyUnregisteredEnumValue1, MyUnregisteredEnumValue2 }; @@ -387,7 +391,36 @@ void tst_Cmptest::compareQImages() QCOMPARE(opA, opB); } -#endif +#endif // QT_GUI_LIB + +static int opaqueFunc() +{ + return 42; +} + +void tst_Cmptest::verify() +{ + QVERIFY(opaqueFunc() > 2); + QVERIFY(opaqueFunc() < 2); +} + +void tst_Cmptest::verify2() +{ + QVERIFY2(opaqueFunc() > 2, QByteArray::number(opaqueFunc()).constData()); + QVERIFY2(opaqueFunc() < 2, QByteArray::number(opaqueFunc()).constData()); +} + +void tst_Cmptest::tryVerify() +{ + QTRY_VERIFY(opaqueFunc() > 2); + QTRY_VERIFY_WITH_TIMEOUT(opaqueFunc() < 2, 1); +} + +void tst_Cmptest::tryVerify2() +{ + QTRY_VERIFY2(opaqueFunc() > 2, QByteArray::number(opaqueFunc()).constData()); + QTRY_VERIFY2_WITH_TIMEOUT(opaqueFunc() < 2, QByteArray::number(opaqueFunc()).constData(), 1); +} QTEST_MAIN(tst_Cmptest) #include "tst_cmptest.moc" -- cgit v1.2.3