Use Boost.Test instead of CppUnit

This commit is contained in:
John Wiegley 2010-06-19 13:33:47 -04:00
parent c9730d781c
commit 2a2c3c1cec
28 changed files with 992 additions and 1625 deletions

View file

@ -64,7 +64,6 @@ h3. For building the current master branch
|gettext|0.17|_optional_|
|libedit|20090111-3.0|_optional_|
|Python|2.4|_optional_|
|cppunit|1.12.1|_optional_, for @make check@|
|doxygen|1.5.7.1|_optional_, for @make docs@|
|graphviz|2.20.3|_optional_, for @make docs@|
|texinfo|4.13|_optional_, for @make docs@|
@ -90,7 +89,7 @@ sudo port install -f automake autoconf libtool python26
libiconv +universal zlib +universal gmp +universal
mpfr +universal ncurses +universal ncursesw +universal
gettext +universal libedit +universal boost-jam
boost +st+python26+icu cppunit texlive doxygen graphviz
boost +st+python26+icu texlive doxygen graphviz
texinfo lcov sloccount
</pre>

10
acprep
View file

@ -809,7 +809,6 @@ class PrepareBuild(CommandLineApp):
'ncursesw', '+universal',
'gettext' ,'+universal',
'libedit' ,'+universal',
'cppunit', '+universal',
#'texlive',
#'doxygen',
#'graphviz',
@ -847,7 +846,6 @@ class PrepareBuild(CommandLineApp):
'gettext',
'cvs',
'libedit-dev',
'libcppunit-dev',
#'texlive-full',
#'doxygen',
#'graphviz',
@ -871,7 +869,6 @@ class PrepareBuild(CommandLineApp):
'libgmp3-dev',
'libmpfr-dev',
'libedit-dev',
'libcppunit-dev',
#'texlive-full',
#'doxygen',
#'graphviz',
@ -902,7 +899,6 @@ class PrepareBuild(CommandLineApp):
'gettext-devel',
#'mpfr-devel'
'libedit-devel',
'cppunit-devel',
#'texlive-full',
#'doxygen',
#'graphviz',
@ -975,12 +971,6 @@ class PrepareBuild(CommandLineApp):
self.CPPFLAGS.append('-D_GLIBCXX_FULLY_DYNAMIC_STRING=1')
if self.current_flavor == 'debug':
if exists('/usr/local/stow/cppunit-%s/include' % self.boost_inc_ident):
self.sys_include_dirs.insert(
0, '/usr/local/stow/cppunit-%s/include' % self.boost_inc_ident)
self.sys_library_dirs.insert(
0, '/usr/local/stow/cppunit-%s/lib' % self.boost_inc_ident)
if exists('/usr/local/stow/icu-%s/include' % self.boost_inc_ident):
self.sys_include_dirs.insert(
0, '/usr/local/stow/icu-%s/include' % self.boost_inc_ident)

View file

@ -45,7 +45,7 @@ BOOST_ICU_DIR = boost_$(BOOST_VERSION)-icu-$(DIR_SUFFIX)
BOOST_ICU_STOW = $(STOW_ROOT)/$(BOOST_ICU_DIR)
BOOST_ICU_BUILD = $(PRODUCTS)/$(BOOST_ICU_DIR)
all: boost-build cppunit-build #icu-build boost-icu-build
all: boost-build #icu-build boost-icu-build
prepare-boost:
perl -i -pe 's/local command = \[ common\.get-invocation-command darwin : g\+\+ : \$$\(command\) \] ;/local command = [ common.get-invocation-command darwin : g++ : $(CXX) ] ;/;' $(BOOST_SOURCE)/tools/build/v2/tools/darwin.jam
@ -57,17 +57,6 @@ boost-build: prepare-boost
./bjam $(OPTJ) debug --prefix=$(BOOST_STOW) --build-dir=$(BOOST_BUILD) \
$(BOOST_FLAGS) install)
cppunit-build:
-(cd cppunit; make distclean)
(cd cppunit; sh autogen.sh; \
./configure CPPFLAGS="$(CPPFLAGS)" \
CFLAGS="$(CFLAGS)" \
LDFLAGS="$(LDFLAGS)" \
CC="$(CC)" CXX="$(CXX)" LD="$(LD)" \
--prefix=$(STOW_ROOT)/cppunit-$(DIR_SUFFIX) \
--disable-doxygen --disable-dot && \
make install)
#icu-build:
# -(cd icu/source; make distclean)
# (cd icu/source; sh autogen.sh; \
@ -87,11 +76,8 @@ cppunit-build:
clean:
-rm -fr $(BOOST_STOW) $(BOOST_BUILD)
-rm -fr $(BOOST_ICU_STOW) $(BOOST_ICU_BUILD)
-rm -fr $(STOW_ROOT)/cppunit-$(DIR_SUFFIX)
-rm -fr $(STOW_ROOT)/icu-$(DIR_SUFFIX)
-(cd cppunit; make distclean)
-(cd icu/source; make distclean)
lib-clean:
-(cd cppunit; make distclean)
-(cd icu/source; make distclean)

View file

@ -1,3 +0,0 @@
#include <cppunit/extensions/HelperMacros.h>
CPPUNIT_REGISTRY_ADD_TO_DEFAULT("data");

View file

@ -1,3 +0,0 @@
#include <cppunit/extensions/HelperMacros.h>
CPPUNIT_REGISTRY_ADD_TO_DEFAULT("expr");

View file

@ -1,3 +0,0 @@
#include <cppunit/extensions/HelperMacros.h>
CPPUNIT_REGISTRY_ADD_TO_DEFAULT("math");

View file

@ -1,3 +0,0 @@
#include <cppunit/extensions/HelperMacros.h>
CPPUNIT_REGISTRY_ADD_TO_DEFAULT("report");

View file

