diff options
author | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2012-01-09 12:51:13 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-09 15:38:52 +0100 |
commit | 7ba9a789c930b420e970e50d3ffba7f408fd8f8c (patch) | |
tree | 1bd0b971203427b3a6dd32758c3b98d9ce0c071a | |
parent | 0ff8577a992b1d5c011b04e47ade84074cbd3034 (diff) | |
download | qtscript-7ba9a789c930b420e970e50d3ffba7f408fd8f8c.tar.gz |
Fix Qt IPC-test on Windows.
- Introduce base class for tests using the lackey executable
that locates the binary and the scripts and provides
convenience functions for error handling and creating
arguments.
- Simplify .pro files accordingly, make all binaries
command line applications (remove QtGui and Mac bundles)
- Use absolute paths for scripts and executable.
- Remove Windows CE code.
- Introduce QTemporaryDir to tst_qsystemsemaphore
and create scripts there instead of creating
many temporary files.
Acked-by: Jo Asplin <jo.asplin@nokia.com>
Change-Id: I26dcda98c2372705d19bcb586b8e36cdccebcd41
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
-rw-r--r-- | tests/auto/qtipc/lackey/lackeytest.h | 141 | ||||
-rw-r--r-- | tests/auto/qtipc/qsharedmemory/qsystemlock/qsystemlock.pro | 10 | ||||
-rw-r--r-- | tests/auto/qtipc/qsharedmemory/qsystemlock/tst_qsystemlock.cpp | 25 | ||||
-rw-r--r-- | tests/auto/qtipc/qsharedmemory/src/qsystemlock_p.h | 2 | ||||
-rw-r--r-- | tests/auto/qtipc/qsharedmemory/test/test.pro | 25 | ||||
-rw-r--r-- | tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp | 53 | ||||
-rw-r--r-- | tests/auto/qtipc/qsystemsemaphore/qsystemsemaphore.pro | 13 | ||||
-rw-r--r-- | tests/auto/qtipc/qsystemsemaphore/tst_qsystemsemaphore.cpp | 152 |
8 files changed, 273 insertions, 148 deletions
diff --git a/tests/auto/qtipc/lackey/lackeytest.h b/tests/auto/qtipc/lackey/lackeytest.h new file mode 100644 index 0000000..a0b25b7 --- /dev/null +++ b/tests/auto/qtipc/lackey/lackeytest.h @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef LACKEYTEST_H +#define LACKEYTEST_H + +#include <QtCore/QStringList> +#include <QtCore/QCoreApplication> +#include <QtCore/QDir> +#include <QtCore/QFileInfo> + +// Mixin base class for tests that use the lackey executable to run scripts. +// Locates the binary starting from the executable directory and the scripts +// directory starting from #define SRCDIR. + +class LackeyTest +{ +public: + LackeyTest(int binaryDepth = 1, int sourceDepth = 1); + + QString lackeyBinary() const { return m_lackeyBinary; } + QString lackeyScriptsDirectory() const { return m_lackeyScriptsDirectory; } + + // For use in initTestCase() + bool isValid(QByteArray *errorMessage) const; + + // Messages for use in QVERIFY2 + static QByteArray msgCannotStartProcess(const QString &binary, + const QString &errorMessage); + + QByteArray msgCannotStartLackey(const QString &errorMessage) const + { return LackeyTest::msgCannotStartProcess(m_lackeyBinary, errorMessage); } + + QString scriptPath(const char *script) const + { return m_lackeyScriptsDirectory + QLatin1Char('/') + QLatin1String(script); } + + QStringList scriptArguments(const char *script) const + { return QStringList(scriptPath(script)); } + +private: + QString m_lackeyBinary; + QString m_lackeyScriptsDirectory; +}; + +LackeyTest::LackeyTest(int binaryDepth, int sourceDepth) +{ + // Find executable in (shadow) build hierarchy. + QDir dir = QDir(QCoreApplication::applicationDirPath()); +#ifdef Q_OS_WIN + // cd up from Windows debug/release folders. + if (!dir.dirName().compare(QLatin1String("debug"), Qt::CaseInsensitive) + || !dir.dirName().compare(QLatin1String("release"), Qt::CaseInsensitive)) + dir.cdUp(); +#endif + const QString lackey = QStringLiteral("lackey"); + QString binary = lackey; +#ifdef Q_OS_WIN + binary += QStringLiteral(".exe"); +#endif + for (int i = 0; i < binaryDepth; ++i) + if (!dir.cdUp()) + return; + if (dir.cd(lackey) && dir.exists(binary)) + m_lackeyBinary = dir.absoluteFilePath(binary); + // Find scripts starting from SRC in source hierarchy. + dir = QDir(QLatin1String(SRCDIR)); + for (int i = 0; i < sourceDepth; ++i) + if (!dir.cdUp()) + return; + if (dir.cd(lackey) && dir.cd(QStringLiteral("scripts"))) + m_lackeyScriptsDirectory = dir.absolutePath(); +} + +bool LackeyTest::isValid(QByteArray *errorMessage) const +{ + if (m_lackeyBinary.isEmpty()) { + *errorMessage = "Lackey executable could not be found starting from " + + QCoreApplication::applicationDirPath().toLocal8Bit(); + return false; + } + if (!QFileInfo(m_lackeyBinary).isExecutable()) { + *errorMessage = "Lackey " + m_lackeyBinary.toLocal8Bit() + " is not executable."; + return false; + } + if (m_lackeyScriptsDirectory.isEmpty()) { + *errorMessage = "Lackey scripts directory could not be found starting from " + + QByteArray(SRCDIR); + return false; + } + return true; +} + +QByteArray LackeyTest::msgCannotStartProcess(const QString &binary, + const QString &errorMessage) +{ + QByteArray result = "Cannot start: '"; + result += binary.toLocal8Bit(); + result += "': "; + result += errorMessage.toLocal8Bit(); + return result; +} + +#endif // LACKEYTEST_H diff --git a/tests/auto/qtipc/qsharedmemory/qsystemlock/qsystemlock.pro b/tests/auto/qtipc/qsharedmemory/qsystemlock/qsystemlock.pro index 67e9121..67f5d13 100644 --- a/tests/auto/qtipc/qsharedmemory/qsystemlock/qsystemlock.pro +++ b/tests/auto/qtipc/qsharedmemory/qsystemlock/qsystemlock.pro @@ -1,17 +1,11 @@ CONFIG += testcase -QT += gui-private testlib +QT = core testlib include(../src/src.pri) win32: CONFIG += console mac:CONFIG -= app_bundle -wince* { - DEFINES += SRCDIR=\\\"\\\" -} else { - DEFINES += SRCDIR=\\\"$$PWD\\\" -} - -DESTDIR = ./ +DEFINES += SRCDIR=\\\"$$PWD\\\" DEFINES += QSHAREDMEMORY_DEBUG DEFINES += QSYSTEMSEMAPHORE_DEBUG diff --git a/tests/auto/qtipc/qsharedmemory/qsystemlock/tst_qsystemlock.cpp b/tests/auto/qtipc/qsharedmemory/qsystemlock/tst_qsystemlock.cpp index 0782b2a..4661c92 100644 --- a/tests/auto/qtipc/qsharedmemory/qsystemlock/tst_qsystemlock.cpp +++ b/tests/auto/qtipc/qsharedmemory/qsystemlock/tst_qsystemlock.cpp @@ -39,13 +39,15 @@ ** ****************************************************************************/ +#include "../../lackey/lackeytest.h" #include <QtTest/QtTest> +#include <QtCore/QVector> #include <qsystemlock.h> #define EXISTING_SHARE "existing" -class tst_QSystemLock : public QObject +class tst_QSystemLock : public QObject, LackeyTest { Q_OBJECT @@ -54,6 +56,7 @@ public: virtual ~tst_QSystemLock(); public Q_SLOTS: + void initTestCase(); void init(); void cleanup(); @@ -73,7 +76,7 @@ private: }; -tst_QSystemLock::tst_QSystemLock() +tst_QSystemLock::tst_QSystemLock() : LackeyTest(2, 2) { } @@ -81,6 +84,12 @@ tst_QSystemLock::~tst_QSystemLock() { } +void tst_QSystemLock::initTestCase() +{ + QByteArray errorMessage; + QVERIFY2(isValid(&errorMessage), errorMessage.constData()); +} + void tst_QSystemLock::init() { existingLock = new QSystemLock(EXISTING_SHARE); @@ -188,24 +197,20 @@ void tst_QSystemLock::processes_data() void tst_QSystemLock::processes() { QSKIP("This test takes about 15 minutes and needs to be trimmed down before we can re-enable it"); + QFETCH(int, readOnly); QFETCH(int, readWrite); - QStringList scripts; - for (int i = 0; i < readOnly; ++i) - scripts.append(QFileInfo(SRCDIR "/../lackey/scripts/systemlock_read.js").absoluteFilePath() ); - for (int i = 0; i < readWrite; ++i) - scripts.append(QFileInfo(SRCDIR "/../lackey/scripts/systemlock_readwrite.js").absoluteFilePath()); + QVector<QString> scripts = QVector<QString>(readOnly, scriptPath("systemlock_read.js")); + scripts += QVector<QString>(readWrite, scriptPath("systemlock_readwrite.js")); QList<QProcess*> consumers; unsigned int failedProcesses = 0; for (int i = 0; i < scripts.count(); ++i) { - - QStringList arguments = QStringList() << scripts.at(i); QProcess *p = new QProcess; p->setProcessChannelMode(QProcess::ForwardedChannels); - p->start("../lackey/lackey", arguments); + p->start(lackeyBinary(), QStringList(scripts.at(i))); // test, if the process could be started. if (p->waitForStarted(2000)) diff --git a/tests/auto/qtipc/qsharedmemory/src/qsystemlock_p.h b/tests/auto/qtipc/qsharedmemory/src/qsystemlock_p.h index 728cfcb..a1ace35 100644 --- a/tests/auto/qtipc/qsharedmemory/src/qsystemlock_p.h +++ b/tests/auto/qtipc/qsharedmemory/src/qsystemlock_p.h @@ -46,7 +46,7 @@ #ifndef QT_NO_SYSTEMLOCK #include "qsystemlock.h" -#include "private/qsharedmemory_p.h" +#include <private/qsharedmemory_p.h> #ifndef Q_OS_WINCE #include <sys/types.h> #endif diff --git a/tests/auto/qtipc/qsharedmemory/test/test.pro b/tests/auto/qtipc/qsharedmemory/test/test.pro index adad14c..48d9310 100644 --- a/tests/auto/qtipc/qsharedmemory/test/test.pro +++ b/tests/auto/qtipc/qsharedmemory/test/test.pro @@ -1,29 +1,14 @@ CONFIG += testcase +QT = core testlib include(../src/src.pri) -QT += core testlib + +mac:CONFIG -= app_bundle DEFINES += QSHAREDMEMORY_DEBUG DEFINES += QSYSTEMSEMAPHORE_DEBUG SOURCES += ../tst_qsharedmemory.cpp -TARGET = ../tst_qsharedmemory - -!wince*:win32 { - CONFIG(debug, debug|release) { - TARGET = ../../debug/tst_qsharedmemory -} else { - TARGET = ../../release/tst_qsharedmemory - } -} +TARGET = tst_qsharedmemory -wince*:{ -requires(contains(QT_CONFIG,script)) -QT += gui script -addFiles.files = $$OUT_PWD/../../lackey/lackey.exe ../../lackey/scripts -addFiles.path = . -DEPLOYMENT += addFiles -DEFINES += SRCDIR=\\\".\\\" -} else { -DEFINES += SRCDIR=\\\"$$PWD/../\\\" -} +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp b/tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp index 683d693..eb98bb6 100644 --- a/tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp +++ b/tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp @@ -42,21 +42,19 @@ #include <QtTest/QtTest> #include <qsharedmemory.h> +#include "../lackey/lackeytest.h" + #include <QtCore/QFile> +#include <QtCore/QFileInfo> +#include <QtCore/QDir> #define EXISTING_SHARE "existing" #define EXISTING_SIZE 1024 -#if defined(Q_OS_WINCE) -#define LACKEYDIR SRCDIR -#else -#define LACKEYDIR "../lackey" -#endif - Q_DECLARE_METATYPE(QSharedMemory::SharedMemoryError) Q_DECLARE_METATYPE(QSharedMemory::AccessMode) -class tst_QSharedMemory : public QObject +class tst_QSharedMemory : public QObject, public LackeyTest { Q_OBJECT @@ -66,8 +64,10 @@ public: public Q_SLOTS: void init(); + void initTestCase(); void cleanup(); + private slots: // basics void constructor(); @@ -130,9 +130,12 @@ protected: QStringList keys; QList<QSharedMemory*> jail; QSharedMemory *existingSharedMemory; + const QString m_lackeyScriptsDirectory; + const QString m_lackeyBinary; }; -tst_QSharedMemory::tst_QSharedMemory() : existingSharedMemory(0) +tst_QSharedMemory::tst_QSharedMemory() : + LackeyTest(2, 2), existingSharedMemory(0) { } @@ -140,6 +143,12 @@ tst_QSharedMemory::~tst_QSharedMemory() { } +void tst_QSharedMemory::initTestCase() +{ + QByteArray errorMessage; + QVERIFY2(isValid(&errorMessage), errorMessage.constData()); +} + void tst_QSharedMemory::init() { existingSharedMemory = new QSharedMemory(EXISTING_SHARE); @@ -435,14 +444,10 @@ void tst_QSharedMemory::emptyMemory() #ifndef Q_OS_WIN void tst_QSharedMemory::readOnly() { - QString program = LACKEYDIR "/lackey"; - QStringList arguments; rememberKey("readonly_segfault"); - arguments << SRCDIR "../lackey/scripts/readonly_segfault.js"; - // ### on windows disable the popup somehow QProcess p; - p.start(program, arguments); + p.start(lackeyBinary(), scriptArguments("readonly_segfault.js")); p.setProcessChannelMode(QProcess::ForwardedChannels); p.waitForFinished(); QCOMPARE(p.error(), QProcess::Crashed); @@ -729,32 +734,18 @@ void tst_QSharedMemory::simpleProcessProducerConsumer() rememberKey("market"); - QStringList arguments = QStringList() << SRCDIR "../lackey/scripts/producer.js"; QProcess producer; producer.setProcessChannelMode(QProcess::ForwardedChannels); - producer.start( LACKEYDIR "/lackey", arguments); - producer.waitForStarted(); - QVERIFY(producer.error() != QProcess::FailedToStart); + producer.start(lackeyBinary(), scriptArguments("producer.js")); + QVERIFY2(producer.waitForStarted(), msgCannotStartLackey(producer.errorString()).constData()); QList<QProcess*> consumers; unsigned int failedProcesses = 0; + const QStringList consumerArguments = scriptArguments("consumer.js"); for (int i = 0; i < processes; ++i) { - QStringList arguments = QStringList() << SRCDIR "../lackey/scripts/consumer.js"; QProcess *p = new QProcess; p->setProcessChannelMode(QProcess::ForwardedChannels); -#ifdef Q_OS_WINCE - // We can't start the same executable twice on Windows CE. - // Create a copy instead. - QString lackeyCopy = QLatin1String(LACKEYDIR "/lackey"); - lackeyCopy.append(QString::number(i)); - lackeyCopy.append(QLatin1String(".exe")); - if (!QFile::exists(lackeyCopy)) - QVERIFY(QFile::copy(LACKEYDIR "/lackey.exe", lackeyCopy)); - p->start(lackeyCopy, arguments); -#else - p->start(LACKEYDIR "/lackey", arguments); -#endif - + p->start(lackeyBinary(), consumerArguments); if (p->waitForStarted(2000)) consumers.append(p); else diff --git a/tests/auto/qtipc/qsystemsemaphore/qsystemsemaphore.pro b/tests/auto/qtipc/qsystemsemaphore/qsystemsemaphore.pro index 3c1cf75..1665c2d 100644 --- a/tests/auto/qtipc/qsystemsemaphore/qsystemsemaphore.pro +++ b/tests/auto/qtipc/qsystemsemaphore/qsystemsemaphore.pro @@ -1,8 +1,9 @@ CONFIG += testcase -QT += testlib +QT = core testlib include(../qsharedmemory/src/src.pri) win32: CONFIG += console +mac:CONFIG -= app_bundle DEFINES += QSHAREDMEMORY_DEBUG DEFINES += QSYSTEMSEMAPHORE_DEBUG @@ -12,12 +13,4 @@ TARGET = tst_qsystemsemaphore RESOURCES += files.qrc -wince*: { -requires(contains(QT_CONFIG,script)) -# this test calls lackey, which then again depends on QtScript. -# let's add it here so that it gets deployed easily -QT += script -lackey.files = $$OUT_PWD/../lackey/lackey.exe ../lackey/scripts -lackey.path = . -DEPLOYMENT += lackey -} +DEFINES += SRCDIR=\\\"$$PWD/\\\" diff --git a/tests/auto/qtipc/qsystemsemaphore/tst_qsystemsemaphore.cpp b/tests/auto/qtipc/qsystemsemaphore/tst_qsystemsemaphore.cpp index 784a10e..2e63252 100644 --- a/tests/auto/qtipc/qsystemsemaphore/tst_qsystemsemaphore.cpp +++ b/tests/auto/qtipc/qsystemsemaphore/tst_qsystemsemaphore.cpp @@ -39,27 +39,25 @@ ** ****************************************************************************/ +#include "../../lackey/lackeytest.h" #include <QtTest/QtTest> -#include <qsystemsemaphore.h> +#include <QtCore/QSystemSemaphore> +#include <QtCore/QVector> +#include <QtCore/QTemporaryDir> #define EXISTING_SHARE "existing" -#ifdef Q_OS_WINCE -#define LACKEYLOC "." -#else -#define LACKEYLOC "../lackey" -#endif #define LACKYWAITTIME 10000 -class tst_QSystemSemaphore : public QObject +class tst_QSystemSemaphore : public QObject, LackeyTest { Q_OBJECT public: tst_QSystemSemaphore(); - virtual ~tst_QSystemSemaphore(); public Q_SLOTS: + void initTestCase(); void init(); void cleanup(); @@ -83,43 +81,70 @@ private slots: private: QSystemSemaphore *existingLock; - QString makeFile(const QString &resource) - { - QFile memory(resource); - if (!memory.open(QIODevice::ReadOnly)) { - qDebug() << "error reading resource" << resource; - return QString(); - } - QTemporaryFile *file = new QTemporaryFile; - file->open(); - file->write(memory.readAll()); - tempFiles.append(file); - file->flush(); -#ifdef Q_OS_WINCE - // flush does not flush to disk on Windows CE. It flushes it into its application - // cache. Thus we need to close the file to be able that other processes(lackey) can read it - QString fileName = file->fileName(); - file->close(); - return fileName; -#endif - return file->fileName(); - } + QTemporaryDir m_temporaryDir; - QString acquire_js() { return makeFile(":/systemsemaphore_acquire.js"); } - QString release_js() { return makeFile(":/systemsemaphore_release.js"); } - QString acquirerelease_js() { return makeFile(":/systemsemaphore_acquirerelease.js"); } - QList<QTemporaryFile*> tempFiles; + QString m_acquireJs; + QString m_releaseJs; + QString m_acquirereleaseJs; }; -tst_QSystemSemaphore::tst_QSystemSemaphore() +static inline QString tempDirPattern() +{ + QString result = QDir::tempPath(); + if (!result.endsWith(QLatin1Char('/'))) + result += QLatin1Char('/'); + result += QStringLiteral("tst_qsystemsemaphoreXXXXXX"); + return result; +} + +tst_QSystemSemaphore::tst_QSystemSemaphore() : m_temporaryDir(tempDirPattern()) { - if (!QFile::exists(LACKEYLOC "/lackey")) - qWarning() << "lackey executable doesn't exists!"; + m_temporaryDir.setAutoRemove(true); } -tst_QSystemSemaphore::~tst_QSystemSemaphore() +static bool createFile(const QString &resource, + const QString &target, + QByteArray *errorMessage) { - qDeleteAll(tempFiles); + QFile memory(resource); + if (!memory.open(QIODevice::ReadOnly | QIODevice::Text)) { + *errorMessage = "Error reading resource '" + + resource.toLocal8Bit() + "': " + + memory.errorString().toLocal8Bit(); + return false; + } + QFile file(target); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { + *errorMessage = "Error writing '" + + target.toLocal8Bit() + "': " + + file.errorString().toLocal8Bit(); + return false; + } + file.write(memory.readAll()); + file.close(); + return true; +} + +void tst_QSystemSemaphore::initTestCase() +{ + QByteArray errorMessage; + QVERIFY2(isValid(&errorMessage), errorMessage.constData()); + QVERIFY(m_temporaryDir.isValid()); + // Write out files from resources to temporary folder + const QString acquireJs = QStringLiteral("systemsemaphore_acquire.js"); + m_acquireJs = m_temporaryDir.path() + QLatin1Char('/') + acquireJs; + QVERIFY2(createFile(QStringLiteral(":/") + acquireJs, m_acquireJs, &errorMessage), + errorMessage.constData()); + + const QString releaseJs = QStringLiteral("systemsemaphore_release.js"); + m_releaseJs = m_temporaryDir.path() + QLatin1Char('/') + releaseJs; + QVERIFY2(createFile(QStringLiteral(":/") + releaseJs, m_releaseJs, &errorMessage), + errorMessage.constData()); + + const QString acquireReleaseJs = QStringLiteral("systemsemaphore_acquirerelease.js"); + m_acquirereleaseJs = m_temporaryDir.path() + QLatin1Char('/') + acquireReleaseJs; + QVERIFY2(createFile(QStringLiteral(":/") + acquireReleaseJs, m_acquirereleaseJs, &errorMessage), + errorMessage.constData()); } void tst_QSystemSemaphore::init() @@ -190,19 +215,21 @@ void tst_QSystemSemaphore::basicProcesses() { QSystemSemaphore sem("store", 0, QSystemSemaphore::Create); - QStringList acquireArguments = QStringList() << acquire_js(); - QStringList releaseArguments = QStringList() << release_js(); + QStringList acquireArguments = QStringList(m_acquireJs); + QStringList releaseArguments = QStringList(m_releaseJs); QProcess acquire; acquire.setProcessChannelMode(QProcess::ForwardedChannels); QProcess release; release.setProcessChannelMode(QProcess::ForwardedChannels); - acquire.start(LACKEYLOC "/lackey", acquireArguments); + acquire.start(lackeyBinary(), acquireArguments); + QVERIFY2(acquire.waitForStarted(), msgCannotStartLackey(acquire.errorString()).constData()); acquire.waitForFinished(LACKYWAITTIME); QVERIFY(acquire.state() == QProcess::Running); acquire.kill(); - release.start(LACKEYLOC "/lackey", releaseArguments); + release.start(lackeyBinary(), releaseArguments); + QVERIFY2(release.waitForStarted(), msgCannotStartLackey(release.errorString()).constData()); acquire.waitForFinished(LACKYWAITTIME); release.waitForFinished(LACKYWAITTIME); QVERIFY(acquire.state() == QProcess::NotRunning); @@ -223,30 +250,14 @@ void tst_QSystemSemaphore::processes() QSystemSemaphore sem("store", 1, QSystemSemaphore::Create); QFETCH(int, processes); - QStringList scripts; - for (int i = 0; i < processes; ++i) - scripts.append(acquirerelease_js()); + QVector<QString> scripts(processes, m_acquirereleaseJs); QList<QProcess*> consumers; for (int i = 0; i < scripts.count(); ++i) { - QStringList arguments = QStringList() << scripts.at(i); QProcess *p = new QProcess; p->setProcessChannelMode(QProcess::ForwardedChannels); consumers.append(p); -#ifdef Q_OS_WINCE - // We can't start the same executable twice on Windows CE. - // Create a copy instead. - QString lackeyCopy = QLatin1String(LACKEYLOC "/lackey"); - if (i > 0) { - lackeyCopy.append(QString::number(i)); - lackeyCopy.append(QLatin1String(".exe")); - if (!QFile::exists(lackeyCopy)) - QVERIFY(QFile::copy(LACKEYLOC "/lackey.exe", lackeyCopy)); - } - p->start(lackeyCopy, arguments); -#else - p->start(LACKEYLOC "/lackey", arguments); -#endif + p->start(lackeyBinary(), QStringList(scripts.at(i))); } while (!consumers.isEmpty()) { @@ -263,16 +274,18 @@ void tst_QSystemSemaphore::undo() { QSystemSemaphore sem("store", 1, QSystemSemaphore::Create); - QStringList acquireArguments = QStringList() << acquire_js(); + QStringList acquireArguments = QStringList(m_acquireJs); QProcess acquire; acquire.setProcessChannelMode(QProcess::ForwardedChannels); - acquire.start(LACKEYLOC "/lackey", acquireArguments); + acquire.start(lackeyBinary(), acquireArguments); + QVERIFY2(acquire.waitForStarted(), msgCannotStartLackey(acquire.errorString()).constData()); acquire.waitForFinished(LACKYWAITTIME); QVERIFY(acquire.state()== QProcess::NotRunning); // At process exit the kernel should auto undo - acquire.start(LACKEYLOC "/lackey", acquireArguments); + acquire.start(lackeyBinary(), acquireArguments); + QVERIFY2(acquire.waitForStarted(), msgCannotStartLackey(acquire.errorString()).constData()); acquire.waitForFinished(LACKYWAITTIME); QVERIFY(acquire.state()== QProcess::NotRunning); } @@ -282,24 +295,27 @@ void tst_QSystemSemaphore::initialValue() { QSystemSemaphore sem("store", 1, QSystemSemaphore::Create); - QStringList acquireArguments = QStringList() << acquire_js(); - QStringList releaseArguments = QStringList() << release_js(); + QStringList acquireArguments = QStringList(m_acquireJs); + QStringList releaseArguments = QStringList(m_releaseJs); QProcess acquire; acquire.setProcessChannelMode(QProcess::ForwardedChannels); QProcess release; release.setProcessChannelMode(QProcess::ForwardedChannels); - acquire.start(LACKEYLOC "/lackey", acquireArguments); + acquire.start(lackeyBinary(), acquireArguments); + QVERIFY2(acquire.waitForStarted(), msgCannotStartLackey(acquire.errorString()).constData()); acquire.waitForFinished(LACKYWAITTIME); QVERIFY(acquire.state()== QProcess::NotRunning); - acquire.start(LACKEYLOC "/lackey", acquireArguments << "2"); + acquire.start(lackeyBinary(), acquireArguments << QLatin1String("2")); + QVERIFY2(acquire.waitForStarted(), msgCannotStartLackey(acquire.errorString()).constData()); acquire.waitForFinished(LACKYWAITTIME); QVERIFY(acquire.state()== QProcess::Running); acquire.kill(); - release.start(LACKEYLOC "/lackey", releaseArguments); + release.start(lackeyBinary(), releaseArguments); + QVERIFY2(release.waitForStarted(), msgCannotStartLackey(release.errorString()).constData()); acquire.waitForFinished(LACKYWAITTIME); release.waitForFinished(LACKYWAITTIME); QVERIFY(acquire.state()== QProcess::NotRunning); |