]> git.localhorst.tv Git - blank.git/blob - tst/integration/TestInstance.hpp
test for invoking with unknown argument
[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 programs 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
37         /// read next line from programs stderr
38         void ReadErrorLine(std::string &line);
39         /// assert that the next line the program writes to stderr will
40         /// be the given one (without a trailing newline character)
41         void AssertErrorLine(const std::string &line);
42         /// wait until program writes given line to stderr
43         void WaitErrorLine(const std::string &line);
44
45         /// make sure the process terminated with given status
46         void AssertExitStatus(int expected);
47
48         // the following methods are only valid when a command service is connected
49
50         /// wait for given message on the command service
51         void WaitCommandMessage(const std::string &line);
52         /// wait for given error on the command service
53         void WaitCommandError(const std::string &line);
54         /// wait for given broadcast on the command service
55         void WaitCommandBroadcast(const std::string &line);
56         /// wait for given line on the command service
57         void WaitCommandLine(const std::string &line);
58
59         /// send command line to program
60         void SendCommand(const std::string &);
61
62 private:
63         TempDir dir;
64         Process proc;
65         tcp::Socket conn;
66         size_t head;
67         LineBuffer<BUFSIZ> out_buf;
68         LineBuffer<BUFSIZ> err_buf;
69         LineBuffer<BUFSIZ> cmd_buf;
70
71 };
72
73 }
74 }
75
76 #endif