Changeset 914


Ignore:
Timestamp:
Jul 27, 2011, 10:47:10 PM (9 years ago)
Author:
Dmitry A. Kuminov
Message:

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

Location:
tests/process/process-sync
Files:
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • tests/process/process-sync/process-sync-helper.cmd

    r907 r914  
    11/**/
    2 call SysSleep 3
     2parse arg args
     3
     4if (args == 'sleep') then do
     5  call SysSleep 3
     6  exit
     7end
     8
     9if (args == 'delayed_write') then do
     10  call SysSleep 3
     11  str = linein()
     12  say 'Got ['str'] from stdin.'
     13  exit
     14end
     15
     16if (args == 'delayed_read') then do
     17  call SysSleep 3
     18  say 'Hello from child.'
     19  exit
     20end
  • 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    printf ("test_hang: start cmd /c pause and wait for termination. "
     186            "Requires killing cmd.exe.\n");
     187
    121188    QProcess p;
    122189
     
    152219        if (qstrcmp (argv [1], "hang") == 0)
    153220                return test_hang();
     221        if (qstrcmp (argv [1], "delayed_write") == 0)
     222                return test_delayed_write();
     223        if (qstrcmp (argv [1], "delayed_read") == 0)
     224                return test_delayed_read();
    154225    }
    155226
  • tests/process/process-sync/process-sync.pro

    r910 r914  
    88SOURCES = process-sync.cpp
    99
    10 FILES = process-sync-test.cmd ../sleep.cmd
     10FILES = process-sync-test.cmd process-sync-helper.cmd
    1111
    1212bigfile.target = $$DESTDIR/bigfile.txt
Note: See TracChangeset for help on using the changeset viewer.