|
From: <ric...@us...> - 2009-09-26 19:42:16
|
Revision: 1018
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1018&view=rev
Author: rich_sposato
Date: 2009-09-26 19:42:09 +0000 (Sat, 26 Sep 2009)
Log Message:
-----------
Added tests which compare host to memento.
Modified Paths:
--------------
trunk/test/Checker/main.cpp
Modified: trunk/test/Checker/main.cpp
===================================================================
--- trunk/test/Checker/main.cpp 2009-09-26 19:40:20 UTC (rev 1017)
+++ trunk/test/Checker/main.cpp 2009-09-26 19:42:09 UTC (rev 1018)
@@ -80,6 +80,17 @@
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.
static bool StaticIsValid( void );
@@ -95,6 +106,9 @@
// This shows how to declare checkers for non-static functions in a host class.
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.
typedef ::Loki::CheckStaticFor CheckStaticFor;
@@ -221,7 +235,7 @@
// This example shows how to use the equality checker.
unsigned int Thingy::DoSomething( bool doThrow ) const
{
- CheckFor::Equality checker( this, &Thingy::IsValid );
+ CheckMementoFor::Equality checker( this, &Thingy::IsValid );
(void)checker;
if ( doThrow )
throw ::std::logic_error( "Test Exception." );
@@ -233,7 +247,7 @@
// This example shows how to use the no-change checker.
void Thingy::DoSomethingElse( void ) const
{
- CheckFor::NoChange checker( this, &Thingy::IsValid );
+ CheckMementoFor::NoChange checker( this, &Thingy::IsValid );
(void)checker;
}
@@ -256,7 +270,7 @@
// 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-
// 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 )
return 0;
const unsigned int count = m_counts[ index ];
@@ -456,7 +470,7 @@
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;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|