Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

wvstream.t.cc

Go to the documentation of this file.
00001 #include "wvtest.h"
00002 #include "wvtimeutils.h"
00003 
00004 #define private public
00005 #define protected public
00006 #include "wvstream.h"
00007 
00008 #if WVSTREAMS_UNITTEST_FIXES_BUGS_FOUND_BELOW
00009 
00010 WVTEST_MAIN()
00011 {
00012     WvStream s;
00013     char buf[1024];
00014     
00015     // buffered reads and writes
00016     WVPASS(!s.isreadable());
00017     WVPASS(!s.iswritable());
00018     WVFAIL(s.read(buf, 1024) != 0);
00019     WVPASS(s.write(buf, 1024) == 1024);
00020     WVPASS(!s.iswritable());
00021     WVPASS(!s.isreadable());
00022     WVPASS(s.isok());
00023     
00024     // close() shouldn't have to wait to flush buffers, because plain
00025     // WvStream has no way to actually flush them.
00026     WvTime t1 = wvtime();
00027     s.close();
00028     WvTime t2 = wvtime();
00029     WVPASS(msecdiff(t2, t1) >= 0);
00030     WVPASS(msecdiff(t2, t1) < 1000);
00031         
00032     // after close()
00033     WVPASS(!s.isok());
00034 }
00035 
00036 
00037 WVTEST_MAIN()
00038 {
00039     WvStream s;
00040     char buf[1024];
00041 
00042     // noread/nowrite behaviour
00043     s.nowrite();
00044     WVPASS(s.isok());
00045     WVFAIL(s.write(buf, 1024) != 0);
00046     s.noread();
00047     WVPASS(s.isok());
00048 }
00049 
00050 WVTEST_MAIN()
00051 {
00052     WvStream s;
00053     char buf[1024];
00054     
00055     WVPASS(!s.isreadable());
00056     s.inbuf.putstr("a\n b \r\nline");
00057     WVPASS(s.isreadable());
00058     s.noread();
00059     WVPASS(s.isreadable());
00060     
00061     WVPASS(s.read(buf, 2) == 2);
00062     char *line = s.getline(0);
00063     WVPASS(line);
00064     WVPASS(line && !strcmp(line, " b \r"));
00065     line = s.getline(0);
00066     WVPASS(line);
00067     WVPASS(line && !strcmp(line, "line"));
00068     WVPASS(!s.getline(0));
00069     
00070     WvTime t1 = wvtime();
00071     WVPASS(!s.getline(500));
00072     WvTime t2 = wvtime();
00073     WVPASS(msecdiff(t2, t1) >= 0);
00074     WVPASS(msecdiff(t2, t1) < 400); // noread().  shouldn't actually wait!
00075     
00076     ::alarm(5);
00077     // FIXME: avoid aborting the entire test here
00078     //WVPASS(!s.getline(-1));
00079     ::alarm(0);
00080 }
00081 #endif
00082 
00083 // FIXME: lots of remaining untested stuff
00084 //    callback / closecallback
00085 //    autoforward/noautoforward
00086 //    continue_select / continue_read
00087 //    seterr
00088 //    read_requires_writable / write_requires_readable
00089 //    flush_then_close
00090 //    alarm() and alarm_remaining()
00091 //    delay_output()
00092 //    drain()
00093 //    queuemin()
00094 //    select including globallist (runonce())
00095 //        force_select
00096 //    print() with a format
00097 //    src()
00098 //    
00099 // Wow, jbrown was right.  This *is* a pretty tangled mess!

Generated on Sat Mar 13 14:55:56 2004 for WvStreams by doxygen 1.3.6-20040222