home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 400_01 / socketpp-1.5 / test / testall.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-06  |  2.8 KB  |  93 lines

  1. // testall.cc. Test for -*- C++ -*- socket library
  2. // Copyright (C) 1992,1993 Gnanasekaran Swaminathan <gs4t@virginia.edu>
  3. // 
  4. // Permission is granted to use at your own risk and distribute this software
  5. // in source and binary forms provided the above copyright
  6. // notice and this paragraph are preserved on all copies.
  7. // This software is provided "as is" with no express or implied warranty.
  8. //
  9. // Version: 07Nov93 1.5
  10.  
  11. #include <pipestream.h>
  12.  
  13. extern "C" {
  14.     int    sprintf(char*, const char* fmt, ...);
  15.     int    sleep(int);
  16. }
  17.  
  18. main(int ac, char** av)
  19. {
  20.     char    buf[256];
  21.     int    portno;
  22.     char    thostname[64];
  23.     
  24.     ipipestream tdunread("tdunread /tmp/soc");
  25.     tdunread.getline(buf, 255);
  26.     cout << buf << endl;
  27.     ipipestream tdunwrite("tdunwrite /tmp/soc mary had a little lamb");
  28.     while ( tdunread.getline(buf, 255) ) cout << buf << endl;
  29.     cout << endl;
  30.  
  31.     ipipestream tdinread("tdinread");
  32.     tdinread >> buf >> buf >> thostname >> buf >> buf >> portno;
  33.     tdinread.getline(buf, 255);
  34.     sprintf(buf, "tdinwrite %s %d mary had a little lamb",
  35.         thostname, portno);
  36.     ipipestream tdinwrite(buf);
  37.     while ( tdinread.getline(buf, 255) ) cout << buf << endl;
  38.     tdinwrite.getline(buf, 255);
  39.     tdinwrite.getline(buf, 255);
  40.     while ( tdinwrite.getline(buf, 255) ) cout << buf << endl;
  41.     cout << endl;
  42.  
  43.     ipipestream tsunread("tsunread /tmp/soc");
  44.     tsunread.getline(buf, 255);
  45.     cout << buf << endl;
  46.     ipipestream tsunwrite("tsunwrite /tmp/soc mary had a little lamb");
  47.     while ( tsunread.getline(buf, 255) ) cout << buf << endl;
  48.     cout << endl;
  49.  
  50.     ipipestream tsinread("tsinread");
  51.     tsinread >> buf >> buf >> thostname >> buf >> buf >> portno;
  52.     tsinread.getline(buf, 255);
  53.     sprintf(buf, "tsinwrite %s %d %%d%%s%%f 356 haha 23.5",
  54.         thostname, portno);
  55.     ipipestream tsinwrite1(buf);
  56.     sprintf(buf, "tsinwrite %s %d %%s%%c oooiiii !",
  57.         thostname, portno);
  58.     cout << "sleeping for 3 sec\n";
  59.     sleep(3);
  60.     ipipestream tsinwrite2(buf);
  61.     while ( tsinread.getline(buf, 255) ) cout << "tsinread: " << buf << endl;
  62.     while ( tsinwrite1.getline(buf, 255) )
  63.         cout << "tsinwrite1: " << buf << endl;
  64.     while ( tsinwrite2.getline(buf, 255) )
  65.         cout << "tsinwrite2: " << buf << endl;
  66.     cout << endl;
  67.     
  68.     ipipestream tpipe("tpipe mary had a little lamb");
  69.     while ( tpipe.getline(buf, 255) ) cout << "tpipe " << buf << endl;
  70.     cout << endl;
  71.  
  72.     ipipestream tsockpair("tsockpair mary had a little lamb");
  73.     while ( tsockpair.getline(buf, 255) )
  74.         cout << "tsockpair " << buf << endl;
  75.     cout << endl;
  76.  
  77.     ipipestream tpopen ("tpopen");
  78.     while ( tpopen.getline(buf, 255) )
  79.         cout << "tpopen " << buf << endl;
  80.     cout << endl;
  81.  
  82.     ipipestream twhois("twhois .knuth,donald");
  83.     cout <<"twhois:\n";
  84.     while ( twhois.getline(buf, 255) ) cout << buf << endl;
  85.     cout << endl;
  86.  
  87.     ipipestream thost("thostnames uvaarpa.virginia.edu");
  88.     cout << "thostnames:\n";
  89.     while ( thost.getline(buf, 255) ) cout << buf << endl;
  90.     cout << endl;
  91. }
  92.  
  93.