diff options
author | tripun <tripun@gmail.com> | 2014-08-18 23:24:25 +0530 |
---|---|---|
committer | tripun <tripun@gmail.com> | 2014-08-18 23:24:25 +0530 |
commit | b2bd337c31b1bf2481f643967b6670ada9d3cb2e (patch) | |
tree | b0e729e9648bbf64ecd94837b6833e010bd64c98 /test/unit | |
parent | cb39ea25080a65ebc67d42d24f9de72c7b49bea2 (diff) | |
download | fork-ledger-b2bd337c31b1bf2481f643967b6670ada9d3cb2e.tar.gz fork-ledger-b2bd337c31b1bf2481f643967b6670ada9d3cb2e.tar.bz2 fork-ledger-b2bd337c31b1bf2481f643967b6670ada9d3cb2e.zip |
add additional tests for sequence_t and fix the old ones
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/t_value.cc | 72 |
1 files changed, 50 insertions, 22 deletions
diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index b0b9b382..ad400daa 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -35,6 +35,7 @@ BOOST_FIXTURE_TEST_SUITE(value, value_fixture) BOOST_AUTO_TEST_CASE(testConstructors) { + value_t::sequence_t s1; value_t v1; value_t v2(true); value_t v3(boost::posix_time::from_time_t(time_t(NULL))); @@ -45,7 +46,7 @@ BOOST_AUTO_TEST_CASE(testConstructors) value_t v8(amount_t("4 GBP")); value_t v9(balance_t("3 EUR")); value_t v10(mask_t("regex")); - value_t v11(new value_t::sequence_t()); + value_t v11(s1); value_t v12(string("$1")); value_t v13("2 CAD"); value_t v14("comment", true); @@ -70,6 +71,7 @@ BOOST_AUTO_TEST_CASE(testConstructors) BOOST_AUTO_TEST_CASE(testAssignment) { + value_t::sequence_t s1; value_t v1; value_t v2 = true; value_t v3 = boost::posix_time::from_time_t(time_t(NULL)); @@ -80,7 +82,7 @@ BOOST_AUTO_TEST_CASE(testAssignment) value_t v8 = amount_t("4 GBP"); value_t v9 = balance_t("3 EUR"); value_t v10 = mask_t("regex"); - value_t v11 = new value_t::sequence_t(); + value_t v11 = s1; value_t v12 = new value_t(string("$1")); value_t v13 = new value_t("2 CAD"); value_t v14 = new value_t("comment",true); @@ -108,6 +110,7 @@ BOOST_AUTO_TEST_CASE(testEquality) struct tm localtime; strptime("10 February 2010", "%d %b %Y", &localtime); time_t time_var = mktime(&localtime); + value_t::sequence_t s1; value_t v1; value_t v2(true); @@ -119,7 +122,7 @@ BOOST_AUTO_TEST_CASE(testEquality) value_t v8(amount_t("4 GBP")); value_t v9(balance_t("4 GBP")); value_t v10(mask_t("regex")); - value_t v11(new value_t::sequence_t()); + value_t v11(s1); value_t v12(string("$1")); value_t v13("2 CAD"); value_t v14("comment", true); @@ -144,7 +147,7 @@ BOOST_AUTO_TEST_CASE(testEquality) BOOST_CHECK(v20 == value_t(balance_t(2L))); BOOST_CHECK(v14 == v15); BOOST_CHECK(v10 == value_t(mask_t("regex"))); - BOOST_CHECK(v11 == value_t(new value_t::sequence_t())); + BOOST_CHECK(v11 == value_t(s1)); BOOST_CHECK_THROW(v8 == v10, value_error); @@ -204,6 +207,7 @@ BOOST_AUTO_TEST_CASE(testAddition) struct tm localtime; strptime("10 February 2010 00:00:00", "%d %b %Y %H:%M:%S", &localtime); time_t time_var = mktime(&localtime); + value_t::sequence_t s1; value_t v1; value_t v2(true); @@ -215,7 +219,7 @@ BOOST_AUTO_TEST_CASE(testAddition) value_t v8(amount_t("4 GBP")); value_t v9(balance_t("4 GBP")); value_t v10(mask_t("regex")); - value_t v11(new value_t::sequence_t()); + value_t v11(s1); value_t v12(string("$1")); value_t v13("2 CAD"); value_t v14("comment", true); @@ -269,15 +273,18 @@ BOOST_AUTO_TEST_CASE(testAddition) v18 += v19; BOOST_CHECK_EQUAL(v9, v18); - value_t v20(new value_t::sequence_t()); - v11.push_back(value_t(2L)); - v11.push_back(value_t("4 GBP")); - v20.push_back(value_t(2L)); + value_t v20(s1); + v11 += value_t(2L); + v11 += value_t("4 GBP"); BOOST_CHECK_THROW(v11 += v20,value_error); BOOST_CHECK_THROW(v10 += v8, value_error); + v20 += value_t(2L); v20 += value_t("4 GBP"); BOOST_CHECK_EQUAL(v11, v20); + v11 += v20; + v20 += v20; + BOOST_CHECK_EQUAL(v11, v20); BOOST_CHECK(v1.valid()); BOOST_CHECK(v2.valid()); @@ -306,6 +313,7 @@ BOOST_AUTO_TEST_CASE(testSubtraction) struct tm localtime; strptime("10 February 2010 00:00:04", "%d %b %Y %H:%M:%S", &localtime); time_t time_var = mktime(&localtime); + value_t::sequence_t s1; value_t v1; value_t v2(true); @@ -317,7 +325,7 @@ BOOST_AUTO_TEST_CASE(testSubtraction) value_t v8(amount_t("4 GBP")); value_t v9(balance_t("4 GBP")); value_t v10(mask_t("regex")); - value_t v11(new value_t::sequence_t()); + value_t v11(s1); value_t v12(string("$1")); value_t v13("2 CAD"); value_t v14("comment", true); @@ -364,15 +372,25 @@ BOOST_AUTO_TEST_CASE(testSubtraction) v18 -=v19; BOOST_CHECK_EQUAL(v18, value_t("0")); - value_t v20(new value_t::sequence_t()); + value_t v20(s1); value_t v21(2L); value_t v22("4 GBP"); v11.push_back(v21); v11.push_back(v22); - v20.push_back(v21); BOOST_CHECK_THROW(v11 -= v20,value_error); BOOST_CHECK_THROW(v10 -= v8, value_error); + v20.push_back(v21); + v20.push_back(v22); + v11 -= v20; + value_t v23(s1); + v23.push_back(value_t(0L)); + v23.push_back(value_t("0")); + BOOST_CHECK_EQUAL(v11, v23); + v20 -= v21; + v20 -= v22; + BOOST_CHECK_EQUAL(v20, value_t(s1)); + BOOST_CHECK(v1.valid()); BOOST_CHECK(v2.valid()); BOOST_CHECK(v3.valid()); @@ -399,6 +417,7 @@ BOOST_AUTO_TEST_CASE(testMultiplication) struct tm localtime; strptime("10 February 2010 00:00:00", "%d %b %Y %H:%M:%S", &localtime); time_t time_var = mktime(&localtime); + value_t::sequence_t s1; value_t v1; value_t v2(true); @@ -410,7 +429,7 @@ BOOST_AUTO_TEST_CASE(testMultiplication) value_t v8(amount_t("4 GBP")); value_t v9(balance_t("4 GBP")); value_t v10(mask_t("regex")); - value_t v11(new value_t::sequence_t()); + value_t v11(s1); value_t v12(string("$1")); value_t v13("2 CAD"); value_t v14("comment", true); @@ -441,6 +460,14 @@ BOOST_AUTO_TEST_CASE(testMultiplication) v18 += value_t(4L); BOOST_CHECK_EQUAL(v17, v18); + value_t v20(s1); + v11.push_back(value_t(2L)); + v11.push_back(value_t("2 GBP")); + v20.push_back(value_t(4L)); + v20.push_back(value_t("4 GBP")); + v11 *= value_t(2L); + BOOST_CHECK_EQUAL(v11 ,v20); + BOOST_CHECK_THROW(v10 += v8, value_error); BOOST_CHECK(v1.valid()); BOOST_CHECK(v2.valid()); @@ -467,6 +494,7 @@ BOOST_AUTO_TEST_CASE(testDivision) struct tm localtime; strptime("10 February 2010 00:00:00", "%d %b %Y %H:%M:%S", &localtime); time_t time_var = mktime(&localtime); + value_t::sequence_t s1; value_t v1; value_t v2(true); @@ -478,7 +506,7 @@ BOOST_AUTO_TEST_CASE(testDivision) value_t v8(amount_t("4 GBP")); value_t v9(balance_t("4 GBP")); value_t v10(mask_t("regex")); - value_t v11(new value_t::sequence_t()); + value_t v11(s1); value_t v12(string("$1")); value_t v13("2 CAD"); value_t v14("comment", true); @@ -527,6 +555,7 @@ BOOST_AUTO_TEST_CASE(testDivision) BOOST_AUTO_TEST_CASE(testType) { + value_t::sequence_t s1; value_t v1; value_t v2(true); value_t v3(boost::posix_time::from_time_t(time_t(NULL))); @@ -537,7 +566,7 @@ BOOST_AUTO_TEST_CASE(testType) value_t v8(amount_t("4 GBP")); value_t v9(balance_t("3 EUR")); value_t v10(mask_t("regex")); - value_t v11(new value_t::sequence_t()); + value_t v11(s1); value_t v12(string("$1")); value_t v13("2 CAD"); value_t v14("comment", true); @@ -553,15 +582,12 @@ BOOST_AUTO_TEST_CASE(testType) BOOST_CHECK(v8.is_amount()); BOOST_CHECK(v9.is_balance()); BOOST_CHECK(v10.is_mask()); - BOOST_CHECK(v11.is_boolean()); + BOOST_CHECK(v11.is_sequence()); BOOST_CHECK(v12.is_amount()); BOOST_CHECK(v13.is_amount()); BOOST_CHECK(v14.is_string()); BOOST_CHECK(v15.is_string()); - v11.push_back(v6); - BOOST_CHECK(v11.is_sequence()); - BOOST_CHECK(v1.valid()); BOOST_CHECK(v2.valid()); BOOST_CHECK(v3.valid()); @@ -581,6 +607,7 @@ BOOST_AUTO_TEST_CASE(testType) BOOST_AUTO_TEST_CASE(testForZero) { + value_t::sequence_t s1; value_t v1; value_t v2(true); value_t v3(boost::posix_time::from_time_t(time_t(NULL))); @@ -591,7 +618,7 @@ BOOST_AUTO_TEST_CASE(testForZero) value_t v8(amount_t("4 GBP")); value_t v9(balance_t("0")); value_t v10(mask_t("")); - value_t v11(new value_t::sequence_t()); + value_t v11(s1); value_t v12(string("$1")); value_t v13("2 CAD"); value_t v14("comment", true); @@ -607,7 +634,7 @@ BOOST_AUTO_TEST_CASE(testForZero) BOOST_CHECK(v8.is_nonzero()); BOOST_CHECK(v9.is_zero()); BOOST_CHECK_THROW(v10.is_zero(), value_error); - BOOST_CHECK(v11.is_nonzero()); + BOOST_CHECK(v11.is_zero()); BOOST_CHECK(v12.is_nonzero()); BOOST_CHECK(v13.is_nonzero()); BOOST_CHECK(v14.is_nonzero()); @@ -635,6 +662,7 @@ BOOST_AUTO_TEST_CASE(testForZero) BOOST_AUTO_TEST_CASE(testNegation) { + value_t::sequence_t s1; value_t v1; value_t v2(true); value_t v3(boost::posix_time::from_time_t(time_t(NULL))); @@ -645,7 +673,7 @@ BOOST_AUTO_TEST_CASE(testNegation) value_t v8(amount_t("4 GBP")); value_t v9(balance_t("4 GBP")); value_t v10(mask_t("")); - value_t v11(new value_t::sequence_t()); + value_t v11(s1); value_t v12(string("$1")); value_t v13("$-1"); value_t v14("comment", true); |