}
} // eo IOImplementation::doWrite
+/**
+ * Return a copy of the input buffer.
+ */
+std::string IOImplementation::getInput() const
+{
+ return m_input_buffer;
+}
+
+/**
+ * Return the input buffer and clear it.
+ */
+std::string IOImplementation::getInputClear()
+{
+ std::string retbuf;
+
+ retbuf.swap(m_input_buffer);
+
+ return retbuf;
+}
+
+/**
+ * Return true if there are bytes available in the input buffer.
+ */
+bool IOImplementation::inputAvailable() const
+{
+ return !m_input_buffer.empty();
+}
+
+/**
+ * Cut off the first len bytes from the input buffer.
+ * @returns The number of bytes actually shortened
+ */
+std::string::size_type IOImplementation::shortenInput(std::string::size_type len)
+{
+ std::string::size_type real_len=len;
+ if (real_len > m_input_buffer.size())
+ real_len=m_input_buffer.size();
+
+ if (real_len > 0)
+ m_input_buffer.erase(0,real_len);
+
+ return real_len;
+}
/*
* implementation of SimpleIO
virtual bool writable() const;
virtual bool empty() const;
+ virtual std::string getInput() const;
+ virtual std::string getInputClear();
+ virtual bool inputAvailable() const;
+ virtual std::string::size_type shortenInput(std::string::size_type len);
+
protected:
void addFilter(FilterBasePtr filter);
BOOST_CHECK_EQUAL( Signal::USR1 , proc.exitCode()>>8 );
} // eo SignaledProcessTermination
+/**
+ * fork an echo subprocess and read back the output. Directly use ProcessImplementation without helper class.
+ */
+BOOST_AUTO_TEST_CASE(DirectProcessImplementationTestEcho)
+{
+ DOUT("enter SimpleProcessTestEcho");
+ bool res;
+ BOOST_REQUIRE(backend);
+
+ ProcessImplementation proc(
+ "/bin/echo",
+ TransientPushBackFiller<std::string, std::vector >()("Eine")("Zeichenkette")
+ );
+
+ res= proc.startProcess();
+ BOOST_CHECK_EQUAL(true, res);
+
+ res= backend->doOneStep(200);
+ BOOST_CHECK_EQUAL(true, res);
+ for(int i=20; i-->0 && (proc.processState()!= ProcessState::stopped || !proc.eof());)
+ {
+ backend->doOneStep(10);
+ }
+
+ BOOST_CHECK_EQUAL( ProcessState(ProcessState::stopped), proc.processState() );
+ BOOST_CHECK_EQUAL( true, proc.eof() );
+ BOOST_CHECK_EQUAL( 0, proc.exitCode() );
+ BOOST_CHECK_EQUAL( std::string("Eine Zeichenkette\n"), proc.getInput());
+ BOOST_CHECK_EQUAL( 5, proc.shortenInput(5));
+ BOOST_CHECK_EQUAL( std::string("Zeichenkette\n"), proc.getInput());
+ BOOST_CHECK_EQUAL( true, proc.inputAvailable());
+ BOOST_CHECK_EQUAL( std::string("Zeichenkette\n"), proc.getInputClear());
+ BOOST_CHECK_EQUAL( false, proc.inputAvailable());
+} // eo SimpleProcessTestEcho
BOOST_AUTO_TEST_CASE(CallOut1)