Catch/include/internal/catch_config.hpp

160 lines
3.9 KiB
C++
Raw Normal View History

/*
* Created by Phil on 08/11/2010.
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
*
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef TWOBLUECUBES_CATCH_RUNNERCONFIG_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_RUNNERCONFIG_HPP_INCLUDED
2012-08-23 15:08:50 -04:00
#include "catch_test_spec.h"
#include "catch_interfaces_reporter.h"
#include "catch_context.h"
#include <memory>
#include <vector>
#include <string>
2011-01-05 16:04:13 -05:00
#include <iostream>
2012-05-15 18:58:23 -04:00
namespace Catch {
struct Include { enum WhichResults {
FailedOnly,
SuccessfulResults
}; };
struct List{ enum What {
None = 0,
Reports = 1,
Tests = 2,
All = 3,
2012-08-23 15:08:50 -04:00
TestNames = 6,
WhatMask = 0xf,
AsText = 0x10,
AsXml = 0x11,
AsMask = 0xf0
}; };
2012-06-08 03:22:56 -04:00
struct ConfigData {
ConfigData()
: listSpec( List::None ),
shouldDebugBreak( false ),
includeWhichResults( Include::FailedOnly ),
cutoff( -1 ),
allowThrows( true )
{}
std::string reporter;
std::string outputFilename;
List::What listSpec;
2012-08-23 15:08:50 -04:00
std::vector<TestCaseFilters> filters;
2012-06-08 03:22:56 -04:00
bool shouldDebugBreak;
std::string stream;
Include::WhichResults includeWhichResults;
std::string name;
int cutoff;
bool allowThrows;
};
2012-07-20 14:07:42 -04:00
class Config : public IConfig {
private:
Config( const Config& other );
Config& operator = ( const Config& other );
virtual void dummy();
public:
Config()
2012-06-08 03:22:56 -04:00
: m_streambuf( NULL ),
m_os( std::cout.rdbuf() )
{}
Config( const ConfigData& data )
: m_data( data ),
m_streambuf( NULL ),
2012-06-08 03:22:56 -04:00
m_os( std::cout.rdbuf() )
{}
virtual ~Config() {
m_os.rdbuf( std::cout.rdbuf() );
delete m_streambuf;
}
2012-06-08 03:22:56 -04:00
void setFilename( const std::string& filename ) {
m_data.outputFilename = filename;
}
2011-01-18 14:49:00 -05:00
2012-05-15 18:58:23 -04:00
List::What getListSpec( void ) const {
2012-06-08 03:22:56 -04:00
return m_data.listSpec;
2011-01-18 14:49:00 -05:00
}
2011-01-11 14:48:48 -05:00
2012-05-15 18:58:23 -04:00
const std::string& getFilename() const {
2012-06-08 03:22:56 -04:00
return m_data.outputFilename ;
}
2012-05-15 18:58:23 -04:00
List::What listWhat() const {
2012-06-08 03:22:56 -04:00
return static_cast<List::What>( m_data.listSpec & List::WhatMask );
2011-01-11 14:48:48 -05:00
}
2012-05-15 18:58:23 -04:00
List::What listAs() const {
2012-06-08 03:22:56 -04:00
return static_cast<List::What>( m_data.listSpec & List::AsMask );
}
2012-05-15 18:58:23 -04:00
std::string getName() const {
2012-06-08 03:22:56 -04:00
return m_data.name;
}
2012-05-15 18:58:23 -04:00
bool shouldDebugBreak() const {
2012-06-08 03:22:56 -04:00
return m_data.shouldDebugBreak;
2010-12-30 13:51:02 -05:00
}
2012-05-15 18:58:23 -04:00
virtual std::ostream& stream() const {
return m_os;
}
2012-05-15 18:58:23 -04:00
void setStreamBuf( std::streambuf* buf ) {
m_os.rdbuf( buf ? buf : std::cout.rdbuf() );
}
2012-05-15 18:58:23 -04:00
void useStream( const std::string& streamName ) {
std::streambuf* newBuf = createStreamBuf( streamName );
setStreamBuf( newBuf );
delete m_streambuf;
m_streambuf = newBuf;
}
2012-05-15 18:58:23 -04:00
virtual bool includeSuccessfulResults() const {
2012-06-08 03:22:56 -04:00
return m_data.includeWhichResults == Include::SuccessfulResults;
}
int getCutoff() const {
2012-06-08 03:22:56 -04:00
return m_data.cutoff;
}
2012-06-08 03:22:56 -04:00
virtual bool allowThrows() const {
return m_data.allowThrows;
}
2012-06-08 03:22:56 -04:00
ConfigData& data() {
return m_data;
}
2011-01-18 14:49:00 -05:00
private:
2012-06-08 03:22:56 -04:00
ConfigData m_data;
// !TBD Move these out of here
std::streambuf* m_streambuf;
mutable std::ostream m_os;
};
2012-06-08 03:22:56 -04:00
} // end namespace Catch
#endif // TWOBLUECUBES_CATCH_RUNNERCONFIG_HPP_INCLUDED