From 61ef82ec2b2ca396667f92a4e5c6ceb729c42086 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Sun, 15 May 2016 17:11:27 +0300 Subject: Port to MinGW --- tests/pager/buildfile | 7 ++++ tests/pager/driver.cxx | 111 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 tests/pager/buildfile create mode 100644 tests/pager/driver.cxx (limited to 'tests/pager') diff --git a/tests/pager/buildfile b/tests/pager/buildfile new file mode 100644 index 0000000..e42f3b0 --- /dev/null +++ b/tests/pager/buildfile @@ -0,0 +1,7 @@ +# file : tests/pager/buildfile +# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +exe{driver}: cxx{driver} ../../butl/lib{butl} + +include ../../butl/ diff --git a/tests/pager/driver.cxx b/tests/pager/driver.cxx new file mode 100644 index 0000000..cab3078 --- /dev/null +++ b/tests/pager/driver.cxx @@ -0,0 +1,111 @@ +// file : tests/pager/driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include +#include +#include // move() +#include +#include +#include + +#include + +using namespace std; +using namespace butl; + +int +main (int argc, const char* argv[]) +{ + bool child (false); + bool interactive (false); + string pgprog; + vector pgopts; + + assert (argc > 0); + + int i (1); + for (; i != argc; ++i) + { + string v (argv[i]); + if (pgprog.empty ()) + { + if (v == "-c") + child = true; + else if (v == "-i") + interactive = true; + else + { + pgprog = move (v); + interactive = true; + } + } + else + pgopts.emplace_back (move (v)); + } + + if (i != argc) + { + if (!child) + cerr << "usage: " << argv[0] << " [-c] [-i] [ []]" + << endl; + + return 1; + } + + const char* s (R"delim( +class fdstream_base +{ +protected: + fdstream_base () = default; + fdstream_base (int fd): buf_ (fd) {} + +protected: + fdbuf buf_; +}; + +class ifdstream: fdstream_base, public std::istream +{ +public: + ifdstream (): std::istream (&buf_) {} + ifdstream (int fd): fdstream_base (fd), std::istream (&buf_) {} + + void close () {buf_.close ();} + void open (int fd) {buf_.open (fd);} + bool is_open () const {return buf_.is_open ();} +}; +)delim"); + + if (child) + { + string il; + string ol; + istringstream is (s); + do + { + getline (cin, il); + getline (is, ol); + } + while (cin.good () && is.good () && il == ol); + return cin.eof () && !cin.bad () && is.eof () ? 0 : 1; + } + + try + { + string prog (argv[0]); + vector opts ({"-c"}); + + pager p ("pager test", + false, + interactive ? (pgprog.empty () ? nullptr : &pgprog) : &prog, + interactive ? (pgopts.empty () ? nullptr : &pgopts) : &opts); + + p.stream () << s; + + assert (p.wait ()); + } + catch (const system_error&) + { + assert (false); + } +} -- cgit v1.1