1 #include <msp/core/thread.h>
2 #include <msp/io/pipe.h>
3 #include <msp/io/poll.h>
4 #include <msp/time/timedelta.h>
5 #include <msp/test/test.h>
9 class PipeTests: public Test::RegisteredTest<PipeTests>
14 static const char *get_name() { return "Pipe"; }
22 class PipeWriter: public Thread
28 PipeWriter(IO::Pipe &);
35 PipeTests::PipeTests()
37 add(&PipeTests::readwrite, "Read/write");
38 add(&PipeTests::poll, "Poll");
41 void PipeTests::readwrite()
44 PipeWriter writer(pipe);
46 for(unsigned i=0; i<256; ++i)
48 unsigned char c = pipe.get();
56 void PipeTests::poll()
61 IO::PollEvent ev = IO::poll(pipe, IO::P_INPUT);
62 EXPECT_EQUAL(ev, IO::P_INPUT);
66 ev = IO::poll(pipe, IO::P_INPUT, 100*Time::msec);
67 EXPECT_EQUAL(ev, IO::P_NONE);
71 PipeWriter::PipeWriter(IO::Pipe &p):
77 void PipeWriter::main()
79 for(unsigned i=0; i<256; ++i)