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>
This commit is contained in:
parent
0bf30a7cab
commit
a3530859e9
@ -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);
|
||||
|
||||
@ -2520,6 +2520,14 @@ QTestData &QTest::newRow(const char *dataTag)
|
||||
\sa QTest::newRow(), QFETCH(), QMetaType
|
||||
*/
|
||||
|
||||
/*!
|
||||
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.
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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()
|
||||
|
@ -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());
|
||||
|
@ -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"));
|
||||
|
Loading…
Reference in New Issue
Block a user