diff options
author | John Wiegley <johnw@newartisans.com> | 2009-01-28 20:49:26 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-01-28 20:49:26 -0400 |
commit | e851c02d2747be0acc336bc278da9e0460b75738 (patch) | |
tree | df813c5c572922cf05a6317b7eb1d6062dedac05 /test/unit/t_times.cc | |
parent | 3020f0f8513d8cef04d4a291dc9b5fa50e1b832c (diff) | |
download | fork-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/t_times.cc')
-rw-r--r-- | test/unit/t_times.cc | 142 |
1 files changed, 85 insertions, 57 deletions
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 } |