@ -1,116 +0,0 @@
#include <system.hh>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>
#include <cppunit/TextTestProgressListener.h>
#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/XmlOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include "UnitTests.h"
#include "utils.h"
// Create the CppUnit registry
CPPUNIT_REGISTRY_ADD_TO_DEFAULT("Framework");
// Create a sample test, which acts both as a template, and a
// verification that the basic framework is functioning.
class UnitTests : public CPPUNIT_NS::TestCase
{
CPPUNIT_TEST_SUITE( UnitTests );
CPPUNIT_TEST( testInitialization );
CPPUNIT_TEST_SUITE_END();
public:
UnitTests() {}
virtual ~UnitTests() {}
virtual void setUp() {}
virtual void tearDown() {}
void testInitialization() {
assertEqual(std::string("Hello, world!"),
std::string("Hello, world!"));
}
private:
UnitTests( const UnitTests &copy );
void operator =( const UnitTests &copy );
};
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(UnitTests, "framework");
// Create the various runners and commence running the tests!
int main(int argc, char* argv[])
{
int index = 1;
if (argc > index && std::string(argv[index]) == "--verify") {
#if defined(VERIFY_ON)
ledger::verify_enabled = true;
#endif
index++;
}
// Retreive test path from command line first argument. Default to
// "" which resolves to the top level suite.
std::string testPath = ((argc > index) ? std::string(argv[index]) :
std::string(""));
// Create the event manager and test controller
CPPUNIT_NS::TestResult controller;
// Add a listener that collects test results
CPPUNIT_NS::TestResultCollector result;
controller.addListener(&result);
// Add a listener that print dots as test run.
#if 1
CPPUNIT_NS::TextTestProgressListener progress;
#else
CPPUNIT_NS::BriefTestProgressListener progress;
#endif
controller.addListener(&progress);
// Add the top suite to the test runner
CPPUNIT_NS::TestRunner runner;
runner.addTest(CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest());
try {
#if defined(VERIFY_ON)
IF_VERIFY()
ledger::initialize_memory_tracing();
#endif
runner.run(controller, testPath);
#if defined(VERIFY_ON)
IF_VERIFY()
ledger::shutdown_memory_tracing();
#endif
#if 1
// Print test in a compiler compatible format.
CPPUNIT_NS::CompilerOutputter outputter(&result, CPPUNIT_NS::stdCOut());
outputter.write();
#else
// Uncomment this for XML output
std::ofstream file("tests.xml");
CPPUNIT_NS::XmlOutputter xml(&result, file);
xml.setStyleSheet("report.xsl");
xml.write();
file.close();
#endif
}
catch (std::invalid_argument &e) { // Test path not resolved
CPPUNIT_NS::stdCOut() << "\nERROR: " << e.what() << "\n";
return 0;
}
return result.wasSuccessful() ? 0 : 1;
}

View file

@ -1,20 +0,0 @@
#ifndef _UNITTESTS_H
#define _UNITTESTS_H
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/Exception.h>
#include <cppunit/Portability.h>
#define assertDoublesEqual(x,y,z,w) CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(x,y,z,w)
#define assertEqual(x,y) CPPUNIT_ASSERT_EQUAL(x,y)
#define assertNotEqual(x,y) CPPUNIT_ASSERT((x) != (y))
#define assertTrue(x) CPPUNIT_ASSERT(x)
#define assertFalse(x) CPPUNIT_ASSERT(! (x))
#define assertValid(x) CPPUNIT_ASSERT((x).valid())
#define assertEqualMessage(x,y,z) CPPUNIT_ASSERT_EQUAL_MESSAGE(x,y,z)
#define assertMessage(x,y) CPPUNIT_ASSERT_MESSAGE(x,y)
#define assertThrow(x,y) CPPUNIT_ASSERT_THROW(x,y)
#define internalAmount(x) amount_t::exact(x)
#endif /* _UNITTESTS_H */

View file

@ -1,3 +0,0 @@
#include <cppunit/extensions/HelperMacros.h>
CPPUNIT_REGISTRY_ADD_TO_DEFAULT("util");

View file

