summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@digia.com>2013-09-25 16:23:45 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-26 18:45:16 +0200
commita3530859e9a7423db0b6839f15538f248aaf4a79 (patch)
tree72bc9467a84a8e74b212d9539201087777b06e11
parent0bf30a7caba53aa85dcbdc877ace5e25bf45b526 (diff)
Expose QTest::currentAppName() and remove hard-coded argv[0] in tests
Except where we're actually testing QCoreApplication::applicationName() and friends. Change-Id: I25514884c11f43a4f82b1f818f822dc3d79f69a3 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
-rw-r--r--src/testlib/qtestcase.cpp12
-rw-r--r--src/testlib/qtestcase.h2
-rw-r--r--src/testlib/qtestlog.cpp2
-rw-r--r--src/testlib/qtestresult.cpp10
-rw-r--r--src/testlib/qtestresult_p.h4
-rw-r--r--tests/auto/corelib/global/qglobal/tst_qglobal.cpp2
-rw-r--r--tests/auto/corelib/io/qprocess-noapplication/tst_qprocessnoapplication.cpp3
-rw-r--r--tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp32
-rw-r--r--tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp11
-rw-r--r--tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp2
-rw-r--r--tests/auto/sql/kernel/qsql/tst_qsql.cpp20
11 files changed, 59 insertions, 41 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index bae4a29457..ff90ed1c0e 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -1612,7 +1612,7 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml)
}
}
- bool installedTestCoverage = installCoverageTool(QTestResult::currentAppname(), QTestResult::currentTestObjectName());
+ bool installedTestCoverage = installCoverageTool(QTestResult::currentAppName(), QTestResult::currentTestObjectName());
QTestLog::setInstalledTestCoverage(installedTestCoverage);
// If no loggers were created by the long version of the -o command-line
@@ -2167,7 +2167,7 @@ int QTest::qExec(QObject *testObject, int argc, char **argv)
QTestResult::setCurrentTestObject(metaObject->className());
if (argc > 0)
- QTestResult::setCurrentAppname(argv[0]);
+ QTestResult::setCurrentAppName(argv[0]);
qtest_qParseArgs(argc, argv, false);
@@ -2521,6 +2521,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 6b5e7a574b..ba727b5afe 100644
--- a/src/testlib/qtestcase.h
+++ b/src/testlib/qtestcase.h
@@ -200,6 +200,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/qtestlog.cpp b/src/testlib/qtestlog.cpp
index 10936f5c03..5b6cbe658c 100644
--- a/src/testlib/qtestlog.cpp
+++ b/src/testlib/qtestlog.cpp
@@ -394,7 +394,7 @@ void QTestLog::stopLogging()
QTest::TestLoggers::stopLogging();
QTest::TestLoggers::destroyLoggers();
QTest::loggerUsingStdout = false;
- saveCoverageTool(QTestResult::currentAppname(), failCount() != 0, QTestLog::installedTestCoverage());
+ saveCoverageTool(QTestResult::currentAppName(), failCount() != 0, QTestLog::installedTestCoverage());
}
void QTestLog::addLogger(LogMode mode, const char *filename)
diff --git a/src/testlib/qtestresult.cpp b/src/testlib/qtestresult.cpp
index 7ab317f209..d94b2bf85c 100644
--- a/src/testlib/qtestresult.cpp
+++ b/src/testlib/qtestresult.cpp
@@ -63,7 +63,7 @@ namespace QTest
static const char *expectFailComment = 0;
static int expectFailMode = 0;
- static const char *currentAppname = 0;
+ static const char *currentAppName = 0;
}
void QTestResult::reset()
@@ -318,14 +318,14 @@ bool QTestResult::skipCurrentTest()
return QTest::skipCurrentTest;
}
-void QTestResult::setCurrentAppname(const char *appname)
+void QTestResult::setCurrentAppName(const char *appName)
{
- QTest::currentAppname = appname;
+ QTest::currentAppName = appName;
}
-const char *QTestResult::currentAppname()
+const char *QTestResult::currentAppName()
{
- return QTest::currentAppname;
+ return QTest::currentAppName;
}
QT_END_NAMESPACE
diff --git a/src/testlib/qtestresult_p.h b/src/testlib/qtestresult_p.h
index 769800d90d..ea8173b169 100644
--- a/src/testlib/qtestresult_p.h
+++ b/src/testlib/qtestresult_p.h
@@ -93,8 +93,8 @@ public:
static void setSkipCurrentTest(bool value);
static bool skipCurrentTest();
- static void setCurrentAppname(const char *appname);
- static const char *currentAppname();
+ static void setCurrentAppName(const char *appName);
+ static const char *currentAppName();
private:
Q_DISABLE_COPY(QTestResult)
diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp
index 290afec776..4a50a45ea6 100644
--- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp
+++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp
@@ -324,7 +324,7 @@ void tst_QGlobal::qCoreAppStartupFunction()
{
QCOMPARE(qStartupFunctionValue, 0);
int argc = 1;
- char *argv[] = { const_cast<char*>("tst_qglobal") };
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
QCoreApplication app(argc, argv);
QCOMPARE(qStartupFunctionValue, 124);
}
diff --git a/tests/auto/corelib/io/qprocess-noapplication/tst_qprocessnoapplication.cpp b/tests/auto/corelib/io/qprocess-noapplication/tst_qprocessnoapplication.cpp
index 33146cafd1..21d03cd04d 100644
--- a/tests/auto/corelib/io/qprocess-noapplication/tst_qprocessnoapplication.cpp
+++ b/tests/auto/corelib/io/qprocess-noapplication/tst_qprocessnoapplication.cpp
@@ -70,8 +70,7 @@ void tst_QProcessNoApplication::initializationDeadlock()
}
};
- static char argv0[] = "tst_QProcessNoApplication";
- char *argv[] = { argv0, 0 };
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()), 0 };
int argc = 1;
QCoreApplication app(argc, argv);
MyThread thread;
diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp
index ccaa2bec4f..78f2cdae69 100644
--- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp
+++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp
@@ -88,7 +88,7 @@ public:
void tst_QCoreApplication::sendEventsOnProcessEvents()
{
int argc = 1;
- char *argv[] = { const_cast<char*>("tst_qcoreapplication") };
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
QCoreApplication app(argc, argv);
EventSpy spy;
@@ -110,7 +110,7 @@ void tst_QCoreApplication::getSetCheck()
// Test the property
{
int argc = 1;
- char *argv[] = { const_cast<char*>("tst_qcoreapplication") };
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
QCoreApplication app(argc, argv);
QCOMPARE(app.property("applicationVersion").toString(), v);
}
@@ -135,7 +135,7 @@ void tst_QCoreApplication::argc()
{
{
int argc = 1;
- char *argv[] = { const_cast<char*>("tst_qcoreapplication") };
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
QCoreApplication app(argc, argv);
QCOMPARE(argc, 1);
QCOMPARE(app.arguments().count(), 1);
@@ -143,7 +143,7 @@ void tst_QCoreApplication::argc()
{
int argc = 4;
- char *argv[] = { const_cast<char*>("tst_qcoreapplication"),
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()),
const_cast<char*>("arg1"),
const_cast<char*>("arg2"),
const_cast<char*>("arg3") };
@@ -162,7 +162,7 @@ void tst_QCoreApplication::argc()
{
int argc = 2;
- char *argv[] = { const_cast<char*>("tst_qcoreapplication"),
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()),
const_cast<char*>("-qmljsdebugger=port:3768,block") };
QCoreApplication app(argc, argv);
QCOMPARE(argc, 1);
@@ -196,7 +196,7 @@ public:
void tst_QCoreApplication::postEvent()
{
int argc = 1;
- char *argv[] = { const_cast<char*>("tst_qcoreapplication") };
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
QCoreApplication app(argc, argv);
EventSpy spy;
@@ -281,7 +281,7 @@ void tst_QCoreApplication::postEvent()
void tst_QCoreApplication::removePostedEvents()
{
int argc = 1;
- char *argv[] = { const_cast<char*>("tst_qcoreapplication") };
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
QCoreApplication app(argc, argv);
EventSpy spy;
@@ -460,7 +460,7 @@ public:
void tst_QCoreApplication::deliverInDefinedOrder()
{
int argc = 1;
- char *argv[] = { const_cast<char*>("tst_qcoreapplication") };
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
QCoreApplication app(argc, argv);
DeliverInDefinedOrderObject obj(&app);
@@ -500,7 +500,7 @@ public:
void tst_QCoreApplication::globalPostedEventsCount()
{
int argc = 1;
- char *argv[] = { const_cast<char*>("tst_qcoreapplication") };
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
QCoreApplication app(argc, argv);
QCoreApplication::sendPostedEvents();
@@ -546,7 +546,7 @@ public:
void tst_QCoreApplication::processEventsAlwaysSendsPostedEvents()
{
int argc = 1;
- char *argv[] = { const_cast<char*>("tst_qcoreapplication") };
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
QCoreApplication app(argc, argv);
ProcessEventsAlwaysSendsPostedEventsObject object;
@@ -564,7 +564,7 @@ void tst_QCoreApplication::processEventsAlwaysSendsPostedEvents()
void tst_QCoreApplication::reexec()
{
int argc = 1;
- char *argv[] = { const_cast<char*>("tst_qcoreapplication") };
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
QCoreApplication app(argc, argv);
// exec once
@@ -579,7 +579,7 @@ void tst_QCoreApplication::reexec()
void tst_QCoreApplication::execAfterExit()
{
int argc = 1;
- char *argv[] = { const_cast<char*>("tst_qcoreapplication") };
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
QCoreApplication app(argc, argv);
app.exit(1);
@@ -590,7 +590,7 @@ void tst_QCoreApplication::execAfterExit()
void tst_QCoreApplication::eventLoopExecAfterExit()
{
int argc = 1;
- char *argv[] = { const_cast<char*>("tst_qcoreapplication") };
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
QCoreApplication app(argc, argv);
// exec once and exit
@@ -648,7 +648,7 @@ void tst_QCoreApplication::customEventDispatcher()
QVERIFY(!weak_ed.isNull());
{
int argc = 1;
- char *argv[] = { const_cast<char*>("tst_qcoreapplication") };
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
QCoreApplication app(argc, argv);
// instantiating app should not overwrite the ED
QCOMPARE(QCoreApplication::eventDispatcher(), ed);
@@ -763,7 +763,7 @@ private slots:
void tst_QCoreApplication::testQuitLock()
{
int argc = 1;
- char *argv[] = { const_cast<char*>("tst_qcoreapplication") };
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
QCoreApplication app(argc, argv);
QuitTester tester;
@@ -782,7 +782,7 @@ void tst_QCoreApplication::QTBUG31606_QEventDestructorDeadLock()
};
int argc = 1;
- char *argv[] = { const_cast<char*>("tst_qcoreapplication") };
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
QCoreApplication app(argc, argv);
EventSpy spy;
diff --git a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp
index 9219ff72df..d8965dee5d 100644
--- a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp
+++ b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp
@@ -48,6 +48,9 @@ class tst_QCommandLineParser : public QObject
{
Q_OBJECT
+public slots:
+ void initTestCase();
+
private slots:
void parsingModes_data();
@@ -81,9 +84,15 @@ private slots:
void testQuoteEscaping();
};
-static char *empty_argv[] = { const_cast<char*>("tst_qcommandlineparser") };
+static char *empty_argv[] = { 0 };
static int empty_argc = 1;
+void tst_QCommandLineParser::initTestCase()
+{
+ Q_ASSERT(!empty_argv[0]);
+ empty_argv[0] = const_cast<char*>(QTest::currentAppName());
+}
+
Q_DECLARE_METATYPE(QCommandLineParser::SingleDashWordOptionMode)
void tst_QCommandLineParser::parsingModes_data()
diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
index 0f224c4909..7884426d68 100644
--- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
+++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
@@ -768,7 +768,7 @@ void tst_QGuiApplication::genericPluginsAndWindowSystemEvents()
testPluginInfo.rawMetaData = qt_plugin_query_metadata;
qRegisterStaticPluginFunction(testPluginInfo);
int argc = 3;
- char *argv[] = { const_cast<char*>("tst_qguiapplication"), const_cast<char*>("-plugin"), const_cast<char*>("testplugin") };
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()), const_cast<char*>("-plugin"), const_cast<char*>("testplugin") };
QGuiApplication app(argc, argv);
QVERIFY(QGuiApplication::primaryScreen());
diff --git a/tests/auto/sql/kernel/qsql/tst_qsql.cpp b/tests/auto/sql/kernel/qsql/tst_qsql.cpp
index bc6b36931a..5747683e4e 100644
--- a/tests/auto/sql/kernel/qsql/tst_qsql.cpp
+++ b/tests/auto/sql/kernel/qsql/tst_qsql.cpp
@@ -114,8 +114,8 @@ void tst_QSql::cleanup()
void tst_QSql::basicDriverTest()
{
int argc = 1;
- const char *argv[] = {"test"};
- QGuiApplication app(argc, const_cast<char **>(argv), false);
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
+ QGuiApplication app(argc, argv, false);
tst_Databases dbs;
dbs.open();
@@ -155,10 +155,10 @@ void tst_QSql::open()
{
int i;
int argc = 1;
- const char *argv[] = {"test"};
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
int count = -1;
for (i = 0; i < 10; ++i) {
- QGuiApplication app(argc, const_cast<char **>(argv), false);
+ QGuiApplication app(argc, argv, false);
tst_Databases dbs;
dbs.open();
@@ -184,8 +184,8 @@ void tst_QSql::openInvalid()
void tst_QSql::concurrentAccess()
{
int argc = 1;
- const char *argv[] = {"test"};
- QGuiApplication app(argc, const_cast<char **>(argv), false);
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
+ QGuiApplication app(argc, argv, false);
tst_Databases dbs;
dbs.open();
@@ -213,8 +213,8 @@ void tst_QSql::concurrentAccess()
void tst_QSql::openErrorRecovery()
{
int argc = 1;
- const char *argv[] = {"test"};
- QGuiApplication app(argc, const_cast<char **>(argv), false);
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
+ QGuiApplication app(argc, argv, false);
tst_Databases dbs;
dbs.addDbs();
@@ -261,8 +261,8 @@ void tst_QSql::openErrorRecovery()
void tst_QSql::registerSqlDriver()
{
int argc = 1;
- const char *argv[] = {"test"};
- QGuiApplication app(argc, const_cast<char **>(argv), false);
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
+ QGuiApplication app(argc, argv, false);
QSqlDatabase::registerSqlDriver("QSQLTESTDRIVER", new QSqlDriverCreator<QSqlNullDriver>);
QVERIFY(QSqlDatabase::drivers().contains("QSQLTESTDRIVER"));