diff options
author | Samuel Gaist <samuel.gaist@edeltech.ch> | 2013-11-03 22:00:18 (GMT) |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-04 10:14:21 (GMT) |
commit | 6bf8bbeb813f70b44105994d745133d9ed5f9ea1 (patch) | |
tree | 6c862877d857241de5017f7bd91565aaeb225601 | |
parent | be4e275fdb2f144b79c90b7fe612132ab3dbc0a9 (diff) | |
download | Qt-6bf8bbeb813f70b44105994d745133d9ed5f9ea1.zip Qt-6bf8bbeb813f70b44105994d745133d9ed5f9ea1.tar.gz Qt-6bf8bbeb813f70b44105994d745133d9ed5f9ea1.tar.bz2 |
Expose QTest::currentAppName() and remove hard-coded argv[0] in tests
Except where we're actually testing QCoreApplication::applicationName()
and friends.
Based on a3530859e9a7423db0b6839f15538f248aaf4a79
Change-Id: I36ef8cbb5d8bce45225a7f81409f46f1d584287b
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
-rw-r--r-- | src/testlib/qtestcase.cpp | 11 | ||||
-rw-r--r-- | src/testlib/qtestcase.h | 2 | ||||
-rw-r--r-- | src/testlib/qtestresult.cpp | 11 | ||||
-rw-r--r-- | src/testlib/qtestresult_p.h | 3 | ||||
-rw-r--r-- | tests/auto/qcoreapplication/tst_qcoreapplication.cpp | 28 | ||||
-rw-r--r-- | tests/auto/qsql/tst_qsql.cpp | 47 |
6 files changed, 68 insertions, 34 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 7dd274e..1345e73 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1896,6 +1896,9 @@ int QTest::qExec(QObject *testObject, int argc, char **argv) QTEST_ASSERT(metaObject); QTestResult::setCurrentTestObject(metaObject->className()); + if (argc > 0) + QTestResult::setCurrentAppName(argv[0]); + qtest_qParseArgs(argc, argv, false); if (QTest::randomOrder) { seedRandom(); @@ -2139,6 +2142,14 @@ QTestData &QTest::newRow(const char *dataTag) */ /*! + Returns the name of the binary that is currently executed. +*/ +const char *QTest::currentAppName() +{ + return QTestResult::currentAppName(); +} + +/*! Returns the name of the test function that is currently executed. Example: diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h index 19e04bf..225d68b 100644 --- a/src/testlib/qtestcase.h +++ b/src/testlib/qtestcase.h @@ -147,6 +147,8 @@ namespace QTest Q_TESTLIB_EXPORT void *qElementData(const char *elementName, int metaTypeId); Q_TESTLIB_EXPORT QObject *testObject(); + Q_TESTLIB_EXPORT const char *currentAppName(); + Q_TESTLIB_EXPORT const char *currentTestFunction(); Q_TESTLIB_EXPORT const char *currentDataTag(); Q_TESTLIB_EXPORT bool currentTestFailed(); diff --git a/src/testlib/qtestresult.cpp b/src/testlib/qtestresult.cpp index de92ddb..d87075a 100644 --- a/src/testlib/qtestresult.cpp +++ b/src/testlib/qtestresult.cpp @@ -68,6 +68,8 @@ namespace QTest static const char *expectFailComment = 0; static int expectFailMode = 0; + + static const char *currentAppName = 0; } void QTestResult::reset() @@ -349,4 +351,13 @@ bool QTestResult::skipCurrentTest() return QTest::skipCurrentTest; } +void QTestResult::setCurrentAppName(const char *appName) +{ + QTest::currentAppName = appName; +} +const char *QTestResult::currentAppName() +{ + return QTest::currentAppName; +} + QT_END_NAMESPACE diff --git a/src/testlib/qtestresult_p.h b/src/testlib/qtestresult_p.h index 1301a62..f452a9a 100644 --- a/src/testlib/qtestresult_p.h +++ b/src/testlib/qtestresult_p.h @@ -103,6 +103,9 @@ public: static void setSkipCurrentTest(bool value); static bool skipCurrentTest(); + static void setCurrentAppName(const char *appName); + static const char *currentAppName(); + private: Q_DISABLE_COPY(QTestResult) }; diff --git a/tests/auto/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/qcoreapplication/tst_qcoreapplication.cpp index 9eb53ee..74605f7 100644 --- a/tests/auto/qcoreapplication/tst_qcoreapplication.cpp +++ b/tests/auto/qcoreapplication/tst_qcoreapplication.cpp @@ -80,7 +80,7 @@ public: void tst_QCoreApplication::sendEventsOnProcessEvents() { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>(QTest::currentAppName()) }; QCoreApplication app(argc, argv); EventSpy spy; @@ -102,7 +102,7 @@ void tst_QCoreApplication::getSetCheck() // Test the property { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>(QTest::currentAppName()) }; QCoreApplication app(argc, argv); QCOMPARE(app.property("applicationVersion").toString(), v); } @@ -114,7 +114,7 @@ void tst_QCoreApplication::getSetCheck() void tst_QCoreApplication::qAppName() { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>(QTest::currentAppName()) }; QCoreApplication app(argc, argv); QVERIFY(!::qAppName().isEmpty()); } @@ -123,7 +123,7 @@ void tst_QCoreApplication::argc() { { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>(QTest::currentAppName()) }; QCoreApplication app(argc, argv); QCOMPARE(argc, 1); QCOMPARE(app.argc(), 1); @@ -131,7 +131,7 @@ void tst_QCoreApplication::argc() { int argc = 4; - char *argv[] = { "tst_qcoreapplication", "arg1", "arg2", "arg3" }; + char *argv[] = { const_cast<char*>(QTest::currentAppName()), "arg1", "arg2", "arg3" }; QCoreApplication app(argc, argv); QCOMPARE(argc, 4); QCOMPARE(app.argc(), 4); @@ -147,7 +147,7 @@ void tst_QCoreApplication::argc() { int argc = 2; - char *argv[] = { "tst_qcoreapplication", "-qmljsdebugger=port:3768,block" }; + char *argv[] = { const_cast<char*>(QTest::currentAppName()), "-qmljsdebugger=port:3768,block" }; QCoreApplication app(argc, argv); QCOMPARE(argc, 1); QCOMPARE(app.argc(), 1); @@ -179,7 +179,7 @@ public: void tst_QCoreApplication::postEvent() { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>(QTest::currentAppName()) }; QCoreApplication app(argc, argv); EventSpy spy; @@ -264,7 +264,7 @@ void tst_QCoreApplication::postEvent() void tst_QCoreApplication::removePostedEvents() { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>(QTest::currentAppName()) }; QCoreApplication app(argc, argv); EventSpy spy; @@ -431,7 +431,7 @@ public: void tst_QCoreApplication::deliverInDefinedOrder() { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>(QTest::currentAppName()) }; QCoreApplication app(argc, argv); DeliverInDefinedOrderObject obj(&app); @@ -474,7 +474,7 @@ public: void tst_QCoreApplication::globalPostedEventsCount() { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>(QTest::currentAppName()) }; QCoreApplication app(argc, argv); QCoreApplication::sendPostedEvents(); @@ -520,7 +520,7 @@ public: void tst_QCoreApplication::processEventsAlwaysSendsPostedEvents() { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>(QTest::currentAppName()) }; QCoreApplication app(argc, argv); ProcessEventsAlwaysSendsPostedEventsObject object; @@ -538,7 +538,7 @@ void tst_QCoreApplication::processEventsAlwaysSendsPostedEvents() void tst_QCoreApplication::reexec() { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>(QTest::currentAppName()) }; QCoreApplication app(argc, argv); // exec once @@ -553,7 +553,7 @@ void tst_QCoreApplication::reexec() void tst_QCoreApplication::execAfterExit() { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>(QTest::currentAppName()) }; QCoreApplication app(argc, argv); app.exit(1); @@ -564,7 +564,7 @@ void tst_QCoreApplication::execAfterExit() void tst_QCoreApplication::eventLoopExecAfterExit() { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>(QTest::currentAppName()) }; QCoreApplication app(argc, argv); // exec once and exit diff --git a/tests/auto/qsql/tst_qsql.cpp b/tests/auto/qsql/tst_qsql.cpp index 4565588..37a07eb 100644 --- a/tests/auto/qsql/tst_qsql.cpp +++ b/tests/auto/qsql/tst_qsql.cpp @@ -119,8 +119,10 @@ void tst_QSql::cleanup() // of a field "id"(integer) and "name"(char/varchar). void tst_QSql::basicDriverTest() { - int argc = 0; - QApplication app( argc, 0, false ); + int argc = 1; + char *argv[] = { const_cast<char*>(QTest::currentAppName()) }; + QApplication app( argc, argv, false ); + tst_Databases dbs; dbs.open(); @@ -201,21 +203,22 @@ void tst_QSql::basicDriverTest() void tst_QSql::open() { int i; - int argc = 0; + int argc = 1; + char *argv[] = { const_cast<char*>(QTest::currentAppName()) }; int count = -1; for ( i = 0; i < 10; ++i ) { - QApplication app( argc, 0, false ); - tst_Databases dbs; - - dbs.open(); - if ( count == -1 ) - // first iteration: see how many dbs are open - count = (int) dbs.dbNames.count(); - else - // next iterations: make sure all are opened again - QCOMPARE( count, (int)dbs.dbNames.count() ); - dbs.close(); + QApplication app( argc, argv, false ); + tst_Databases dbs; + + dbs.open(); + if ( count == -1 ) + // first iteration: see how many dbs are open + count = (int) dbs.dbNames.count(); + else + // next iterations: make sure all are opened again + QCOMPARE( count, (int)dbs.dbNames.count() ); + dbs.close(); } } @@ -230,8 +233,9 @@ void tst_QSql::openInvalid() void tst_QSql::concurrentAccess() { - int argc = 0; - QApplication app( argc, 0, false ); + int argc = 1; + char *argv[] = { const_cast<char*>(QTest::currentAppName()) }; + QApplication app( argc, argv, false ); tst_Databases dbs; dbs.open(); @@ -258,8 +262,10 @@ void tst_QSql::concurrentAccess() void tst_QSql::openErrorRecovery() { - int argc = 0; - QApplication app( argc, 0, false ); + int argc = 1; + char *argv[] = { const_cast<char*>(QTest::currentAppName()) }; + QApplication app( argc, argv, false ); + tst_Databases dbs; dbs.addDbs(); @@ -305,8 +311,9 @@ void tst_QSql::openErrorRecovery() void tst_QSql::registerSqlDriver() { - int argc = 0; - QApplication app( argc, 0, false ); + int argc = 1; + char *argv[] = { const_cast<char*>(QTest::currentAppName()) }; + QApplication app( argc, argv, false ); QSqlDatabase::registerSqlDriver( "QSQLTESTDRIVER", new QSqlDriverCreator<QSqlNullDriver> ); QVERIFY( QSqlDatabase::drivers().contains( "QSQLTESTDRIVER" ) ); |