1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
/***************************************************************************
mymoneypricetest.cpp
-------------------
copyright : (C) 2005 by Thomas Baumgart
email : ipwizard@users.sourceforge.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "mymoneypricetest.h"
#include "mymoneyexception.h"
MyMoneyPriceTest::MyMoneyPriceTest()
{
}
void MyMoneyPriceTest::setUp()
{
m = new MyMoneyPrice();
}
void MyMoneyPriceTest::tearDown()
{
delete m;
}
void MyMoneyPriceTest::testDefaultConstructor()
{
CPPUNIT_ASSERT(m->isValid() == false);
}
void MyMoneyPriceTest::testConstructor()
{
MyMoneyPrice n(TQString("from"), TQString("to"), TQDate(2005,9,23), MyMoneyMoney(1,3), TQString("MySource"));
CPPUNIT_ASSERT(n.isValid() == true);
CPPUNIT_ASSERT(n.from() == TQString("from"));
CPPUNIT_ASSERT(n.to() == TQString("to"));
CPPUNIT_ASSERT(n.date() == TQDate(2005,9,23));
CPPUNIT_ASSERT(n.source() == TQString("MySource"));
CPPUNIT_ASSERT(n.rate("to") == MyMoneyMoney(1,3));
}
void MyMoneyPriceTest::testValidity()
{
TQString emptyId;
MyMoneyPrice n1(emptyId, TQString("to"), TQDate(2005,9,23), MyMoneyMoney(1,3), TQString("MySource"));
MyMoneyPrice n2(TQString("from"), emptyId, TQDate(2005,9,23), MyMoneyMoney(1,3), TQString("MySource"));
MyMoneyPrice n3(TQString("from"), TQString("to"), TQDate(), MyMoneyMoney(1,3), TQString("MySource"));
MyMoneyPrice n4(TQString("from"), TQString("to"), TQDate(2005,9,23), MyMoneyMoney(1,3), TQString("MySource"));
CPPUNIT_ASSERT(n1.isValid() == false);
CPPUNIT_ASSERT(n2.isValid() == false);
CPPUNIT_ASSERT(n3.isValid() == false);
CPPUNIT_ASSERT(n4.isValid() == true);
}
void MyMoneyPriceTest::testRate()
{
MyMoneyPrice n1(TQString("from"), TQString("to"), TQDate(2005,9,23), MyMoneyMoney(1,3), TQString("MySource"));
MyMoneyPrice n2(TQString("from"), TQString("to"), TQDate(), MyMoneyMoney(1,3), TQString("MySource"));
try {
CPPUNIT_ASSERT(n1.rate("to") == MyMoneyMoney(1,3));
CPPUNIT_ASSERT(n1.rate("from") == MyMoneyMoney(3,1));
CPPUNIT_ASSERT(n1.rate(TQString()) == MyMoneyMoney(1,3));
CPPUNIT_ASSERT(n2.isValid() == false);
CPPUNIT_ASSERT(n2.rate("to") == MyMoneyMoney(1,1));
} catch(MyMoneyException *e) {
CPPUNIT_FAIL("Unexpected exception");
delete e;
}
try {
n1.rate("unknown");
CPPUNIT_FAIL("Missing expected exception");
} catch(MyMoneyException *e) {
delete e;
}
}
|