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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
/***************************************************************************
convertertest.cpp
-------------------
copyright : (C) 2002 by Thomas Baumgart
email : ipwizard@users.sourceforge.net
Ace Jones <ace.j@hotpop.com>
***************************************************************************/
/***************************************************************************
* *
* 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 <tqvaluelist.h>
#include <tqvaluevector.h>
#include <tqdom.h>
#include <tqfile.h>
#include <kdebug.h>
#include <kdeversion.h>
#include <kglobal.h>
#include <kglobalsettings.h>
#include <klocale.h>
#include <kstandarddirs.h>
#include "convertertest.h"
// uses helper functions from reports tests
#include "../reports/reportstestcommon.h"
using namespace test;
#include <kmymoney/mymoneysecurity.h>
#include <kmymoney/mymoneyprice.h>
#include <kmymoney/mymoneyreport.h>
#include <kmymoney/mymoneystatement.h>
#include "../mymoney/storage/mymoneystoragexml.h"
#include "../mymoney/storage/mymoneystoragedump.h"
#define private public
#include "../converter/webpricequote.h"
#undef private
ConverterTest::ConverterTest()
{
}
using namespace convertertest;
void ConverterTest::setUp () {
storage = new MyMoneySeqAccessMgr;
file = MyMoneyFile::instance();
file->attachStorage(storage);
MyMoneyFileTransaction ft;
file->addCurrency(MyMoneySecurity("CAD", "Canadian Dollar", "C$"));
file->addCurrency(MyMoneySecurity("USD", "US Dollar", "$"));
file->addCurrency(MyMoneySecurity("JPY", "Japanese Yen", TQChar(0x00A5), 100, 1));
file->addCurrency(MyMoneySecurity("GBP", "British Pound", "#"));
file->setBaseCurrency(file->currency("USD"));
MyMoneyPayee payeeTest("Test Payee");
file->addPayee(payeeTest);
MyMoneyPayee payeeTest2("Thomas Baumgart");
file->addPayee(payeeTest2);
acAsset = (MyMoneyFile::instance()->asset().id());
acLiability = (MyMoneyFile::instance()->liability().id());
acExpense = (MyMoneyFile::instance()->expense().id());
acIncome = (MyMoneyFile::instance()->income().id());
acChecking = makeAccount("Checking Account",MyMoneyAccount::Checkings,moConverterCheckingOpen,TQDate(2004,5,15),acAsset);
acCredit = makeAccount("Credit Card",MyMoneyAccount::CreditCard,moConverterCreditOpen,TQDate(2004,7,15),acLiability);
acSolo = makeAccount("Solo",MyMoneyAccount::Expense,0,TQDate(2004,1,11),acExpense);
acParent = makeAccount("Parent",MyMoneyAccount::Expense,0,TQDate(2004,1,11),acExpense);
acChild = makeAccount("Child",MyMoneyAccount::Expense,0,TQDate(2004,2,11),acParent);
acForeign = makeAccount("Foreign",MyMoneyAccount::Expense,0,TQDate(2004,1,11),acExpense);
MyMoneyInstitution i("Bank of the World","","","","","","");
file->addInstitution(i);
inBank = i.id();
ft.commit();
}
void ConverterTest::tearDown ()
{
file->detachStorage(storage);
delete storage;
}
void ConverterTest::testWebQuotes()
{
#ifdef PERFORM_ONLINE_TESTS
try
{
WebPriceQuote q;
QuoteReceiver qr(&q);
q.launch("DIS");
// kdDebug(2) << "ConverterTest::testWebQuotes(): quote for " << q.m_symbol << " on " << qr.m_date.toString() << " is " << qr.m_price.toString() << " errors(" << qr.m_errors.count() << "): " << qr.m_errors.join(" /// ") << endl;
// No errors allowed
CPPUNIT_ASSERT(qr.m_errors.count() == 0);
// Quote date should be within the last week, or something bad is going on.
CPPUNIT_ASSERT(qr.m_date <= TQDate::currentDate());
CPPUNIT_ASSERT(qr.m_date >= TQDate::currentDate().addDays(-7));
// Quote value should at least be positive
CPPUNIT_ASSERT(qr.m_price.isPositive());
q.launch("MF8AAUKS.L","Yahoo UK");
// kdDebug(2) << "ConverterTest::testWebQuotes(): quote for " << q.m_symbol << " on " << qr.m_date.toString() << " is " << qr.m_price.toString() << " errors(" << qr.m_errors.count() << "): " << qr.m_errors.join(" /// ") << endl;
CPPUNIT_ASSERT(qr.m_errors.count() == 0);
CPPUNIT_ASSERT(qr.m_date <= TQDate::currentDate().addDays(1));
CPPUNIT_ASSERT(qr.m_date >= TQDate::currentDate().addDays(-7));
CPPUNIT_ASSERT(qr.m_price.isPositive());
q.launch("EUR > USD","Yahoo Currency");
// kdDebug(2) << "ConverterTest::testWebQuotes(): quote for " << q.m_symbol << " on " << qr.m_date.toString() << " is " << qr.m_price.toString() << " errors(" << qr.m_errors.count() << "): " << qr.m_errors.join(" /// ") << endl;
CPPUNIT_ASSERT(qr.m_errors.count() == 0);
CPPUNIT_ASSERT(qr.m_date <= TQDate::currentDate().addDays(1));
CPPUNIT_ASSERT(qr.m_date >= TQDate::currentDate().addDays(-7));
CPPUNIT_ASSERT(qr.m_price.isPositive());
q.launch("50492","Globe & Mail");
// kdDebug(2) << "ConverterTest::testWebQuotes(): quote for " << q.m_symbol << " on " << qr.m_date.toString() << " is " << qr.m_price.toString() << " errors(" << qr.m_errors.count() << "): " << qr.m_errors.join(" /// ") << endl;
CPPUNIT_ASSERT(qr.m_errors.count() == 0);
CPPUNIT_ASSERT(qr.m_date <= TQDate::currentDate().addDays(1));
CPPUNIT_ASSERT(qr.m_date >= TQDate::currentDate().addDays(-7));
CPPUNIT_ASSERT(qr.m_price.isPositive());
q.launch("TDB647","MSN.CA");
// kdDebug(2) << "ConverterTest::testWebQuotes(): quote for " << q.m_symbol << " on " << qr.m_date.toString() << " is " << qr.m_price.toString() << " errors(" << qr.m_errors.count() << "): " << qr.m_errors.join(" /// ") << endl;
CPPUNIT_ASSERT(qr.m_errors.count() == 0);
CPPUNIT_ASSERT(qr.m_date <= TQDate::currentDate().addDays(1));
CPPUNIT_ASSERT(qr.m_date >= TQDate::currentDate().addDays(-7));
CPPUNIT_ASSERT(qr.m_price.isPositive());
}
catch (MyMoneyException* e)
{
CPPUNIT_FAIL(e->what());
}
#endif
}
void ConverterTest::testDateFormat()
{
try
{
MyMoneyDateFormat format("%mm-%dd-%yyyy");
CPPUNIT_ASSERT(format.convertString("1-5-2005") == TQDate(2005,1,5));
CPPUNIT_ASSERT(format.convertString("jan-15-2005") == TQDate(2005,1,15));
CPPUNIT_ASSERT(format.convertString("august-25-2005") == TQDate(2005,8,25));
format = MyMoneyDateFormat("%mm/%dd/%yy");
CPPUNIT_ASSERT(format.convertString("1/5/05") == TQDate(2005,1,5));
CPPUNIT_ASSERT(format.convertString("jan/15/05") == TQDate(2005,1,15));
CPPUNIT_ASSERT(format.convertString("august/25/05") == TQDate(2005,8,25));
format = MyMoneyDateFormat("%d\\.%m\\.%yy");
CPPUNIT_ASSERT(format.convertString("1.5.05") == TQDate(2005,5,1));
CPPUNIT_ASSERT(format.convertString("15.jan.05") == TQDate(2005,1,15));
CPPUNIT_ASSERT(format.convertString("25.august.05") == TQDate(2005,8,25));
format = MyMoneyDateFormat("%yyyy\\\\%dddd\\\\%mmmmmmmmmmm");
CPPUNIT_ASSERT(format.convertString("2005\\31\\12") == TQDate(2005,12,31));
CPPUNIT_ASSERT(format.convertString("2005\\15\\jan") == TQDate(2005,1,15));
CPPUNIT_ASSERT(format.convertString("2005\\25\\august") == TQDate(2005,8,25));
format = MyMoneyDateFormat("%m %dd, %yyyy");
CPPUNIT_ASSERT(format.convertString("jan 15, 2005") == TQDate(2005,1,15));
CPPUNIT_ASSERT(format.convertString("august 25, 2005") == TQDate(2005,8,25));
CPPUNIT_ASSERT(format.convertString("january 1st, 2005") == TQDate(2005,1,1));
format = MyMoneyDateFormat("%m %d %y");
CPPUNIT_ASSERT(format.convertString("12/31/50",false,2000) == TQDate(1950,12,31));
CPPUNIT_ASSERT(format.convertString("1/1/90",false,2000) == TQDate(1990,1,1));
CPPUNIT_ASSERT(format.convertString("december 31st, 5",false) == TQDate(2005,12,31));
}
catch (MyMoneyException* e)
{
CPPUNIT_FAIL(e->what());
}
}
// vim:cin:si:ai:et:ts=2:sw=2:
|