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