Remove some testing of an engine API that has been removed.

The engine used to have functions that made it possible to orphan a Split.
   As this is no longer possible, we can't test anymore.

   Incidental:
      Fix three or four small leaks in the test functions.
      Allow test-period to be randomized based on optional command-line arg.



git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13458 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Chris Shoemaker
2006-03-04 00:09:31 +00:00
parent ed94e594b2
commit 241f37379a
3 changed files with 55 additions and 70 deletions

View File

@@ -930,9 +930,6 @@ add_random_splits(QofBook *book, Transaction *trn, GList *account_list)
xaccTransBeginEdit(trn);
s = get_random_split(book, acc, trn);
/* Occasionally leave a dangling split around */
if (do_bork()) xaccAccountRemoveSplit (s->acc, s);
bcc = get_random_list_element (account_list);
if ((bcc == acc) && (!do_bork()))
{
@@ -963,7 +960,6 @@ add_random_splits(QofBook *book, Transaction *trn, GList *account_list)
xaccSplitSetAmount(s, gnc_numeric_neg(num));
}
if (do_bork()) xaccAccountRemoveSplit (s->acc, s);
xaccTransCommitEdit(trn);
}
@@ -1278,6 +1274,7 @@ get_random_split(QofBook *book, Account *acct, Transaction *trn)
const gchar *str;
gnc_commodity *com;
int scu;
Timespec *ts;
com = xaccTransGetCurrency (trn);
scu = gnc_commodity_get_fraction(com);
@@ -1291,7 +1288,9 @@ get_random_split(QofBook *book, Account *acct, Transaction *trn)
xaccSplitSetReconcile(ret, possible_chars[get_random_int_in_range(0, 3)]);
xaccSplitSetDateReconciledTS(ret, get_random_timespec());
ts = get_random_timespec();
xaccSplitSetDateReconciledTS(ret, ts);
g_free(ts);
/* Split must be in an account before we can set an amount */
/* and in a transaction before it can be added to an account. */
@@ -1332,6 +1331,7 @@ void
make_random_changes_to_split (Split *split)
{
Transaction *trans;
Timespec *ts;
g_return_if_fail (split);
@@ -1344,7 +1344,9 @@ make_random_changes_to_split (Split *split)
xaccSplitSetReconcile (split, possible_chars[get_random_int_in_range(0, 3)]);
xaccSplitSetDateReconciledTS (split, get_random_timespec());
ts = get_random_timespec();
xaccSplitSetDateReconciledTS (split, ts);
g_free(ts);
xaccSplitSetSlots_nc (split, get_random_kvp_frame());
@@ -1401,7 +1403,7 @@ get_random_transaction_with_currency(QofBook *book,
Transaction* trans;
KvpFrame *f;
gint num;
gchar *numstr;
gchar numstr[10];
if (!account_list)
{
@@ -1424,7 +1426,7 @@ get_random_transaction_with_currency(QofBook *book,
get_random_commodity (book));
num = get_random_int_in_range (1, max_trans_num);
numstr = g_strdup_printf("%d", num);
g_snprintf(numstr, 10, "%d", num);
xaccTransSetNum(trans, numstr);
set_tran_random_string_from_array(trans, xaccTransSetDescription,
sane_descriptions);

View File

@@ -37,10 +37,11 @@
#include "test-engine-stuff.h"
#include "Transaction.h"
static int num_trans = 0;
static void
run_test (void)
{
QofSession *sess;
QofSession *sess1, *sess2;
QofBook *openbook, *closedbook;
AccountGroup *grp;
AccountList *acclist, *anode;
@@ -50,10 +51,10 @@ run_test (void)
Transaction *tfirst, *tlast;
Timespec tsfirst, tslast, tsmiddle;
sess = get_random_session ();
openbook = qof_session_get_book (sess);
sess = get_random_session ();
closedbook = qof_session_get_book(sess);
sess1 = get_random_session ();
openbook = qof_session_get_book (sess1);
sess2 = get_random_session ();
closedbook = qof_session_get_book(sess2);
acc = NULL;
equity = get_random_account(openbook);
if (!openbook)
@@ -62,7 +63,7 @@ run_test (void)
exit(get_rv());
}
add_random_transactions_to_book (openbook, 120);
add_random_transactions_to_book (openbook, num_trans);
grp = xaccGetAccountGroup (openbook);
@@ -118,7 +119,7 @@ run_test (void)
tsmiddle = tsfirst;
tsmiddle.tv_sec = (tsfirst.tv_sec + tslast.tv_sec)/2;
gnc_set_logfile (stdout);
gnc_set_log_level_global (GNC_LOG_FATAL);
gnc_set_log_level_global (GNC_LOG_WARNING);
closedbook = gnc_book_close_period (openbook, tsmiddle,
equity, "this is opening balance dude");
@@ -134,11 +135,20 @@ run_test (void)
int
main (int argc, char **argv)
{
qof_init();
if(cashobjects_register()) {
run_test ();
print_test_results();
}
qof_close();
return 0;
if (argc == 2)
num_trans = atoi(argv[1]);
else num_trans = 120;
qof_init();
gnc_log_default();
qof_log_set_level(GNC_MOD_ENGINE, QOF_LOG_WARNING);
g_log_set_always_fatal( G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING );
if(cashobjects_register()) {
srand(num_trans);
run_test ();
print_test_results();
}
qof_close();
return 0;
}

View File

@@ -37,7 +37,7 @@ run_test (void)
{
Account *act1;
Account *act2;
Split *spl;
//Split *spl;
QofSession *session;
QofBook *book;
@@ -45,57 +45,30 @@ run_test (void)
book = qof_session_get_book (session);
act1 = get_random_account(book);
if(!act1)
{
failure("act1 not created");
return;
}
success("act1 created");
act2 = get_random_account(book);
if(!act2)
{
failure("act2 not created");
return;
}
success("act2 created");
/* if we use a trans here, the scrub routines
will add a pointer to a newly created Orphan-...
account. */
spl = get_random_split(book, act1, NULL);
if(!spl)
{
failure("spl not created");
return;
}
success("random split created");
if(act1 != xaccSplitGetAccount(spl))
{
failure("xaccAccountInsertSplit is broken");
return;
}
success("xaccAccountInsertSplit works");
/* this is weird -- we are testing an engine private function.
* is this really what is intended here ??? */
xaccAccountRemoveSplit (act1, spl);
do_test(act1 != NULL, "random account created");
if(xaccSplitGetAccount(spl))
{
failure_args("xaccAccountRemoveSplit()",
__FILE__, __LINE__, "account not NULL");
return;
}
success("xaccSplitGetAccount works");
act2 = get_random_account(book);
do_test(act2 != NULL, "random account created");
#if 0
spl = get_random_split(book, act1, NULL);
do_test(spl != NULL, "random split created");
do_test(act1 == xaccSplitGetAccount(spl), "xaccAccountInsertSplit()");
#endif
//FIXME
//xaccSplitSetAccount (spl, NULL);
//do_test(xaccSplitGetAccount(spl) == NULL, "xaccAccountRemoveSplit()");
}
int
main (int argc, char **argv)
{
qof_init();
if(cashobjects_register()) {
xaccLogDisable ();
run_test ();
print_test_results();
}
qof_close();
return 0;
qof_init();
if(cashobjects_register()) {
xaccLogDisable ();
run_test ();
print_test_results();
}
qof_close();
return 0;
}