Timestamp:
Jul 28, 2011, 12:47:10 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

tests: Added a bunch of new tests to process-sync.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/process/process-sync/process-sync.cpp

    r907 r914  
    100100int test_sleep()
    101101{
    102     QProcess p;
    103 
    104     p.start ("cmd",
    105              QStringList() << "/c" << "sleep.cmd");
    106 
    107     if (p.waitForStarted())
    108     {
     102    printf ("test_sleep: start a 3s sleepy and wait for termination.\n");
     103
     104    QProcess p;
     105
     106    p.start ("cmd",
     107             QStringList() << "/c" <<
     108             "process-sync-helper.cmd" << "sleep");
     109
     110    if (p.waitForStarted())
     111    {
     112        p.waitForFinished();
     113        printf ("Process finished with %d (%d)\n",
     114                p.exitCode(), p.exitStatus());
     115    }
     116    else
     117        printf ("waitForStarted() failed\n");
     118
     119    return 0;
     120}
     121
     122int test_delayed_write()
     123{
     124    printf ("test_sleep: start a 3s delayed write to child's stdin "
     125            "and wait until written.\n");
     126
     127    QProcess p;
     128
     129    p.start ("cmd",
     130             QStringList() << "/c" <<
     131             "process-sync-helper.cmd" << "delayed_write",
     132             QIODevice::ReadWrite);
     133
     134    if (p.waitForStarted())
     135    {
     136        p.write (QByteArray("Hello from parent.\n"));
     137        p.waitForBytesWritten();
     138
     139        if (p.waitForReadyRead()) {
     140            QByteArray ba = p.read (p.bytesAvailable());
     141            printf ("Child says:\n%s\n", ba.constData());
     142        }
     143
     144        p.waitForFinished();
     145        printf ("Process finished with %d (%d)\n",
     146                p.exitCode(), p.exitStatus());
     147    }
     148    else
     149        printf ("waitForStarted() failed\n");
     150
     151    return 0;
     152}
     153
     154int test_delayed_read()
     155{
     156    printf ("test_sleep: start a 3s delayed read from child's stdout "
     157            "and wait until read.\n");
     158
     159    QProcess p;
     160
     161    p.start ("cmd",
     162             QStringList() << "/c" <<
     163             "process-sync-helper.cmd" << "delayed_read",
     164             QIODevice::ReadOnly);
     165
     166    if (p.waitForStarted())
     167    {
     168        if (p.waitForReadyRead()) {
     169            QByteArray ba = p.read (p.bytesAvailable());
     170            printf ("Child says:\n%s\n", ba.constData());
     171        }
     172
    109173        p.waitForFinished();
    110174        printf ("Process finished with %d (%d)\n",
     
    119183int test_hang()
    120184{
     185
     186
     187
    121188    QProcess p;
    122189
     
    152219        if (qstrcmp (argv [1], "hang") == 0)
    153220                return test_hang();
     221
     222
     223
     224
    154225    }
    155226
Note: See TracChangeset for help on using the changeset viewer.