tests/auto/qprocess/tst_qprocess.cpp
changeset 33 3e2da88830cd
parent 18 2f34d5167611
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
    91 
    91 
    92 private slots:
    92 private slots:
    93     void getSetCheck();
    93     void getSetCheck();
    94     void constructing();
    94     void constructing();
    95     void simpleStart();
    95     void simpleStart();
       
    96     void execute();
    96     void startDetached();
    97     void startDetached();
    97     void crashTest();
    98     void crashTest();
    98     void crashTest2();
    99     void crashTest2();
    99     void echoTest_data();
   100     void echoTest_data();
   100     void echoTest();
   101     void echoTest();
   129     void waitForFinishedWithTimeout();
   130     void waitForFinishedWithTimeout();
   130     void waitForReadyReadInAReadyReadSlot();
   131     void waitForReadyReadInAReadyReadSlot();
   131     void waitForBytesWrittenInABytesWrittenSlot();
   132     void waitForBytesWrittenInABytesWrittenSlot();
   132     void spaceArgsTest_data();
   133     void spaceArgsTest_data();
   133     void spaceArgsTest();
   134     void spaceArgsTest();
       
   135 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
       
   136     void nativeArguments();
       
   137 #endif
   134     void exitCodeTest();
   138     void exitCodeTest();
   135     void setEnvironment_data();
   139     void setEnvironment_data();
   136     void setEnvironment();
   140     void setEnvironment();
   137     void setProcessEnvironment_data();
   141     void setProcessEnvironment_data();
   138     void setProcessEnvironment();
   142     void setProcessEnvironment();
   281     QCOMPARE(spy.count(), 3);
   285     QCOMPARE(spy.count(), 3);
   282     QCOMPARE(qVariantValue<QProcess::ProcessState>(spy.at(0).at(0)), QProcess::Starting);
   286     QCOMPARE(qVariantValue<QProcess::ProcessState>(spy.at(0).at(0)), QProcess::Starting);
   283     QCOMPARE(qVariantValue<QProcess::ProcessState>(spy.at(1).at(0)), QProcess::Running);
   287     QCOMPARE(qVariantValue<QProcess::ProcessState>(spy.at(1).at(0)), QProcess::Running);
   284     QCOMPARE(qVariantValue<QProcess::ProcessState>(spy.at(2).at(0)), QProcess::NotRunning);
   288     QCOMPARE(qVariantValue<QProcess::ProcessState>(spy.at(2).at(0)), QProcess::NotRunning);
   285 }
   289 }
       
   290 //-----------------------------------------------------------------------------
       
   291 void tst_QProcess::execute()
       
   292 {
       
   293     QCOMPARE(QProcess::execute("testProcessNormal/testProcessNormal",
       
   294                                QStringList() << "arg1" << "arg2"), 0);
       
   295     QCOMPARE(QProcess::execute("nonexistingexe"), -2);
       
   296 }
       
   297 
   286 //-----------------------------------------------------------------------------
   298 //-----------------------------------------------------------------------------
   287 void tst_QProcess::startDetached()
   299 void tst_QProcess::startDetached()
   288 {
   300 {
   289     QProcess proc;
   301     QProcess proc;
   290     QVERIFY(proc.startDetached("testProcessNormal/testProcessNormal",
   302     QVERIFY(proc.startDetached("testProcessNormal/testProcessNormal",
  1619 
  1631 
  1620     delete process;
  1632     delete process;
  1621     process = 0;
  1633     process = 0;
  1622 }
  1634 }
  1623 
  1635 
       
  1636 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
       
  1637 
       
  1638 //-----------------------------------------------------------------------------
       
  1639 void tst_QProcess::nativeArguments()
       
  1640 {
       
  1641     QProcess proc;
       
  1642 
       
  1643     // This doesn't actually need special quoting, so it is pointless to use
       
  1644     // native arguments here, but that's not the point of this test.
       
  1645     proc.setNativeArguments("hello kitty, \"*\"!");
       
  1646 
       
  1647     proc.start(QString::fromLatin1("testProcessSpacesArgs/nospace"), QStringList());
       
  1648 
       
  1649 #if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
       
  1650     QVERIFY(proc.waitForStarted(5000));
       
  1651     QVERIFY(proc.waitForFinished(5000));
       
  1652 #else
       
  1653     QVERIFY(proc.waitForStarted(10000));
       
  1654     QVERIFY(proc.waitForFinished(10000));
       
  1655 #endif
       
  1656 
       
  1657 #if defined(Q_OS_SYMBIAN) || defined(Q_OS_WINCE)
       
  1658     // Symbian test outputs to a file, so check that
       
  1659 # ifdef Q_OS_SYMBIAN
       
  1660     FILE* file = fopen("c:\\logs\\qprocess_args_test.txt","r");
       
  1661 # else
       
  1662     FILE* file = fopen("\\temp\\qprocess_args_test.txt","r");
       
  1663 # endif
       
  1664     char buf[256];
       
  1665     fgets(buf, 256, file);
       
  1666     fclose(file);
       
  1667     QStringList actual = QString::fromLatin1(buf).split("|");
       
  1668 #else
       
  1669     QStringList actual = QString::fromLatin1(proc.readAll()).split("|");
       
  1670 #endif
       
  1671     QVERIFY(!actual.isEmpty());
       
  1672     // not interested in the program name, it might be different.
       
  1673     actual.removeFirst();
       
  1674     QStringList expected;
       
  1675 #if defined(Q_OS_WINCE)
       
  1676     expected << "hello" << "kitty," << "\"*\"!"; // Weird, weird ...
       
  1677 #else
       
  1678     expected << "hello" << "kitty," << "*!";
       
  1679 #endif
       
  1680     QCOMPARE(actual, expected);
       
  1681 }
       
  1682 
       
  1683 #endif
       
  1684 
  1624 //-----------------------------------------------------------------------------
  1685 //-----------------------------------------------------------------------------
  1625 void tst_QProcess::exitCodeTest()
  1686 void tst_QProcess::exitCodeTest()
  1626 {
  1687 {
  1627 #if defined(Q_OS_SYMBIAN)
  1688 #if defined(Q_OS_SYMBIAN)
  1628     // Kernel will run out of process handles on some hw, as there is some
  1689     // Kernel will run out of process handles on some hw, as there is some