mirror of
https://github.com/catchorg/Catch2.git
synced 2025-05-31 17:07:52 +00:00
parent
503d5d0c8e
commit
f3d1f08c3b
62 changed files with 527 additions and 527 deletions
|
@ -28,17 +28,17 @@ template<typename T>
|
|||
class BetweenGenerator : public IGenerator<T> {
|
||||
public:
|
||||
BetweenGenerator( T from, T to ) : m_from( from ), m_to( to ){}
|
||||
|
||||
|
||||
virtual T getValue( std::size_t index ) const {
|
||||
return m_from+static_cast<int>( index );
|
||||
}
|
||||
|
||||
|
||||
virtual std::size_t size() const {
|
||||
return static_cast<std::size_t>( 1+m_to-m_from );
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
T m_from;
|
||||
T m_to;
|
||||
};
|
||||
|
@ -47,11 +47,11 @@ template<typename T>
|
|||
class ValuesGenerator : public IGenerator<T> {
|
||||
public:
|
||||
ValuesGenerator(){}
|
||||
|
||||
|
||||
void add( T value ) {
|
||||
m_values.push_back( value );
|
||||
}
|
||||
|
||||
|
||||
virtual T getValue( std::size_t index ) const {
|
||||
return m_values[index];
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ public:
|
|||
virtual std::size_t size() const {
|
||||
return m_values.size();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
std::vector<T> m_values;
|
||||
};
|
||||
|
@ -68,27 +68,27 @@ template<typename T>
|
|||
class CompositeGenerator {
|
||||
public:
|
||||
CompositeGenerator() : m_totalSize( 0 ) {}
|
||||
|
||||
|
||||
// *** Move semantics, similar to auto_ptr ***
|
||||
CompositeGenerator( CompositeGenerator& other )
|
||||
: m_fileInfo( other.m_fileInfo ),
|
||||
m_totalSize( 0 )
|
||||
CompositeGenerator( CompositeGenerator& other )
|
||||
: m_fileInfo( other.m_fileInfo ),
|
||||
m_totalSize( 0 )
|
||||
{
|
||||
move( other );
|
||||
}
|
||||
|
||||
|
||||
CompositeGenerator& setFileInfo( const char* fileInfo ) {
|
||||
m_fileInfo = fileInfo;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
~CompositeGenerator() {
|
||||
deleteAll( m_composed );
|
||||
}
|
||||
|
||||
|
||||
operator T () const {
|
||||
size_t overallIndex = getCurrentContext().getGeneratorIndex( m_fileInfo, m_totalSize );
|
||||
|
||||
|
||||
typename std::vector<const IGenerator<T>*>::const_iterator it = m_composed.begin();
|
||||
typename std::vector<const IGenerator<T>*>::const_iterator itEnd = m_composed.end();
|
||||
for( size_t index = 0; it != itEnd; ++it )
|
||||
|
@ -103,32 +103,32 @@ public:
|
|||
CATCH_INTERNAL_ERROR( "Indexed past end of generated range" );
|
||||
return T(); // Suppress spurious "not all control paths return a value" warning in Visual Studio - if you know how to fix this please do so
|
||||
}
|
||||
|
||||
|
||||
void add( const IGenerator<T>* generator ) {
|
||||
m_totalSize += generator->size();
|
||||
m_composed.push_back( generator );
|
||||
}
|
||||
|
||||
|
||||
CompositeGenerator& then( CompositeGenerator& other ) {
|
||||
move( other );
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
CompositeGenerator& then( T value ) {
|
||||
ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
|
||||
valuesGen->add( value );
|
||||
add( valuesGen );
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
void move( CompositeGenerator& other ) {
|
||||
std::copy( other.m_composed.begin(), other.m_composed.end(), std::back_inserter( m_composed ) );
|
||||
m_totalSize += other.m_totalSize;
|
||||
other.m_composed.clear();
|
||||
}
|
||||
|
||||
|
||||
std::vector<const IGenerator<T>*> m_composed;
|
||||
std::string m_fileInfo;
|
||||
size_t m_totalSize;
|
||||
|
@ -177,9 +177,9 @@ namespace Generators
|
|||
}
|
||||
|
||||
} // end namespace Generators
|
||||
|
||||
|
||||
using namespace Generators;
|
||||
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#define INTERNAL_CATCH_LINESTR2( line ) #line
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue