summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/doc/snippets/code/doc_src_qtestlib.cpp30
-rw-r--r--src/testlib/doc/src/qttestlib-manual.qdoc4
-rw-r--r--src/testlib/qtestcase.h16
-rw-r--r--src/testlib/qtestsystem.h4
-rw-r--r--src/testlib/qxctestlogger.mm10
-rw-r--r--src/testlib/qxctestlogger_p.h2
6 files changed, 51 insertions, 15 deletions
diff --git a/src/testlib/doc/snippets/code/doc_src_qtestlib.cpp b/src/testlib/doc/snippets/code/doc_src_qtestlib.cpp
index 0dc45bef76..de301b8df9 100644
--- a/src/testlib/doc/snippets/code/doc_src_qtestlib.cpp
+++ b/src/testlib/doc/snippets/code/doc_src_qtestlib.cpp
@@ -48,19 +48,41 @@
**
****************************************************************************/
+#include <QtTest>
+
//! [0]
class MyFirstTest: public QObject
{
Q_OBJECT
+
+private:
+ bool myCondition()
+ {
+ return true;
+ }
+
private slots:
void initTestCase()
- { qDebug("called before everything else"); }
+ {
+ qDebug("Called before everything else.");
+ }
+
void myFirstTest()
- { QVERIFY(1 == 1); }
+ {
+ QVERIFY(true); // check that a condition is satisfied
+ QCOMPARE(1, 1); // compare two values
+ }
+
void mySecondTest()
- { QVERIFY(1 != 2); }
+ {
+ QVERIFY(myCondition());
+ QVERIFY(1 != 2);
+ }
+
void cleanupTestCase()
- { qDebug("called after myFirstTest and mySecondTest"); }
+ {
+ qDebug("Called after myFirstTest and mySecondTest.");
+ }
};
//! [0]
diff --git a/src/testlib/doc/src/qttestlib-manual.qdoc b/src/testlib/doc/src/qttestlib-manual.qdoc
index 9bd210d71f..2e2af8d67f 100644
--- a/src/testlib/doc/src/qttestlib-manual.qdoc
+++ b/src/testlib/doc/src/qttestlib-manual.qdoc
@@ -69,8 +69,8 @@
\li Qt Test supports benchmarking and provides several measurement back-ends.
\row
\li \b {IDE friendly}
- \li Qt Test outputs messages that can be interpreted by Visual
- Studio and KDevelop.
+ \li Qt Test outputs messages that can be interpreted by Qt Creator, Visual
+ Studio, and KDevelop.
\row
\li \b Thread-safety
\li The error reporting is thread safe and atomic.
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/src/testlib/qtestsystem.h b/src/testlib/qtestsystem.h
index 046fe1a3e7..a6cea26884 100644
--- a/src/testlib/qtestsystem.h
+++ b/src/testlib/qtestsystem.h
@@ -74,10 +74,8 @@ namespace QTest
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
remaining = deadline.remainingTime();
- if (remaining > 0) {
+ if (remaining > 0)
QTest::qSleep(qMin(10, remaining));
- remaining = deadline.remainingTime();
- }
if (predicate())
return true;
diff --git a/src/testlib/qxctestlogger.mm b/src/testlib/qxctestlogger.mm
index 62fd73070f..9fa9da2fdd 100644
--- a/src/testlib/qxctestlogger.mm
+++ b/src/testlib/qxctestlogger.mm
@@ -200,7 +200,7 @@ private:
[autoreleasepool release];
}
-+ (id)defaultTestSuite
++ (QTestLibTests *)defaultTestSuite
{
return [[QtTestLibTests alloc] initWithName:@"QtTestLib"];
}
@@ -255,7 +255,7 @@ static XCTestSuiteRun *s_qtTestSuiteRun = 0;
@implementation QtTestLibTest
-- (id)initWithInvocation:(NSInvocation *)invocation
+- (instancetype)initWithInvocation:(NSInvocation *)invocation
{
if (self = [super initWithInvocation:invocation]) {
// The test object name and function name are used by XCTest after QtTestLib has
@@ -322,7 +322,7 @@ QXcodeTestLogger *QXcodeTestLogger::s_currentTestLogger = 0;
QXcodeTestLogger::QXcodeTestLogger()
: QAbstractTestLogger(0)
- , m_testRuns([[NSMutableArray arrayWithCapacity:2] retain])
+ , m_testRuns([[NSMutableArray<XCTestRun *> arrayWithCapacity:2] retain])
{
Q_ASSERT(!s_currentTestLogger);
@@ -383,11 +383,11 @@ static bool isTestFunctionInActiveScope(const char *function)
Q_ASSERT(activeScope == Selected);
- static NSArray *forcedTests = [@[ @"initTestCase", @"initTestCase_data", @"cleanupTestCase" ] retain];
+ static NSArray<NSString *> *forcedTests = [@[ @"initTestCase", @"initTestCase_data", @"cleanupTestCase" ] retain];
if ([forcedTests containsObject:[NSString stringWithUTF8String:function]])
return true;
- static NSArray *testsInScope = [[testScope componentsSeparatedByString:@","] retain];
+ static NSArray<NSString *> *testsInScope = [[testScope componentsSeparatedByString:@","] retain];
bool inScope = [testsInScope containsObject:[NSString stringWithFormat:@"%s/%s",
QTestResult::currentTestObjectName(), function]];
diff --git a/src/testlib/qxctestlogger_p.h b/src/testlib/qxctestlogger_p.h
index 1b641f18af..8baa5aa27f 100644
--- a/src/testlib/qxctestlogger_p.h
+++ b/src/testlib/qxctestlogger_p.h
@@ -90,7 +90,7 @@ private:
void pushTestRunForTest(XCTest *test, bool start);
XCTestRun *popTestRun();
- NSMutableArray *m_testRuns;
+ NSMutableArray<XCTestRun *> *m_testRuns;
static QXcodeTestLogger *s_currentTestLogger;
};