summaryrefslogtreecommitdiff
path: root/test/unit
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-01-28 20:49:26 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-01-28 20:49:26 -0400
commite851c02d2747be0acc336bc278da9e0460b75738 (patch)
treedf813c5c572922cf05a6317b7eb1d6062dedac05 /test/unit
parent3020f0f8513d8cef04d4a291dc9b5fa50e1b832c (diff)
downloadfork-ledger-e851c02d2747be0acc336bc278da9e0460b75738.tar.gz
fork-ledger-e851c02d2747be0acc336bc278da9e0460b75738.tar.bz2
fork-ledger-e851c02d2747be0acc336bc278da9e0460b75738.zip
Unit test for Python are now auto-generated from the C++ tests.
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/t_amount.cc134
-rw-r--r--test/unit/t_amount.h2
-rw-r--r--test/unit/t_balance.cc1
-rw-r--r--test/unit/t_commodity.cc38
-rw-r--r--test/unit/t_expr.cc5
-rw-r--r--test/unit/t_times.cc142
-rw-r--r--test/unit/t_utils.cc9
7 files changed, 198 insertions, 133 deletions
diff --git a/test/unit/t_amount.cc b/test/unit/t_amount.cc
index c95384a8..6f181555 100644
--- a/test/unit/t_amount.cc
+++ b/test/unit/t_amount.cc
@@ -42,11 +42,13 @@ void AmountTestCase::testParser()
assertEqual(amount_t::precision_t(2), x12.commodity().precision());
+#ifndef NOT_FOR_PYTHON
string buf("$100...");
std::istringstream input(buf);
amount_t x13;
x13.parse(input);
assertEqual(x12, x13);
+#endif // NOT_FOR_PYTHON
amount_t x14;
assertThrow(x14.parse("DM"), amount_error);
@@ -210,6 +212,7 @@ void AmountTestCase::testCommodityConstructors()
assertValid(x10);
}
+#ifndef NOT_FOR_PYTHON
void AmountTestCase::testAssignment()
{
amount_t x0;
@@ -315,6 +318,7 @@ void AmountTestCase::testCommodityAssignment()
assertValid(x9);
assertValid(x10);
}
+#endif // NOT_FOR_PYTHON
void AmountTestCase::testEquality()
{
@@ -350,35 +354,24 @@ void AmountTestCase::testEquality()
void AmountTestCase::testCommodityEquality()
{
amount_t x0;
- amount_t x1;
- amount_t x2;
- amount_t x3;
- amount_t x4;
- amount_t x5;
- amount_t x6;
- amount_t x7;
- amount_t x8;
- amount_t x9;
- amount_t x10;
-
- x1 = "$123.45";
- x2 = "-$123.45";
- x3 = "$-123.45";
- x4 = "DM 123.45";
- x5 = "-DM 123.45";
- x6 = "DM -123.45";
- x7 = "123.45 euro";
- x8 = "-123.45 euro";
- x9 = "123.45€";
- x10 = "-123.45€";
+ amount_t x1("$123.45");
+ amount_t x2("-$123.45");
+ amount_t x3("$-123.45");
+ amount_t x4("DM 123.45");
+ amount_t x5("-DM 123.45");
+ amount_t x6("DM -123.45");
+ amount_t x7("123.45 euro");
+ amount_t x8("-123.45 euro");
+ amount_t x9("123.45€");
+ amount_t x10("-123.45€");
assertTrue(x0.is_null());
assertThrow(x0.is_zero(), amount_error);
assertThrow(x0.is_realzero(), amount_error);
- assertThrow(assert(x0.sign() == 0), amount_error);
- assertThrow(assert(x0.compare(x1) < 0), amount_error);
- assertThrow(assert(x0.compare(x2) > 0), amount_error);
- assertThrow(assert(x0.compare(x0) == 0), amount_error);
+ assertThrow(x0.sign() == 0, amount_error);
+ assertThrow(x0.compare(x1) < 0, amount_error);
+ assertThrow(x0.compare(x2) > 0, amount_error);
+ assertThrow(x0.compare(x0) == 0, amount_error);
assertTrue(x1 != x2);
assertTrue(x1 != x4);
@@ -1335,7 +1328,7 @@ void AmountTestCase::testTruth()
amount_t x1("1234");
amount_t x2("1234.56");
- assertThrow(assert(x0 ? 1 : 0), amount_error);
+ assertThrow(x0 ? 1 : 0, amount_error);
assertTrue(x1);
assertTrue(x2);
@@ -1442,24 +1435,24 @@ void AmountTestCase::testCommodityConversion()
assertValid(x1);
}
+#ifndef NOT_FOR_PYTHON
void AmountTestCase::testPrinting()
{
amount_t x0;
amount_t x1("982340823.380238098235098235098235098");
-#if 0
{
- std::ostringstream bufstr;
- assertThrow(bufstr << x0, amount_error);
+ std::ostringstream bufstr;
+ x0.print(bufstr);
+ assertEqual(std::string("<null>"), bufstr.str());
}
-#endif
{
- std::ostringstream bufstr;
- bufstr << x1;
+ std::ostringstream bufstr;
+ x1.print(bufstr);
- assertEqual(std::string("982340823.380238098235098235098235098"),
- bufstr.str());
+ assertEqual(std::string("982340823.380238098235098235098235098"),
+ bufstr.str());
}
assertValid(x0);
@@ -1472,26 +1465,26 @@ void AmountTestCase::testCommodityPrinting()
amount_t x2("$982340823.38");
{
- std::ostringstream bufstr;
- bufstr << x1;
+ std::ostringstream bufstr;
+ x1.print(bufstr);
- assertEqual(std::string("$982340823.386238098235098235098235098"),
- bufstr.str());
+ assertEqual(std::string("$982340823.386238098235098235098235098"),
+ bufstr.str());
}
{
- std::ostringstream bufstr;
- bufstr << (x1 * x2).to_string();
+ std::ostringstream bufstr;
+ (x1 * x2).print(bufstr);
- assertEqual(std::string("$964993493285024293.18099172508158508135413499124"),
- bufstr.str());
+ assertEqual(std::string("$964993493285024293.18099172508158508135413499124"),
+ bufstr.str());
}
{
- std::ostringstream bufstr;
- bufstr << (x2 * x1).to_string();
+ std::ostringstream bufstr;
+ (x2 * x1).print(bufstr);
- assertEqual(std::string("$964993493285024293.18"), bufstr.str());
+ assertEqual(std::string("$964993493285024293.18"), bufstr.str());
}
assertValid(x1);
@@ -1512,14 +1505,14 @@ void AmountTestCase::testSerialization()
std::string buf;
{
- std::ostringstream storage;
- assertThrow(x0.write(storage), amount_error);
- x1.write(storage);
- x2.write(storage);
- x3.write(storage);
- x4.write(storage);
- x5.write(storage);
- buf = storage.str();
+ std::ostringstream storage;
+ assertThrow(x0.write(storage), amount_error);
+ x1.write(storage);
+ x2.write(storage);
+ x3.write(storage);
+ x4.write(storage);
+ x5.write(storage);
+ buf = storage.str();
}
amount_t x1b;
@@ -1528,12 +1521,12 @@ void AmountTestCase::testSerialization()
amount_t x4b;
amount_t x5b;
{
- std::istringstream storage(buf);
- x1b.read(storage);
- x2b.read(storage);
- x3b.read(storage);
- x4b.read(storage);
- x5b.read(storage);
+ std::istringstream storage(buf);
+ x1b.read(storage);
+ x2b.read(storage);
+ x3b.read(storage);
+ x4b.read(storage);
+ x5b.read(storage);
}
assertEqual(x1, x1b);
@@ -1541,6 +1534,7 @@ void AmountTestCase::testSerialization()
assertEqual(x3, x3b);
assertEqual(x4, x4b);
+#ifndef NOT_FOR_PYTHON
const char * ptr = buf.c_str();
amount_t x1c;
@@ -1549,17 +1543,18 @@ void AmountTestCase::testSerialization()
amount_t x4c;
amount_t x5c;
{
- x1c.read(ptr);
- x2c.read(ptr);
- x3c.read(ptr);
- x4c.read(ptr);
- x5c.read(ptr);
+ x1c.read(ptr);
+ x2c.read(ptr);
+ x3c.read(ptr);
+ x4c.read(ptr);
+ x5c.read(ptr);
}
assertEqual(x1, x1b);
assertEqual(x2, x2b);
assertEqual(x3, x3b);
assertEqual(x4, x4b);
+#endif // NOT_FOR_PYTHON
assertValid(x1);
assertValid(x2);
@@ -1574,3 +1569,14 @@ void AmountTestCase::testSerialization()
assertValid(x3c);
assertValid(x4c);
}
+
+void AmountTestCase::testXmlSerialization()
+{
+ amount_t x1("$8,192.34");
+
+ std::ostringstream storage;
+ x1.write_xml(storage);
+
+ assertEqual(std::string("<amount>\n <commodity flags=\"PT\">\n <symbol>$</symbol>\n </commodity>\n <quantity>8192.34</quantity>\n</amount>\n"), storage.str());
+}
+#endif // NOT_FOR_PYTHON
diff --git a/test/unit/t_amount.h b/test/unit/t_amount.h
index a8310673..21224a09 100644
--- a/test/unit/t_amount.h
+++ b/test/unit/t_amount.h
@@ -48,6 +48,7 @@ class AmountTestCase : public CPPUNIT_NS::TestCase
CPPUNIT_TEST(testPrinting);
CPPUNIT_TEST(testCommodityPrinting);
CPPUNIT_TEST(testSerialization);
+ CPPUNIT_TEST(testXmlSerialization);
CPPUNIT_TEST_SUITE_END();
@@ -99,6 +100,7 @@ public:
void testPrinting();
void testCommodityPrinting();
void testSerialization();
+ void testXmlSerialization();
private:
AmountTestCase(const AmountTestCase &copy);
diff --git a/test/unit/t_balance.cc b/test/unit/t_balance.cc
index 93d97d6a..78a3a3fc 100644
--- a/test/unit/t_balance.cc
+++ b/test/unit/t_balance.cc
@@ -26,4 +26,5 @@ void BalanceTestCase::tearDown()
void BalanceTestCase::testConstructors()
{
+ int x = 1;
}
diff --git a/test/unit/t_commodity.cc b/test/unit/t_commodity.cc
index 62ec557e..a75fb727 100644
--- a/test/unit/t_commodity.cc
+++ b/test/unit/t_commodity.cc
@@ -17,14 +17,25 @@ void CommodityTestCase::tearDown() {
void CommodityTestCase::testPriceHistory()
{
- datetime_t jan17_05 = parse_datetime("2005/01/17 00:00:00");
- datetime_t jan17_06 = parse_datetime("2006/01/17 00:00:00");
- datetime_t jan17_07 = parse_datetime("2007/01/17 00:00:00");
- datetime_t feb27_07 = parse_datetime("2007/02/27 18:00:00");
- datetime_t feb28_07 = parse_datetime("2007/02/28 06:00:00");
- datetime_t feb28_07sbm = parse_datetime("2007/02/28 11:59:59");
- datetime_t mar01_07 = parse_datetime("2007/03/01 00:00:00");
- datetime_t apr15_07 = parse_datetime("2007/04/15 13:00:00");
+#ifndef NOT_FOR_PYTHON
+ datetime_t jan17_05;
+ datetime_t jan17_06;
+ datetime_t jan17_07;
+ datetime_t feb27_07;
+ datetime_t feb28_07;
+ datetime_t feb28_07sbm;
+ datetime_t mar01_07;
+ datetime_t apr15_07;
+#endif // NOT_FOR_PYTHON
+
+ jan17_05 = parse_datetime("2005/01/17 00:00:00");
+ jan17_06 = parse_datetime("2006/01/17 00:00:00");
+ jan17_07 = parse_datetime("2007/01/17 00:00:00");
+ feb27_07 = parse_datetime("2007/02/27 18:00:00");
+ feb28_07 = parse_datetime("2007/02/28 06:00:00");
+ feb28_07sbm = parse_datetime("2007/02/28 11:59:59");
+ mar01_07 = parse_datetime("2007/03/01 00:00:00");
+ apr15_07 = parse_datetime("2007/04/15 13:00:00");
amount_t x0;
amount_t x1("100.10 AAPL");
@@ -45,15 +56,18 @@ void CommodityTestCase::testPriceHistory()
aapl.add_price(jan17_05, amount_t("EUR 23.00"));
aapl.add_price(jan17_06, amount_t("CAD 25.00"));
- commodity_t& euro(amount_t("EUR 1.00").commodity());
+ amount_t one_euro("EUR 1.00");
+ commodity_t& euro(one_euro.commodity());
euro.add_price(feb27_07, amount_t("CAD 1.40"));
euro.add_price(jan17_05, amount_t("$0.78"));
- commodity_t& cad(amount_t("CAD 1.00").commodity());
+ amount_t one_cad("CAD 1.00");
+ commodity_t& cad(one_cad.commodity());
cad.add_price(jan17_06, amount_t("$1.11"));
+#ifndef NOT_FOR_PYTHON
optional<amount_t> amt = x1.value(feb28_07sbm);
assertTrue(amt);
assertEqual(amount_t("$1831.83"), *amt);
@@ -76,6 +90,7 @@ void CommodityTestCase::testPriceHistory()
amt = x1.value(current_time, cad);
assertTrue(amt);
assertEqual(amount_t("CAD 3223.22"), *amt);
+#endif // NOT_FOR_PYTHON
assertValid(x1);
}
@@ -83,15 +98,18 @@ void CommodityTestCase::testPriceHistory()
void CommodityTestCase::testLots()
{
// jww (2007-04-17): tbd
+ int x = 1;
}
void CommodityTestCase::testScalingBase()
{
// jww (2007-04-17): tbd
+ int x = 1;
}
void CommodityTestCase::testReduction()
{
// jww (2007-04-17): tbd
+ int x = 1;
}
diff --git a/test/unit/t_expr.cc b/test/unit/t_expr.cc
index a6655f6a..209bb934 100644
--- a/test/unit/t_expr.cc
+++ b/test/unit/t_expr.cc
@@ -9,15 +9,20 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ValueExprTestCase, "expr");
void ValueExprTestCase::setUp()
{
amount_t::initialize();
+#ifndef NOT_FOR_PYTHON
expr_t::initialize();
+#endif // NOT_FOR_PYTHON
}
void ValueExprTestCase::tearDown()
{
+#ifndef NOT_FOR_PYTHON
expr_t::shutdown();
+#endif // NOT_FOR_PYTHON
amount_t::shutdown();
}
void ValueExprTestCase::testConstructors()
{
+ int x = 1;
}
diff --git a/test/unit/t_times.cc b/test/unit/t_times.cc
index 7f35bf50..a249ad3b 100644
--- a/test/unit/t_times.cc
+++ b/test/unit/t_times.cc
@@ -1,81 +1,109 @@
#include "t_times.h"
+#include "utils.h"
+
+using namespace ledger;
+
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(DateTimeTestCase, "util");
-void DateTimeTestCase::setUp() {}
-void DateTimeTestCase::tearDown() {}
+void DateTimeTestCase::setUp() {
+ int x = 1;
+}
+void DateTimeTestCase::tearDown() {
+ int x = 1;
+}
void DateTimeTestCase::testConstructors()
{
-#if 0
- std::time_t time_t_now = std::time(NULL);
- struct tm * moment = std::localtime(&time_t_now);
-
+#ifndef NOT_FOR_PYTHON
+ std::time_t now = std::time(NULL);
+ struct tm * moment = std::localtime(&now);
std::time_t localMoment = std::mktime(moment);
+#endif // NOT_FOR_PYTHON
- ptime d0;
- ptime d1(parse_datetime("1990/01/01"));
- ptime d3(boost::posix_time::from_time_t(localMoment));
- ptime d4(parse_datetime("2006/12/25"));
- //ptime d5(parse_datetime("12/25"));
- ptime d6(parse_datetime("2006.12.25"));
- //ptime d7(parse_datetime("12.25"));
- ptime d8(parse_datetime("2006-12-25"));
- //ptime d9(parse_datetime("12-25"));
-#if 0
- ptime d10(parse_datetime("tue"));
- ptime d11(parse_datetime("tuesday"));
- ptime d12(parse_datetime("feb"));
- ptime d13(parse_datetime("february"));
- ptime d14(parse_datetime("2006"));
-#endif
- ptime d15(d3);
+#ifndef NOT_FOR_PYTHON
+ datetime_t d0;
+ datetime_t d1;
+ datetime_t d3;
+ datetime_t d4;
+ datetime_t d5;
+ datetime_t d6;
+ datetime_t d7;
+ datetime_t d8;
+ datetime_t d9;
+
+ datetime_t d10;
+ datetime_t d11;
+ datetime_t d12;
+ datetime_t d13;
+ datetime_t d14;
+ datetime_t d15;
+#endif // NOT_FOR_PYTHON
+ d1 = parse_datetime("1990/01/01");
+#ifndef NOT_FOR_PYTHON
+ d3 = boost::posix_time::from_time_t(localMoment);
+#endif // NOT_FOR_PYTHON
+ d4 = parse_datetime("2006/12/25");
+ d5 = parse_datetime("12/25");
+ d6 = parse_datetime("2006.12.25");
+ d7 = parse_datetime("12.25");
+ d8 = parse_datetime("2006-12-25");
+ d9 = parse_datetime("12-25");
+
+ d10 = parse_datetime("tue");
+ d11 = parse_datetime("tuesday");
+ d12 = parse_datetime("feb");
+ d13 = parse_datetime("february");
+ d14 = parse_datetime("2006");
+#ifndef NOT_FOR_PYTHON
+ d15 = d3;
+#endif // NOT_FOR_PYTHON
+
+#ifndef NOT_FOR_PYTHON
assertTrue(d0.is_not_a_date_time());
assertFalse(d1.is_not_a_date_time());
assertFalse(d4.is_not_a_date_time());
+#endif // NOT_FOR_PYTHON
- assertTrue(now > d1);
- //assertTrue(now <= d3);
- assertTrue(now > d4);
+ assertTrue(current_time > d1);
+ assertTrue(current_time > d4);
+#ifndef NOT_FOR_PYTHON
assertEqual(d3, d15);
+#endif // NOT_FOR_PYTHON
assertEqual(d4, d6);
assertEqual(d4, d8);
- //assertEqual(d5, d7);
- //assertEqual(d5, d9);
-#if 0
+ assertEqual(d5, d7);
+ assertEqual(d5, d9);
assertEqual(d10, d11);
assertEqual(d12, d13);
-#endif
#if 0
- assertThrow(parse_datetime("2007/02/29"), datetime_error *);
- assertThrow(parse_datetime("2007/13/01"), datetime_error *);
- assertThrow(parse_datetime("2007/00/01"), datetime_error *);
- assertThrow(parse_datetime("2007/01/00"), datetime_error *);
- assertThrow(parse_datetime("2007/00/00"), datetime_error *);
- assertThrow(parse_datetime("2007/05/32"), datetime_error *);
-
- assertThrow(parse_datetime("2006x/12/25"), datetime_error *);
- assertThrow(parse_datetime("2006/12x/25"), datetime_error *);
- //assertThrow(parse_datetime("2006/12/25x"), datetime_error *);
-
- assertThrow(parse_datetime("feb/12/25"), datetime_error *);
- assertThrow(parse_datetime("2006/mon/25"), datetime_error *);
- assertThrow(parse_datetime("2006/12/web"), datetime_error *);
-
- assertThrow(parse_datetime("12*25"), datetime_error *);
-
- assertThrow(parse_datetime("tuf"), datetime_error *);
- assertThrow(parse_datetime("tufsday"), datetime_error *);
- assertThrow(parse_datetime("fec"), datetime_error *);
- assertThrow(parse_datetime("fecruary"), datetime_error *);
- assertThrow(parse_datetime("207x"), datetime_error *);
- assertThrow(parse_datetime("hello"), datetime_error *);
-
- interval_t i1;
- interval_t i2;
-#endif
+#ifndef NOT_FOR_PYTHON
+ assertThrow(parse_datetime("2007/02/29"), boost::gregorian::bad_day_of_month);
+ //assertThrow(parse_datetime("2007/13/01"), datetime_error);
+ //assertThrow(parse_datetime("2007/00/01"), datetime_error);
+ assertThrow(parse_datetime("2007/01/00"), boost::gregorian::bad_day_of_month);
+ //assertThrow(parse_datetime("2007/00/00"), boost::gregorian::bad_day_of_month);
+ //assertThrow(parse_datetime("2007/05/32"), boost::gregorian::bad_day_of_month);
+
+ assertThrow(parse_datetime("2006x/12/25"), datetime_error);
+ assertThrow(parse_datetime("2006/12x/25"), datetime_error);
+ assertThrow(parse_datetime("2006/12/25x"), datetime_error);
+
+ assertThrow(parse_datetime("feb/12/25"), datetime_error);
+ assertThrow(parse_datetime("2006/mon/25"), datetime_error);
+ assertThrow(parse_datetime("2006/12/web"), datetime_error);
+
+ assertThrow(parse_datetime("12*25"), datetime_error);
+
+ assertThrow(parse_datetime("tuf"), datetime_error);
+ assertThrow(parse_datetime("tufsday"), datetime_error);
+ assertThrow(parse_datetime("fec"), datetime_error);
+ assertThrow(parse_datetime("fecruary"), datetime_error);
+ assertThrow(parse_datetime("207x"), datetime_error);
+ assertThrow(parse_datetime("hello"), datetime_error);
+#endif // NOT_FOR_PYTHON
#endif
}
diff --git a/test/unit/t_utils.cc b/test/unit/t_utils.cc
index 57c2a5d4..3c32cf78 100644
--- a/test/unit/t_utils.cc
+++ b/test/unit/t_utils.cc
@@ -2,9 +2,14 @@
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(UtilitiesTestCase, "util");
-void UtilitiesTestCase::setUp() {}
-void UtilitiesTestCase::tearDown() {}
+void UtilitiesTestCase::setUp() {
+ int x = 1;
+}
+void UtilitiesTestCase::tearDown() {
+ int x = 1;
+}
void UtilitiesTestCase::testConstructors()
{
+ int x = 1;
}