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) 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>
25 #include "nsIGenericFactory.h"
26 #include "nsComponentManagerUtils.h"
28 #include "nsArrayUtils.h"
29 #include "nsEmbedString.h"
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 <abstract/report/aaIBalanceSheet.h>
49 #include "aaTranscript.h"
50 #include "aaBalanceSheet.h"
51 #include <abstract/storage/aaTestConsts.h>
53 #define AA_REPORT_TEST_CID \
54 {0xca303dca, 0xd6d4, 0x4049, {0xba, 0x4c, 0x51, 0x4b, 0xf2, 0x3c, 0x82, 0x98}}
55 #define AA_REPORT_TEST_CONTRACT_ID "@aasii.org/report/unit;1"
57 class aaReportTest
: public nsITest
61 virtual ~aaReportTest() {;}
66 nsCOMPtr
<aaISession
> mSession
;
67 nsCOMPtr
<aaILoadQuery
> mFlows
;
69 nsresult
testTranscript(nsITestRunner
*aTestRunner
);
70 nsresult
testPnLTranscript(nsITestRunner
*aTestRunner
);
71 nsresult
testBalanceSheet(nsITestRunner
*aTestRunner
);
77 RAII(aaReportTest
*t
);
86 aaReportTest::Test(nsITestRunner
*aTestRunner
)
89 if (NS_FAILED( res
.status
)) {
90 aTestRunner
->AddError(nsITestRunner::errorJS
, \
91 AA_REPORT_TEST_CONTRACT_ID
" not initialized");
92 return NS_ERROR_NOT_INITIALIZED
;
94 testTranscript( aTestRunner
);
95 testPnLTranscript(aTestRunner
);
96 testBalanceSheet(aTestRunner
);
100 NS_IMPL_ISUPPORTS1(aaReportTest
, nsITest
);
104 testFact(nsITestRunner
*cxxUnitTestRunner
, aaIFact
*node
, PRInt64 fromFlowId
,
105 PRInt64 toFlowId
, double sum
)
108 PRBool equals
= PR_TRUE
;
110 NS_TEST_ASSERT_MSG(node
, " 'fact' is null");
111 if (NS_UNLIKELY( ! node
))
113 nsCOMPtr
<aaIFlow
> flow
;
115 node
->GetTakeFrom(getter_AddRefs( flow
));
118 if (NS_UNLIKELY( id
!= fromFlowId
)) {
120 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'fact.takeFrom.id' is wrong" );
122 } else if (NS_UNLIKELY( fromFlowId
!= 0 )) {
124 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'fact.takeFrom.id' is wrong" );
127 node
->GetGiveTo(getter_AddRefs( flow
));
130 if (NS_UNLIKELY( id
!= toFlowId
)) {
132 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'fact.giveTo.id' is wrong" );
134 } else if (NS_UNLIKELY( toFlowId
!= 0 )) {
136 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'fact.giveTo.id' is wrong" );
140 rv
= node
->GetAmount(&amount
);
142 if (diff
> 0.0001 || diff
< -0.0001) {
144 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'fact.amount' is wrong" );
151 testTxn(nsITestRunner
*cxxUnitTestRunner
, aaITransaction
*txn
,
152 PRInt64 fromFlowId
, PRInt64 toFlowId
, double amount
, double value
,
153 PRBool status
= 0, double earnings
= 0.0)
155 PRBool equals
= PR_TRUE
;
157 NS_TEST_ASSERT_MSG(txn
, " 'txn' is null");
158 if (NS_UNLIKELY( ! txn
))
160 if (! testFact(cxxUnitTestRunner
, txn
->PickFact(), fromFlowId
, toFlowId
,
167 if (! isZero(diff
)) {
169 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'txn.value' is wrong" );
173 txn
->GetHasEarnings(&b
);
176 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'txn.hasEarnings' is wrong" );
186 testBalance(nsITestRunner
*cxxUnitTestRunner
, aaIBalance
*node
, PRInt64 flowId
,
187 PRInt64 resourceId
, double amount
, double value
, PRBool aSide
)
190 PRBool equals
= PR_TRUE
;
191 if (NS_UNLIKELY( ! node
)) {
192 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'balance' is null");
195 nsCOMPtr
<aaIFlow
> flow
;
196 rv
= node
->GetFlow(getter_AddRefs( flow
));
197 NS_TEST_ASSERT_MSG(flow
, " 'balance.flow' is null");
199 if (NS_LIKELY( flow
)) {
201 if (NS_UNLIKELY( id
!= flowId
) ) {
202 nsEmbedCString
msg(" 'balance.flow.id' is wrong - ");
205 NS_TEST_ASSERT_MSG(PR_FALSE
, msg
.get());
211 nsCOMPtr
<aaIResource
> resource
;
212 rv
= node
->GetResource(getter_AddRefs( resource
));
213 NS_TEST_ASSERT_MSG(resource
, " 'balance.resource' is null" );
214 if (NS_LIKELY( resource
)) {
215 resource
->GetId(&id
);
216 if (NS_UNLIKELY( id
!= resourceId
) ) {
217 nsEmbedCString
msg(" 'balance.resource.id' is wrong - ");
220 NS_TEST_ASSERT_MSG(PR_FALSE
, msg
.get());
227 node
->GetAmount(&sum
);
229 if (NS_UNLIKELY(diff
> 0.0001 || diff
< -0.0001)) {
231 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'balance.amount' is wrong");
234 node
->GetValue(&sum
);
236 if (NS_UNLIKELY(diff
> 0.0001 || diff
< -0.0001)) {
238 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'balance.value' is wrong");
242 node
->GetSide(&side
);
243 if (NS_UNLIKELY( side
!= aSide
)) {
245 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'balance.side' is wrong");
251 testIncomeState(nsITestRunner
*cxxUnitTestRunner
, aaIBalance
*node
,
252 double value
, PRBool aSide
)
255 PRBool equals
= PR_TRUE
;
256 if (NS_UNLIKELY( ! node
)) {
257 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'income state' is null");
260 nsCOMPtr
<aaIFlow
> flow
;
261 rv
= node
->GetFlow(getter_AddRefs( flow
));
263 if (NS_LIKELY( flow
)) {
265 nsEmbedCString
msg(" 'income state.flow' is wrong - ");
267 if (NS_UNLIKELY( id
)) {
269 NS_TEST_ASSERT_MSG(PR_FALSE
, msg
.get());
273 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'income state.flow' is null");
276 nsCOMPtr
<aaIResource
> resource
;
277 rv
= node
->GetResource(getter_AddRefs( resource
));
278 if (NS_UNLIKELY( resource
)) {
279 resource
->GetId(&id
);
280 nsEmbedCString
msg(" 'income state.resource' is not null -" );
283 NS_TEST_ASSERT_MSG(PR_FALSE
, msg
.get());
287 node
->GetAmount(&sum
);
291 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'income state.amount' is wrong");
294 node
->GetValue(&sum
);
296 if (NS_UNLIKELY(diff
> 0.0001 || diff
< -0.0001)) {
298 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'income state.value' is wrong");
302 node
->GetSide(&side
);
303 if (NS_UNLIKELY( side
!= aSide
)) {
305 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'income state.side' is wrong");
310 RAII::RAII(aaReportTest
*t
)
311 :status(PR_FALSE
), test(nsnull
)
314 nsCOMPtr
<aaISession
> session(do_CreateInstance(AA_SESSION_CONTRACT_ID
, &rv
));
315 if (NS_UNLIKELY( ! session
))
320 test
->mSession
= session
;
325 test
->mSession
= nsnull
;
329 /* Module and Factory code */
330 NS_GENERIC_FACTORY_CONSTRUCTOR(aaReportTest
)
332 static const nsModuleComponentInfo kComponents
[] =
335 "Report Module Unit Test",
337 AA_REPORT_TEST_CONTRACT_ID
,
338 aaReportTestConstructor
341 NS_IMPL_NSGETMODULE(aareportt
, kComponents
)
343 /* Private methods */
345 aaReportTest::testTranscript(nsITestRunner
*aTestRunner
)
348 NS_TEST_BEGIN( aTestRunner
);
350 nsCOMPtr
<mozIStorageConnection
> connection
;
351 rv
= mSession
->GetConnection(getter_AddRefs( connection
));
352 NS_TEST_ASSERT_OK(rv
);
354 nsCOMPtr
<aaITranscript
> transcript( do_CreateInstance(
355 AA_TRANSCRIPT_CONTRACT_ID
, connection
) );
356 NS_TEST_ASSERT_MSG(transcript
, "[transcript] intance creation");
357 NS_ENSURE_TRUE(transcript
, rv
);
359 rv
= mSession
->CreateQuery(AA_LOADFLOW_CONTRACT_ID
, getter_AddRefs(mFlows
));
360 NS_TEST_ASSERT_MSG(mFlows
, "[transcript] creating flow loader");
361 NS_ENSURE_TRUE(mFlows
, rv
);
364 NS_TEST_ASSERT_OK(rv
); NS_ENSURE_SUCCESS(rv
, rv
);
366 /* Set flow to bank */
367 nsCOMPtr
<aaIFlow
> bank
= do_QueryElementAt(mFlows
, 2);
368 transcript
->SetFlow( bank
);
370 /* *** Transcript [1] *** */
372 /* Set start time to 2007-08-28 */
373 PRExplodedTime tm
= {0,0,0,12,28,7,2007};
374 transcript
->SetStart(PR_ImplodeTime(&tm
));
375 /* Set end time to 2007-08-29 */
377 transcript
->SetEnd(PR_ImplodeTime(&tm
));
379 rv
= transcript
->Load();
380 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[transcript] [1] loading");
382 nsCOMPtr
<aaIBalance
> balance
;
383 rv
= transcript
->GetOpening(getter_AddRefs( balance
));
384 NS_TEST_ASSERT_OK(rv
);
385 NS_TEST_ASSERT_MSG(! balance
, "[transcript] [1] opening must be null");
387 rv
= transcript
->GetClosing(getter_AddRefs( balance
));
388 NS_TEST_ASSERT_OK(rv
);
389 NS_TEST_ASSERT_MSG(testBalance(aTestRunner
, balance
, 3, 1, AA_EVENT_AMOUNT_2
390 + AA_EVENT_AMOUNT_3
, AA_EVENT_AMOUNT_2
+ AA_EVENT_AMOUNT_3
, 1),
391 "[transcript] [1] closing is wrong");
394 rv
= transcript
->GetLength(&count
);
395 NS_TEST_ASSERT_OK(rv
);
396 NS_TEST_ASSERT_MSG(count
== 2, "[transcript] [1] wrong fact count");
398 nsCOMPtr
<aaITransaction
> txn
= do_QueryElementAt(transcript
, 0);
399 NS_TEST_ASSERT_MSG(testFact(aTestRunner
, txn
->PickFact(), 2, 3,
400 AA_EVENT_AMOUNT_2
), "[transcript] [1] 1st fact is wrong");
402 txn
= do_QueryElementAt(transcript
, 1);
403 NS_TEST_ASSERT_MSG(testFact(aTestRunner
, txn
->PickFact(), 1, 3,
404 AA_EVENT_AMOUNT_3
), "[transcript] [1] 2nd fact is wrong");
406 /* *** Transcript [2] *** */
408 /* Set start time to 2007-08-28 */
410 transcript
->SetStart(PR_ImplodeTime(&tm
));
411 /* Set end time to 2007-08-30 */
413 transcript
->SetEnd(PR_ImplodeTime(&tm
));
415 rv
= transcript
->Load();
416 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[transcript] [2] loading");
418 rv
= transcript
->GetOpening(getter_AddRefs( balance
));
419 NS_TEST_ASSERT_OK(rv
);
420 NS_TEST_ASSERT_MSG(! balance
, "[transcript] [2] opening must be null");
422 rv
= transcript
->GetClosing(getter_AddRefs( balance
));
423 NS_TEST_ASSERT_OK(rv
);
424 NS_TEST_ASSERT_MSG(testBalance(aTestRunner
, balance
, 3, 1, AA_EVENT_AMOUNT_2
425 + AA_EVENT_AMOUNT_3
- AA_EVENT_AMOUNT_4
- AA_EVENT_AMOUNT_6
* AA_EVENT_RATE_2
, AA_EVENT_AMOUNT_2
426 + AA_EVENT_AMOUNT_3
- AA_EVENT_AMOUNT_4
- AA_EVENT_AMOUNT_6
* AA_EVENT_RATE_2
, 1),
427 "[transcript] [2] closing is wrong");
430 rv
= transcript
->GetLength(&count
);
431 NS_TEST_ASSERT_OK(rv
);
432 NS_TEST_ASSERT_MSG(count
== 4, "[transcript] [2] wrong fact count");
434 txn
= do_QueryElementAt(transcript
, 0);
435 NS_TEST_ASSERT_MSG(testFact(aTestRunner
, txn
->PickFact(), 2, 3,
436 AA_EVENT_AMOUNT_2
), "[transcript] [2] 1st fact is wrong");
438 txn
= do_QueryElementAt(transcript
, 1);
439 NS_TEST_ASSERT_MSG(testFact(aTestRunner
, txn
->PickFact(), 1, 3,
440 AA_EVENT_AMOUNT_3
), "[transcript] [2] 2nd fact is wrong");
442 txn
= do_QueryElementAt(transcript
, 2);
443 NS_TEST_ASSERT_MSG(testFact(aTestRunner
, txn
->PickFact(), 3, 4,
444 AA_EVENT_AMOUNT_4
), "[update txn] pending fact is wrong");
446 /* *** Transcript [3] *** */
448 /* Set start time to 2007-08-29 */
450 transcript
->SetStart(PR_ImplodeTime(&tm
));
451 /* Set end time to 2007-08-31 */
453 transcript
->SetEnd(PR_ImplodeTime(&tm
));
455 rv
= transcript
->Load();
456 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[transcript] [3] loading");
458 rv
= transcript
->GetOpening(getter_AddRefs( balance
));
459 NS_TEST_ASSERT_OK(rv
);
460 NS_TEST_ASSERT_MSG(testBalance(aTestRunner
, balance
, 3, 1, AA_EVENT_AMOUNT_2
461 + AA_EVENT_AMOUNT_3
, AA_EVENT_AMOUNT_2
+ AA_EVENT_AMOUNT_3
, 1),
462 "[transcript] [3] opening is wrong");
464 rv
= transcript
->GetClosing(getter_AddRefs( balance
));
465 NS_TEST_ASSERT_OK(rv
);
466 NS_TEST_ASSERT_MSG(testBalance(aTestRunner
, balance
, 3, 1, AA_EVENT_AMOUNT_2
467 + AA_EVENT_AMOUNT_3
- AA_EVENT_AMOUNT_4
468 - AA_EVENT_AMOUNT_6
* AA_EVENT_RATE_2
, AA_EVENT_AMOUNT_2
469 + AA_EVENT_AMOUNT_3
- AA_EVENT_AMOUNT_4
470 - AA_EVENT_AMOUNT_6
* AA_EVENT_RATE_2
, 1),
471 "[transcript] [3] closing is wrong");
474 rv
= transcript
->GetLength(&count
);
475 NS_TEST_ASSERT_OK(rv
);
476 NS_TEST_ASSERT_MSG(count
== 2, "[transcript] [3] wrong fact count");
478 txn
= do_QueryElementAt(transcript
, 0);
479 NS_TEST_ASSERT_MSG(testFact(aTestRunner
, txn
->PickFact(), 3, 4,
480 AA_EVENT_AMOUNT_4
), "[transcript] [3] pending fact is wrong");
482 /* *** Transcript [4] *** */
484 /* Set start time to 2007-08-28 */
486 transcript
->SetStart(PR_ImplodeTime(&tm
));
487 /* Set end time to 2007-08-29 */
489 transcript
->SetEnd(PR_ImplodeTime(&tm
));
491 rv
= transcript
->Load();
492 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[transcript] [4] loading");
494 rv
= transcript
->GetOpening(getter_AddRefs( balance
));
495 NS_TEST_ASSERT_OK(rv
);
496 NS_TEST_ASSERT_MSG(! balance
, "[transcript] [4] opening must be null");
498 rv
= transcript
->GetClosing(getter_AddRefs( balance
));
499 NS_TEST_ASSERT_OK(rv
);
500 NS_TEST_ASSERT_MSG(! balance
, "[transcript] [4] closing must be null");
503 rv
= transcript
->GetLength(&count
);
504 NS_TEST_ASSERT_OK(rv
);
505 NS_TEST_ASSERT_MSG(count
== 0, "[transcript] [4] wrong fact count");
507 /* *** Transcript [5] *** */
509 /* Set start time to 2007-08-28 */
511 transcript
->SetStart(PR_ImplodeTime(&tm
));
512 /* Set end time to 2007-08-30 */
514 transcript
->SetEnd(PR_ImplodeTime(&tm
));
516 nsCOMPtr
<aaIFlow
> purchase
= do_QueryElementAt(mFlows
, 3);
517 transcript
->SetFlow(purchase
);
518 rv
= transcript
->Load();
519 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[transcript] [5] loading");
521 rv
= transcript
->GetOpening(getter_AddRefs( balance
));
522 NS_TEST_ASSERT_OK(rv
);
523 NS_TEST_ASSERT_MSG(! balance
, "[transcript] [5] opening must be null");
525 rv
= transcript
->GetClosing(getter_AddRefs( balance
));
526 NS_TEST_ASSERT_OK(rv
);
527 NS_TEST_ASSERT_MSG(testBalance(aTestRunner
, balance
, 4, 3, AA_EVENT_AMOUNT_5
,
528 AA_EVENT_AMOUNT_4
, 1), "[transcript] [5] closing is wrong");
531 rv
= transcript
->GetLength(&count
);
532 NS_TEST_ASSERT_OK(rv
);
533 NS_TEST_ASSERT_MSG(count
== 1, "[transcript] [5] wrong fact count");
535 txn
= do_QueryElementAt(transcript
, 0);
536 NS_TEST_ASSERT_MSG(testFact(aTestRunner
, txn
->PickFact(), 3, 4,
537 AA_EVENT_AMOUNT_4
), "[update txn] pending fact is wrong");
543 aaReportTest::testPnLTranscript(nsITestRunner
*aTestRunner
)
546 NS_TEST_BEGIN( aTestRunner
);
548 nsCOMPtr
<aaITranscript
> transcript
;
549 rv
= mSession
->CreateQuery(AA_TRANSCRIPT_CONTRACT_ID
,
550 getter_AddRefs(transcript
));
551 NS_TEST_ASSERT_MSG(transcript
, "[transcript] intance creation");
552 NS_ENSURE_TRUE(transcript
, rv
);
554 /* Set flow to PnL */
555 nsCOMPtr
<aaIFlow
> finres
= do_CreateInstance("@aasii.org/base/income-flow;1");
556 transcript
->SetFlow( finres
);
558 /* *** Transcript [6] *** */
560 /* Set start time to 2007-08-28 */
561 PRExplodedTime tm
= {0,0,0,12,28,7,2007};
562 transcript
->SetStart(PR_ImplodeTime(&tm
));
563 /* Set end time to 2007-09-10 */
566 transcript
->SetEnd(PR_ImplodeTime(&tm
));
568 rv
= transcript
->Load();
569 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[transcript] [6] loading");
571 nsCOMPtr
<aaIBalance
> balance
;
572 rv
= transcript
->GetOpening(getter_AddRefs( balance
));
573 NS_TEST_ASSERT_OK(rv
);
574 NS_TEST_ASSERT_MSG(! balance
, "[transcript] [6] opening must be null");
576 rv
= transcript
->GetClosing(getter_AddRefs( balance
));
577 NS_TEST_ASSERT_OK(rv
);
578 NS_TEST_ASSERT_MSG(testIncomeState(aTestRunner
, balance
, AA_EVENT_AMOUNT_15
579 * (AA_EVENT_RATE_5
- AA_EVENT_RATE_4
), 0),
580 "[transcript] [6] closing is wrong");
583 rv
= transcript
->GetLength(&count
);
584 NS_TEST_ASSERT_OK(rv
);
585 NS_TEST_ASSERT_MSG(count
== 8, "[transcript] [8] wrong txn count");
587 nsCOMPtr
<aaITransaction
> txn
= do_QueryElementAt(transcript
, 0);
588 NS_TEST_ASSERT_MSG(testTxn(aTestRunner
, txn
, 6, 7, AA_EVENT_AMOUNT_6
,
589 AA_EVENT_AMOUNT_6
* AA_EVENT_RATE_2
, 1, AA_EVENT_AMOUNT_6
590 * (AA_EVENT_RATE_3
- AA_EVENT_RATE_2
)), "[transcript] [8] 1st txn is wrong");
592 txn
= do_QueryElementAt(transcript
, 7);
593 NS_TEST_ASSERT_MSG(testTxn(aTestRunner
, txn
, 0, 10, AA_EVENT_AMOUNT_15
, 0.0,
594 1, AA_EVENT_AMOUNT_15
* AA_EVENT_RATE_5
),
595 "[transcript] [8] 8th txn is wrong");
601 aaReportTest::testBalanceSheet(nsITestRunner
*aTestRunner
)
604 NS_TEST_BEGIN( aTestRunner
);
606 nsCOMPtr
<aaIBalanceSheet
> sheet
;
607 rv
= mSession
->CreateQuery(AA_BALANCESHEET_CONTRACT_ID
,
608 getter_AddRefs(sheet
));
609 NS_TEST_ASSERT_MSG(sheet
, "[balance sheet] intance creation");
610 NS_ENSURE_TRUE(sheet
, rv
);
613 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[balance sheet] [1] loading");
616 rv
= sheet
->GetLength(&count
);
617 NS_TEST_ASSERT_OK(rv
);
618 NS_TEST_ASSERT_MSG(count
== 7, "[balance sheet] [1] wrong line count");
620 nsCOMPtr
<aaIBalance
> balance
= do_QueryElementAt(sheet
, 6);
621 NS_TEST_ASSERT_MSG(balance
, "[balance sheet] income not loaded" );
623 NS_TEST_ASSERT_MSG(testIncomeState(aTestRunner
, balance
, AA_EVENT_AMOUNT_15
624 * (AA_EVENT_RATE_5
- AA_EVENT_RATE_4
), 0),
625 "[balance sheet] income is wrong");
627 double assets
, liabilities
;
628 rv
= sheet
->GetTotalAssets(&assets
);
629 NS_TEST_ASSERT_OK(rv
);
630 NS_TEST_ASSERT_MSG(isZero(assets
- 242300),
631 "[balance sheet] [1] wrong total assets");
633 rv
= sheet
->GetTotalLiabilities(&liabilities
);
634 NS_TEST_ASSERT_OK(rv
);
635 NS_TEST_ASSERT_MSG(isZero(liabilities
- 242300),
636 "[balance sheet] [1] wrong total liabilities");
638 /* Set date to 2007-09-07 */
639 PRExplodedTime tm
= {0,0,0,12,7,8,2007};
640 rv
= sheet
->SetDate(PR_ImplodeTime(&tm
));
643 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[balance sheet] [2] loading");
645 sheet
->GetLength(&count
);
646 NS_TEST_ASSERT_MSG(count
== 6, "[balance sheet] [2] wrong flow count");
648 balance
= do_QueryElementAt(sheet
, 0);
649 NS_TEST_ASSERT_MSG(testBalance(aTestRunner
, balance
, 2, 2, AA_EVENT_AMOUNT_2
650 / AA_FLOW_SHARE_RATE
, AA_EVENT_AMOUNT_2
, 0),
651 "[balance sheet] flow2 is wrong");
653 balance
= do_QueryElementAt(sheet
, 1);
654 NS_TEST_ASSERT_MSG(testBalance(aTestRunner
, balance
, 1, 2, AA_EVENT_AMOUNT_3
655 / AA_FLOW_SHARE_RATE
, AA_EVENT_AMOUNT_3
, 0),
656 "[balance sheet] flow1 is wrong");
658 balance
= do_QueryElementAt(sheet
, 2);
659 NS_TEST_ASSERT_MSG(testBalance(aTestRunner
, balance
, 4, 3, AA_EVENT_AMOUNT_5
,
660 AA_EVENT_AMOUNT_4
, 1), "[balance sheet] flow4 is wrong");
662 balance
= do_QueryElementAt(sheet
, 3);
663 NS_TEST_ASSERT_MSG(testBalance(aTestRunner
, balance
, 6, 4,
664 2400, 2400 * AA_EVENT_RATE_4
, 1),
665 "[balance sheet] flow6 is wrong");
667 balance
= do_QueryElementAt(sheet
, 4);
668 NS_TEST_ASSERT_MSG(testBalance(aTestRunner
, balance
, 9, 5,
669 1, AA_EVENT_RATE_6
, 1),
670 "[balance sheet] flow9 is wrong");
672 balance
= do_QueryElementAt(sheet
, 5);
673 NS_TEST_ASSERT_MSG(testBalance(aTestRunner
, balance
, 3, 1, 87920, 87920,
674 1), "[balance sheet] flow3 is wrong");
676 rv
= sheet
->GetTotalAssets(&assets
);
677 NS_TEST_ASSERT_OK(rv
);
678 NS_TEST_ASSERT_MSG(isZero(assets
- 242000),
679 "[balance sheet] [2] wrong total assets");
681 rv
= sheet
->GetTotalLiabilities(&liabilities
);
682 NS_TEST_ASSERT_OK(rv
);
683 NS_TEST_ASSERT_MSG(isZero(liabilities
- 242000),
684 "[balance sheet] [2] wrong total liabilities");