diff options
Diffstat (limited to 'tests/auto/qprocess/tst_qprocess.cpp')
-rw-r--r-- | tests/auto/qprocess/tst_qprocess.cpp | 422 |
1 files changed, 392 insertions, 30 deletions
diff --git a/tests/auto/qprocess/tst_qprocess.cpp b/tests/auto/qprocess/tst_qprocess.cpp index 978f17e..6bb2174 100644 --- a/tests/auto/qprocess/tst_qprocess.cpp +++ b/tests/auto/qprocess/tst_qprocess.cpp @@ -47,9 +47,17 @@ #include <QtCore/QThread> #include <QtCore/QRegExp> #include <QtCore/QDebug> +#include <QtCore/QMetaType> +#if !defined(Q_OS_SYMBIAN) +// Network test unnecessary? #include <QtNetwork/QHostInfo> +#endif #include <stdlib.h> +#ifdef QT_NO_PROCESS +QTEST_NOOP_MAIN +#else + #if defined(Q_OS_WIN) #include <windows.h> #endif @@ -124,6 +132,10 @@ private slots: void spaceArgsTest_data(); void spaceArgsTest(); void exitCodeTest(); + void setEnvironment_data(); + void setEnvironment(); + void setProcessEnvironment_data(); + void setProcessEnvironment(); void systemEnvironment(); void spaceInName(); void lockupsInStartDetached(); @@ -154,7 +166,7 @@ protected slots: void restartProcess(); void waitForReadyReadInAReadyReadSlotSlot(); void waitForBytesWrittenInABytesWrittenSlotSlot(); - + private: QProcess *process; qint64 bytesAvailable; @@ -191,6 +203,12 @@ tst_QProcess::~tst_QProcess() void tst_QProcess::init() { +#ifdef Q_OS_SYMBIAN + QString dirStr = QString::fromLatin1("c:\\logs"); + QDir dir; + if (!dir.exists(dirStr)) + dir.mkpath(dirStr); +#endif } void tst_QProcess::cleanup() @@ -246,8 +264,11 @@ void tst_QProcess::simpleStart() QVERIFY(process->waitForStarted(5000)); QCOMPARE(process->state(), QProcess::Running); #if defined(Q_OS_WINCE) + // Note: This actually seems incorrect, it will only exit the while loop when finishing fails while (process->waitForFinished(5000)) { } +#elif defined(Q_OS_SYMBIAN) + QVERIFY(process->waitForFinished(5000)); #else while (process->waitForReadyRead(5000)) { } @@ -373,6 +394,9 @@ void tst_QProcess::echoTest() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif QFETCH(QByteArray, input); @@ -431,6 +455,9 @@ void tst_QProcess::echoTest2() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif process = new QProcess; connect(process, SIGNAL(readyRead()), this, SLOT(exitLoopSlot())); @@ -482,6 +509,9 @@ void tst_QProcess::echoTest_performance() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif QProcess process; #ifdef Q_OS_MAC @@ -536,6 +566,9 @@ void tst_QProcess::echoTestGui() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif QProcess process; @@ -566,11 +599,14 @@ void tst_QProcess::batFiles() #if defined(Q_OS_WINCE) QSKIP("Batch files are not supported on Windows CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Batch files are not supported on Symbian", SkipAll); +#endif QFETCH(QString, batFile); QFETCH(QByteArray, output); QProcess proc; - + proc.start(batFile, QStringList()); QVERIFY(proc.waitForFinished(5000)); @@ -636,6 +672,9 @@ void tst_QProcess::loopBackTest() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif process = new QProcess; #ifdef Q_OS_MAC @@ -666,6 +705,9 @@ void tst_QProcess::readTimeoutAndThenCrash() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif process = new QProcess; #ifdef Q_OS_MAC @@ -707,18 +749,30 @@ void tst_QProcess::waitForFinished() process.start("testProcessOutput/testProcessOutput"); #endif -#ifndef Q_OS_WINCE +#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) QVERIFY(process.waitForFinished(5000)); #else - QVERIFY(process.waitForFinished(15000)); + QVERIFY(process.waitForFinished(30000)); #endif QCOMPARE(process.exitStatus(), QProcess::NormalExit); -#if defined (Q_OS_WINCE) +#if defined(Q_OS_SYMBIAN) + // Symbian test outputs to a file, so check that + FILE* file = fopen("c:\\logs\\qprocess_output_test.txt","r"); + int retval = 0; + int count = 0; + while((int)(retval = fgetc(file) )!= EOF) + if (retval == '\n') + count++; + fclose(file); + QCOMPARE(count, 200); +#else +# if defined (Q_OS_WINCE) QEXPECT_FAIL("", "Reading and writing to a process is not supported on Qt/CE", Continue); -#endif +# endif QString output = process.readAll(); QCOMPARE(output.count("\n"), 10*1024); +#endif process.start("blurdybloop"); QVERIFY(!process.waitForFinished()); @@ -731,6 +785,9 @@ void tst_QProcess::deadWhileReading() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif QProcess process; @@ -756,6 +813,10 @@ void tst_QProcess::restartProcessDeadlock() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif + // The purpose of this test is to detect whether restarting a // process in the finished() connected slot causes a deadlock // because of the way QProcessManager uses its locks. @@ -793,6 +854,9 @@ void tst_QProcess::closeWriteChannel() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif QProcess more; more.start("testProcessEOF/testProcessEOF"); @@ -822,6 +886,9 @@ void tst_QProcess::closeReadChannel() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif for (int i = 0; i < 10; ++i) { QProcess::ProcessChannel channel1 = QProcess::StandardOutput; @@ -859,6 +926,9 @@ void tst_QProcess::openModes() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif QProcess proc; QVERIFY(!proc.isOpen()); @@ -909,6 +979,9 @@ void tst_QProcess::emitReadyReadOnlyWhenNewDataArrives() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif QProcess proc; connect(&proc, SIGNAL(readyRead()), this, SLOT(exitLoopSlot())); @@ -945,6 +1018,9 @@ void tst_QProcess::emitReadyReadOnlyWhenNewDataArrives() //----------------------------------------------------------------------------- void tst_QProcess::hardExit() { +#if defined(Q_OS_SYMBIAN) + QSKIP("Killing started processes is not supported on Qt/Symbian due platform security", SkipAll); +#endif QProcess proc; #if defined(Q_OS_MAC) @@ -971,6 +1047,9 @@ void tst_QProcess::hardExit() //----------------------------------------------------------------------------- void tst_QProcess::softExit() { +#if defined(Q_OS_SYMBIAN) + QSKIP("Terminating started processes is not supported on Qt/Symbian due platform security", SkipAll); +#endif QProcess proc; proc.start("testSoftExit/testSoftExit"); @@ -992,7 +1071,7 @@ class SoftExitProcess : public QProcess Q_OBJECT public: bool waitedForFinished; - + SoftExitProcess(int n) : waitedForFinished(false), n(n), killing(false) { connect(this, SIGNAL(finished(int, QProcess::ExitStatus)), @@ -1075,6 +1154,9 @@ void tst_QProcess::softExitInSlots() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif QFETCH(QString, appName); @@ -1094,6 +1176,9 @@ void tst_QProcess::mergedChannels() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif QProcess process; process.setReadChannelMode(QProcess::MergedChannels); @@ -1124,11 +1209,14 @@ void tst_QProcess::forwardedChannels() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif QProcess process; process.setReadChannelMode(QProcess::ForwardedChannels); QCOMPARE(process.readChannelMode(), QProcess::ForwardedChannels); - + #ifdef Q_OS_MAC process.start("testProcessEcho2/testProcessEcho2.app"); #else @@ -1151,6 +1239,9 @@ void tst_QProcess::atEnd() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif QProcess process; @@ -1183,6 +1274,10 @@ public: return exitCode; } +#if defined(Q_OS_SYMBIAN) + int serial; +#endif + protected: inline void run() { @@ -1194,11 +1289,21 @@ protected: #ifdef Q_OS_MAC process.start("testProcessEcho/testProcessEcho.app"); +#elif defined(Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86) + // WINSCW builds in Symbian do not allow multiple processes to load Qt libraries, + // so use just a simple process instead of testDetached. + process.start("testProcessNormal"); +#elif defined(Q_OS_SYMBIAN) + // testDetached used because it does something, but doesn't take too long. + QFile infoFile(QString("c:\\logs\\detinfo%1").arg(serial)); + QStringList args; + args << infoFile.fileName(); + process.start("testDetached", args); #else process.start("testProcessEcho/testProcessEcho"); #endif -#if !defined(Q_OS_WINCE) +#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) QCOMPARE(process.write("abc\0", 4), qint64(4)); #endif exitCode = exec(); @@ -1213,13 +1318,25 @@ protected slots: private: int exitCode; +#ifdef Q_OS_SYMBIAN + enum + { + /** + * The maximum stack size. + */ + SymbianStackSize = 0x14000 + }; +#endif }; //----------------------------------------------------------------------------- void tst_QProcess::processInAThread() { - for (int i = 0; i < 3; ++i) { + for (int i = 0; i < 10; ++i) { TestThread thread; +#if defined(Q_OS_SYMBIAN) + thread.setStackSize(SymbianStackSize); +#endif thread.start(); QVERIFY(thread.wait(10000)); QCOMPARE(thread.code(), 0); @@ -1229,11 +1346,24 @@ void tst_QProcess::processInAThread() //----------------------------------------------------------------------------- void tst_QProcess::processesInMultipleThreads() { +#if defined(Q_OS_SYMBIAN) + int serialCounter = 0; +#endif + for (int i = 0; i < 10; ++i) { TestThread thread1; TestThread thread2; TestThread thread3; +#if defined(Q_OS_SYMBIAN) + thread1.serial = serialCounter++; + thread2.serial = serialCounter++; + thread3.serial = serialCounter++; + + thread1.setStackSize(SymbianStackSize); + thread2.setStackSize(SymbianStackSize); + thread3.setStackSize(SymbianStackSize); +#endif thread1.start(); thread2.start(); thread3.start(); @@ -1259,14 +1389,26 @@ void tst_QProcess::waitForFinishedWithTimeout() #ifdef Q_OS_MAC process->start("testProcessEcho/testProcessEcho.app"); +#elif defined(Q_OS_SYMBIAN) + process->start("testProcessOutput"); #else process->start("testProcessEcho/testProcessEcho"); #endif + +#if defined(Q_OS_SYMBIAN) + QVERIFY(process->waitForStarted(50)); + QVERIFY(!process->waitForFinished(1)); +#else QVERIFY(process->waitForStarted(5000)); QVERIFY(!process->waitForFinished(1)); process->write("", 1); +#endif + QVERIFY(process->waitForFinished()); + + delete process; + process = 0; } //----------------------------------------------------------------------------- @@ -1275,6 +1417,9 @@ void tst_QProcess::waitForReadyReadInAReadyReadSlot() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif process = new QProcess(this); connect(process, SIGNAL(readyRead()), this, SLOT(waitForReadyReadInAReadyReadSlotSlot())); @@ -1294,7 +1439,7 @@ void tst_QProcess::waitForReadyReadInAReadyReadSlot() QVERIFY(!QTestEventLoop::instance().timeout()); QCOMPARE(spy.count(), 1); - + process->disconnect(); QVERIFY(process->waitForFinished(5000)); QVERIFY(process->bytesAvailable() > bytesAvailable); @@ -1308,6 +1453,9 @@ void tst_QProcess::waitForReadyReadInAReadyReadSlotSlot() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif bytesAvailable = process->bytesAvailable(); process->write("bar", 4); @@ -1321,6 +1469,9 @@ void tst_QProcess::waitForBytesWrittenInABytesWrittenSlot() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif process = new QProcess(this); connect(process, SIGNAL(bytesWritten(qint64)), this, SLOT(waitForBytesWrittenInABytesWrittenSlotSlot())); @@ -1353,6 +1504,9 @@ void tst_QProcess::waitForBytesWrittenInABytesWrittenSlotSlot() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif process->write("b"); QVERIFY(process->waitForBytesWritten(5000)); @@ -1411,18 +1565,20 @@ void tst_QProcess::spaceArgsTest() QStringList programs; programs << QString::fromLatin1("testProcessSpacesArgs/nospace") +#if defined(Q_OS_SYMBIAN) + ; // Symbian toolchain doesn't like exes with spaces in the name +#else << QString::fromLatin1("testProcessSpacesArgs/one space") << QString::fromLatin1("testProcessSpacesArgs/two space s"); +#endif process = new QProcess(this); for (int i = 0; i < programs.size(); ++i) { - QString program = programs.at(i); - process->start(program, args); -#ifndef Q_OS_WINCE +#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) QVERIFY(process->waitForStarted(5000)); QVERIFY(process->waitForFinished(5000)); #else @@ -1430,10 +1586,19 @@ void tst_QProcess::spaceArgsTest() QVERIFY(process->waitForFinished(10000)); #endif -#if !defined(Q_OS_WINCE) +#if defined(Q_OS_SYMBIAN) + // Symbian test outputs to a file, so check that + FILE* file = fopen("c:\\logs\\qprocess_args_test.txt","r"); + char buf[256]; + fgets(buf, 256, file); + fclose(file); + QStringList actual = QString::fromLatin1(buf).split("|"); +#elif !defined(Q_OS_WINCE) QStringList actual = QString::fromLatin1(process->readAll()).split("|"); +#endif +#if !defined(Q_OS_WINCE) QVERIFY(!actual.isEmpty()); - // not onterested in the program name, it might be different. + // not interested in the program name, it might be different. actual.removeFirst(); QCOMPARE(actual, args); @@ -1450,10 +1615,18 @@ void tst_QProcess::spaceArgsTest() QVERIFY(process->waitForStarted(5000)); QVERIFY(process->waitForFinished(5000)); -#if !defined(Q_OS_WINCE) +#if defined(Q_OS_SYMBIAN) + // Symbian test outputs to a file, so check that + file = fopen("c:\\logs\\qprocess_args_test.txt","r"); + fgets(buf, 256, file); + fclose(file); + actual = QString::fromLatin1(buf).split("|"); +#elif !defined(Q_OS_WINCE) actual = QString::fromLatin1(process->readAll()).split("|"); +#endif +#if !defined(Q_OS_WINCE) QVERIFY(!actual.isEmpty()); - // not onterested in the program name, it might be different. + // not interested in the program name, it might be different. actual.removeFirst(); QCOMPARE(actual, args); @@ -1467,7 +1640,13 @@ void tst_QProcess::spaceArgsTest() //----------------------------------------------------------------------------- void tst_QProcess::exitCodeTest() { +#if defined(Q_OS_SYMBIAN) + // Kernel will run out of process handles on some hw, as there is some + // delay before they are recycled, so limit the amount of processes. + for (int i = 0; i < 50; ++i) { +#else for (int i = 0; i < 255; ++i) { +#endif QProcess process; process.start("testExitCodes/testExitCodes " + QString::number(i)); QVERIFY(process.waitForFinished(5000)); @@ -1489,10 +1668,10 @@ void tst_QProcess::failToStart() QSignalSpy finishedSpy(&process, SIGNAL(finished(int))); QSignalSpy finishedSpy2(&process, SIGNAL(finished(int, QProcess::ExitStatus))); -// Mac OS X and HP-UX have a really low defualt process limit (~100), so spawning +// Mac OS X and HP-UX have a really low defualt process limit (~100), so spawning // to many processes here will cause test failures later on. #if defined Q_OS_HPUX - const int attempts = 15; + const int attempts = 15; #elif defined Q_OS_MAC const int attempts = 15; #else @@ -1530,7 +1709,7 @@ void tst_QProcess::failToStart() QCOMPARE(finishedSpy2.count(), 0); int it = j * attempts + i + 1; - + QCOMPARE(stateSpy.count(), it * 2); QCOMPARE(qVariantValue<QProcess::ProcessState>(stateSpy.at(it * 2 - 2).at(0)), QProcess::Starting); QCOMPARE(qVariantValue<QProcess::ProcessState>(stateSpy.at(it * 2 - 1).at(0)), QProcess::NotRunning); @@ -1595,6 +1774,9 @@ void tst_QProcess::removeFileWhileProcessIsRunning() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif QFile file("removeFile.txt"); QVERIFY(file.open(QFile::WriteOnly)); @@ -1615,13 +1797,140 @@ void tst_QProcess::removeFileWhileProcessIsRunning() } //----------------------------------------------------------------------------- +void tst_QProcess::setEnvironment_data() +{ + QTest::addColumn<QString>("name"); + QTest::addColumn<QString>("value"); + + QTest::newRow("setting-empty") << "tst_QProcess" << ""; + QTest::newRow("setting") << "tst_QProcess" << "value"; + +#ifdef Q_OS_WIN + QTest::newRow("unsetting") << "PROMPT" << QString(); + QTest::newRow("overriding") << "PROMPT" << "value"; +#else + QTest::newRow("unsetting") << "PATH" << QString(); + QTest::newRow("overriding") << "PATH" << "value"; +#endif +} + +void tst_QProcess::setEnvironment() +{ +#if defined (Q_OS_WINCE) || defined(Q_OS_SYMBIAN) + QSKIP("OS doesn't support environment variables", SkipAll); +#endif + + // make sure our environment variables are correct + QVERIFY(qgetenv("tst_QProcess").isEmpty()); + QVERIFY(!qgetenv("PATH").isEmpty()); +#ifdef Q_OS_WIN + QVERIFY(!qgetenv("PROMPT").isEmpty()); +#endif + + QFETCH(QString, name); + QFETCH(QString, value); + QString executable = QDir::currentPath() + "/testProcessEnvironment/testProcessEnvironment"; + + { + QProcess process; + QStringList environment = QProcess::systemEnvironment(); + if (value.isNull()) { + int pos; + QRegExp rx(name + "=.*"); +#ifdef Q_OS_WIN + rx.setCaseSensitivity(Qt::CaseInsensitive); +#endif + while ((pos = environment.indexOf(rx)) != -1) + environment.removeAt(pos); + } else { + environment.append(name + '=' + value); + } + process.setEnvironment(environment); + process.start(executable, QStringList() << name); + + QVERIFY(process.waitForFinished()); + if (value.isNull()) + QCOMPARE(process.exitCode(), 1); + else if (!value.isEmpty()) + QCOMPARE(process.exitCode(), 0); + + QCOMPARE(process.readAll(), value.toLocal8Bit()); + } + + // re-do the test but set the environment twice, to make sure + // that the latter addition overrides + // this test doesn't make sense in unsetting + if (!value.isNull()) { + QProcess process; + QStringList environment = QProcess::systemEnvironment(); + environment.prepend(name + "=This is not the right value"); + environment.append(name + '=' + value); + process.setEnvironment(environment); + process.start(executable, QStringList() << name); + + QVERIFY(process.waitForFinished()); + if (!value.isEmpty()) + QCOMPARE(process.exitCode(), 0); + + QCOMPARE(process.readAll(), value.toLocal8Bit()); + } +#endif +} + +//----------------------------------------------------------------------------- +void tst_QProcess::setProcessEnvironment_data() +{ + setEnvironment_data(); +} + +void tst_QProcess::setProcessEnvironment() +{ +#if !defined (Q_OS_WINCE) + // there is no concept of system variables on Windows CE as there is no console + + // make sure our environment variables are correct + QVERIFY(qgetenv("tst_QProcess").isEmpty()); + QVERIFY(!qgetenv("PATH").isEmpty()); +#ifdef Q_OS_WIN + QVERIFY(!qgetenv("PROMPT").isEmpty()); +#endif + + QFETCH(QString, name); + QFETCH(QString, value); + QString executable = QDir::currentPath() + "/testProcessEnvironment/testProcessEnvironment"; + + { + QProcess process; + QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); + if (value.isNull()) + environment.remove(name); + else + environment.insert(name, value); + process.setProcessEnvironment(environment); + process.start(executable, QStringList() << name); + + QVERIFY(process.waitForFinished()); + if (value.isNull()) + QCOMPARE(process.exitCode(), 1); + else if (!value.isEmpty()) + QCOMPARE(process.exitCode(), 0); + + QCOMPARE(process.readAll(), value.toLocal8Bit()); + } +} +//----------------------------------------------------------------------------- void tst_QProcess::systemEnvironment() { -#if defined (Q_OS_WINCE) +#if defined (Q_OS_WINCE) || defined(Q_OS_SYMBIAN) // there is no concept of system variables on Windows CE as there is no console QVERIFY(QProcess::systemEnvironment().isEmpty()); + QVERIFY(QProcessEnvironment::systemEnvironment().isEmpty()); #else QVERIFY(!QProcess::systemEnvironment().isEmpty()); + QVERIFY(!QProcessEnvironment::systemEnvironment().isEmpty()); + + QVERIFY(QProcessEnvironment::systemEnvironment().contains("PATH")); + QVERIFY(!QProcess::systemEnvironment().filter(QRegExp("^PATH=", Qt::CaseInsensitive)).isEmpty()); #endif } @@ -1631,6 +1940,9 @@ void tst_QProcess::spaceInName() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif QProcess process; process.start("test Space In Name/testSpaceInName", QStringList()); QVERIFY(process.waitForStarted()); @@ -1641,7 +1953,10 @@ void tst_QProcess::spaceInName() //----------------------------------------------------------------------------- void tst_QProcess::lockupsInStartDetached() { +#if !defined(Q_OS_SYMBIAN) + // What exactly is this call supposed to achieve anyway? QHostInfo::lookupHost(QString("something.invalid"), 0, 0); +#endif QProcess::execute("yjhbrty"); QProcess::startDetached("yjhbrty"); } @@ -1652,6 +1967,9 @@ void tst_QProcess::atEnd2() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif QProcess process; @@ -1677,7 +1995,7 @@ void tst_QProcess::waitForReadyReadForNonexistantProcess() // Start a program that doesn't exist, process events and then try to waitForReadyRead qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus"); - + QProcess process; QSignalSpy errorSpy(&process, SIGNAL(error(QProcess::ProcessError))); QSignalSpy finishedSpy1(&process, SIGNAL(finished(int))); @@ -1697,11 +2015,14 @@ void tst_QProcess::setStandardInputFile() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif static const char data[] = "A bunch\1of\2data\3\4\5\6\7..."; QProcess process; QFile file("data"); - + QVERIFY(file.open(QIODevice::WriteOnly)); file.write(data, sizeof data); file.close(); @@ -1713,7 +2034,7 @@ void tst_QProcess::setStandardInputFile() process.start("testProcessEcho/testProcessEcho"); #endif - QPROCESS_VERIFY(process, waitForFinished()); + QPROCESS_VERIFY(process, waitForFinished()); QByteArray all = process.readAll(); QCOMPARE(all.size(), int(sizeof data) - 1); // testProcessEcho drops the ending \0 QVERIFY(all == data); @@ -1753,6 +2074,9 @@ void tst_QProcess::setStandardOutputFile() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif static const char data[] = "Original data. "; static const char testdata[] = "Test data."; @@ -1784,7 +2108,7 @@ void tst_QProcess::setStandardOutputFile() process.start("testProcessEcho2/testProcessEcho2"); #endif process.write(testdata, sizeof testdata); - QPROCESS_VERIFY(process,waitForFinished()); + QPROCESS_VERIFY(process,waitForFinished()); // open the file again and verify the data QVERIFY(file.open(QIODevice::ReadOnly)); @@ -1818,10 +2142,13 @@ void tst_QProcess::setStandardOutputProcess() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif QProcess source; QProcess sink; - + QFETCH(bool, merged); source.setReadChannelMode(merged ? QProcess::MergedChannels : QProcess::SeparateChannels); source.setStandardOutputProcess(&sink); @@ -1853,6 +2180,9 @@ void tst_QProcess::fileWriterProcess() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif QString stdinStr; for (int i = 0; i < 5000; ++i) @@ -1879,17 +2209,30 @@ void tst_QProcess::fileWriterProcess() //----------------------------------------------------------------------------- void tst_QProcess::detachedWorkingDirectoryAndPid() { +#if defined(Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86) + // WINSCW builds in Symbian do not allow multiple processes to load Qt libraries, + // so this test must be skipped. + QSKIP("Multiple processes loading Qt are not allowed in Qt/Symbian emulator.", SkipAll); +#endif qint64 pid; #ifdef Q_OS_WINCE QTest::qSleep(1000); #endif +#if defined(Q_OS_SYMBIAN) + // Symbian has no working directory support, so use logs dir as a shared directory + QFile infoFile(QLatin1String("c:\\logs\\detachedinfo.txt")); +#else QFile infoFile(QDir::currentPath() + QLatin1String("/detachedinfo.txt")); +#endif infoFile.remove(); QString workingDir = QDir::currentPath() + "/testDetached"; + +#ifndef Q_OS_SYMBIAN QVERIFY(QFile::exists(workingDir)); +#endif QStringList args; args << infoFile.fileName(); @@ -1913,6 +2256,9 @@ void tst_QProcess::detachedWorkingDirectoryAndPid() qint64 actualPid = processIdString.toLongLong(&ok); QVERIFY(ok); +#if defined(Q_OS_SYMBIAN) + QEXPECT_FAIL("", "Working directory is not supported on Qt/symbian", Continue); +#endif QCOMPARE(actualWorkingDir, workingDir); QCOMPARE(actualPid, pid); } @@ -1923,8 +2269,11 @@ void tst_QProcess::switchReadChannels() #ifdef Q_OS_WINCE QSKIP("Reading and writing to a process is not supported on Qt/CE", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Reading and writing to a process is not supported on Qt/Symbian", SkipAll); +#endif const char data[] = "ABCD"; - + QProcess process; #ifdef Q_OS_MAC @@ -1942,7 +2291,7 @@ void tst_QProcess::switchReadChannels() process.setReadChannel(QProcess::StandardError); QCOMPARE(process.read(1), QByteArray(&data[i], 1)); } - + process.ungetChar('D'); process.setReadChannel(QProcess::StandardOutput); process.ungetChar('D'); @@ -1958,6 +2307,9 @@ void tst_QProcess::setWorkingDirectory() #ifdef Q_OS_WINCE QSKIP("Windows CE does not support working directory logic", SkipAll); #endif +#if defined(Q_OS_SYMBIAN) + QSKIP("Symbian does not support working directory logic", SkipAll); +#endif process = new QProcess; process->setWorkingDirectory("test"); #ifdef Q_OS_MAC @@ -1990,13 +2342,22 @@ void tst_QProcess::startFinishStartFinish() #else process.start("testProcessOutput/testProcessOutput"); #endif -#ifndef Q_OS_WINCE +#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) QVERIFY(process.waitForReadyRead(10000)); QCOMPARE(QString::fromLatin1(process.readLine().trimmed()), QString("0 -this is a number")); #endif if (process.state() != QProcess::NotRunning) QVERIFY(process.waitForFinished(10000)); +#if defined(Q_OS_SYMBIAN) + // Symbian test outputs to a file, so check that + FILE* file = fopen("c:\\logs\\qprocess_output_test.txt","r"); + char buf[30]; + fgets(buf, 30, file); + QCOMPARE(QString::fromLatin1(buf), + QString("0 -this is a number\n")); + fclose(file); +#endif } } @@ -2026,3 +2387,4 @@ void tst_QProcess::invalidProgramString() QTEST_MAIN(tst_QProcess) #include "tst_qprocess.moc" +#endif |