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>
24 #include "nsIGenericFactory.h"
25 #include "nsComponentManagerUtils.h"
26 #include "nsArrayUtils.h"
27 #include "nsStringAPI.h"
28 #include "nsEmbedString.h"
31 #include <unstable/mozIStorageConnection.h>
32 #include <abstract/cxxunit/nsCxxUnit.h>
33 #include <abstract/cxxunit/nsITest.h>
34 #include <abstract/cxxunit/nsITestRunner.h>
36 /* Project includes */
37 #include <abstract/base/aaIResource.h>
38 #include <abstract/base/aaIFact.h>
39 #include <abstract/base/aaIFlow.h>
40 #include <abstract/base/aaIQuote.h>
41 #include <abstract/base/aaITransaction.h>
42 #include <abstract/base/aaIBalance.h>
43 #include <abstract/storage/aaISession.h>
44 #include <abstract/storage/aaBaseLoaders.h>
45 #include <abstract/storage/aaAccountLoaders.h>
46 #include <abstract/storage/aaIFilter.h>
47 #include <abstract/storage/aaILoadQuery.h>
48 #include "aaStorageTest.h"
49 #include "aaSaveTransaction.h"
50 /* XXX _acc This is a temporary hack to acquire connection
51 * It has to be replaced with a 'chart'
53 #include "aaSession.h"
55 #define AA_ACCOUNT_TEST_CID \
56 {0x9f3b3e19, 0x2f06, 0x4a75, {0xbc, 0xb8, 0xd7, 0xd3, 0x5c, 0xaf, 0x9d, 0x36}}
57 #define AA_ACCOUNT_TEST_CONTRACT_ID "@aasii.org/storage/unit-account;1"
59 class aaAccountTest
: public nsITest
63 virtual ~aaAccountTest() {;}
68 nsCOMPtr
<aaISession
> mSession
;
69 nsCOMPtr
<aaILoadQuery
> mFlows
;
70 nsCOMPtr
<aaILoadQuery
> mResources
;
71 nsCOMPtr
<aaIFact
> mPendingFact
;
76 nsresult
testEmptyBalance(nsITestRunner
*aTestRunner
);
77 nsresult
testPendingFacts(nsITestRunner
*aTestRunner
);
78 nsresult
testQuote(nsITestRunner
*aTestRunner
);
79 nsresult
testTransaction(nsITestRunner
*aTestRunner
);
80 nsresult
testUpdateTransaction(nsITestRunner
*aTestRunner
);
81 nsresult
testReplaceTransaction(nsITestRunner
*aTestRunner
);
82 nsresult
testFlowBalance(nsITestRunner
*aTestRunner
);
88 RAII(aaAccountTest
*t
);
98 aaAccountTest::Test(nsITestRunner
*aTestRunner
)
101 if (NS_FAILED( res
.status
)) {
102 aTestRunner
->AddError(nsITestRunner::errorJS
, \
103 AA_ACCOUNT_TEST_CONTRACT_ID
" not initialized");
104 return NS_ERROR_NOT_INITIALIZED
;
106 testEmptyBalance(aTestRunner
);
107 testPendingFacts(aTestRunner
);
108 testQuote(aTestRunner
);
109 testTransaction(aTestRunner
);
110 testUpdateTransaction(aTestRunner
);
111 testReplaceTransaction(aTestRunner
);
112 testFlowBalance(aTestRunner
);
116 NS_IMPL_ISUPPORTS1(aaAccountTest
, nsITest
);
118 /* Boilerplate - factory & module */
119 NS_GENERIC_FACTORY_CONSTRUCTOR(aaAccountTest
)
121 static const nsModuleComponentInfo kComponents
[] =
124 "Account Submodule Unit Test",
126 AA_ACCOUNT_TEST_CONTRACT_ID
,
127 aaAccountTestConstructor
130 NS_IMPL_NSGETMODULE(aaaccountt
, kComponents
)
134 testFact(nsITestRunner
*cxxUnitTestRunner
, aaIFact
*node
, PRInt64 fromFlowId
,
135 PRInt64 toFlowId
, double sum
)
138 PRBool equals
= PR_TRUE
;
140 nsCOMPtr
<aaIFlow
> flow
;
142 node
->GetTakeFrom(getter_AddRefs( flow
));
145 if (NS_UNLIKELY( id
!= fromFlowId
)) {
147 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'fact.takeFrom.id' is wrong" );
149 } else if (NS_UNLIKELY( fromFlowId
!= 0 )) {
151 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'fact.takeFrom.id' is wrong" );
154 node
->GetGiveTo(getter_AddRefs( flow
));
157 if (NS_UNLIKELY( id
!= toFlowId
)) {
159 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'fact.giveTo.id' is wrong" );
161 } else if (NS_UNLIKELY( toFlowId
!= 0 )) {
163 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'fact.giveTo.id' is wrong" );
167 rv
= node
->GetAmount(&amount
);
169 if (diff
> 0.0001 || diff
< -0.0001) {
171 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'fact.amount' is wrong" );
178 testBalance(nsITestRunner
*cxxUnitTestRunner
, aaIBalance
*node
, PRInt64 flowId
,
179 PRInt64 resourceId
, double amount
, double value
, PRBool aSide
)
182 PRBool equals
= PR_TRUE
;
183 if (NS_UNLIKELY( ! node
)) {
184 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'balance' is null");
187 nsCOMPtr
<aaIFlow
> flow
;
188 rv
= node
->GetFlow(getter_AddRefs( flow
));
189 NS_TEST_ASSERT_MSG(flow
, " 'balance.flow' is null");
191 if (NS_LIKELY( flow
)) {
193 if (NS_UNLIKELY( id
!= flowId
) ) {
195 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'balance.flow.id' is wrong");
201 nsCOMPtr
<aaIResource
> resource
;
202 rv
= node
->GetResource(getter_AddRefs( resource
));
203 NS_TEST_ASSERT_MSG(resource
, " 'balance.resource' is null" );
204 if (NS_LIKELY( resource
)) {
205 resource
->GetId(&id
);
206 if (NS_UNLIKELY( id
!= resourceId
) ) {
207 nsEmbedCString
msg(" 'balance.resource.id' is wrong - ");
210 NS_TEST_ASSERT_MSG(PR_FALSE
, msg
.get());
217 node
->GetAmount(&sum
);
219 if (NS_UNLIKELY(diff
> 0.0001 || diff
< -0.0001)) {
221 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'balance.amount' is wrong");
224 node
->GetValue(&sum
);
226 if (NS_UNLIKELY(diff
> 0.0001 || diff
< -0.0001)) {
228 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'balance.value' is wrong");
232 node
->GetSide(&side
);
233 if (NS_UNLIKELY( side
!= aSide
)) {
235 NS_TEST_ASSERT_MSG(PR_FALSE
, " 'balance.side' is wrong");
240 RAII::RAII(aaAccountTest
*t
)
241 :status(PR_FALSE
), test(nsnull
)
244 nsCOMPtr
<aaISession
> session(do_CreateInstance(AA_SESSION_CONTRACT_ID
, &rv
));
245 if (NS_UNLIKELY( ! session
))
248 nsCOMPtr
<aaILoadQuery
> flows
;
249 rv
= session
->CreateQuery(AA_LOADFLOW_CONTRACT_ID
, getter_AddRefs( flows
));
250 if (NS_UNLIKELY( ! flows
))
256 nsCOMPtr
<aaILoadQuery
> resources
;
257 rv
= session
->CreateQuery(AA_LOADRESOURCE_CONTRACT_ID
, getter_AddRefs( resources
));
258 if (NS_UNLIKELY( ! resources
))
260 rv
= resources
->Load();
266 test
->mSession
= session
;
267 test
->mFlows
= flows
;
268 test
->mResources
= resources
;
273 test
->mPendingFact
= nsnull
;
274 test
->mResources
= nsnull
;
275 test
->mFlows
= nsnull
;
276 test
->mSession
= nsnull
;
280 /* Private methods */
282 aaAccountTest::testEmptyBalance(nsITestRunner
*aTestRunner
)
285 NS_TEST_BEGIN(aTestRunner
);
286 aaSession
*session
= static_cast<aaSession
*>(mSession
.get());
287 NS_TEST_ASSERT_MSG(session
, "[empty balance] 'session' cast" );
288 NS_ENSURE_TRUE(session
, NS_ERROR_UNEXPECTED
);
290 nsCOMPtr
<aaILoadQuery
> set(do_CreateInstance(
291 AA_LOADBALANCE_CONTRACT_ID
, session
->mConnection
, &rv
));
292 NS_TEST_ASSERT_MSG(set
, "[empty balance] query instance creation" );
293 NS_ENSURE_TRUE(set
, rv
);
296 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[empty balance] loading");
297 NS_TEST_ASSERT_MSG(set
, "[empty balance] result set not loaded" );
298 NS_ENSURE_TRUE(set
, rv
);
301 set
->GetLength(&count
);
302 NS_TEST_ASSERT_MSG(count
== 0, "[empty balance] wrong flow count");
308 aaAccountTest::testPendingFacts(nsITestRunner
*aTestRunner
)
311 NS_TEST_BEGIN(aTestRunner
);
312 aaSession
*session
= static_cast<aaSession
*>(mSession
.get());
313 NS_TEST_ASSERT_MSG(session
, "[pending facts] 'session' cast" );
314 NS_ENSURE_TRUE(session
, NS_ERROR_UNEXPECTED
);
316 nsCOMPtr
<aaILoadQuery
> set(do_CreateInstance(
317 AA_LOADPENDINGFACTS_CONTRACT_ID
, session
->mConnection
, &rv
));
318 NS_TEST_ASSERT_MSG(set
, "[pending facts] query instance creation" );
319 NS_ENSURE_TRUE(set
, rv
);
322 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[pending facts] loading");
323 NS_TEST_ASSERT_MSG(set
, "[pending facts] result set not loaded" );
324 NS_ENSURE_TRUE(set
, rv
);
327 set
->GetLength(&count
);
328 NS_TEST_ASSERT_MSG(count
== 3, "[pending facts] wrong flow count");
330 mPendingFact
= do_QueryElementAt(set
, 0, &rv
);
331 NS_TEST_ASSERT_MSG(mPendingFact
, "[pending facts] 1st fact not loaded" );
333 NS_TEST_ASSERT_MSG(testFact(aTestRunner
, mPendingFact
, 2, 3,
334 AA_EVENT_AMOUNT_2
), "[pending facts] 1st fact is wrong");
339 aaAccountTest::testQuote(nsITestRunner
*aTestRunner
)
342 NS_TEST_BEGIN(aTestRunner
);
343 nsCOMPtr
<aaIQuote
> node(do_CreateInstance("@aasii.org/base/quote;1", &rv
));
344 NS_TEST_ASSERT_MSG(node
, "[quote] instance not created" );
345 NS_ENSURE_TRUE(node
, rv
);
347 nsCOMPtr
<aaIResource
> rub
= do_QueryElementAt(mResources
, 0, &rv
);
348 node
->SetResource( rub
);
350 /* Set time to 2007-08-29 */
351 PRExplodedTime tm
= {0,0,0,12,29,7,2007};
352 node
->SetTime(PR_ImplodeTime(&tm
));
355 rv
= mSession
->Save( node
, nsnull
);
356 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[quote] saving");
358 aaSession
*session
= static_cast<aaSession
*>(mSession
.get());
359 NS_TEST_ASSERT_MSG(session
, "[quote] 'session' cast" );
360 NS_ENSURE_TRUE(session
, NS_ERROR_UNEXPECTED
);
362 nsCOMPtr
<aaILoadQuery
> set(do_CreateInstance(
363 AA_LOADQUOTE_CONTRACT_ID
, session
->mConnection
, &rv
));
364 NS_TEST_ASSERT_MSG(set
, "[quote] query instance creation" );
365 NS_ENSURE_TRUE(set
, rv
);
368 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[quote] loading");
369 NS_TEST_ASSERT_MSG(set
, "[quote] result set not loaded" );
370 NS_ENSURE_TRUE(set
, rv
);
373 set
->GetLength(&count
);
374 NS_TEST_ASSERT_MSG(count
== 1, "[quote] wrong quote count");
376 nsCOMPtr
<aaIQuote
> quote
= do_QueryElementAt(set
, 0, &rv
);
377 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[quote] quering 1st quote");
378 NS_TEST_ASSERT_MSG(quote
, "[quote] 1st quote not loaded" );
379 NS_ENSURE_TRUE(quote
, NS_ERROR_FAILURE
);
381 nsCOMPtr
<aaIResource
> obj
;
386 quote
->GetResource(getter_AddRefs( obj
));
387 if (NS_LIKELY( obj
)) {
388 obj
->GetId( &objId
);
389 NS_TEST_ASSERT_MSG(objId
== 1, "[quote] wrong resource id");
391 NS_TEST_ASSERT_MSG(obj
, "[quote] resource is null");
393 quote
->GetTime( &time
);
394 NS_TEST_ASSERT_MSG(time
== PR_ImplodeTime(&tm
), "[quote] wrong start time");
395 quote
->GetRate( &rate
);
396 NS_TEST_ASSERT_MSG(rate
< 1.00009 && rate
> 0.99991, "[quote] wrong rate");
402 aaAccountTest::testTransaction(nsITestRunner
*aTestRunner
)
405 NS_TEST_BEGIN(aTestRunner
);
406 aaSession
*session
= static_cast<aaSession
*>(mSession
.get());
407 NS_TEST_ASSERT_MSG(session
, "[transaction] 'session' cast" );
408 NS_ENSURE_TRUE(session
, NS_ERROR_UNEXPECTED
);
410 nsCOMPtr
<aaISaveQuery
> saver(do_CreateInstance(
411 AA_SAVETRANSACTION_CONTRACT_ID
, session
->mConnection
, &rv
));
412 NS_TEST_ASSERT_MSG(saver
, "[transaction] query instance creation" );
413 NS_ENSURE_TRUE(saver
, rv
);
415 nsCOMPtr
<aaITransaction
> node(do_CreateInstance(
416 "@aasii.org/base/transaction;1", &rv
));
417 NS_TEST_ASSERT_MSG(node
, "[transaction] instance not created" );
418 NS_ENSURE_TRUE(node
, rv
);
420 node
->SetFact(mPendingFact
);
422 rv
= saver
->Save(node
, nsnull
);
423 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[transaction] saving" );
425 nsCOMPtr
<aaILoadQuery
> set
;
426 rv
= mSession
->CreateQuery(AA_LOADBALANCE_CONTRACT_ID
, getter_AddRefs( set
));
427 NS_TEST_ASSERT_MSG(set
, "[transaction] result set not created" );
428 NS_ENSURE_TRUE(set
, rv
);
430 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[transaction] result set not loaded" );
433 set
->GetLength(&count
);
434 NS_TEST_ASSERT_MSG(count
== 2, "[transaction] wrong flow count");
436 nsCOMPtr
<aaIBalance
> balance(do_QueryElementAt(set
, 0));
437 NS_TEST_ASSERT_MSG(testBalance(aTestRunner
, balance
, 2, 2, AA_EVENT_AMOUNT_2
438 / AA_FLOW_SHARE_RATE
, AA_EVENT_AMOUNT_2
, 0),
439 "[transaction] flow2 is wrong");
441 balance
= do_QueryElementAt(set
, 1);
442 NS_TEST_ASSERT_MSG(testBalance(aTestRunner
, balance
, 3, 1, AA_EVENT_AMOUNT_2
,
443 AA_EVENT_AMOUNT_2
, 1), "[transaction] flow3 is wrong");
445 rv
= mSession
->CreateQuery(AA_LOADPENDINGFACTS_CONTRACT_ID
,
446 getter_AddRefs( set
));
447 NS_TEST_ASSERT_MSG(set
, "[transaction] fact set not created" );
448 NS_ENSURE_TRUE(set
, rv
);
450 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[transaction] fact set not loaded" );
452 set
->GetLength(&count
);
453 NS_TEST_ASSERT_MSG(count
== 2, "[transaction] wrong fact count");
455 mPendingFact
= do_QueryElementAt(set
, 0, &rv
);
456 NS_TEST_ASSERT_MSG(mPendingFact
, "[transaction] pending fact not loaded" );
458 NS_TEST_ASSERT_MSG(testFact(aTestRunner
, mPendingFact
, 1, 3,
459 AA_EVENT_AMOUNT_3
), "[transaction] pending fact is wrong");
464 aaAccountTest::testUpdateTransaction(nsITestRunner
*aTestRunner
)
467 NS_TEST_BEGIN(aTestRunner
);
469 nsCOMPtr
<aaITransaction
> node(do_CreateInstance(
470 "@aasii.org/base/transaction;1", &rv
));
471 NS_TEST_ASSERT_MSG(node
, "[update txn] instance not created" );
472 NS_ENSURE_TRUE(node
, rv
);
474 node
->SetFact(mPendingFact
);
476 rv
= mSession
->Save(node
, nsnull
);
477 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[update txn] saving" );
479 nsCOMPtr
<aaILoadQuery
> set
;
480 rv
= mSession
->CreateQuery(AA_LOADBALANCE_CONTRACT_ID
, getter_AddRefs( set
));
481 NS_TEST_ASSERT_MSG(set
, "[update txn] result set not created" );
482 NS_ENSURE_TRUE(set
, rv
);
484 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[update txn] result set not loaded" );
487 set
->GetLength(&count
);
488 NS_TEST_ASSERT_MSG(count
== 3, "[update txn] wrong flow count");
490 nsCOMPtr
<aaIBalance
> balance(do_QueryElementAt(set
, 0));
491 NS_TEST_ASSERT_MSG(testBalance(aTestRunner
, balance
, 2, 2, AA_EVENT_AMOUNT_2
492 / AA_FLOW_SHARE_RATE
, AA_EVENT_AMOUNT_2
, 0),
493 "[update txn] flow2 is wrong");
495 balance
= do_QueryElementAt(set
, 1);
496 NS_TEST_ASSERT_MSG(testBalance(aTestRunner
, balance
, 3, 1, AA_EVENT_AMOUNT_2
497 + AA_EVENT_AMOUNT_3
, AA_EVENT_AMOUNT_2
+ AA_EVENT_AMOUNT_3
, 1),
498 "[update txn] flow3 is wrong");
500 balance
= do_QueryElementAt(set
, 2);
501 NS_TEST_ASSERT_MSG(testBalance(aTestRunner
, balance
, 1, 2, AA_EVENT_AMOUNT_3
502 / AA_FLOW_SHARE_RATE
, AA_EVENT_AMOUNT_3
, 0),
503 "[update txn] flow1 is wrong");
505 rv
= mSession
->CreateQuery(AA_LOADPENDINGFACTS_CONTRACT_ID
,
506 getter_AddRefs( set
));
507 NS_TEST_ASSERT_MSG(set
, "[update txn] fact set not created" );
508 NS_ENSURE_TRUE(set
, rv
);
510 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[update txn] fact set not loaded" );
512 set
->GetLength(&count
);
513 NS_TEST_ASSERT_MSG(count
== 1, "[update txn] wrong fact count");
515 mPendingFact
= do_QueryElementAt(set
, 0, &rv
);
516 NS_TEST_ASSERT_MSG(mPendingFact
, "[update txn] pending fact not loaded" );
518 NS_TEST_ASSERT_MSG(testFact(aTestRunner
, mPendingFact
, 3, 4,
519 AA_EVENT_AMOUNT_4
), "[update txn] pending fact is wrong");
524 aaAccountTest::testReplaceTransaction(nsITestRunner
*aTestRunner
)
527 NS_TEST_BEGIN(aTestRunner
);
529 nsCOMPtr
<aaITransaction
> node(do_CreateInstance(
530 "@aasii.org/base/transaction;1", &rv
));
531 NS_TEST_ASSERT_MSG(node
, "[replace txn] instance not created" );
532 NS_ENSURE_TRUE(node
, rv
);
534 node
->SetFact(mPendingFact
);
536 rv
= mSession
->Save(node
, nsnull
);
537 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[replace txn] saving" );
539 nsCOMPtr
<aaILoadQuery
> set
;
540 rv
= mSession
->CreateQuery(AA_LOADBALANCE_CONTRACT_ID
, getter_AddRefs( set
));
541 NS_TEST_ASSERT_MSG(set
, "[replace txn] result set not created" );
542 NS_ENSURE_TRUE(set
, rv
);
544 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[replace txn] result set not loaded" );
547 set
->GetLength(&count
);
548 NS_TEST_ASSERT_MSG(count
== 4, "[replace txn] wrong flow count");
550 nsCOMPtr
<aaIBalance
> balance(do_QueryElementAt(set
, 0));
551 NS_TEST_ASSERT_MSG(testBalance(aTestRunner
, balance
, 2, 2, AA_EVENT_AMOUNT_2
552 / AA_FLOW_SHARE_RATE
, AA_EVENT_AMOUNT_2
, 0),
553 "[replace txn] flow2 is wrong");
555 balance
= do_QueryElementAt(set
, 1);
556 NS_TEST_ASSERT_MSG(testBalance(aTestRunner
, balance
, 1, 2, AA_EVENT_AMOUNT_3
557 / AA_FLOW_SHARE_RATE
, AA_EVENT_AMOUNT_3
, 0),
558 "[replace txn] flow1 is wrong");
560 balance
= do_QueryElementAt(set
, 2);
561 NS_TEST_ASSERT_MSG(testBalance(aTestRunner
, balance
, 3, 1, AA_EVENT_AMOUNT_2
562 + AA_EVENT_AMOUNT_3
- AA_EVENT_AMOUNT_4
, AA_EVENT_AMOUNT_2
563 + AA_EVENT_AMOUNT_3
- AA_EVENT_AMOUNT_4
, 1),
564 "[replace txn] flow3 is wrong");
566 balance
= do_QueryElementAt(set
, 3);
567 NS_TEST_ASSERT_MSG(testBalance(aTestRunner
, balance
, 4, 3, AA_EVENT_AMOUNT_5
,
568 AA_EVENT_AMOUNT_4
, 1), "[replace txn] flow4 is wrong");
570 rv
= mSession
->CreateQuery(AA_LOADPENDINGFACTS_CONTRACT_ID
,
571 getter_AddRefs( set
));
572 NS_TEST_ASSERT_MSG(set
, "[replace txn] fact set not created" );
573 NS_ENSURE_TRUE(set
, rv
);
575 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[replace txn] fact set not loaded" );
577 set
->GetLength(&count
);
578 NS_TEST_ASSERT_MSG(count
== 0, "[replace txn] wrong fact count");
582 #define AA_FB_FILTER1 "balance.flow_id=3 AND balance.start=(SELECT MAX(start)\
583 FROM balance WHERE flow_id=3 AND start < 2454343)"
586 aaAccountTest::testFlowBalance(nsITestRunner
*aTestRunner
)
589 NS_TEST_BEGIN(aTestRunner
);
591 nsCOMPtr
<aaILoadQuery
> set
;
592 rv
= mSession
->CreateQuery(AA_LOADBALANCE_CONTRACT_ID
, getter_AddRefs( set
));
593 NS_TEST_ASSERT_MSG(set
, "[replace txn] result set not created" );
594 NS_ENSURE_TRUE(set
, rv
);
596 nsCOMPtr
<aaIStringFilter
> filter(do_CreateInstance(AA_FILTER_CONTRACT_ID
));
597 filter
->SetExpression(NS_LITERAL_CSTRING(AA_FB_FILTER1
));
598 set
->SetFilter(filter
);
600 NS_TEST_ASSERT_MSG(NS_SUCCEEDED(rv
), "[replace txn] result set not loaded" );
603 set
->GetLength(&count
);
604 NS_TEST_ASSERT_MSG(count
== 1, "[flow balance] wrong count");
606 nsCOMPtr
<aaIBalance
> balance(do_QueryElementAt(set
, 0));
607 NS_TEST_ASSERT_MSG(testBalance(aTestRunner
, balance
, 3, 1, AA_EVENT_AMOUNT_2
608 + AA_EVENT_AMOUNT_3
, AA_EVENT_AMOUNT_2
+ AA_EVENT_AMOUNT_3
, 1),
609 "[replace txn] flow3 is wrong");