Blame examples/money/MoneyTest.cpp

Packit Service e31359
// MoneyTest.cpp
Packit Service e31359
Packit Service e31359
#include "StdAfx.h"
Packit Service e31359
#include <cppunit/config/SourcePrefix.h>
Packit Service e31359
#include "Money.h"
Packit Service e31359
#include "MoneyTest.h"
Packit Service e31359
Packit Service e31359
// Registers the fixture into the 'registry'
Packit Service e31359
CPPUNIT_TEST_SUITE_REGISTRATION( MoneyTest );
Packit Service e31359
Packit Service e31359
Packit Service e31359
void 
Packit Service e31359
MoneyTest::setUp()
Packit Service e31359
{
Packit Service e31359
}
Packit Service e31359
Packit Service e31359
Packit Service e31359
void 
Packit Service e31359
MoneyTest::tearDown()
Packit Service e31359
{
Packit Service e31359
}
Packit Service e31359
Packit Service e31359
Packit Service e31359
void 
Packit Service e31359
MoneyTest::testConstructor()
Packit Service e31359
{
Packit Service e31359
  // Set up
Packit Service e31359
  const std::string currencyFF( "FF" );
Packit Service e31359
  const double longNumber = 1234.5678;
Packit Service e31359
Packit Service e31359
  // Process
Packit Service e31359
  Money money( longNumber, currencyFF );
Packit Service e31359
Packit Service e31359
  // Check
Packit Service e31359
  CPPUNIT_ASSERT_EQUAL( longNumber, money.getAmount() );
Packit Service e31359
  CPPUNIT_ASSERT_EQUAL( currencyFF, money.getCurrency() );
Packit Service e31359
}
Packit Service e31359
Packit Service e31359
Packit Service e31359
void
Packit Service e31359
MoneyTest::testEqual()
Packit Service e31359
{
Packit Service e31359
  // Set up
Packit Service e31359
  const Money money123FF( 123, "FF" );
Packit Service e31359
  const Money money123USD( 123, "USD" );
Packit Service e31359
  const Money money12FF( 12, "FF" );
Packit Service e31359
  const Money money12USD( 12, "USD" );
Packit Service e31359
Packit Service e31359
  // Process & Check
Packit Service e31359
  CPPUNIT_ASSERT( money123FF == money123FF );    // ==
Packit Service e31359
  CPPUNIT_ASSERT( money12FF != money123FF );     // != amount
Packit Service e31359
  CPPUNIT_ASSERT( money123USD != money123FF );   // != currency
Packit Service e31359
  CPPUNIT_ASSERT( money12USD != money123FF );    // != currency and != amount
Packit Service e31359
}
Packit Service e31359
Packit Service e31359
Packit Service e31359
void 
Packit Service e31359
MoneyTest::testAdd()
Packit Service e31359
{
Packit Service e31359
  // Set up
Packit Service e31359
  const Money money12FF( 12, "FF" );
Packit Service e31359
  const Money expectedMoney( 135, "FF" );
Packit Service e31359
Packit Service e31359
  // Process
Packit Service e31359
  Money money( 123, "FF" );
Packit Service e31359
  money += money12FF;
Packit Service e31359
Packit Service e31359
  // Check
Packit Service e31359
  CPPUNIT_ASSERT_EQUAL( expectedMoney, money );           // add works
Packit Service e31359
  CPPUNIT_ASSERT( &money == &(money += money12FF) );  // add returns ref. on 'this'.
Packit Service e31359
}
Packit Service e31359
Packit Service e31359
Packit Service e31359
void 
Packit Service e31359
MoneyTest::testAddThrow()
Packit Service e31359
{
Packit Service e31359
  // Set up
Packit Service e31359
  const Money money123FF( 123, "FF" );
Packit Service e31359
Packit Service e31359
  // Process
Packit Service e31359
  Money money( 123, "USD" );
Packit Service e31359
  CPPUNIT_ASSERT_THROW( money += money123FF, IncompatibleMoneyError );
Packit Service e31359
}