]> git.localhorst.tv Git - blank.git/blob - tst/integration/TestInstance.hpp
simple test for client
[blank.git] / tst / integration / TestInstance.hpp
1 #ifndef BLANK_TEST_INTEGRATION_TESTINSTANCE_HPP_
2 #define BLANK_TEST_INTEGRATION_TESTINSTANCE_HPP_
3
4 #include "app/Process.hpp"
5 #include "io/filesystem.hpp"
6 #include "io/LineBuffer.hpp"
7 #include "net/tcp.hpp"
8
9 #include <list>
10 #include <string>
11
12
13 namespace blank {
14 namespace test {
15
16 class TestInstance {
17
18 public:
19         /// Launch a blank instance with given arguments (program name
20         /// will be prepended by the constructor).
21         /// If connect is true, a command service connection will be
22         /// established during construction.
23         explicit TestInstance(const Process::Arguments &args, bool connect = false);
24         ~TestInstance();
25
26 public:
27         /// Write given text to program's stdin.
28         /// Data is not modified, so if you want to push a line, be
29         /// sure to include a newline character.
30         void WriteInput(const std::string &data);
31
32         /// read next line from program's stdout
33         void ReadOutputLine(std::string &line);
34         /// assert that the next line the program writes to stdout will
35         /// be the given one (without a trailing newline character)
36         void AssertOutputLine(const std::string &line);
37         /// wait until program writes given line to stdout
38         void WaitOutputLine(const std::string &line);
39         /// read from program's stdout until EOF
40         void ExhaustOutput(std::string &output);
41         /// assert that the program produces no more output
42         void AssertNoOutput();
43
44         /// read next line from program's stderr
45         void ReadErrorLine(std::string &line);
46         /// assert that the next line the program writes to stderr will
47         /// be the given one (without a trailing newline character)
48         void AssertErrorLine(const std::string &line);
49         /// wait until program writes given line to stderr
50         void WaitErrorLine(const std::string &line);
51         /// read from program's stdout until EOF
52         void ExhaustError(std::string &error);
53         /// assert that the program produces no more output on stderr
54         void AssertNoError();
55
56         /// send termination signal
57         void Terminate();
58         /// assert that the program has not exited
59         void AssertRunning();
60         /// assert that the program has exited
61         void AssertTerminated();
62         /// make sure the process terminated with given status
63         void AssertExitStatus(int expected);
64
65         // the following methods are only valid when a command service is connected
66
67         /// wait for given message on the command service
68         void WaitCommandMessage(const std::string &line);
69         /// wait for given error on the command service
70         void WaitCommandError(const std::string &line);
71         /// wait for given broadcast on the command service
72         void WaitCommandBroadcast(const std::string &line);
73         /// wait for given line on the command service
74         void WaitCommandLine(const std::string &line);
75
76         /// send command line to program
77         void SendCommand(const std::string &);
78
79 private:
80         TempDir dir;
81         Process proc;
82         tcp::Socket conn;
83         size_t head;
84         LineBuffer<BUFSIZ> out_buf;
85         LineBuffer<BUFSIZ> err_buf;
86         LineBuffer<BUFSIZ> cmd_buf;
87         std::string name;
88         std::list<std::string> past_out;
89         std::list<std::string> past_err;
90         std::list<std::string> past_cmd;
91
92 };
93
94 }
95 }
96
97 #endif