@ -1,9 +1,9 @@
#!/usr/bin/env python
# convert.py: This script converts a C++ Ledger unit test into an equivalent
# Python unit test.
# convert.py: This script converts a Boost.Test unit test into an
# equivalent Python unit test.
#
# Copyright (c) 2003-2009, John Wiegley. All rights reserved.
# Copyright (c) 2003-2010, John Wiegley. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
@ -61,12 +61,10 @@ from datetime import *
internalAmount = Amount.exact
class %sTestCase(unittest.TestCase):
testSession = None
def assertValid(self, amt):
self.assertTrue(amt.valid())''' % os.path.basename(base))
testSession = None''' % os.path.basename(base))
not_for_python = 0
class_name = None
for line in fd.readlines():
if re.match('^#ifndef NOT_FOR_PYTHON', line):
@ -83,6 +81,32 @@ for line in fd.readlines():
continue
if not re.search('assert', line):
match = re.match('^};', line)
if match:
continue
match = re.match('BOOST_.*_TEST_SUITE', line)
if match:
continue
match = re.match('^struct (.*?) {', line)
if match:
class_name = match.group(1)
continue
if class_name:
match = re.search('(~)?%s\(\) {' % class_name, line)
if match:
if match.group(1):
fo.write(' def tearDown(self):\n')
else:
fo.write(' def setUp(self):\n')
continue
match = re.match('BOOST_AUTO_TEST_CASE\((.+?)\)', line)
if match:
fo.write(' def %s(self):\n' % match.group(1))
continue
match = re.match('void [^:]+::(test[^(]+|setUp|tearDown)\(\)', line)
if match:
fo.write(' def %s(self):\n' % match.group(1))
@ -105,19 +129,15 @@ for line in fd.readlines():
if match:
line = ' %s = %s\n' % (match.group(2), match.group(3))
line = re.sub('CPPUNIT_ASSERT', 'self.assertTrue', line)
line = re.sub('assertValid', 'self.assertValid', line)
line = re.sub('assertTrue', 'self.assertTrue', line)
line = re.sub('assertFalse', 'self.assertFalse', line)
line = re.sub('assertNotEqual', 'self.assertNotEqual', line)
line = re.sub('assertEqual', 'self.assertEqual', line)
line = re.sub('assertThrow\(([^,]+), ([^,)]+?)\)',
line = re.sub('BOOST_CHECK_NE', 'self.assertNotEqual', line)
line = re.sub('BOOST_CHECK_EQUAL', 'self.assertEqual', line)
line = re.sub('BOOST_CHECK_THROW\(([^,]+), ([^,)]+?)\)',
'self.assertRaises(\\2, lambda: \\1)', line)
#line = re.sub('optional<([^>]+?)>', '\\1', line)
line = re.sub('amount_t::precision_t\(([^)]+?)\)', '\\1', line)
line = re.sub('BOOST_CHECK', 'self.assertTrue', line)
# Determine this list automatically by scanning the class_ lines in
# src/py_*.cc
# jww (2010-06-20): Determine this list automatically by scanning
# the class_ lines in src/py_*.cc
line = re.sub('amount_t::precision_t\(([^)]+?)\)', '\\1', line)
line = re.sub('amount_t::', 'Amount.', line)
line = re.sub('Amount\.PARSE_', 'AmountParse.', line)
line = re.sub('commodity_t\(([^)]+?)\)', '\\1', line)

View file

@ -1,11 +0,0 @@
#!/bin/sh
if [ -n "$1" ]; then
ledger --seed=$1 --actual --args-only generate > /tmp/cout
else
ledger --actual --args-only generate > /tmp/cout
fi
ledger -f /tmp/cout --actual --args-only print > /tmp/print
diff -w -U3 /tmp/cout /tmp/print

View file

@ -1,180 +0,0 @@
#!/usr/bin/env python
import random
import string
import signal
import os
import sys
true, false = 1, 0
options = [
"--account=TempAccount",
"--actual",
"--add-budget",
"--amount-data",
"--amount=a",
"--ansi",
"--ansi-invert",
"--average",
#"--balance-format",
"--basis",
"--begin=2004/01",
"--budget",
"--by-payee",
#"--cache=/tmp/cache",
"--cleared",
"--collapse",
"--comm-as-payee",
#"--csv-register-format",
"--current",
"--date-format=%Y",
"--descend='$100'",
"--descend-if='t=={$100}'",
"--deviation",
"--display='a>10'",
"--dow",
"--download",
"--effective",
"--empty",
"--end=2005/01",
#"--equity-format",
#"--file=/tmp/file",
"--forecast='d<[2006]'",
"--format=%Y",
#"--full-help",
"--gain",
"--head=10",
#"--help",
#"--help-calc",
#"--help-comm",
#"--help-disp",
#"--init-file=/tmp/init",
#"--input-date-format",
"--limit='a>10'",
"--lots",
"--lot-prices",
"--lot-dates",
"--lot-tags",
"--market",
"--monthly",
"--no-cache",
#"--output=/tmp/output",
#"--pager",
#"--percentage",
"--performance",
"--period-sort=A\\(t\\)",
"--period=oct",
#"--plot-amount-format",
#"--plot-total-format",
"--price",
"--price-exp=1000",
#"--price-db=/tmp/foo",
#"--prices-format",
#"--print-format",
"--quantity",
"--real",
#"--reconcile",
#"--reconcile-date",
#"--register-format",
"--related",
"--sort=A\\(t\\)",
"--subtotal",
"--tail=5",
"--total-data",
"--total=O",
"--totals",
"--unbudgeted",
"--uncleared",
#"--version",
"--weekly",
"--wide",
"--yearly",
]
commands = [
"bal rent",
"bal ira",
"bal auto",
"reg rent",
"reg ira",
"reg expenses:food",
"print rent",
"print irc",
"xml rent",
"xml irc",
"equity rent",
"equity ira",
"prices AAPL",
]
random.seed ()
loop = true
count = 0
errors = 0
if len(sys.argv) > 1:
errors = int(sys.argv[1])
signals = 0
while loop:
try:
n = random.randint (0, len (options))
opts = random.sample (options, n)
for cmd in commands:
if os.path.exists ("/tmp/out"):
os.unlink ("/tmp/out")
cmd = "./ledger -f tools/standard.dat " + string.join(opts, " ") + " " + cmd + \
" >> /tmp/out 2>&1"
sys.stdout = open ("/tmp/out", "w")
print "::", cmd
sys.stdout.close ()
ret = os.system (cmd)
sys.stdout = open ("/tmp/out", "a")
# Convert an odd UNIX return type into the appropriate
# signal indication.
if ret and ret % 256 == 0 and ret / 256 > 127:
ret = 0x100 + (ret / 256 - 128)
if ret and ret % 256 == 0:
print "ERROR: Return value", ret / 256
sys.stdout.close ()
os.system ("cat /tmp/out >> errors.out")
errors += 1
elif ret:
if ret % 256 == signal.SIGINT:
loop = false
break
print "SIGNAL: Return value", ret % 256
sys.stdout.close ()
os.system ("cat /tmp/out >> signals.out")
signals += 1
else:
sys.stdout.close ()
os.system ("cat /tmp/out >> results.out")
sys.stdout = sys.__stdout__
count += 1
if count < 10 or \
(count < 100 and count % 10 == 0) or \
(count < 1000 and count % 100 == 0) or \
count % 1000 == 0:
if signals > 0 and errors > 0:
print "%d tests ... (%d signals, %d errors)" % \
(count, signals, errors)
elif signals > 0:
print "%d tests ... (%d signals)" % \
(count, signals)
elif errors > 0:
print "%d tests ... (%d errors)" % \
(count, errors)
else:
print "%d tests ..." % count
except KeyboardInterrupt:
loop = false

File diff suppressed because it is too large Load diff

View file

@ -1,105 +0,0 @@
#ifndef _T_AMOUNT_H
#define _T_AMOUNT_H
#include "UnitTests.h"
class AmountTestCase : public CPPUNIT_NS::TestCase
{
CPPUNIT_TEST_SUITE(AmountTestCase);
CPPUNIT_TEST(testConstructors);
CPPUNIT_TEST(testCommodityConstructors);
CPPUNIT_TEST(testParser);
CPPUNIT_TEST(testAssignment);
CPPUNIT_TEST(testCommodityAssignment);
CPPUNIT_TEST(testEquality);
CPPUNIT_TEST(testCommodityEquality);
CPPUNIT_TEST(testComparisons);
CPPUNIT_TEST(testCommodityComparisons);
CPPUNIT_TEST(testIntegerAddition);
CPPUNIT_TEST(testFractionalAddition);
CPPUNIT_TEST(testCommodityAddition);
CPPUNIT_TEST(testIntegerSubtraction);
CPPUNIT_TEST(testFractionalSubtraction);
CPPUNIT_TEST(testCommoditySubtraction);
CPPUNIT_TEST(testIntegerMultiplication);
CPPUNIT_TEST(testFractionalMultiplication);
CPPUNIT_TEST(testCommodityMultiplication);
CPPUNIT_TEST(testIntegerDivision);
CPPUNIT_TEST(testFractionalDivision);
CPPUNIT_TEST(testCommodityDivision);
CPPUNIT_TEST(testNegation);
CPPUNIT_TEST(testCommodityNegation);
CPPUNIT_TEST(testAbs);
CPPUNIT_TEST(testCommodityAbs);
#if 0
CPPUNIT_TEST(testReduction);
#endif
CPPUNIT_TEST(testSign);
CPPUNIT_TEST(testCommoditySign);
CPPUNIT_TEST(testTruth);
CPPUNIT_TEST(testCommodityTruth);
CPPUNIT_TEST(testForZero);
CPPUNIT_TEST(testCommodityForZero);
CPPUNIT_TEST(testIntegerConversion);
CPPUNIT_TEST(testFractionalConversion);
CPPUNIT_TEST(testCommodityConversion);
CPPUNIT_TEST(testPrinting);
CPPUNIT_TEST(testCommodityPrinting);
CPPUNIT_TEST_SUITE_END();
public:
AmountTestCase() {}
virtual ~AmountTestCase() {}
virtual void setUp();
virtual void tearDown();
void testConstructors();
void testCommodityConstructors();
void testParser();
void testAssignment();
void testCommodityAssignment();
void testEquality();
void testCommodityEquality();
void testComparisons();
void testCommodityComparisons();
void testIntegerAddition();
void testFractionalAddition();
void testCommodityAddition();
void testIntegerSubtraction();
void testFractionalSubtraction();
void testCommoditySubtraction();
void testIntegerMultiplication();
void testFractionalMultiplication();
void testCommodityMultiplication();
void testIntegerDivision();
void testFractionalDivision();
void testCommodityDivision();
void testNegation();
void testCommodityNegation();
void testAbs();
void testCommodityAbs();
void testFractionalRound();
void testCommodityRound();
void testCommodityDisplayRound();
void testReduction();
void testSign();
void testCommoditySign();
void testTruth();
void testCommodityTruth();
void testForZero();
void testCommodityForZero();
void testIntegerConversion();
void testFractionalConversion();
void testCommodityConversion();
void testPrinting();
void testCommodityPrinting();
private:
AmountTestCase(const AmountTestCase &copy);
void operator=(const AmountTestCase &copy);
};
#endif // _T_AMOUNT_H

View file

@ -1,29 +1,33 @@
#define BOOST_TEST_DYN_LINK
//#define BOOST_TEST_MODULE balance
#include <boost/test/unit_test.hpp>
#include <system.hh>
#include "t_balance.h"
#include "utils.h"
#include "amount.h"
#include "balance.h"
using namespace ledger;
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(BalanceTestCase, "math");
struct balance_fixture {
balance_fixture() {
times_initialize();
amount_t::initialize();
void BalanceTestCase::setUp()
{
times_initialize();
amount_t::initialize();
// Cause the display precision for dollars to be initialized to 2.
amount_t x1("$1.00");
BOOST_CHECK(x1);
// Cause the display precision for dollars to be initialized to 2.
amount_t x1("$1.00");
assertTrue(x1);
amount_t::stream_fullstrings = true; // make reports from UnitTests accurate
}
amount_t::stream_fullstrings = true; // make reports from UnitTests accurate
}
~balance_fixture()
{
amount_t::stream_fullstrings = false;
amount_t::shutdown();
times_shutdown();
}
};
void BalanceTestCase::tearDown()
{
amount_t::stream_fullstrings = false;
amount_t::shutdown();
times_shutdown();
}
//BOOST_FIXTURE_TEST_SUITE(balance, balance_fixture)
//BOOST_AUTO_TEST_SUITE_END()

View file

@ -1,28 +0,0 @@
#ifndef _T_BALANCE_H
#define _T_BALANCE_H
#include "UnitTests.h"
class BalanceTestCase : public CPPUNIT_NS::TestCase
{
CPPUNIT_TEST_SUITE(BalanceTestCase);
//CPPUNIT_TEST(testConstructors);
CPPUNIT_TEST_SUITE_END();
public:
BalanceTestCase() {}
virtual ~BalanceTestCase() {}
virtual void setUp();
virtual void tearDown();
//void testConstructors();
private:
BalanceTestCase(const BalanceTestCase &copy);
void operator=(const BalanceTestCase &copy);
};
#endif // _T_BALANCE_H

View file

@ -1,26 +1,30 @@
#include <system.hh>
#define BOOST_TEST_DYN_LINK
//#define BOOST_TEST_MODULE commodity
#include <boost/test/unit_test.hpp>
#include "t_commodity.h"
#include <system.hh>
#include "amount.h"
#include "commodity.h"
using namespace ledger;
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(CommodityTestCase, "math");
struct commodity_fixture {
commodity_fixture() {
times_initialize();
amount_t::initialize();
amount_t::stream_fullstrings = true;
}
void CommodityTestCase::setUp() {
times_initialize();
amount_t::initialize();
amount_t::stream_fullstrings = true;
}
~commodity_fixture() {
amount_t::shutdown();
times_shutdown();
}
};
void CommodityTestCase::tearDown() {
amount_t::shutdown();
times_shutdown();
}
BOOST_FIXTURE_TEST_SUITE(commodity, commodity_fixture)
void CommodityTestCase::testPriceHistory()
BOOST_AUTO_TEST_CASE(testPriceHistory)
{
#ifndef NOT_FOR_PYTHON
datetime_t jan17_05;
@ -45,8 +49,8 @@ void CommodityTestCase::testPriceHistory()
amount_t x0;
amount_t x1("100.10 AAPL");
assertThrow(x0.value(), amount_error);
assertFalse(x1.value());
BOOST_CHECK_THROW(x0.value(), amount_error);
BOOST_CHECK(! x1.value());
// Commodities cannot be constructed by themselves, since a great deal
// of their state depends on how they were seen to be used.
@ -74,33 +78,36 @@ void CommodityTestCase::testPriceHistory()
#ifndef NOT_FOR_PYTHON
optional<amount_t> amt = x1.value(feb28_07sbm);
assertTrue(amt);
assertEqual(amount_t("$1831.83"), *amt);
BOOST_CHECK(amt);
BOOST_CHECK_EQUAL(amount_t("$1831.83"), *amt);
amt = x1.value(CURRENT_TIME());
assertTrue(amt);
assertEqual(string("$2124.12"), amt->to_string());
BOOST_CHECK(amt);
BOOST_CHECK_EQUAL(string("$2124.12"), amt->to_string());
#ifdef INTEGER_MATH
assertEqual(string("$2124.12"), amt->to_fullstring());
BOOST_CHECK_EQUAL(string("$2124.12"), amt->to_fullstring());
#else
assertEqual(string("$2124.122"), amt->to_fullstring());
BOOST_CHECK_EQUAL(string("$2124.122"), amt->to_fullstring());
#endif
amt = x1.value(CURRENT_TIME(), euro);
assertTrue(amt);
assertEqual(string("EUR 1366.87"), amt->rounded().to_string());
BOOST_CHECK(amt);
BOOST_CHECK_EQUAL(string("EUR 1366.87"), amt->rounded().to_string());
// Add a newer Euro pricing
aapl.add_price(jan17_07, amount_t("EUR 23.00"));
amt = x1.value(CURRENT_TIME(), euro);
assertTrue(amt);
assertEqual(string("EUR 2302.30"), amt->to_string());
BOOST_CHECK(amt);
BOOST_CHECK_EQUAL(string("EUR 2302.30"), amt->to_string());
amt = x1.value(CURRENT_TIME(), cad);
assertTrue(amt);
assertEqual(string("CAD 3223.22"), amt->to_string());
BOOST_CHECK(amt);
BOOST_CHECK_EQUAL(string("CAD 3223.22"), amt->to_string());
#endif // NOT_FOR_PYTHON
assertValid(x1);
BOOST_CHECK(x1.valid());
}
BOOST_AUTO_TEST_SUITE_END()

View file

@ -1,28 +0,0 @@
#ifndef _T_COMMMODITY_H
#define _T_COMMMODITY_H
#include "UnitTests.h"
class CommodityTestCase : public CPPUNIT_NS::TestCase
{
CPPUNIT_TEST_SUITE(CommodityTestCase);
CPPUNIT_TEST(testPriceHistory);
CPPUNIT_TEST_SUITE_END();
public:
CommodityTestCase() {}
virtual ~CommodityTestCase() {}
virtual void setUp();
virtual void tearDown();
void testPriceHistory();
private:
CommodityTestCase(const CommodityTestCase &copy);
void operator=(const CommodityTestCase &copy);
};
#endif // _T_COMMMODITY_H

View file

@ -1,6 +1,8 @@
#include <system.hh>
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE expr
#include <boost/test/unit_test.hpp>
#include "t_expr.h"
#include <system.hh>
#include "expr.h"
#include "predicate.h"
@ -9,19 +11,17 @@
using namespace ledger;
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ValueExprTestCase, "expr");
struct expr_fixture {
expr_fixture() {
times_initialize();
amount_t::initialize();
}
void ValueExprTestCase::setUp()
{
times_initialize();
amount_t::initialize();
}
void ValueExprTestCase::tearDown()
{
amount_t::shutdown();
times_shutdown();
}
~expr_fixture() {
amount_t::shutdown();
times_shutdown();
}
};
// 1. foo and bar
// 2. 'foo and bar'
@ -40,7 +40,9 @@ void ValueExprTestCase::tearDown()
// 15. foo and bar|baz
// 16. foo 'and bar|baz'
void ValueExprTestCase::testPredicateTokenizer1()
BOOST_FIXTURE_TEST_SUITE(expr, expr_fixture)
BOOST_AUTO_TEST_CASE(testPredicateTokenizer1)
{
value_t args;
args.push_back(string_value("foo"));
@ -50,14 +52,14 @@ void ValueExprTestCase::testPredicateTokenizer1()
#ifndef NOT_FOR_PYTHON
query_t::lexer_t tokens(args.begin(), args.end());
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
#endif
}
void ValueExprTestCase::testPredicateTokenizer2()
BOOST_AUTO_TEST_CASE(testPredicateTokenizer2)
{
value_t args;
args.push_back(string_value("foo and bar"));
@ -65,14 +67,14 @@ void ValueExprTestCase::testPredicateTokenizer2()
#ifndef NOT_FOR_PYTHON
query_t::lexer_t tokens(args.begin(), args.end(), false);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
#endif
}
void ValueExprTestCase::testPredicateTokenizer3()
BOOST_AUTO_TEST_CASE(testPredicateTokenizer3)
{
value_t args;
args.push_back(string_value("(foo"));
@ -82,16 +84,16 @@ void ValueExprTestCase::testPredicateTokenizer3()
#ifndef NOT_FOR_PYTHON
query_t::lexer_t tokens(args.begin(), args.end());
assertEqual(query_t::lexer_t::token_t::LPAREN, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::RPAREN, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::LPAREN, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::RPAREN, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
#endif
}
void ValueExprTestCase::testPredicateTokenizer4()
BOOST_AUTO_TEST_CASE(testPredicateTokenizer4)
{
value_t args;
args.push_back(string_value("("));
@ -103,16 +105,16 @@ void ValueExprTestCase::testPredicateTokenizer4()
#ifndef NOT_FOR_PYTHON
query_t::lexer_t tokens(args.begin(), args.end());
assertEqual(query_t::lexer_t::token_t::LPAREN, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::RPAREN, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::LPAREN, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::RPAREN, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
#endif
}
void ValueExprTestCase::testPredicateTokenizer5()
BOOST_AUTO_TEST_CASE(testPredicateTokenizer5)
{
value_t args;
args.push_back(string_value("( foo and"));
@ -121,16 +123,16 @@ void ValueExprTestCase::testPredicateTokenizer5()
#ifndef NOT_FOR_PYTHON
query_t::lexer_t tokens(args.begin(), args.end(), false);
assertEqual(query_t::lexer_t::token_t::LPAREN, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::RPAREN, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::LPAREN, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::RPAREN, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
#endif
}
void ValueExprTestCase::testPredicateTokenizer6()
BOOST_AUTO_TEST_CASE(testPredicateTokenizer6)
{
value_t args;
args.push_back(string_value("=foo"));
@ -140,15 +142,15 @@ void ValueExprTestCase::testPredicateTokenizer6()
#ifndef NOT_FOR_PYTHON
query_t::lexer_t tokens(args.begin(), args.end());
assertEqual(query_t::lexer_t::token_t::TOK_EQ, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_EQ, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
#endif
}
void ValueExprTestCase::testPredicateTokenizer7()
BOOST_AUTO_TEST_CASE(testPredicateTokenizer7)
{
value_t args;
args.push_back(string_value("=foo and bar"));
@ -156,13 +158,13 @@ void ValueExprTestCase::testPredicateTokenizer7()
#ifndef NOT_FOR_PYTHON
query_t::lexer_t tokens(args.begin(), args.end());
assertEqual(query_t::lexer_t::token_t::TOK_EQ, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_EQ, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
#endif
}
void ValueExprTestCase::testPredicateTokenizer8()
BOOST_AUTO_TEST_CASE(testPredicateTokenizer8)
{
value_t args;
args.push_back(string_value("expr 'foo and bar'"));
@ -170,13 +172,13 @@ void ValueExprTestCase::testPredicateTokenizer8()
#ifndef NOT_FOR_PYTHON
query_t::lexer_t tokens(args.begin(), args.end(), false);
assertEqual(query_t::lexer_t::token_t::TOK_EXPR, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_EXPR, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
#endif
}
void ValueExprTestCase::testPredicateTokenizer9()
BOOST_AUTO_TEST_CASE(testPredicateTokenizer9)
{
value_t args;
args.push_back(string_value("expr"));
@ -185,13 +187,13 @@ void ValueExprTestCase::testPredicateTokenizer9()
#ifndef NOT_FOR_PYTHON
query_t::lexer_t tokens(args.begin(), args.end());
assertEqual(query_t::lexer_t::token_t::TOK_EXPR, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_EXPR, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
#endif
}
void ValueExprTestCase::testPredicateTokenizer10()
BOOST_AUTO_TEST_CASE(testPredicateTokenizer10)
{
value_t args;
args.push_back(string_value("expr"));
@ -202,15 +204,15 @@ void ValueExprTestCase::testPredicateTokenizer10()
#ifndef NOT_FOR_PYTHON
query_t::lexer_t tokens(args.begin(), args.end());
assertEqual(query_t::lexer_t::token_t::TOK_EXPR, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_EXPR, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
#endif
}
void ValueExprTestCase::testPredicateTokenizer11()
BOOST_AUTO_TEST_CASE(testPredicateTokenizer11)
{
value_t args;
args.push_back(string_value("foo"));
@ -222,16 +224,16 @@ void ValueExprTestCase::testPredicateTokenizer11()
#ifndef NOT_FOR_PYTHON
query_t::lexer_t tokens(args.begin(), args.end());
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TOK_OR, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_OR, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
#endif
}
void ValueExprTestCase::testPredicateTokenizer12()
BOOST_AUTO_TEST_CASE(testPredicateTokenizer12)
{
value_t args;
args.push_back(string_value("foo"));
@ -243,16 +245,16 @@ void ValueExprTestCase::testPredicateTokenizer12()
#ifndef NOT_FOR_PYTHON
query_t::lexer_t tokens(args.begin(), args.end());
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TOK_OR, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_OR, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
#endif
}
void ValueExprTestCase::testPredicateTokenizer13()
BOOST_AUTO_TEST_CASE(testPredicateTokenizer13)
{
value_t args;
args.push_back(string_value("foo"));
@ -263,16 +265,16 @@ void ValueExprTestCase::testPredicateTokenizer13()
#ifndef NOT_FOR_PYTHON
query_t::lexer_t tokens(args.begin(), args.end());
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TOK_OR, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_OR, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
#endif
}
void ValueExprTestCase::testPredicateTokenizer14()
BOOST_AUTO_TEST_CASE(testPredicateTokenizer14)
{
value_t args;
args.push_back(string_value("foo"));
@ -283,16 +285,16 @@ void ValueExprTestCase::testPredicateTokenizer14()
#ifndef NOT_FOR_PYTHON
query_t::lexer_t tokens(args.begin(), args.end());
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TOK_OR, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_OR, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
#endif
}
void ValueExprTestCase::testPredicateTokenizer15()
BOOST_AUTO_TEST_CASE(testPredicateTokenizer15)
{
value_t args;
args.push_back(string_value("foo"));
@ -302,16 +304,16 @@ void ValueExprTestCase::testPredicateTokenizer15()
#ifndef NOT_FOR_PYTHON
query_t::lexer_t tokens(args.begin(), args.end());
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TOK_OR, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_OR, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
#endif
}
void ValueExprTestCase::testPredicateTokenizer16()
BOOST_AUTO_TEST_CASE(testPredicateTokenizer16)
{
value_t args;
args.push_back(string_value("foo"));
@ -320,11 +322,13 @@ void ValueExprTestCase::testPredicateTokenizer16()
#ifndef NOT_FOR_PYTHON
query_t::lexer_t tokens(args.begin(), args.end(), false);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TOK_OR, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
assertEqual(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_AND, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TOK_OR, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::TERM, tokens.next_token().kind);
BOOST_CHECK_EQUAL(query_t::lexer_t::token_t::END_REACHED, tokens.next_token().kind);
#endif
}
BOOST_AUTO_TEST_SUITE_END()

View file

@ -1,60 +0,0 @@
#ifndef _T_EXPR_H
#define _T_EXPR_H
#include "UnitTests.h"
class ValueExprTestCase : public CPPUNIT_NS::TestCase
{
CPPUNIT_TEST_SUITE(ValueExprTestCase);
//CPPUNIT_TEST(testConstructors);
CPPUNIT_TEST(testPredicateTokenizer1);
CPPUNIT_TEST(testPredicateTokenizer2);
CPPUNIT_TEST(testPredicateTokenizer3);
CPPUNIT_TEST(testPredicateTokenizer4);
CPPUNIT_TEST(testPredicateTokenizer5);
CPPUNIT_TEST(testPredicateTokenizer6);
CPPUNIT_TEST(testPredicateTokenizer7);
CPPUNIT_TEST(testPredicateTokenizer8);
CPPUNIT_TEST(testPredicateTokenizer9);
CPPUNIT_TEST(testPredicateTokenizer10);
CPPUNIT_TEST(testPredicateTokenizer11);
CPPUNIT_TEST(testPredicateTokenizer12);
CPPUNIT_TEST(testPredicateTokenizer13);
CPPUNIT_TEST(testPredicateTokenizer14);
CPPUNIT_TEST(testPredicateTokenizer15);
CPPUNIT_TEST(testPredicateTokenizer16);
CPPUNIT_TEST_SUITE_END();
public:
ValueExprTestCase() {}
virtual ~ValueExprTestCase() {}
virtual void setUp();
virtual void tearDown();
//void testConstructors();
void testPredicateTokenizer1();
void testPredicateTokenizer2();
void testPredicateTokenizer3();
void testPredicateTokenizer4();
void testPredicateTokenizer5();
void testPredicateTokenizer6();
void testPredicateTokenizer7();
void testPredicateTokenizer8();
void testPredicateTokenizer9();
void testPredicateTokenizer10();
void testPredicateTokenizer11();
void testPredicateTokenizer12();
void testPredicateTokenizer13();
void testPredicateTokenizer14();
void testPredicateTokenizer15();
void testPredicateTokenizer16();
private:
ValueExprTestCase(const ValueExprTestCase &copy);
void operator=(const ValueExprTestCase &copy);
};
#endif // _T_EXPR_H

View file

@ -1,25 +1,26 @@
#include <system.hh>
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE util
#include <boost/test/unit_test.hpp>
#include "t_times.h"
#include <system.hh>
#include "utils.h"
#include "times.h"
using namespace ledger;
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(DateTimeTestCase, "util");
struct times_fixture {
times_fixture() {
times_initialize();
}
~times_fixture() {
times_shutdown();
}
};
void DateTimeTestCase::setUp()
{
times_initialize();
}
BOOST_FIXTURE_TEST_SUITE(times, times_fixture)
void DateTimeTestCase::tearDown()
{
times_shutdown();
}
void DateTimeTestCase::testConstructors()
BOOST_AUTO_TEST_CASE(testConstructors)
{
#ifndef NOT_FOR_PYTHON
std::time_t now = std::time(NULL);
@ -71,51 +72,51 @@ void DateTimeTestCase::testConstructors()
#endif // NOT_FOR_PYTHON
#ifndef NOT_FOR_PYTHON
assertTrue(d0.is_not_a_date());
assertFalse(d1.is_not_a_date());
assertFalse(d4.is_not_a_date());
BOOST_CHECK(d0.is_not_a_date());
BOOST_CHECK(! d1.is_not_a_date());
BOOST_CHECK(! d4.is_not_a_date());
#endif // NOT_FOR_PYTHON
assertTrue(CURRENT_DATE() > d1);
assertTrue(CURRENT_DATE() > d4);
BOOST_CHECK(CURRENT_DATE() > d1);
BOOST_CHECK(CURRENT_DATE() > d4);
#ifndef NOT_FOR_PYTHON
#if 0
assertEqual(d3, d15);
BOOST_CHECK_EQUAL(d3, d15);
#endif
#endif // NOT_FOR_PYTHON
assertEqual(d4, d6);
assertEqual(d4, d8);
assertEqual(d5, d7);
assertEqual(d5, d9);
BOOST_CHECK_EQUAL(d4, d6);
BOOST_CHECK_EQUAL(d4, d8);
BOOST_CHECK_EQUAL(d5, d7);
BOOST_CHECK_EQUAL(d5, d9);
#ifndef NOT_FOR_PYTHON
#if 0
assertEqual(d10, d11);
assertEqual(d12, d13);
BOOST_CHECK_EQUAL(d10, d11);
BOOST_CHECK_EQUAL(d12, d13);
assertThrow(parse_date("2007/02/29"), boost::gregorian::bad_day_of_month);
//assertThrow(parse_date("2007/13/01"), datetime_error);
//assertThrow(parse_date("2007/00/01"), datetime_error);
assertThrow(parse_date("2007/01/00"), boost::gregorian::bad_day_of_month);
//assertThrow(parse_date("2007/00/00"), boost::gregorian::bad_day_of_month);
//assertThrow(parse_date("2007/05/32"), boost::gregorian::bad_day_of_month);
BOOST_CHECK_THROW(parse_date("2007/02/29"), boost::gregorian::bad_day_of_month);
//BOOST_CHECK_THROW(parse_date("2007/13/01"), datetime_error);
//BOOST_CHECK_THROW(parse_date("2007/00/01"), datetime_error);
BOOST_CHECK_THROW(parse_date("2007/01/00"), boost::gregorian::bad_day_of_month);
//BOOST_CHECK_THROW(parse_date("2007/00/00"), boost::gregorian::bad_day_of_month);
//BOOST_CHECK_THROW(parse_date("2007/05/32"), boost::gregorian::bad_day_of_month);
assertThrow(parse_date("2006x/12/25"), datetime_error);
assertThrow(parse_date("2006/12x/25"), datetime_error);
assertThrow(parse_date("2006/12/25x"), datetime_error);
BOOST_CHECK_THROW(parse_date("2006x/12/25"), datetime_error);
BOOST_CHECK_THROW(parse_date("2006/12x/25"), datetime_error);
BOOST_CHECK_THROW(parse_date("2006/12/25x"), datetime_error);
assertThrow(parse_date("feb/12/25"), datetime_error);
assertThrow(parse_date("2006/mon/25"), datetime_error);
assertThrow(parse_date("2006/12/web"), datetime_error);
BOOST_CHECK_THROW(parse_date("feb/12/25"), datetime_error);
BOOST_CHECK_THROW(parse_date("2006/mon/25"), datetime_error);
BOOST_CHECK_THROW(parse_date("2006/12/web"), datetime_error);
assertThrow(parse_date("12*25"), datetime_error);
BOOST_CHECK_THROW(parse_date("12*25"), datetime_error);
assertThrow(parse_date("tuf"), datetime_error);
assertThrow(parse_date("tufsday"), datetime_error);
assertThrow(parse_date("fec"), datetime_error);
assertThrow(parse_date("fecruary"), datetime_error);
assertThrow(parse_date("207x"), datetime_error);
assertThrow(parse_date("hello"), datetime_error);
BOOST_CHECK_THROW(parse_date("tuf"), datetime_error);
BOOST_CHECK_THROW(parse_date("tufsday"), datetime_error);
BOOST_CHECK_THROW(parse_date("fec"), datetime_error);
BOOST_CHECK_THROW(parse_date("fecruary"), datetime_error);
BOOST_CHECK_THROW(parse_date("207x"), datetime_error);
BOOST_CHECK_THROW(parse_date("hello"), datetime_error);
d1 = parse_date("2002-02-02");
d1 = parse_date("2002/02/02");
@ -160,7 +161,9 @@ void DateTimeTestCase::testConstructors()
d1 = parse_date("2002-02-02 12p");
d1 = parse_date("2002-02-02 12a");
assertValid(d1);
BOOST_CHECK(d1.valid());
#endif // NOT_FOR_PYTHON
#endif
}
BOOST_AUTO_TEST_SUITE_END()

View file

@ -1,28 +0,0 @@
#ifndef _T_TIMES_H
#define _T_TIMES_H
#include "UnitTests.h"
class DateTimeTestCase : public CPPUNIT_NS::TestCase
{
CPPUNIT_TEST_SUITE(DateTimeTestCase);
CPPUNIT_TEST(testConstructors);
CPPUNIT_TEST_SUITE_END();
public:
DateTimeTestCase() {}
virtual ~DateTimeTestCase() {}
virtual void setUp();
virtual void tearDown();
void testConstructors();
private:
DateTimeTestCase(const DateTimeTestCase &copy);
void operator=(const DateTimeTestCase &copy);
};
#endif /* _T_TIMES_H */

View file

@ -1,6 +0,0 @@
#include <system.hh>
#include "t_utils.h"
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(UtilitiesTestCase, "util");

View file

@ -1,28 +0,0 @@
#ifndef _T_UTILS_H
#define _T_UTILS_H
#include "UnitTests.h"
class UtilitiesTestCase : public CPPUNIT_NS::TestCase
{
CPPUNIT_TEST_SUITE(UtilitiesTestCase);
//CPPUNIT_TEST(testConstructors);
CPPUNIT_TEST_SUITE_END();
public:
UtilitiesTestCase() {}
virtual ~UtilitiesTestCase() {}
//virtual void setUp();
//virtual void tearDown();
//void testConstructors();
private:
UtilitiesTestCase(const UtilitiesTestCase &copy);
void operator=(const UtilitiesTestCase &copy);
};
#endif /* _T_UTILS_H */

View file

@ -252,13 +252,13 @@ endif
TESTS = RegressTests BaselineTests ManualTests ConfirmTests \
GenerateTests
if HAVE_CPPUNIT
TESTS += \
if HAVE_BOOST_TEST
TESTS += \
UtilTests \
MathTests \
ExprTests \
DataTests \
ReportTests
ExprTests
# DataTests \
# ReportTests
endif
if DEBUG
@ -271,54 +271,35 @@ endif
check_PROGRAMS = $(TESTS)
TESTLIBS = -lboost_unit_test_framework$(BOOST_SUFFIX) \
-lboost_test_exec_monitor$(BOOST_SUFFIX)
UtilTests_SOURCES = \
test/UnitTests.cc \
test/UnitTests.h \
test/UtilTests.cc \
test/unit/t_utils.cc \
test/unit/t_utils.h \
test/unit/t_times.cc \
test/unit/t_times.h
test/unit/t_times.cc
UtilTests_CPPFLAGS = -I$(srcdir)/test $(lib_cppflags)
UtilTests_LDADD = libledger_util.la -lcppunit
UtilTests_LDADD = libledger_util.la $(TESTLIBS)
MathTests_SOURCES = \
test/UnitTests.cc \
test/UnitTests.h \
test/MathTests.cc \
test/unit/t_commodity.cc \
test/unit/t_commodity.h \
test/unit/t_amount.cc \
test/unit/t_amount.h \
test/unit/t_balance.cc \
test/unit/t_balance.h
test/unit/t_balance.cc
MathTests_CPPFLAGS = -I$(srcdir)/test $(lib_cppflags)
MathTests_LDADD = libledger_math.la $(UtilTests_LDADD)
ExprTests_SOURCES = \
test/UnitTests.cc \
test/UnitTests.h \
test/ExprTests.cc \
test/unit/t_expr.cc \
test/unit/t_expr.h
test/unit/t_expr.cc
ExprTests_CPPFLAGS = -I$(srcdir)/test $(lib_cppflags)
ExprTests_LDADD = libledger_expr.la $(MathTests_LDADD)
DataTests_SOURCES = \
test/UnitTests.cc \
test/UnitTests.h \
test/DataTests.cc
DataTests_SOURCES =
DataTests_CPPFLAGS = -I$(srcdir)/test $(lib_cppflags)
DataTests_LDADD = libledger_data.la $(ExprTests_LDADD)
ReportTests_SOURCES = \
test/UnitTests.cc \
test/UnitTests.h \
test/ReportTests.cc
ReportTests_SOURCES =
ReportTests_CPPFLAGS = -I$(srcdir)/test $(lib_cppflags)
ReportTests_LDADD = libledger_report.la $(DataTests_LDADD)
@ -424,8 +405,8 @@ CheckTests:
FULLCHECK=$(srcdir)/test/fullcheck.sh
if HAVE_CPPUNIT
cppunittests: check
if HAVE_BOOST_TEST
unittests: check
@sh $(FULLCHECK) $(top_builddir)/UtilTests$(EXEEXT) --verify \
2>&1 | grep -v '^GuardMalloc:'
@sh $(FULLCHECK) $(top_builddir)/MathTests$(EXEEXT) --verify \
@ -437,11 +418,11 @@ cppunittests: check
@sh $(FULLCHECK) $(top_builddir)/ReportTests$(EXEEXT) --verify \
2>&1 | grep -v '^GuardMalloc:'
else
cppunittests: check
unittests: check
@test 1 -eq 1
endif
fullcheck: cppunittests
fullcheck: unittests
@$(top_builddir)/RegressTests --verify
@$(top_builddir)/BaselineTests --verify
@$(top_builddir)/ManualTests --verify

View file

@ -401,31 +401,24 @@ else
AM_CONDITIONAL(HAVE_BOOST_PYTHON, false)
fi
# check for CppUnit
# check for Boost.Test
AC_CACHE_CHECK(
[if cppunit is available],
[cppunit_avail_cv_],
[cppunit_save_libs=$LIBS
LIBS="-lcppunit $LIBS"
[if boost_test is available],
[boost_test_avail_cv_],
[boost_test_save_libs=$LIBS
LIBS="-lboost_unit_test_framework$BOOST_SUFFIX -lboost_test_exec_monitor$BOOST_SUFFIX $LIBS"
AC_LANG_PUSH(C++)
AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[[#include <cppunit/CompilerOutputter.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>
#include <cppunit/TextTestProgressListener.h>
#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/XmlOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>]],
[[CPPUNIT_NS::TestResult controller;
CPPUNIT_NS::TestResultCollector result;]])],
[cppunit_avail_cv_=true],
[cppunit_avail_cv_=false])
[AC_LANG_SOURCE(
[[#define BOOST_TEST_MODULE sample
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(test_test) {}]])],
[boost_test_avail_cv_=true],
[boost_test_avail_cv_=false])
AC_LANG_POP
LIBS=$cppunit_save_libs])
LIBS=$boost_test_save_libs])
AM_CONDITIONAL(HAVE_CPPUNIT, test x$cppunit_avail_cv_ = xtrue)
AM_CONDITIONAL(HAVE_BOOST_TEST, test x$boost_test_avail_cv_ = xtrue)
# Checks for header files.
AC_HEADER_STDC

View file

@ -30,7 +30,6 @@ install-sh
intl/
ledger
ledger.so
lib/cppunit/
lib/utfcpp/
libtool
ltmain.sh