Added tests which compare host to memento.
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@1018 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
76aeea2390
commit
9b083bd028
1 changed files with 18 additions and 4 deletions
|
@ -80,6 +80,17 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
class Memento
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit Memento( const Thingy & t ) : m_count( t.m_counts.size() ) {}
|
||||||
|
bool operator == ( const Thingy & t ) const
|
||||||
|
{
|
||||||
|
return ( m_count == t.m_counts.size() );
|
||||||
|
}
|
||||||
|
unsigned int m_count;
|
||||||
|
};
|
||||||
|
|
||||||
/// This is a static validator.
|
/// This is a static validator.
|
||||||
static bool StaticIsValid( void );
|
static bool StaticIsValid( void );
|
||||||
|
|
||||||
|
@ -95,6 +106,9 @@ private:
|
||||||
// This shows how to declare checkers for non-static functions in a host class.
|
// This shows how to declare checkers for non-static functions in a host class.
|
||||||
typedef ::Loki::CheckFor< Thingy > CheckFor;
|
typedef ::Loki::CheckFor< Thingy > CheckFor;
|
||||||
|
|
||||||
|
// This shows how to declare checkers for non-static functions in a host class.
|
||||||
|
typedef ::Loki::CheckFor< Thingy, Memento > CheckMementoFor;
|
||||||
|
|
||||||
// This shows how to declare checkers for static functions of a host class.
|
// This shows how to declare checkers for static functions of a host class.
|
||||||
typedef ::Loki::CheckStaticFor CheckStaticFor;
|
typedef ::Loki::CheckStaticFor CheckStaticFor;
|
||||||
|
|
||||||
|
@ -221,7 +235,7 @@ unsigned int Thingy::GetValue( void ) const
|
||||||
// This example shows how to use the equality checker.
|
// This example shows how to use the equality checker.
|
||||||
unsigned int Thingy::DoSomething( bool doThrow ) const
|
unsigned int Thingy::DoSomething( bool doThrow ) const
|
||||||
{
|
{
|
||||||
CheckFor::Equality checker( this, &Thingy::IsValid );
|
CheckMementoFor::Equality checker( this, &Thingy::IsValid );
|
||||||
(void)checker;
|
(void)checker;
|
||||||
if ( doThrow )
|
if ( doThrow )
|
||||||
throw ::std::logic_error( "Test Exception." );
|
throw ::std::logic_error( "Test Exception." );
|
||||||
|
@ -233,7 +247,7 @@ unsigned int Thingy::DoSomething( bool doThrow ) const
|
||||||
// This example shows how to use the no-change checker.
|
// This example shows how to use the no-change checker.
|
||||||
void Thingy::DoSomethingElse( void ) const
|
void Thingy::DoSomethingElse( void ) const
|
||||||
{
|
{
|
||||||
CheckFor::NoChange checker( this, &Thingy::IsValid );
|
CheckMementoFor::NoChange checker( this, &Thingy::IsValid );
|
||||||
(void)checker;
|
(void)checker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +270,7 @@ unsigned int Thingy::GetCount( unsigned int index ) const
|
||||||
// This function's checker cares about class invariants and both the pre- and
|
// This function's checker cares about class invariants and both the pre- and
|
||||||
// post-conditions, so it passes in pointers for all 3 validators. The pre-
|
// post-conditions, so it passes in pointers for all 3 validators. The pre-
|
||||||
// and post-conditions are both about making sure the container is not empty.
|
// and post-conditions are both about making sure the container is not empty.
|
||||||
CheckFor::NoChangeOrThrow checker( this, &Thingy::IsValid, &Thingy::IsValidFull, &Thingy::IsValidFull );
|
CheckMementoFor::NoChangeOrThrow checker( this, &Thingy::IsValid, &Thingy::IsValidFull, &Thingy::IsValidFull );
|
||||||
if ( m_counts.size() <= index )
|
if ( m_counts.size() <= index )
|
||||||
return 0;
|
return 0;
|
||||||
const unsigned int count = m_counts[ index ];
|
const unsigned int count = m_counts[ index ];
|
||||||
|
@ -456,7 +470,7 @@ int main( unsigned int argc, const char * const argv[] )
|
||||||
cout << "Caught an exception!" << endl;
|
cout << "Caught an exception!" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "All done!" << endl;
|
cout << "All done! If you see this line, and no assertions failed, then the test passed!" << endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue