fix test cases that are wildly misusing internal routines with great borkeness.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6054 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2001-11-25 09:10:17 +00:00
parent fed69ff72c
commit 381504ad5a
6 changed files with 43 additions and 20 deletions

View File

@ -59,13 +59,23 @@ reparent (Transaction *trans, GNCBook *book)
{
GList *node;
xaccTransBeginEdit (trans);
for (node = trans->splits; node; node = node->next)
{
Account *twin;
Split *s = node->data;
twin = xaccAccountLookupTwin (s->acc, book);
xaccSplitSetAccount
}
xaccRemoveEntity(trans->book->entity_table, &trans->guid);
xaccStoreEntity(book->entity_table, trans, &trans->guid, GNC_ID_TRANS);
trans->book = book;
xaccTransCommitEdit (trans);
}
/* ================================================================ */

View File

@ -373,8 +373,6 @@ gnc_numeric xaccSplitGetValue (Split * split);
Account * xaccSplitGetAccount (Split *split);
const GUID * xaccSplitGetAccountGUID(Split *split);
void xaccSplitSetAccount(Split *s, Account *act);
void xaccSplitSetAccountGUID(Split *s, GUID id);
/* split types: normal stock-split */
const char *xaccSplitGetType(const Split *s);

View File

@ -210,11 +210,20 @@ void xaccTransSetGUID (Transaction *trans, const GUID *guid);
* call this on an existing split! */
void xaccSplitSetGUID (Split *split, const GUID *guid);
/* Set the value of the splits account pointer. These are 'dangerous'
* routines, because they fail to actually remove the split from
* its old parent account, or insert it into its new parent account.
* Using these incorrectly is guarenteed to scramble your data
* or even lead to bizarre crashes and hangs! Achtung!
*/
void xaccSplitSetAccount(Split *s, Account *act);
void xaccSplitSetAccountGUID(Split *s, GUID id);
/* The xaccFreeSplit() method simply frees all memory associated
* with the split. It does not verify that the split isn't
* referenced in some account. If the split is referenced by an
* account, then calling this method will leave the system in an
* inconsistent state.
* inconsistent state. This *will* lead to crashes and hangs.
*/
void xaccFreeSplit (Split *split); /* frees memory */

View File

@ -14,6 +14,8 @@
#include "Group.h"
#include "gnc-engine.h"
#include "gnc-engine-util.h"
#include "TransactionP.h"
#include "test-engine-stuff.h"
#include "test-stuff.h"
@ -908,6 +910,11 @@ get_random_split(GNCBook *book, gnc_numeric num)
{
GUID *ranguid = get_random_guid();
/* ???????? this is not enough to insert the split into an account!!
* you need to do a 'xaccAccountInsertSplit' to do that !!!
* does ths code actually work ????
*/
xaccSplitSetAccountGUID(ret, *ranguid);
g_free(ranguid);
}
@ -1457,6 +1464,11 @@ get_random_book (void)
book = gnc_book_new ();
/* XXX fixme -- gnc_book_set_group is a private engine function,
* it should not be invoked in ordinary test cases. Its should
* be more like make_random_pricedb below... */
gnc_book_set_group (book, get_random_group (book));
make_random_group (book, gnc_book_get_group (book));
make_random_pricedb (book, gnc_book_get_pricedb (book));

View File

@ -4,7 +4,7 @@
#include "GNCIdP.h"
#include "Account.h"
#include "AccountP.h"
#include "TransLog.h"
#include "gnc-engine.h"
#include "gnc-module.h"
@ -64,41 +64,35 @@ run_test (void)
return;
}
xaccSplitSetAccount(spl, act1);
xaccAccountInsertSplit(act1, spl);
if(act1 != xaccSplitGetAccount(spl))
{
failure("xaccSplitSetAccount is broken");
failure("xaccAccountInsertSplit is broken");
return;
}
if(!guid_equal(xaccAccountGetGUID(act1), xaccSplitGetAccountGUID(spl)))
{
failure("xaccSplitGetAccountGUID "
"after xaccSplitSetAccount failed");
"after xaccAccountInsertSplit failed");
return;
}
xaccSplitSetAccountGUID(spl, *xaccAccountGetGUID(act2));
if(act2 != xaccSplitGetAccount(spl))
{
failure("xaccSplitSetAccountGUID is broken");
return;
}
xaccSplitSetAccount(spl, NULL);
/* this is weird -- we are testing an engine private function.
* is this really what is intended here ??? */
xaccAccountRemoveSplit (act1, spl);
if(xaccSplitGetAccount(spl))
{
failure_args("xaccSplitSetAccount(NULL)",
failure_args("xaccAccountRemoveSplit()",
__FILE__, __LINE__, "account not NULL");
return;
}
if(!is_null_guid(xaccSplitGetAccountGUID(spl)))
{
failure_args("xaccSplitSetAccount(NULL)",
failure_args("xaccAccountRemoveSplit()",
__FILE__, __LINE__, "account guid not NULL");
return;
}

View File

@ -27,10 +27,10 @@ transaction_set_splits_to_accounts(Transaction *tr, Account *a1, Account *a2)
split = xaccTransGetSplit(tr, 0);
xaccSplitSetAccount(split, a1);
xaccAccountInsertSplit(a1, split);
split = xaccTransGetSplit(tr, 1);
xaccSplitSetAccount(split, a2);
xaccAccountInsertSplit(a2, split);
return;
}