class MoneyTest : public CppUnit::TestFixture
{ CPPUNIT_TEST_SUITE(MoneyTest); ///< declares that our Fiture's test suite CPPUNIT_TEST(testConstructor); ///< adds a test to our test suite. The test is implemented by a method named testConstructor() CPPUNIT_TEST( testEqual ); CPPUNIT_TEST( testAdd ); CPPUNIT_TEST_EXCEPTION( testAddThrow, IncompatibleMoneyError ); CPPUNIT_TEST_SUITE_END();
public:
MoneyTest();
virtual ~MoneyTest();
void setUp(); ///< setUp some fixtures
void tearDown(); ///< tearDown some fixtures
// Get the top level suite from the registry
CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
// Adds the test to the list of test to run CppUnit::TextUi::TestRunner runner;
runner.addTest( suite );
// Change the default outputter to a compiler error format outputter
runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
std::cerr ) );
// Run the tests.
bool wasSucessful = runner.run();
// printf("Hello World!\n");
// Return error code 1 if the one of test failed.
return wasSucessful ? 0 : 1;
// return 0;
}
#include <cppunit/portability/Stream.h> // or <iostream> if portability is not an issue
// The function below could be prototyped as:
// inline std::ostream &operator <<( std::ostream &os, const Money &value )
// If you know that you will never compile on a platform without std::ostream
// (such as embedded vc++ 4.0; though even that platform you can use STLPort)
inline CPPUNIT_NS::OStream &operator <<( CPPUNIT_NS::OStream &os, const Money &value )
{
return os << "Money< value =" << value.getAmount() << "; currency = " << value.getCurrency() << ">";
}