X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=tst%2Fintegration%2FTestInstance.hpp;fp=tst%2Fintegration%2FTestInstance.hpp;h=3bd23d4e8003ea5d5e339d965aaf71e4d4fbc228;hb=307482574d3acac09e38263de521a1826ceec7ce;hp=0000000000000000000000000000000000000000;hpb=fd86376a8e7d3f1b09be3d018f772ef884937238;p=blank.git diff --git a/tst/integration/TestInstance.hpp b/tst/integration/TestInstance.hpp new file mode 100644 index 0000000..3bd23d4 --- /dev/null +++ b/tst/integration/TestInstance.hpp @@ -0,0 +1,76 @@ +#ifndef BLANK_TEST_INTEGRATION_TESTINSTANCE_HPP_ +#define BLANK_TEST_INTEGRATION_TESTINSTANCE_HPP_ + +#include "app/Process.hpp" +#include "io/filesystem.hpp" +#include "io/LineBuffer.hpp" +#include "net/tcp.hpp" + + +namespace blank { +namespace test { + +class TestInstance { + +public: + /// Launch a blank instance with given arguments (program name + /// will be prepended by the constructor). + /// If connect is true, a command service connection will be + /// established during construction. + explicit TestInstance(const Process::Arguments &args, bool connect = false); + ~TestInstance(); + +public: + /// Write given text to program's stdin. + /// Data is not modified, so if you want to push a line, be + /// sure to include a newline character. + void WriteInput(const std::string &data); + + /// read next line from programs stdout + void ReadOutputLine(std::string &line); + /// assert that the next line the program writes to stdout will + /// be the given one (without a trailing newline character) + void AssertOutputLine(const std::string &line); + /// wait until program writes given line to stdout + void WaitOutputLine(const std::string &line); + + /// read next line from programs stderr + void ReadErrorLine(std::string &line); + /// assert that the next line the program writes to stderr will + /// be the given one (without a trailing newline character) + void AssertErrorLine(const std::string &line); + /// wait until program writes given line to stderr + void WaitErrorLine(const std::string &line); + + /// make sure the process terminated with given status + void AssertExitStatus(int expected); + + // the following methods are only valid when a command service is connected + + /// wait for given message on the command service + void WaitCommandMessage(const std::string &line); + /// wait for given error on the command service + void WaitCommandError(const std::string &line); + /// wait for given broadcast on the command service + void WaitCommandBroadcast(const std::string &line); + /// wait for given line on the command service + void WaitCommandLine(const std::string &line); + + /// send command line to program + void SendCommand(const std::string &); + +private: + TempDir dir; + Process proc; + tcp::Socket conn; + size_t head; + LineBuffer out_buf; + LineBuffer err_buf; + LineBuffer cmd_buf; + +}; + +} +} + +#endif