From 53572549d35c6907f4e76798cfba018f502de501 Mon Sep 17 00:00:00 2001 From: tripun Date: Fri, 15 Aug 2014 16:45:40 +0530 Subject: add t_value unit test --- test/unit/CMakeLists.txt | 2 +- test/unit/t_value.cc | 0 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 test/unit/t_value.cc (limited to 'test/unit') diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 23bb0ea4..8d13d2d6 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -9,7 +9,7 @@ if (BUILD_LIBRARY) add_executable(UtilTests t_times.cc) add_ledger_test(UtilTests) - add_executable(MathTests t_amount.cc t_commodity.cc t_balance.cc t_expr.cc) + add_executable(MathTests t_amount.cc t_commodity.cc t_balance.cc t_expr.cc t_value.cc) add_ledger_test(MathTests) set_target_properties(check PROPERTIES DEPENDS LedgerUtilTests) diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc new file mode 100644 index 00000000..e69de29b -- cgit v1.2.3 From b8cb110720c4034db2b0e8a61acc965ff2bc8c59 Mon Sep 17 00:00:00 2001 From: tripun Date: Sat, 16 Aug 2014 19:36:36 +0530 Subject: initialize value fixture --- test/unit/t_value.cc | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'test/unit') diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index e69de29b..96d644a6 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -0,0 +1,37 @@ +#define BOOST_TEST_DYN_LINK + +#include + +#include + +#include "value.h" + +using namespace ledger; + +struct value_fixture { + value_fixture() { + times_initialize(); + amount_t::initialize(); + value_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 + } + + ~value_fixture() + { + amount_t::stream_fullstrings = false; + amount_t::shutdown(); + times_shutdown(); + value_t::shutdown(); + } +}; + +BOOST_FIXTURE_TEST_SUITE(value, value_fixture) + +BOOST_AUTO_TEST_SUITE_END() + -- cgit v1.2.3 From 66478aa89416509c28ecf8a3886a232c2351cf48 Mon Sep 17 00:00:00 2001 From: tripun Date: Sun, 17 Aug 2014 16:20:30 +0530 Subject: add constructors unit test for value --- test/unit/t_value.cc | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'test/unit') diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index 96d644a6..88d1f9fd 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -33,5 +33,40 @@ struct value_fixture { BOOST_FIXTURE_TEST_SUITE(value, value_fixture) +BOOST_AUTO_TEST_CASE(testConstructors) +{ + value_t v1; + value_t v2(true); + value_t v3(boost::posix_time::from_time_t(time_t(NULL))); + value_t v4(date_t(parse_date("2014/08/14"))); + value_t v5(2L); + value_t v6(4UL); + value_t v7(1.00); + 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 v12(string("$1")); + value_t v13("2 CAD"); + value_t v14("comment",true); + value_t v15(string("tag"),true); + + BOOST_CHECK(v1.valid()); + BOOST_CHECK(v2.valid()); + BOOST_CHECK(v3.valid()); + BOOST_CHECK(v4.valid()); + BOOST_CHECK(v5.valid()); + BOOST_CHECK(v6.valid()); + BOOST_CHECK(v7.valid()); + BOOST_CHECK(v8.valid()); + BOOST_CHECK(v9.valid()); + BOOST_CHECK(v10.valid()); + BOOST_CHECK(v11.valid()); + BOOST_CHECK(v12.valid()); + BOOST_CHECK(v13.valid()); + BOOST_CHECK(v14.valid()); + BOOST_CHECK(v15.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 6c7a951a2da1e2aeb395930b573b1bc0f531efaa Mon Sep 17 00:00:00 2001 From: tripun Date: Sun, 17 Aug 2014 16:30:14 +0530 Subject: add assignment unit test for value --- test/unit/t_value.cc | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'test/unit') diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index 88d1f9fd..b6068652 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -68,5 +68,40 @@ BOOST_AUTO_TEST_CASE(testConstructors) BOOST_CHECK(v15.valid()); } +BOOST_AUTO_TEST_CASE(testAssignment) +{ + value_t v1; + value_t v2 = true; + value_t v3 = boost::posix_time::from_time_t(time_t(NULL)); + value_t v4 = date_t(parse_date("2014/08/14")); + value_t v5 = -2L; + value_t v6 = 4UL; + value_t v7 = 1.00; + 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 v12 = new value_t(string("$1")); + value_t v13 = new value_t("2 CAD"); + value_t v14 = new value_t("comment",true); + value_t v15 = new value_t(string("tag"),true); + + BOOST_CHECK(v1.valid()); + BOOST_CHECK(v2.valid()); + BOOST_CHECK(v3.valid()); + BOOST_CHECK(v4.valid()); + BOOST_CHECK(v5.valid()); + BOOST_CHECK(v6.valid()); + BOOST_CHECK(v7.valid()); + BOOST_CHECK(v8.valid()); + BOOST_CHECK(v9.valid()); + BOOST_CHECK(v10.valid()); + BOOST_CHECK(v11.valid()); + BOOST_CHECK(v12.valid()); + BOOST_CHECK(v13.valid()); + BOOST_CHECK(v14.valid()); + BOOST_CHECK(v15.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 2e5520a5cfcbcd17a4eebbc5a180fe465796fe55 Mon Sep 17 00:00:00 2001 From: tripun Date: Sun, 17 Aug 2014 18:53:30 +0530 Subject: add unit test of equality for value --- test/unit/t_value.cc | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'test/unit') diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index b6068652..8d398214 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -103,5 +103,69 @@ BOOST_AUTO_TEST_CASE(testAssignment) BOOST_CHECK(v15.valid()); } +BOOST_AUTO_TEST_CASE(testEquality) +{ + struct tm localtime; + strptime("10 February 2010", "%d %b %Y", &localtime); + time_t time_var = mktime(&localtime); + + value_t v1; + value_t v2(true); + value_t v3(boost::posix_time::from_time_t(time_var)); + value_t v4(date_t(parse_date("2014/08/14"))); + value_t v5(2L); + value_t v6(2UL); + value_t v7(1.00); + 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 v12(string("$1")); + value_t v13("2 CAD"); + value_t v14("comment",true); + value_t v15(string("comment"),true); + value_t v16; + + BOOST_CHECK_EQUAL(v1, value_t()); + BOOST_CHECK_EQUAL(v2, value_t(true)); + BOOST_CHECK_EQUAL(v3, value_t(boost::posix_time::from_time_t(time_var))); + BOOST_CHECK(!(v4 == value_t(date_t(parse_date("2014/08/15"))))); + + value_t v19(amount_t("2")); + value_t v20(balance_t("2")); + BOOST_CHECK_EQUAL(v5, v6); + BOOST_CHECK_EQUAL(v5, v19); + BOOST_CHECK_EQUAL(v5, v20); + BOOST_CHECK(v19 == v5); + BOOST_CHECK(v19 == v20); + BOOST_CHECK(v19 == value_t(amount_t("2"))); + BOOST_CHECK(v20 == v5); + BOOST_CHECK(v20 == v19); + 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_THROW(v8 == v10, value_error); + + BOOST_CHECK(v1.valid()); + BOOST_CHECK(v2.valid()); + BOOST_CHECK(v3.valid()); + BOOST_CHECK(v4.valid()); + BOOST_CHECK(v5.valid()); + BOOST_CHECK(v6.valid()); + BOOST_CHECK(v7.valid()); + BOOST_CHECK(v8.valid()); + BOOST_CHECK(v9.valid()); + BOOST_CHECK(v10.valid()); + BOOST_CHECK(v11.valid()); + BOOST_CHECK(v12.valid()); + BOOST_CHECK(v13.valid()); + BOOST_CHECK(v14.valid()); + BOOST_CHECK(v15.valid()); + BOOST_CHECK(v19.valid()); + BOOST_CHECK(v20.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 2eac1ef328bf8dc7d5f36606d4547a233ab60708 Mon Sep 17 00:00:00 2001 From: tripun Date: Sun, 17 Aug 2014 22:53:30 +0530 Subject: add unit test Addition for value --- test/unit/t_value.cc | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) (limited to 'test/unit') diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index 8d398214..fbf8c25e 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -167,5 +167,107 @@ BOOST_AUTO_TEST_CASE(testEquality) BOOST_CHECK(v20.valid()); } +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 v1; + value_t v2(true); + value_t v3(boost::posix_time::from_time_t(time_var)); + value_t v4(date_t(parse_date("2014/08/14"))); + value_t v5(2L); + value_t v6(2UL); + value_t v7(1.00); + 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 v12(string("$1")); + value_t v13("2 CAD"); + value_t v14("comment", true); + value_t v15(string("comment"), true); + value_t v16(amount_t("2")); + + v14 += v15; + BOOST_CHECK_EQUAL(v14, value_t(string("commentcomment"), true)); + v14 += v12; + BOOST_CHECK_EQUAL(v14, value_t(string("commentcomment$1.00"), true)); + + v3 += value_t(2L); + strptime("10 February 2010 00:00:02", "%d %b %Y %H:%M:%S", &localtime); + BOOST_CHECK_EQUAL(v3, value_t(boost::posix_time::from_time_t(mktime(&localtime)))); + v3 += value_t(amount_t("2")); + strptime("10 February 2010 00:00:04", "%d %b %Y %H:%M:%S", &localtime); + BOOST_CHECK_EQUAL(v3, value_t(boost::posix_time::from_time_t(mktime(&localtime)))); + + v4 += value_t(2L); + BOOST_CHECK_EQUAL(v4, value_t(date_t(parse_date("2014/08/16")))); + v4 += value_t(amount_t("2")); + BOOST_CHECK_EQUAL(v4, value_t(date_t(parse_date("2014/08/18")))); + + v5 += value_t(2L); + BOOST_CHECK_EQUAL(v5, value_t(4L)); + v5 += value_t(amount_t("2")); + BOOST_CHECK_EQUAL(v5, value_t(amount_t("6"))); + v5 += v8; + + v16 += value_t(2L); + v16 += value_t(amount_t("2")); + v16 += v8; + BOOST_CHECK_EQUAL(v5, v16); + + v8 += value_t("6"); + BOOST_CHECK_EQUAL(v8, v16); + + value_t v17(6L); + v17 += value_t(amount_t("4 GBP")); + BOOST_CHECK_EQUAL(v8, v17); + + value_t v18(6L); + v18 += v9; + value_t v19(amount_t("6")); + v19 += v9; + BOOST_CHECK_EQUAL(v18, v19); + + v9 += value_t(2L); + v9 += value_t(amount_t("4")); + v9 += v19; + 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)); + BOOST_CHECK_THROW(v11 += v20,value_error); + BOOST_CHECK_THROW(v10 += v8, value_error); + + v20 += value_t("4 GBP"); + BOOST_CHECK_EQUAL(v11, v20); + + BOOST_CHECK(v1.valid()); + BOOST_CHECK(v2.valid()); + BOOST_CHECK(v3.valid()); + BOOST_CHECK(v4.valid()); + BOOST_CHECK(v5.valid()); + BOOST_CHECK(v6.valid()); + BOOST_CHECK(v7.valid()); + BOOST_CHECK(v8.valid()); + BOOST_CHECK(v9.valid()); + BOOST_CHECK(v10.valid()); + BOOST_CHECK(v11.valid()); + BOOST_CHECK(v12.valid()); + BOOST_CHECK(v13.valid()); + BOOST_CHECK(v14.valid()); + BOOST_CHECK(v15.valid()); + BOOST_CHECK(v16.valid()); + BOOST_CHECK(v17.valid()); + BOOST_CHECK(v18.valid()); + BOOST_CHECK(v19.valid()); + BOOST_CHECK(v20.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 580cb42c81644f46a36a51482aae203380cf3f6e Mon Sep 17 00:00:00 2001 From: tripun Date: Sun, 17 Aug 2014 22:55:09 +0530 Subject: add whitespaces --- test/unit/t_value.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/unit') diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index fbf8c25e..a90523ee 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -48,8 +48,8 @@ BOOST_AUTO_TEST_CASE(testConstructors) value_t v11(new value_t::sequence_t()); value_t v12(string("$1")); value_t v13("2 CAD"); - value_t v14("comment",true); - value_t v15(string("tag"),true); + value_t v14("comment", true); + value_t v15(string("tag"), true); BOOST_CHECK(v1.valid()); BOOST_CHECK(v2.valid()); @@ -122,8 +122,8 @@ BOOST_AUTO_TEST_CASE(testEquality) value_t v11(new value_t::sequence_t()); value_t v12(string("$1")); value_t v13("2 CAD"); - value_t v14("comment",true); - value_t v15(string("comment"),true); + value_t v14("comment", true); + value_t v15(string("comment"), true); value_t v16; BOOST_CHECK_EQUAL(v1, value_t()); -- cgit v1.2.3 From 1834ba568a8d743684e75f29fc644e5342b22b7f Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 00:17:14 +0530 Subject: add unit test subtraction for value --- test/unit/t_value.cc | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) (limited to 'test/unit') diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index a90523ee..d884730e 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -269,5 +269,98 @@ BOOST_AUTO_TEST_CASE(testAddition) BOOST_CHECK(v20.valid()); } +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 v1; + value_t v2(true); + value_t v3(boost::posix_time::from_time_t(time_var)); + value_t v4(date_t(parse_date("2014/08/18"))); + value_t v5(6L); + value_t v6(6UL); + value_t v7(1.00); + 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 v12(string("$1")); + value_t v13("2 CAD"); + value_t v14("comment", true); + value_t v15(string("comment"), true); + value_t v16(amount_t("6")); + + v3 -= value_t(2L); + strptime("10 February 2010 00:00:02", "%d %b %Y %H:%M:%S", &localtime); + BOOST_CHECK_EQUAL(v3, value_t(boost::posix_time::from_time_t(mktime(&localtime)))); + v3 -= value_t(amount_t("2")); + strptime("10 February 2010 00:00:00", "%d %b %Y %H:%M:%S", &localtime); + BOOST_CHECK_EQUAL(v3, value_t(boost::posix_time::from_time_t(mktime(&localtime)))); + + v4 -= value_t(2L); + BOOST_CHECK_EQUAL(v4, value_t(date_t(parse_date("2014/08/16")))); + v4 -= value_t(amount_t("2")); + BOOST_CHECK_EQUAL(v4, value_t(date_t(parse_date("2014/08/14")))); + + v5 -= value_t(2L); + BOOST_CHECK_EQUAL(v5, value_t(4L)); + v5 -= value_t(amount_t("2")); + BOOST_CHECK_EQUAL(v5, value_t(amount_t("2"))); + v5 -= v8; + + v16 -= value_t(2L); + v16 -= value_t(amount_t("2")); + v16 -= v8; + BOOST_CHECK_EQUAL(v5, v16); + + v8 -= value_t("2"); + BOOST_CHECK_EQUAL(-v8, v16); + + value_t v18(6L); + v18 -= v9; + value_t v19(amount_t("6")); + v19 -= v9; + BOOST_CHECK_EQUAL(v18, v19); + + v9 -= value_t(-2L); + v9 -= value_t(amount_t("-10")); + v9 -= value_t(amount_t("12 GBP")); + v9 -= v19; + BOOST_CHECK_EQUAL(v9, v18); + v18 -=v19; + BOOST_CHECK_EQUAL(v18, value_t("0")); + + value_t v20(new value_t::sequence_t()); + 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); + + BOOST_CHECK(v1.valid()); + BOOST_CHECK(v2.valid()); + BOOST_CHECK(v3.valid()); + BOOST_CHECK(v4.valid()); + BOOST_CHECK(v5.valid()); + BOOST_CHECK(v6.valid()); + BOOST_CHECK(v7.valid()); + BOOST_CHECK(v8.valid()); + BOOST_CHECK(v9.valid()); + BOOST_CHECK(v10.valid()); + BOOST_CHECK(v11.valid()); + BOOST_CHECK(v12.valid()); + BOOST_CHECK(v13.valid()); + BOOST_CHECK(v14.valid()); + BOOST_CHECK(v15.valid()); + BOOST_CHECK(v16.valid()); + BOOST_CHECK(v18.valid()); + BOOST_CHECK(v19.valid()); + BOOST_CHECK(v20.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 90f2ca8049b483d6641cc3c86879b3aa88b9f431 Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 00:44:50 +0530 Subject: add Multiplication unit test for value --- test/unit/t_value.cc | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'test/unit') diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index d884730e..a662f786 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -362,5 +362,84 @@ BOOST_AUTO_TEST_CASE(testSubtraction) BOOST_CHECK(v20.valid()); } +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 v1; + value_t v2(true); + value_t v3(boost::posix_time::from_time_t(time_var)); + value_t v4(date_t(parse_date("2014/08/14"))); + value_t v5(2L); + value_t v6(2UL); + value_t v7(1.00); + 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 v12(string("$1")); + value_t v13("2 CAD"); + value_t v14("comment", true); + value_t v15(string("comment"), true); + value_t v16(amount_t("2")); + + v14 *= value_t(2L); + BOOST_CHECK_EQUAL(v14, value_t(string("commentcomment"), true)); + + v5 *= value_t(2L); + BOOST_CHECK_EQUAL(v5, value_t(4L)); + v5 *= value_t(amount_t("2")); + BOOST_CHECK_EQUAL(v5, value_t(amount_t("8"))); + + v16 *= value_t(2L); + v16 *= value_t(amount_t("2")); + BOOST_CHECK_EQUAL(v5, v16); + + v8 *= v9; + BOOST_CHECK_EQUAL(v8, value_t("16 GBP")); + + value_t v17(v9); + v9 *= value_t(2L); + BOOST_CHECK_EQUAL(v9, value_t("8 GBP")); + v17 += value_t(2L); + v17 *= value_t(2L); + value_t v18("8 GBP"); + v18 += value_t(4L); + BOOST_CHECK_EQUAL(v17, 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)); + v20 += value_t("4 GBP"); + v20.push_back(value_t(2L)); + v20 += 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()); + BOOST_CHECK(v3.valid()); + BOOST_CHECK(v4.valid()); + BOOST_CHECK(v5.valid()); + BOOST_CHECK(v6.valid()); + BOOST_CHECK(v7.valid()); + BOOST_CHECK(v8.valid()); + BOOST_CHECK(v9.valid()); + BOOST_CHECK(v10.valid()); + BOOST_CHECK(v11.valid()); + BOOST_CHECK(v12.valid()); + BOOST_CHECK(v13.valid()); + BOOST_CHECK(v14.valid()); + BOOST_CHECK(v15.valid()); + BOOST_CHECK(v16.valid()); + BOOST_CHECK(v17.valid()); + BOOST_CHECK(v18.valid()); + BOOST_CHECK(v20.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 3a87b949960f92b67377c1ed8e9e02657b452b3f Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 00:48:49 +0530 Subject: remove some statements until sequence multiplication run-time error is fixed --- test/unit/t_value.cc | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'test/unit') diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index a662f786..81338cb2 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -409,16 +409,6 @@ BOOST_AUTO_TEST_CASE(testMultiplication) v18 += value_t(4L); BOOST_CHECK_EQUAL(v17, 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)); - v20 += value_t("4 GBP"); - v20.push_back(value_t(2L)); - v20 += 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()); @@ -438,7 +428,6 @@ BOOST_AUTO_TEST_CASE(testMultiplication) BOOST_CHECK(v16.valid()); BOOST_CHECK(v17.valid()); BOOST_CHECK(v18.valid()); - BOOST_CHECK(v20.valid()); } BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 66d89d92f20740d008338bade3dc4b195cbf3692 Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 01:14:36 +0530 Subject: add Division unit test for value --- test/unit/t_value.cc | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'test/unit') diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index 81338cb2..dfbd94d1 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -430,5 +430,68 @@ BOOST_AUTO_TEST_CASE(testMultiplication) BOOST_CHECK(v18.valid()); } +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 v1; + value_t v2(true); + value_t v3(boost::posix_time::from_time_t(time_var)); + value_t v4(date_t(parse_date("2014/08/14"))); + value_t v5(8L); + value_t v6(2UL); + value_t v7(1.00); + 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 v12(string("$1")); + value_t v13("2 CAD"); + value_t v14("comment", true); + value_t v15(string("comment"), true); + value_t v16(amount_t("8")); + + v5 /= value_t(2L); + BOOST_CHECK_EQUAL(v5, value_t(4L)); + v5 /= value_t(amount_t("8")); + BOOST_CHECK_EQUAL(v5, value_t(amount_t("2"))); + + v16 /= value_t(2L); + v16 /= value_t(amount_t("2")); + BOOST_CHECK_EQUAL(v5, v16); + + v8 /= v9; + v8 /= value_t(balance_t(2L)); + BOOST_CHECK_EQUAL(v8, value_t("0.5 GBP")); + + value_t v17(v9); + v9 /= value_t(2L); + BOOST_CHECK_EQUAL(v9, value_t("2 GBP")); + v17 /= value_t("2 GBP"); + v17 /= value_t("2"); + BOOST_CHECK_EQUAL(v17, value_t(balance_t("1 GBP"))); + + BOOST_CHECK_THROW(v10 /= v8, value_error); + BOOST_CHECK(v1.valid()); + BOOST_CHECK(v2.valid()); + BOOST_CHECK(v3.valid()); + BOOST_CHECK(v4.valid()); + BOOST_CHECK(v5.valid()); + BOOST_CHECK(v6.valid()); + BOOST_CHECK(v7.valid()); + BOOST_CHECK(v8.valid()); + BOOST_CHECK(v9.valid()); + BOOST_CHECK(v10.valid()); + BOOST_CHECK(v11.valid()); + BOOST_CHECK(v12.valid()); + BOOST_CHECK(v13.valid()); + BOOST_CHECK(v14.valid()); + BOOST_CHECK(v15.valid()); + BOOST_CHECK(v16.valid()); + BOOST_CHECK(v17.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From e0f2e0ad29204632ffd3be8575173184314932f3 Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 01:24:52 +0530 Subject: check Type unit test for value --- test/unit/t_value.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'test/unit') diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index dfbd94d1..a14ac167 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -493,5 +493,55 @@ BOOST_AUTO_TEST_CASE(testDivision) BOOST_CHECK(v17.valid()); } +BOOST_AUTO_TEST_CASE(testType) +{ + value_t v1; + value_t v2(true); + value_t v3(boost::posix_time::from_time_t(time_t(NULL))); + value_t v4(date_t(parse_date("2014/08/14"))); + value_t v5(2L); + value_t v6(4UL); + value_t v7(1.00); + 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 v12(string("$1")); + value_t v13("2 CAD"); + value_t v14("comment", true); + value_t v15(string("tag"), true); + + BOOST_CHECK(v2.is_boolean()); + BOOST_CHECK(v3.is_datetime()); + BOOST_CHECK(v4.is_date()); + BOOST_CHECK(v5.is_long()); + BOOST_CHECK(v6.is_amount()); + BOOST_CHECK(v7.is_amount()); + BOOST_CHECK(v8.is_amount()); + BOOST_CHECK(v9.is_balance()); + BOOST_CHECK(v10.is_mask()); + BOOST_CHECK(v11.is_boolean()); + BOOST_CHECK(v12.is_amount()); + BOOST_CHECK(v13.is_amount()); + BOOST_CHECK(v14.is_string()); + BOOST_CHECK(v15.is_string()); + + BOOST_CHECK(v1.valid()); + BOOST_CHECK(v2.valid()); + BOOST_CHECK(v3.valid()); + BOOST_CHECK(v4.valid()); + BOOST_CHECK(v5.valid()); + BOOST_CHECK(v6.valid()); + BOOST_CHECK(v7.valid()); + BOOST_CHECK(v8.valid()); + BOOST_CHECK(v9.valid()); + BOOST_CHECK(v10.valid()); + BOOST_CHECK(v11.valid()); + BOOST_CHECK(v12.valid()); + BOOST_CHECK(v13.valid()); + BOOST_CHECK(v14.valid()); + BOOST_CHECK(v15.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 43511a58c11f0643eebd9cafa6fb4e9ba298a438 Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 01:53:06 +0530 Subject: add test for zero for value --- test/unit/t_value.cc | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'test/unit') diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index a14ac167..c9b93272 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -526,6 +526,63 @@ BOOST_AUTO_TEST_CASE(testType) 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()); + BOOST_CHECK(v4.valid()); + BOOST_CHECK(v5.valid()); + BOOST_CHECK(v6.valid()); + BOOST_CHECK(v7.valid()); + BOOST_CHECK(v8.valid()); + BOOST_CHECK(v9.valid()); + BOOST_CHECK(v10.valid()); + BOOST_CHECK(v11.valid()); + BOOST_CHECK(v12.valid()); + BOOST_CHECK(v13.valid()); + BOOST_CHECK(v14.valid()); + BOOST_CHECK(v15.valid()); +} + +BOOST_AUTO_TEST_CASE(testForZero) +{ + value_t v1; + value_t v2(true); + value_t v3(boost::posix_time::from_time_t(time_t(NULL))); + value_t v4(date_t(0)); + value_t v5(2L); + value_t v6(0UL); + value_t v7(1.00); + 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 v12(string("$1")); + value_t v13("2 CAD"); + value_t v14("comment", true); + value_t v15(string(""), true); + + BOOST_CHECK(v1.is_null()); + BOOST_CHECK(v2.is_nonzero()); + BOOST_CHECK(!v3.is_zero()); + BOOST_CHECK(v4.is_nonzero()); + BOOST_CHECK(v5.is_nonzero()); + BOOST_CHECK(v6.is_realzero()); + BOOST_CHECK(v7.is_nonzero()); + 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(v12.is_nonzero()); + BOOST_CHECK(v13.is_nonzero()); + BOOST_CHECK(v14.is_nonzero()); + BOOST_CHECK(v15.is_zero()); + + v11.push_back(v6); + BOOST_CHECK(v11.is_nonzero()); + BOOST_CHECK(v1.valid()); BOOST_CHECK(v2.valid()); BOOST_CHECK(v3.valid()); -- cgit v1.2.3 From f1c3f36e3bf45c9e74359bd64ff91f1aa4a5f525 Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 01:57:19 +0530 Subject: minor additions --- test/unit/t_value.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'test/unit') diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index c9b93272..eae71ea9 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -511,6 +511,7 @@ BOOST_AUTO_TEST_CASE(testType) value_t v14("comment", true); value_t v15(string("tag"), true); + BOOST_CHECK(v1.is_null()); BOOST_CHECK(v2.is_boolean()); BOOST_CHECK(v3.is_datetime()); BOOST_CHECK(v4.is_date()); -- cgit v1.2.3 From c87dd21912b1ecd4cab3aba7de2e5412ce54281b Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 02:33:26 +0530 Subject: add unit test Negation for value --- test/unit/t_value.cc | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'test/unit') diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index eae71ea9..2fbfda3f 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -601,5 +601,51 @@ BOOST_AUTO_TEST_CASE(testForZero) BOOST_CHECK(v15.valid()); } +BOOST_AUTO_TEST_CASE(testNegation) +{ + value_t v1; + value_t v2(true); + value_t v3(boost::posix_time::from_time_t(time_t(NULL))); + value_t v4(date_t(parse_date("2014/08/09"))); + value_t v5(2L); + value_t v6(0UL); + value_t v7(1.00); + 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 v12(string("$1")); + value_t v13("$-1"); + value_t v14("comment", true); + value_t v15(string("comment"), true); + + BOOST_CHECK_THROW(v1.negated(), value_error); + BOOST_CHECK_EQUAL(v2.negated(), value_t(false)); + v5.in_place_negate(); + BOOST_CHECK_EQUAL(v5, value_t(-2L)); + v8.in_place_negate(); + v9.in_place_negate(); + BOOST_CHECK_EQUAL(v8, v9); + BOOST_CHECK_THROW(v10.negated(), value_error); + BOOST_CHECK_EQUAL(-v12, v13); + BOOST_CHECK_THROW(-v14, value_error); + + BOOST_CHECK(v1.valid()); + BOOST_CHECK(v2.valid()); + BOOST_CHECK(v3.valid()); + BOOST_CHECK(v4.valid()); + BOOST_CHECK(v5.valid()); + BOOST_CHECK(v6.valid()); + BOOST_CHECK(v7.valid()); + BOOST_CHECK(v8.valid()); + BOOST_CHECK(v9.valid()); + BOOST_CHECK(v10.valid()); + BOOST_CHECK(v11.valid()); + BOOST_CHECK(v12.valid()); + BOOST_CHECK(v13.valid()); + BOOST_CHECK(v14.valid()); + BOOST_CHECK(v15.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 04d541ed44b189ccdd8ebfc78f4752903c737ca9 Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 22:13:11 +0530 Subject: add test for sequenc_t in value_t --- test/unit/t_value.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'test/unit') diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index 2fbfda3f..b0b9b382 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -167,6 +167,38 @@ BOOST_AUTO_TEST_CASE(testEquality) BOOST_CHECK(v20.valid()); } +BOOST_AUTO_TEST_CASE(testSequence) +{ + value_t::sequence_t s1; + value_t v1(s1); + BOOST_CHECK(v1.is_sequence()); + v1.push_back(value_t(2L)); + v1.push_back(value_t("3 GBP")); + + value_t v2("3 GBP"); + value_t seq(v1); + const value_t v3(seq); + value_t::sequence_t::iterator i = std::find(seq.begin(), seq.end(), v2); + if (i != seq.end()) + BOOST_CHECK(v2 == *i); + value_t::sequence_t::const_iterator j = std::find(v3.begin(), v3.end(), v2); + if (j != v3.end()) + BOOST_CHECK(v2 == *j); + BOOST_CHECK(v2 == seq[1]); + BOOST_CHECK(v2 == v3[1]); + v1.pop_back(); + v1.pop_back(); + v1.push_front(v2); + v1.push_front(value_t(2L)); + BOOST_CHECK(v2 == v1[1]); + BOOST_CHECK(seq == v1); + + BOOST_CHECK(v1.valid()); + BOOST_CHECK(v2.valid()); + BOOST_CHECK(v3.valid()); + BOOST_CHECK(seq.valid()); +} + BOOST_AUTO_TEST_CASE(testAddition) { struct tm localtime; -- cgit v1.2.3 From b2bd337c31b1bf2481f643967b6670ada9d3cb2e Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 23:24:25 +0530 Subject: add additional tests for sequence_t and fix the old ones --- test/unit/t_value.cc | 72 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 22 deletions(-) (limited to 'test/unit') 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); -- cgit v1.2.3 From 9a9d55499ea1a4ca5c2b9efe48d149b8cd2e01df Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 23:28:18 +0530 Subject: fix minor issues --- test/unit/t_value.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'test/unit') diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index ad400daa..e8367bbe 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -83,10 +83,10 @@ BOOST_AUTO_TEST_CASE(testAssignment) value_t v9 = balance_t("3 EUR"); value_t v10 = mask_t("regex"); 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); - value_t v15 = new value_t(string("tag"),true); + value_t v12 = value_t(string("$1")); + value_t v13 = value_t("2 CAD"); + value_t v14 = value_t("comment", true); + value_t v15 = value_t(string("tag"), true); BOOST_CHECK(v1.valid()); BOOST_CHECK(v2.valid()); @@ -181,12 +181,15 @@ BOOST_AUTO_TEST_CASE(testSequence) value_t v2("3 GBP"); value_t seq(v1); const value_t v3(seq); + value_t::sequence_t::iterator i = std::find(seq.begin(), seq.end(), v2); if (i != seq.end()) BOOST_CHECK(v2 == *i); + value_t::sequence_t::const_iterator j = std::find(v3.begin(), v3.end(), v2); if (j != v3.end()) BOOST_CHECK(v2 == *j); + BOOST_CHECK(v2 == seq[1]); BOOST_CHECK(v2 == v3[1]); v1.pop_back(); @@ -468,7 +471,7 @@ BOOST_AUTO_TEST_CASE(testMultiplication) v11 *= value_t(2L); BOOST_CHECK_EQUAL(v11 ,v20); - BOOST_CHECK_THROW(v10 += v8, value_error); + BOOST_CHECK_THROW(v10 *= v8, value_error); BOOST_CHECK(v1.valid()); BOOST_CHECK(v2.valid()); BOOST_CHECK(v3.valid()); -- cgit v1.2.3