[storage] Set 'balance.flow' for income
[abstract.git] / report / aaReportTest.cpp
blob0c0168412d080b851d6ce8d7574aafea6551596e
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: */
3 /*
4 * Copyright (C) 2007 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 <abstract/aacore.h>
24 #include "nsCOMPtr.h"
25 #include "nsIGenericFactory.h"
26 #include "nsComponentManagerUtils.h"
27 #include "nsIArray.h"
28 #include "nsArrayUtils.h"
29 #include "nsEmbedString.h"
31 /* Unfrozen API */
32 #include "unstable/mozIStorageConnection.h"
33 #include <abstract/cxxunit/nsTestUtils.h>
34 #include <abstract/cxxunit/nsITest.h>
35 #include <abstract/cxxunit/nsITestRunner.h>
37 /* Project includes */
38 #include <abstract/base/aaIResource.h>
39 #include <abstract/base/aaIFlow.h>
40 #include <abstract/base/aaIFact.h>
41 #include <abstract/base/aaIBalance.h>
42 #include <abstract/base/aaITransaction.h>
43 #include <abstract/storage/aaBaseLoaders.h>
44 #include <abstract/storage/aaISession.h>
45 #include <abstract/storage/aaIFilter.h>
46 #include <abstract/storage/aaIStateFilter.h>
47 #include <abstract/report/aaITranscript.h>
48 #include "aaTranscript.h"
49 #include "aaBalanceSheet.h"
50 #include <abstract/storage/aaTestConsts.h>
52 #define AA_REPORT_TEST_CID \
53 {0xca303dca, 0xd6d4, 0x4049, {0xba, 0x4c, 0x51, 0x4b, 0xf2, 0x3c, 0x82, 0x98}}
54 #define AA_REPORT_TEST_CONTRACT_ID "@aasii.org/report/unit;1"
56 class aaReportTest: public nsITest
58 public:
59 aaReportTest() {;}
60 virtual ~aaReportTest() {;}
61 NS_DECL_ISUPPORTS
62 NS_DECL_NSITEST
63 private:
64 friend class RAII;
65 nsCOMPtr<aaISession> mSession;
66 nsCOMPtr<aaILoadQuery> mFlows;
68 nsresult testTranscript(nsITestRunner *aTestRunner);
69 nsresult testPnLTranscript(nsITestRunner *aTestRunner);
70 nsresult testBalanceSheet(nsITestRunner *aTestRunner);
73 class RAII
75 public:
76 RAII(aaReportTest *t);
77 ~RAII();
79 PRBool status;
80 private:
81 aaReportTest* test;
84 NS_IMETHODIMP
85 aaReportTest::Test(nsITestRunner *aTestRunner)
87 RAII res(this);
88 if (NS_FAILED( res.status )) {
89 aTestRunner->AddError(nsITestRunner::errorJS, \
90 AA_REPORT_TEST_CONTRACT_ID " not initialized");
91 return NS_ERROR_NOT_INITIALIZED;
93 testTranscript( aTestRunner );
94 testPnLTranscript(aTestRunner);
95 testBalanceSheet(aTestRunner);
96 return NS_OK;
99 NS_IMPL_ISUPPORTS1(aaReportTest, nsITest);
101 /* Helpers */
102 PRBool
103 testFact(nsITestRunner *cxxUnitTestRunner, aaIFact *node, PRInt64 fromFlowId,
104 PRInt64 toFlowId, double sum)
106 nsresult rv;
107 PRBool equals = PR_TRUE;
109 NS_TEST_ASSERT_MSG(node, " 'fact' is null");
110 if (NS_UNLIKELY( ! node ))
111 return PR_FALSE;
112 nsCOMPtr<aaIFlow> flow;
113 PRInt64 id;
114 node->GetTakeFrom(getter_AddRefs( flow ));
115 if ( flow ) {
116 flow->GetId( &id );
117 if (NS_UNLIKELY( id != fromFlowId )) {
118 equals = PR_FALSE;
119 NS_TEST_ASSERT_MSG(PR_FALSE, " 'fact.takeFrom.id' is wrong" );
121 } else if (NS_UNLIKELY( fromFlowId != 0 )) {
122 equals = PR_FALSE;
123 NS_TEST_ASSERT_MSG(PR_FALSE, " 'fact.takeFrom.id' is wrong" );
126 node->GetGiveTo(getter_AddRefs( flow ));
127 if ( flow ) {
128 flow->GetId( &id );
129 if (NS_UNLIKELY( id != toFlowId )) {
130 equals = PR_FALSE;
131 NS_TEST_ASSERT_MSG(PR_FALSE, " 'fact.giveTo.id' is wrong" );
133 } else if (NS_UNLIKELY( toFlowId != 0 )) {
134 equals = PR_FALSE;
135 NS_TEST_ASSERT_MSG(PR_FALSE, " 'fact.giveTo.id' is wrong" );
138 double amount, diff;
139 rv = node->GetAmount(&amount);
140 diff = amount - sum;
141 if (diff > 0.0001 || diff < -0.0001) {
142 equals = PR_FALSE;
143 NS_TEST_ASSERT_MSG(PR_FALSE, " 'fact.amount' is wrong" );
146 return equals;
149 PRBool
150 testTxn(nsITestRunner *cxxUnitTestRunner, aaITransaction *txn,
151 PRInt64 fromFlowId, PRInt64 toFlowId, double amount, double value,
152 PRBool status = 0, double earnings = 0.0)
154 PRBool equals = PR_TRUE;
156 NS_TEST_ASSERT_MSG(txn, " 'txn' is null");
157 if (NS_UNLIKELY( ! txn ))
158 return PR_FALSE;
159 if (! testFact(cxxUnitTestRunner, txn->PickFact(), fromFlowId, toFlowId,
160 amount))
161 return PR_FALSE;
163 double sum, diff;
164 txn->GetValue(&sum);
165 diff = value - sum;
166 if (! isZero(diff)) {
167 equals = PR_FALSE;
168 NS_TEST_ASSERT_MSG(PR_FALSE, " 'txn.value' is wrong" );
171 PRBool b;
172 txn->GetHasEarnings(&b);
173 if (b != status) {
174 equals = PR_FALSE;
175 NS_TEST_ASSERT_MSG(PR_FALSE, " 'txn.hasEarnings' is wrong" );
178 if (!b)
179 return equals;
181 return equals;
184 PRBool
185 testBalance(nsITestRunner *cxxUnitTestRunner, aaIBalance *node, PRInt64 flowId,
186 PRInt64 resourceId, double amount, double value, PRBool aSide)
188 nsresult rv;
189 PRBool equals = PR_TRUE;
190 if (NS_UNLIKELY( ! node )) {
191 NS_TEST_ASSERT_MSG(PR_FALSE, " 'balance' is null");
192 return PR_FALSE;
194 nsCOMPtr<aaIFlow> flow;
195 rv = node->GetFlow(getter_AddRefs( flow ));
196 NS_TEST_ASSERT_MSG(flow, " 'balance.flow' is null");
197 PRInt64 id;
198 if (NS_LIKELY( flow )) {
199 flow->GetId(&id);
200 if (NS_UNLIKELY( id != flowId) ) {
201 equals = PR_FALSE;
202 NS_TEST_ASSERT_MSG(PR_FALSE, " 'balance.flow.id' is wrong");
204 } else {
205 equals = PR_FALSE;
208 nsCOMPtr<aaIResource> resource;
209 rv = node->GetResource(getter_AddRefs( resource ));
210 NS_TEST_ASSERT_MSG(resource, " 'balance.resource' is null" );
211 if (NS_LIKELY( resource )) {
212 resource->GetId(&id);
213 if (NS_UNLIKELY( id != resourceId) ) {
214 nsEmbedCString msg(" 'balance.resource.id' is wrong - ");
215 msg.AppendInt(id);
216 equals = PR_FALSE;
217 NS_TEST_ASSERT_MSG(PR_FALSE, msg.get());
219 } else {
220 equals = PR_FALSE;
223 double sum, diff;
224 node->GetAmount(&sum);
225 diff = amount - sum;
226 if (NS_UNLIKELY(diff > 0.0001 || diff < -0.0001)) {
227 equals = PR_FALSE;
228 NS_TEST_ASSERT_MSG(PR_FALSE, " 'balance.amount' is wrong");
231 node->GetValue(&sum);
232 diff = value - sum;
233 if (NS_UNLIKELY(diff > 0.0001 || diff < -0.0001)) {
234 equals = PR_FALSE;
235 NS_TEST_ASSERT_MSG(PR_FALSE, " 'balance.value' is wrong");
238 PRBool side;
239 node->GetSide(&side);
240 if (NS_UNLIKELY( side != aSide)) {
241 equals = PR_FALSE;
242 NS_TEST_ASSERT_MSG(PR_FALSE, " 'balance.side' is wrong");
244 return equals;
247 PRBool
248 testIncomeState(nsITestRunner *cxxUnitTestRunner, aaIBalance *node,
249 double value, PRBool aSide)
251 nsresult rv;
252 PRBool equals = PR_TRUE;
253 if (NS_UNLIKELY( ! node )) {
254 NS_TEST_ASSERT_MSG(PR_FALSE, " 'income state' is null");
255 return PR_FALSE;
257 nsCOMPtr<aaIFlow> flow;
258 rv = node->GetFlow(getter_AddRefs( flow ));
259 PRInt64 id;
260 if (NS_LIKELY( flow )) {
261 flow->GetId(&id);
262 nsEmbedCString msg(" 'income state.flow' is wrong - ");
263 msg.AppendInt(id);
264 if (NS_UNLIKELY( id )) {
265 equals = PR_FALSE;
266 NS_TEST_ASSERT_MSG(PR_FALSE, msg.get());
268 } else {
269 equals = PR_FALSE;
270 NS_TEST_ASSERT_MSG(PR_FALSE, " 'income state.flow' is null");
273 nsCOMPtr<aaIResource> resource;
274 rv = node->GetResource(getter_AddRefs( resource ));
275 if (NS_UNLIKELY( resource )) {
276 resource->GetId(&id);
277 nsEmbedCString msg(" 'income state.resource' is not null -" );
278 msg.AppendInt(id);
279 equals = PR_FALSE;
280 NS_TEST_ASSERT_MSG(PR_FALSE, msg.get());
283 double sum, diff;
284 node->GetAmount(&sum);
285 diff = sum;
286 if (!isZero(diff)) {
287 equals = PR_FALSE;
288 NS_TEST_ASSERT_MSG(PR_FALSE, " 'income state.amount' is wrong");
291 node->GetValue(&sum);
292 diff = value - sum;
293 if (NS_UNLIKELY(diff > 0.0001 || diff < -0.0001)) {
294 equals = PR_FALSE;
295 NS_TEST_ASSERT_MSG(PR_FALSE, " 'income state.value' is wrong");
298 PRBool side;
299 node->GetSide(&side);
300 if (NS_UNLIKELY( side != aSide)) {
301 equals = PR_FALSE;
302 NS_TEST_ASSERT_MSG(PR_FALSE, " 'income state.side' is wrong");
304 return equals;
307 RAII::RAII(aaReportTest *t)
308 :status(PR_FALSE), test(nsnull)
310 nsresult rv;
311 nsCOMPtr<aaISession> session(do_CreateInstance(AA_SESSION_CONTRACT_ID, &rv));
312 if (NS_UNLIKELY( ! session))
313 return;
315 status = PR_TRUE;
316 test = t;
317 test->mSession = session;
320 RAII::~RAII()
322 test->mSession = nsnull;
323 test = nsnull;
326 /* Module and Factory code */
327 NS_GENERIC_FACTORY_CONSTRUCTOR(aaReportTest)
329 static const nsModuleComponentInfo kComponents[] =
332 "Report Module Unit Test",
333 AA_REPORT_TEST_CID,
334 AA_REPORT_TEST_CONTRACT_ID,
335 aaReportTestConstructor
338 NS_IMPL_NSGETMODULE(aareportt, kComponents)
340 /* Private methods */
341 nsresult
342 aaReportTest::testTranscript(nsITestRunner *aTestRunner)
344 nsresult rv;
345 NS_TEST_BEGIN( aTestRunner );
347 nsCOMPtr<mozIStorageConnection> connection;
348 rv = mSession->GetConnection(getter_AddRefs( connection ));
349 NS_TEST_ASSERT_OK(rv);
351 nsCOMPtr<aaITranscript> transcript( do_CreateInstance(
352 AA_TRANSCRIPT_CONTRACT_ID, connection) );
353 NS_TEST_ASSERT_MSG(transcript, "[transcript] intance creation");
354 NS_ENSURE_TRUE(transcript, rv);
356 rv = mSession->CreateQuery(AA_LOADFLOW_CONTRACT_ID, getter_AddRefs(mFlows));
357 NS_TEST_ASSERT_MSG(mFlows, "[transcript] creating flow loader");
358 NS_ENSURE_TRUE(mFlows, rv);
360 rv = mFlows->Load();
361 NS_TEST_ASSERT_OK(rv); NS_ENSURE_SUCCESS(rv, rv);
363 /* Set flow to bank */
364 nsCOMPtr<aaIFlow> bank = do_QueryElementAt(mFlows, 2);
365 transcript->SetFlow( bank );
367 /* *** Transcript [1] *** */
369 /* Set start time to 2007-08-28 */
370 PRExplodedTime tm = {0,0,0,12,28,7,2007};
371 transcript->SetStart(PR_ImplodeTime(&tm));
372 /* Set end time to 2007-08-29 */
373 tm.tm_mday = 29;
374 transcript->SetEnd(PR_ImplodeTime(&tm));
376 rv = transcript->Load();
377 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv), "[transcript] [1] loading");
379 nsCOMPtr<aaIBalance> balance;
380 rv = transcript->GetOpening(getter_AddRefs( balance ));
381 NS_TEST_ASSERT_OK(rv);
382 NS_TEST_ASSERT_MSG(! balance, "[transcript] [1] opening must be null");
384 rv = transcript->GetClosing(getter_AddRefs( balance ));
385 NS_TEST_ASSERT_OK(rv);
386 NS_TEST_ASSERT_MSG(testBalance(aTestRunner, balance, 3, 1, AA_EVENT_AMOUNT_2
387 + AA_EVENT_AMOUNT_3, AA_EVENT_AMOUNT_2 + AA_EVENT_AMOUNT_3, 1),
388 "[transcript] [1] closing is wrong");
390 PRUint32 count = 0;
391 rv = transcript->GetLength(&count);
392 NS_TEST_ASSERT_OK(rv);
393 NS_TEST_ASSERT_MSG(count == 2, "[transcript] [1] wrong fact count");
395 nsCOMPtr<aaITransaction> txn = do_QueryElementAt(transcript, 0);
396 NS_TEST_ASSERT_MSG(testFact(aTestRunner, txn->PickFact(), 2, 3,
397 AA_EVENT_AMOUNT_2), "[transcript] [1] 1st fact is wrong");
399 txn = do_QueryElementAt(transcript, 1);
400 NS_TEST_ASSERT_MSG(testFact(aTestRunner, txn->PickFact(), 1, 3,
401 AA_EVENT_AMOUNT_3), "[transcript] [1] 2nd fact is wrong");
403 /* *** Transcript [2] *** */
405 /* Set start time to 2007-08-28 */
406 tm.tm_mday = 28;
407 transcript->SetStart(PR_ImplodeTime(&tm));
408 /* Set end time to 2007-08-30 */
409 tm.tm_mday = 30;
410 transcript->SetEnd(PR_ImplodeTime(&tm));
412 rv = transcript->Load();
413 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv), "[transcript] [2] loading");
415 rv = transcript->GetOpening(getter_AddRefs( balance ));
416 NS_TEST_ASSERT_OK(rv);
417 NS_TEST_ASSERT_MSG(! balance, "[transcript] [2] opening must be null");
419 rv = transcript->GetClosing(getter_AddRefs( balance ));
420 NS_TEST_ASSERT_OK(rv);
421 NS_TEST_ASSERT_MSG(testBalance(aTestRunner, balance, 3, 1, AA_EVENT_AMOUNT_2
422 + AA_EVENT_AMOUNT_3 - AA_EVENT_AMOUNT_4- AA_EVENT_AMOUNT_6 * AA_EVENT_RATE_2, AA_EVENT_AMOUNT_2
423 + AA_EVENT_AMOUNT_3 - AA_EVENT_AMOUNT_4- AA_EVENT_AMOUNT_6 * AA_EVENT_RATE_2, 1),
424 "[transcript] [2] closing is wrong");
426 count = 0;
427 rv = transcript->GetLength(&count);
428 NS_TEST_ASSERT_OK(rv);
429 NS_TEST_ASSERT_MSG(count == 4, "[transcript] [2] wrong fact count");
431 txn = do_QueryElementAt(transcript, 0);
432 NS_TEST_ASSERT_MSG(testFact(aTestRunner, txn->PickFact(), 2, 3,
433 AA_EVENT_AMOUNT_2), "[transcript] [2] 1st fact is wrong");
435 txn = do_QueryElementAt(transcript, 1);
436 NS_TEST_ASSERT_MSG(testFact(aTestRunner, txn->PickFact(), 1, 3,
437 AA_EVENT_AMOUNT_3), "[transcript] [2] 2nd fact is wrong");
439 txn = do_QueryElementAt(transcript, 2);
440 NS_TEST_ASSERT_MSG(testFact(aTestRunner, txn->PickFact(), 3, 4,
441 AA_EVENT_AMOUNT_4), "[update txn] pending fact is wrong");
443 /* *** Transcript [3] *** */
445 /* Set start time to 2007-08-29 */
446 tm.tm_mday = 29;
447 transcript->SetStart(PR_ImplodeTime(&tm));
448 /* Set end time to 2007-08-31 */
449 tm.tm_mday = 31;
450 transcript->SetEnd(PR_ImplodeTime(&tm));
452 rv = transcript->Load();
453 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv), "[transcript] [3] loading");
455 rv = transcript->GetOpening(getter_AddRefs( balance ));
456 NS_TEST_ASSERT_OK(rv);
457 NS_TEST_ASSERT_MSG(testBalance(aTestRunner, balance, 3, 1, AA_EVENT_AMOUNT_2
458 + AA_EVENT_AMOUNT_3, AA_EVENT_AMOUNT_2 + AA_EVENT_AMOUNT_3, 1),
459 "[transcript] [3] opening is wrong");
461 rv = transcript->GetClosing(getter_AddRefs( balance ));
462 NS_TEST_ASSERT_OK(rv);
463 NS_TEST_ASSERT_MSG(testBalance(aTestRunner, balance, 3, 1, AA_EVENT_AMOUNT_2
464 + AA_EVENT_AMOUNT_3 - AA_EVENT_AMOUNT_4
465 - AA_EVENT_AMOUNT_6 * AA_EVENT_RATE_2, AA_EVENT_AMOUNT_2
466 + AA_EVENT_AMOUNT_3 - AA_EVENT_AMOUNT_4
467 - AA_EVENT_AMOUNT_6 * AA_EVENT_RATE_2, 1),
468 "[transcript] [3] closing is wrong");
470 count = 0;
471 rv = transcript->GetLength(&count);
472 NS_TEST_ASSERT_OK(rv);
473 NS_TEST_ASSERT_MSG(count == 2, "[transcript] [3] wrong fact count");
475 txn = do_QueryElementAt(transcript, 0);
476 NS_TEST_ASSERT_MSG(testFact(aTestRunner, txn->PickFact(), 3, 4,
477 AA_EVENT_AMOUNT_4), "[transcript] [3] pending fact is wrong");
479 /* *** Transcript [4] *** */
481 /* Set start time to 2007-08-28 */
482 tm.tm_mday = 27;
483 transcript->SetStart(PR_ImplodeTime(&tm));
484 /* Set end time to 2007-08-29 */
485 tm.tm_mday = 28;
486 transcript->SetEnd(PR_ImplodeTime(&tm));
488 rv = transcript->Load();
489 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv), "[transcript] [4] loading");
491 rv = transcript->GetOpening(getter_AddRefs( balance ));
492 NS_TEST_ASSERT_OK(rv);
493 NS_TEST_ASSERT_MSG(! balance, "[transcript] [4] opening must be null");
495 rv = transcript->GetClosing(getter_AddRefs( balance ));
496 NS_TEST_ASSERT_OK(rv);
497 NS_TEST_ASSERT_MSG(! balance, "[transcript] [4] closing must be null");
499 count = 1;
500 rv = transcript->GetLength(&count);
501 NS_TEST_ASSERT_OK(rv);
502 NS_TEST_ASSERT_MSG(count == 0, "[transcript] [4] wrong fact count");
504 /* *** Transcript [5] *** */
506 /* Set start time to 2007-08-28 */
507 tm.tm_mday = 28;
508 transcript->SetStart(PR_ImplodeTime(&tm));
509 /* Set end time to 2007-08-30 */
510 tm.tm_mday = 30;
511 transcript->SetEnd(PR_ImplodeTime(&tm));
513 nsCOMPtr<aaIFlow> purchase = do_QueryElementAt(mFlows, 3);
514 transcript->SetFlow(purchase);
515 rv = transcript->Load();
516 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv), "[transcript] [5] loading");
518 rv = transcript->GetOpening(getter_AddRefs( balance ));
519 NS_TEST_ASSERT_OK(rv);
520 NS_TEST_ASSERT_MSG(! balance, "[transcript] [5] opening must be null");
522 rv = transcript->GetClosing(getter_AddRefs( balance ));
523 NS_TEST_ASSERT_OK(rv);
524 NS_TEST_ASSERT_MSG(testBalance(aTestRunner, balance, 4, 3, AA_EVENT_AMOUNT_5,
525 AA_EVENT_AMOUNT_4, 1), "[transcript] [5] closing is wrong");
527 count = 0;
528 rv = transcript->GetLength(&count);
529 NS_TEST_ASSERT_OK(rv);
530 NS_TEST_ASSERT_MSG(count == 1, "[transcript] [5] wrong fact count");
532 txn = do_QueryElementAt(transcript, 0);
533 NS_TEST_ASSERT_MSG(testFact(aTestRunner, txn->PickFact(), 3, 4,
534 AA_EVENT_AMOUNT_4), "[update txn] pending fact is wrong");
536 return NS_OK;
539 nsresult
540 aaReportTest::testPnLTranscript(nsITestRunner *aTestRunner)
542 nsresult rv;
543 NS_TEST_BEGIN( aTestRunner );
545 nsCOMPtr<aaITranscript> transcript;
546 rv = mSession->CreateQuery(AA_TRANSCRIPT_CONTRACT_ID,
547 getter_AddRefs(transcript));
548 NS_TEST_ASSERT_MSG(transcript, "[transcript] intance creation");
549 NS_ENSURE_TRUE(transcript, rv);
551 /* Set flow to PnL */
552 nsCOMPtr<aaIFlow> finres = do_CreateInstance("@aasii.org/base/income-flow;1");
553 transcript->SetFlow( finres );
555 /* *** Transcript [6] *** */
557 /* Set start time to 2007-08-28 */
558 PRExplodedTime tm = {0,0,0,12,28,7,2007};
559 transcript->SetStart(PR_ImplodeTime(&tm));
560 /* Set end time to 2007-09-10 */
561 tm.tm_month = 8;
562 tm.tm_mday = 10;
563 transcript->SetEnd(PR_ImplodeTime(&tm));
565 rv = transcript->Load();
566 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv), "[transcript] [6] loading");
568 nsCOMPtr<aaIBalance> balance;
569 rv = transcript->GetOpening(getter_AddRefs( balance ));
570 NS_TEST_ASSERT_OK(rv);
571 NS_TEST_ASSERT_MSG(! balance, "[transcript] [6] opening must be null");
573 rv = transcript->GetClosing(getter_AddRefs( balance ));
574 NS_TEST_ASSERT_OK(rv);
575 NS_TEST_ASSERT_MSG(testIncomeState(aTestRunner, balance, AA_EVENT_AMOUNT_15
576 * (AA_EVENT_RATE_5 - AA_EVENT_RATE_4), 0),
577 "[transcript] [6] closing is wrong");
579 PRUint32 count = 0;
580 rv = transcript->GetLength(&count);
581 NS_TEST_ASSERT_OK(rv);
582 NS_TEST_ASSERT_MSG(count == 8, "[transcript] [8] wrong txn count");
584 nsCOMPtr<aaITransaction> txn = do_QueryElementAt(transcript, 0);
585 NS_TEST_ASSERT_MSG(testTxn(aTestRunner, txn, 6, 7, AA_EVENT_AMOUNT_6,
586 AA_EVENT_AMOUNT_6 * AA_EVENT_RATE_2, 1, AA_EVENT_AMOUNT_6
587 * (AA_EVENT_RATE_3 - AA_EVENT_RATE_2)), "[transcript] [8] 1st txn is wrong");
589 txn = do_QueryElementAt(transcript, 7);
590 NS_TEST_ASSERT_MSG(testTxn(aTestRunner, txn, 0, 10, AA_EVENT_AMOUNT_15, 0.0,
591 1, AA_EVENT_AMOUNT_15 * AA_EVENT_RATE_5),
592 "[transcript] [8] 8th txn is wrong");
594 return NS_OK;
597 nsresult
598 aaReportTest::testBalanceSheet(nsITestRunner *aTestRunner)
600 nsresult rv;
601 NS_TEST_BEGIN( aTestRunner );
603 nsCOMPtr<aaILoadQuery> sheet;
604 rv = mSession->CreateQuery(AA_BALANCESHEET_CONTRACT_ID,
605 getter_AddRefs(sheet));
606 NS_TEST_ASSERT_MSG(sheet, "[balance sheet] intance creation");
607 NS_ENSURE_TRUE(sheet, rv);
609 rv = sheet->Load();
610 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv), "[balance sheet] [1] loading");
612 PRUint32 count = 0;
613 rv = sheet->GetLength(&count);
614 NS_TEST_ASSERT_OK(rv);
615 NS_TEST_ASSERT_MSG(count == 7, "[balance sheet] [1] wrong line count");
617 nsCOMPtr<aaIBalance> balance = do_QueryElementAt(sheet, 6);
618 NS_TEST_ASSERT_MSG(balance, "[balance sheet] income not loaded" );
620 NS_TEST_ASSERT_MSG(testIncomeState(aTestRunner, balance, AA_EVENT_AMOUNT_15
621 * (AA_EVENT_RATE_5 - AA_EVENT_RATE_4), 0),
622 "[balance sheet] income is wrong");
624 return NS_OK;