ledger/test/unit/t_balance.cc
2014-08-11 21:01:24 +05:30

53 lines
1.1 KiB
C++

#define BOOST_TEST_DYN_LINK
//#define BOOST_TEST_MODULE balance
#include <boost/test/unit_test.hpp>
#include <system.hh>
#include "balance.h"
using namespace ledger;
struct balance_fixture {
balance_fixture() {
times_initialize();
amount_t::initialize();
// Cause the display precision for dollars to be initialized to 2.
amount_t x1("$1.00");
BOOST_CHECK(x1);
amount_t::stream_fullstrings = true; // make reports from UnitTests accurate
}
~balance_fixture()
{
amount_t::stream_fullstrings = false;
amount_t::shutdown();
times_shutdown();
}
};
BOOST_FIXTURE_TEST_SUITE(balance, balance_fixture)
BOOST_AUTO_TEST_CASE(testConstructors)
{
balance_t b0;
balance_t b1(1.00);
balance_t b2(12345UL);
balance_t b3(123456L);
BOOST_CHECK_EQUAL(balance_t(), b0);
BOOST_CHECK_NE(balance_t("0"), b0);
BOOST_CHECK_NE(balance_t("0.0"), b0);
BOOST_CHECK_EQUAL(balance_t(12345UL), 12345UL);
BOOST_CHECK_EQUAL(balance_t(123456L), 123456L);
BOOST_CHECK(b0.valid());
BOOST_CHECK(b1.valid());
BOOST_CHECK(b2.valid());
BOOST_CHECK(b3.valid());
}
BOOST_AUTO_TEST_SUITE_END()