Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include/internal/catch_stream.hpp
diff options
context:
space:
mode:
authorPhil Nash2015-12-04 10:19:08 +0000
committerPhil Nash2015-12-04 10:19:08 +0000
commitfdc42d0af47f58fa13a42b685bbeaf55a8347673 (patch)
tree779ff3d692eeffd33353d89ad7697a592ab5201e /include/internal/catch_stream.hpp
parentd758428fe297655e558a86cc6a013fcb1bcc8c7d (diff)
parentd274fc571c3980b5ac04cbe1416cf2205e6c99f7 (diff)
downloadcatch3-1.3.0.tar.gz
Merged from develop branchv1.3.0
- now v1.3.0
Diffstat (limited to 'include/internal/catch_stream.hpp')
-rw-r--r--include/internal/catch_stream.hpp38
1 files changed, 27 insertions, 11 deletions
diff --git a/include/internal/catch_stream.hpp b/include/internal/catch_stream.hpp
index 30e9668b..2703df5d 100644
--- a/include/internal/catch_stream.hpp
+++ b/include/internal/catch_stream.hpp
@@ -10,7 +10,6 @@
#define TWOBLUECUBES_CATCH_STREAM_HPP_INCLUDED
#include "catch_stream.h"
-#include "catch_streambuf.h"
#include "catch_debugger.h"
#include <stdexcept>
@@ -57,6 +56,20 @@ namespace Catch {
///////////////////////////////////////////////////////////////////////////
+
+ FileStream::FileStream( std::string const& filename ) {
+ m_ofs.open( filename.c_str() );
+ if( m_ofs.fail() ) {
+ std::ostringstream oss;
+ oss << "Unable to open file: '" << filename << "'";
+ throw std::domain_error( oss.str() );
+ }
+ }
+
+ std::ostream& FileStream::stream() const {
+ return m_ofs;
+ }
+
struct OutputDebugWriter {
void operator()( std::string const&str ) {
@@ -64,20 +77,23 @@ namespace Catch {
}
};
- Stream::Stream()
- : streamBuf( NULL ), isOwned( false )
+ DebugOutStream::DebugOutStream()
+ : m_streamBuf( new StreamBufImpl<OutputDebugWriter>() ),
+ m_os( m_streamBuf.get() )
{}
- Stream::Stream( std::streambuf* _streamBuf, bool _isOwned )
- : streamBuf( _streamBuf ), isOwned( _isOwned )
+ std::ostream& DebugOutStream::stream() const {
+ return m_os;
+ }
+
+ // Store the streambuf from cout up-front because
+ // cout may get redirected when running tests
+ CoutStream::CoutStream()
+ : m_os( Catch::cout().rdbuf() )
{}
- void Stream::release() {
- if( isOwned ) {
- delete streamBuf;
- streamBuf = NULL;
- isOwned = false;
- }
+ std::ostream& CoutStream::stream() const {
+ return m_os;
}
#ifndef CATCH_CONFIG_NOSTDOUT // If you #define this you must implement these functions