1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=cpp: */
4 * Copyright (C) 2008 Sergey Yanovich <ynvich@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include "xpcom-config.h"
25 #include "nsComponentManagerUtils.h"
26 #include "nsEmbedString.h"
28 #include "nsArrayUtils.h"
31 #include "mozIStorageConnection.h"
32 #include "nsTestUtils.h"
34 #include "nsITestRunner.h"
36 /* Project includes */
39 #include "aaIBalance.h"
40 #include "aaISession.h"
41 #include "aaIManager.h"
42 #include "aaIFilter.h"
43 #include "aaBaseLoaders.h"
44 #include "aaBalanceSheet.h"
45 #include "aaTranscript.h"
47 #include "aaBaseTestUtils.h"
48 #include "aaCurrencyReport.h"
50 NS_IMPL_ISUPPORTS1(aaCurrencyReport
, nsITest
)
53 aaCurrencyReport::Test(nsITestRunner
*aTestRunner
)
56 if (NS_FAILED( res
.status
)) {
57 aTestRunner
->AddError(nsITestRunner::errorJS
, \
58 AA_CURRENCY_REPORT_CONTRACT_ID
" not initialized");
59 return NS_ERROR_NOT_INITIALIZED
;
61 testBalanceSheet(aTestRunner
);
62 testTranscript(aTestRunner
);
67 aaCurrencyReport::RAII::RAII(aaCurrencyReport
*t
)
68 :status(PR_FALSE
), test(nsnull
)
71 nsCOMPtr
<aaIManager
> manager
=
72 do_CreateInstance(AA_MANAGER_CONTRACT_ID
, &rv
);
73 if (NS_UNLIKELY( ! manager
))
76 manager
->Restore("currency.sqlite");
77 nsCOMPtr
<aaISession
> session(do_CreateInstance(AA_SESSION_CONTRACT_ID
, &rv
));
78 if (NS_UNLIKELY( ! session
))
83 test
->mSession
= session
;
86 aaCurrencyReport::RAII::~RAII()
88 test
->mFlows
= nsnull
;
89 test
->mSession
= nsnull
;
93 nsCOMPtr
<aaIManager
> manager
=
94 do_CreateInstance(AA_MANAGER_CONTRACT_ID
, &rv
);
95 if (NS_UNLIKELY( ! manager
))
98 manager
->Backup("currency.sqlite");
101 /* Private methods */
103 aaCurrencyReport::testBalanceSheet(nsITestRunner
*aTestRunner
)
106 NS_TEST_BEGIN( aTestRunner
);
108 nsCOMPtr
<aaIBalanceSheet
> sheet
;
109 rv
= mSession
->CreateQuery(AA_BALANCESHEET_CONTRACT_ID
,
110 getter_AddRefs(sheet
));
111 NS_TEST_ASSERT_MSG(sheet
, "[balance sheet] intance creation");
112 NS_ENSURE_TRUE(sheet
, rv
);
115 NS_TEST_ASSERT_OK(rv
);
117 nsCOMPtr
<aaIBalance
> balance
= do_QueryElementAt(sheet
, 0);
118 NS_TEST_ASSERT_MSG(testBalance(aTestRunner
, balance
, 6, 2, 30000, 48000, 0),
119 "[balance sheet] flow 'bx1' is wrong");
125 aaCurrencyReport::testTranscript(nsITestRunner
*aTestRunner
)
128 NS_TEST_BEGIN( aTestRunner
);
130 rv
= mSession
->CreateQuery(AA_LOADFLOW_CONTRACT_ID
,
131 getter_AddRefs(mFlows
));
132 NS_TEST_ASSERT_OK(rv
);
133 NS_ENSURE_TRUE(mFlows
, rv
);
136 NS_TEST_ASSERT_OK(rv
);
137 nsCOMPtr
<aaIFlow
> a2
= do_QueryElementAt(mFlows
, 2);
139 nsCOMPtr
<aaITranscript
> transcript
;
140 rv
= mSession
->CreateQuery(AA_TRANSCRIPT_CONTRACT_ID
,
141 getter_AddRefs(transcript
));
142 NS_TEST_ASSERT_MSG(transcript
, "[transcript] intance creation");
143 NS_ENSURE_TRUE(transcript
, rv
);
145 PRExplodedTime tm
= {0,0,0,12,25,2,2008};
146 transcript
->SetStart(PR_ImplodeTime(&tm
));
148 transcript
->SetEnd(PR_ImplodeTime(&tm
));
149 transcript
->SetFlow(a2
);
151 rv
= transcript
->Load();
152 NS_TEST_ASSERT_OK(rv
);