[Gnucash-changes] fix test-lots and test-period
Neil Williams
codehelp at cvs.gnucash.org
Sat Oct 1 14:03:23 EDT 2005
Log Message:
-----------
fix test-lots and test-period
Tags:
----
gnucash-gnome2-dev
Modified Files:
--------------
gnucash/src/engine:
Account.c
Period.c
cap-gains.c
gnucash/src/engine/test-core:
test-engine-stuff.c
gnucash/src/engine/test:
test-lots.c
test-period.c
Revision Data
-------------
Index: Account.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/Account.c,v
retrieving revision 1.222.4.16
retrieving revision 1.222.4.17
diff -Lsrc/engine/Account.c -Lsrc/engine/Account.c -u -r1.222.4.16 -r1.222.4.17
--- src/engine/Account.c
+++ src/engine/Account.c
@@ -32,30 +32,13 @@
#include "Group.h"
#include "GroupP.h"
#include "TransactionP.h"
-#include "gnc-date.h"
-#include "gnc-engine.h"
-#include "gnc-engine-util.h"
-#include "gnc-event.h"
#include "gnc-lot.h"
#include "gnc-lot-p.h"
#include "gnc-pricedb.h"
-#include "gnc-trace.h"
-#include "kvp_frame.h"
-#include "kvp-util.h"
#include "messages.h"
#include "policy.h"
-#include "qofbackend.h"
-#include "qof-be-utils.h"
-#include "qofbook.h"
-#include "qofquery.h"
-#include "qofclass.h"
-#include "qofid-p.h"
-#include "qofinstance-p.h"
-#include "qofobject.h"
-
-static short module = MOD_ACCOUNT;
-
+static QofLogModule log_module = GNC_MOD_ACCOUNT;
/********************************************************************\
* Because I can't use C++ for this project, doesn't mean that I *
@@ -318,7 +301,8 @@
void
xaccAccountBeginEdit (Account *acc)
{
- QOF_BEGIN_EDIT (&acc->inst);
+ g_return_if_fail(acc);
+ qof_begin_edit(&acc->inst);
}
static inline void noop(QofInstance *inst) {}
@@ -338,7 +322,7 @@
void
xaccAccountCommitEdit (Account *acc)
{
- QOF_COMMIT_EDIT_PART1 (&acc->inst);
+ qof_commit_edit(&acc->inst);
/* If marked for deletion, get rid of subaccounts first,
* and then the splits ... */
@@ -831,7 +815,7 @@
}
}
xaccAccountCommitEdit(acc);
- xaccAccountCommitEdit(old_acc);
+ if(old_acc) { xaccAccountCommitEdit(old_acc); }
LEAVE ("(acc=%p, lot=%p)", acc, lot);
}
Index: cap-gains.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/cap-gains.c,v
retrieving revision 1.13.4.6
retrieving revision 1.13.4.7
diff -Lsrc/engine/cap-gains.c -Lsrc/engine/cap-gains.c -u -r1.13.4.6 -r1.13.4.7
--- src/engine/cap-gains.c
+++ src/engine/cap-gains.c
@@ -67,17 +67,13 @@
#include "TransactionP.h"
#include "cap-gains.h"
#include "gnc-engine.h"
-#include "gnc-engine-util.h"
#include "gnc-lot.h"
#include "gnc-lot-p.h"
-#include "gnc-trace.h"
-#include "kvp-util-p.h"
#include "messages.h"
#include "policy.h"
#include "policy-p.h"
-#include "qofid-p.h"
-static short module = MOD_LOT;
+static QofLogModule log_module = GNC_MOD_LOT;
/* ============================================================== */
@@ -571,7 +567,7 @@
/* Provide a reasonable title for the new lot */
id = kvp_frame_get_gint64 (xaccAccountGetSlots (acc), "/lot-mgmt/next-id");
- snprintf (buff, 200, _("Lot %" G_GINT64_FORMAT), id);
+ snprintf (buff, 200, ("%s %" G_GINT64_FORMAT), _("Lot"), id);
kvp_frame_set_str (gnc_lot_get_slots (lot), "/title", buff);
id ++;
kvp_frame_set_gint64 (xaccAccountGetSlots (acc), "/lot-mgmt/next-id", id);
Index: Period.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/Period.c,v
retrieving revision 1.27.4.4
retrieving revision 1.27.4.5
diff -Lsrc/engine/Period.c -Lsrc/engine/Period.c -u -r1.27.4.4 -r1.27.4.5
--- src/engine/Period.c
+++ src/engine/Period.c
@@ -34,25 +34,18 @@
*/
#include "AccountP.h"
-#include "gnc-engine-util.h"
-#include "gnc-event-p.h"
+#include "qof.h"
#include "gnc-lot.h"
#include "gnc-lot-p.h"
#include "gnc-pricedb.h"
#include "gnc-pricedb-p.h"
-#include "gnc-trace.h"
#include "Group.h"
#include "GroupP.h"
-#include "kvp-util-p.h"
#include "Period.h"
#include "TransactionP.h"
-#include "qofbackend-p.h"
-#include "qofbook.h"
-#include "qofbook-p.h"
-#include "qofid-p.h"
/* This static indicates the debugging module that this .o belongs to. */
-static short module = MOD_BOOK;
+static QofLogModule log_module = GNC_MOD_BOOK;
/* ================================================================ */
@@ -147,7 +140,7 @@
/* If the old and new book don't share backends, then clobber-copy;
* i.e. destroy it in one backend, create it in another. */
- if (book->backend != trans->inst.book->backend)
+ if (qof_book_get_backend(book) != qof_book_get_backend(trans->inst.book))
{
gnc_book_insert_trans_clobber (book, trans);
return;
@@ -219,12 +212,13 @@
QofCollection *col;
SplitList *snode;
Account *twin;
+
if (!lot || !book) return;
/* If this is the same book, its a no-op. */
if (lot->book == book) return;
- if (book->backend != lot->book->backend)
+ if (qof_book_get_backend(book) != qof_book_get_backend(lot->book))
{
gnc_book_insert_lot_clobber (book, lot);
return;
@@ -272,7 +266,7 @@
/* If the old and new book don't share backends, then clobber-copy;
* i.e. destroy it in one backend, create it in another. */
- if (book->backend != pr->inst.book->backend)
+ if (qof_book_get_backend(book) != qof_book_get_backend(pr->inst.book))
{
gnc_book_insert_price_clobber (book, pr);
return;
@@ -538,6 +532,7 @@
time_t now;
TransList *trans_list, *tnode;
LotList *lot_list, *lnode;
+ QofInstance *book_inst;
if (!src_book || !dest_book || !query) return;
ENTER (" src_book=%p dest_book=%p", src_book, dest_book);
@@ -546,8 +541,9 @@
/* hack alert -- FIXME -- this should really be a merge, not a
* clobber copy, but I am too lazy to write a kvp merge routine,
* and it is not needed for the current usage. */
- kvp_frame_delete (dest_book->inst.kvp_data);
- dest_book->inst.kvp_data = kvp_frame_copy (src_book->inst.kvp_data);
+ kvp_frame_delete (qof_book_get_slots(dest_book));
+ book_inst = (QofInstance*)dest_book;
+ book_inst->kvp_data = kvp_frame_copy (qof_book_get_slots(src_book));
/* Next, copy the commodity tables */
src_tbl = gnc_commodity_table_get_table (src_book);
@@ -598,11 +594,11 @@
/* Make note of the sibling books */
now = time(0);
- gnc_kvp_bag_add (src_book->inst.kvp_data, "gemini", now,
- "book_guid", &dest_book->inst.entity.guid,
+ gnc_kvp_bag_add (qof_book_get_slots(src_book), "gemini", now,
+ "book_guid", qof_book_get_guid(dest_book),
NULL);
- gnc_kvp_bag_add (dest_book->inst.kvp_data, "gemini", now,
- "book_guid", &src_book->inst.entity.guid,
+ gnc_kvp_bag_add (qof_book_get_slots(dest_book), "gemini", now,
+ "book_guid", qof_book_get_guid(src_book),
NULL);
LEAVE (" ");
}
@@ -670,6 +666,7 @@
AccountList *acc_list, *node;
if (!closed_grp) return;
+
ENTER (" enter=%s post=%s desc=%s", gnc_print_date(*date_entered),
gnc_print_date (*post_date), desc);
xaccAccountBeginEdit (equity_account);
@@ -693,7 +690,7 @@
xaccAccountBeginEdit (twin);
cwd = xaccAccountGetSlots (twin);
kvp_frame_set_guid (cwd, "/book/prev-acct", xaccAccountGetGUID (candidate));
- kvp_frame_set_guid (cwd, "/book/prev-book", &closed_book->inst.entity.guid);
+ kvp_frame_set_guid (cwd, "/book/prev-book", qof_book_get_guid(closed_book));
xaccAccountSetSlots_nc (twin, twin->inst.kvp_data);
@@ -702,7 +699,7 @@
* the next book is. */
xaccAccountBeginEdit (candidate);
cwd = xaccAccountGetSlots (candidate);
- kvp_frame_set_guid (cwd, "/book/next-book", &open_book->inst.entity.guid);
+ kvp_frame_set_guid (cwd, "/book/next-book", qof_book_get_guid(open_book));
kvp_frame_set_guid (cwd, "/book/next-acct", xaccAccountGetGUID (twin));
xaccAccountSetSlots_nc (candidate, candidate->inst.kvp_data);
@@ -760,7 +757,7 @@
/* Add KVP data showing where the balancing
* transaction came from */
cwd = xaccTransGetSlots (trans);
- kvp_frame_set_guid (cwd, "/book/closed-book", &closed_book->inst.entity.guid);
+ kvp_frame_set_guid (cwd, "/book/closed-book", qof_book_get_guid(closed_book));
kvp_frame_set_guid (cwd, "/book/closed-acct", xaccAccountGetGUID(candidate));
xaccTransCommitEdit (trans);
@@ -802,7 +799,7 @@
period_begin_edit (QofBook *src_book, QofBook *dest_book)
{
QofBackend *be;
- be = src_book->backend;
+ be = qof_book_get_backend(src_book);
if (be && be->begin)
{
// (*be->begin)(be, GNC_ID_PERIOD, dest_book);
@@ -813,7 +810,7 @@
period_commit_edit (QofBook *src_book, QofBook *dest_book)
{
QofBackend *be;
- be = src_book->backend;
+ be = qof_book_get_backend(src_book);
if (be && be->commit)
{
// (*be->commit)(be, GNC_ID_PERIOD, dest_book);
@@ -840,8 +837,8 @@
/* Setup closing book */
closing_book = qof_book_new();
- qof_book_set_backend (closing_book, existing_book->backend);
- closing_book->book_open = 'n';
+ qof_book_set_backend (closing_book, qof_book_get_backend(existing_book));
+ qof_book_mark_closed(closing_book);
period_begin_edit (existing_book, closing_book);
@@ -870,8 +867,8 @@
/* Now add the various identifying kvp's */
/* cwd == 'current working directory' */
- exist_cwd = existing_book->inst.kvp_data;
- partn_cwd = closing_book->inst.kvp_data;
+ exist_cwd = qof_book_get_slots(existing_book);
+ partn_cwd = qof_book_get_slots(closing_book);
/* Mark the boundary date between the books */
kvp_frame_set_timespec (exist_cwd, "/book/open-date", calve_date);
@@ -883,8 +880,8 @@
kvp_frame_set_timespec (partn_cwd, "/book/log-date", ts);
/* Set up pointers to each book from the other. */
- kvp_frame_set_guid (partn_cwd, "/book/next-book", &existing_book->inst.entity.guid);
- kvp_frame_set_guid (exist_cwd, "/book/prev-book", &closing_book->inst.entity.guid);
+ kvp_frame_set_guid (partn_cwd, "/book/next-book", qof_book_get_guid(existing_book));
+ kvp_frame_set_guid (exist_cwd, "/book/prev-book", qof_book_get_guid(closing_book));
/* add in transactions to equity accounts that will
* hold the colsing balances */
Index: test-engine-stuff.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/test-core/test-engine-stuff.c,v
retrieving revision 1.52.4.13
retrieving revision 1.52.4.14
diff -Lsrc/engine/test-core/test-engine-stuff.c -Lsrc/engine/test-core/test-engine-stuff.c -u -r1.52.4.13 -r1.52.4.14
--- src/engine/test-core/test-engine-stuff.c
+++ src/engine/test-core/test-engine-stuff.c
@@ -694,8 +694,8 @@
{
int num_prices;
- num_prices = get_random_int_in_range (0, 40);
- if(num_prices < 1)
+ num_prices = get_random_int_in_range (1, 41);
+ if(num_prices < 1) /* should be impossible */
{
failure_args("engine-stuff", __FILE__, __LINE__,
"get_random_int_in_range failed");
Index: test-lots.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/test/test-lots.c,v
retrieving revision 1.3.4.3
retrieving revision 1.3.4.4
diff -Lsrc/engine/test/test-lots.c -Lsrc/engine/test/test-lots.c -u -r1.3.4.3 -r1.3.4.4
--- src/engine/test/test-lots.c
+++ src/engine/test/test-lots.c
@@ -1,24 +1,42 @@
-
+/***************************************************************************
+ * test-lots.c
+ *
+ * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
+ ****************************************************************************/
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
/**
* @file test-lots.c
* @brief Minimal test to see if automatic lot scrubbing works.
- * @author Copyright (C) 2003 Linas Vepstas <linas at linas.org>
- * License: GPL
+ * @author Linas Vepstas <linas at linas.org>
*/
#include <ctype.h>
#include <glib.h>
-
+#include "qof.h"
#include "Account.h"
#include "Group.h"
#include "Scrub3.h"
-#include "gnc-engine-util.h"
-#include "gnc-module.h"
+#include "cashobjects.h"
#include "test-stuff.h"
#include "test-engine-stuff.h"
#include "Transaction.h"
-
+static gint transaction_num = 720;
+static gint max_iterate = 30;
static void
run_test (void)
@@ -34,7 +52,7 @@
book = qof_session_get_book (sess);
do_test ((NULL != book), "create random data");
- add_random_transactions_to_book (book, 720);
+ add_random_transactions_to_book (book, transaction_num);
grp = xaccGetAccountGroup (book);
xaccGroupScrubLots (grp);
@@ -46,39 +64,35 @@
* XXX not implemented
*/
success ("automatic lot scrubbing lightly tested and seem to work");
- qof_session_destroy (sess);
+ qof_session_end (sess);
}
-static void
-main_helper (void *closure, int argc, char **argv)
+int
+main (int argc, char **argv)
{
- int i;
+ gint i;
+ qof_init();
+ if(cashobjects_register()) {
/* Any tests that cause an error or warning to be printed
* automatically fail! */
g_log_set_always_fatal( G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING );
-
- //set_success_print (TRUE);
-
- do_test((NULL!=gnc_module_load("gnucash/engine", 0)), "load engine");
-
/* Set up a reproducible test-case */
srand(0);
-
/* Iterate the test a number of times */
- for (i=0; i< 100; i++)
+ for (i=0; i< max_iterate; i++)
{
+ fprintf(stdout, " Lots: %d of %d paired tests . . . \r",
+ (i + 1)*2, max_iterate * 2);
+ fflush(stdout);
run_test ();
}
-
+ /* 'erase' the recurring tag line with dummy spaces. */
+ fprintf(stdout, "Lots: Test series complete. \n");
+ fflush(stdout);
print_test_results();
- exit(get_rv());
-}
-
-int
-main (int argc, char **argv)
-{
- scm_boot_guile(argc, argv, main_helper, NULL);
+ }
+ qof_close();
return 0;
}
Index: test-period.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/test/test-period.c,v
retrieving revision 1.9.4.1
retrieving revision 1.9.4.2
diff -Lsrc/engine/test/test-period.c -Lsrc/engine/test/test-period.c -u -r1.9.4.1 -r1.9.4.2
--- src/engine/test/test-period.c
+++ src/engine/test/test-period.c
@@ -1,27 +1,40 @@
-
-/* Test file created by Linas Vepstas <linas at linas.org>
+/***************************************************************************
+ * test-period.c
+ *
+ * December 2001
+ * Copyright 2001 Linas Vepstas <linas at linas.org
+ ****************************************************************************/
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+ /*
* Minimal test to see if a book can be split into two periods
* without crashing.
- * December 2001
- * License: GPL
*/
#include <ctype.h>
#include <glib.h>
-#include <libguile.h>
+#include "qof.h"
#include <time.h>
-
+#include "cashobjects.h"
#include "Account.h"
#include "Group.h"
#include "Period.h"
-#include "gnc-engine-util.h"
-#include "gnc-module.h"
#include "test-stuff.h"
#include "test-engine-stuff.h"
#include "Transaction.h"
-#include "qofbook.h"
-
-
static void
run_test (void)
@@ -30,22 +43,18 @@
QofBook *openbook, *closedbook;
AccountGroup *grp;
AccountList *acclist, *anode;
- Account * acc = NULL;
+ Account *acc, *equity;
SplitList *splist;
Split *sfirst, *slast;
Transaction *tfirst, *tlast;
Timespec tsfirst, tslast, tsmiddle;
-
-
- if(!gnc_module_load("gnucash/engine", 0))
- {
- failure("couldn't load gnucash/engine");
- exit(get_rv());
- }
-
sess = get_random_session ();
openbook = qof_session_get_book (sess);
+ sess = get_random_session ();
+ closedbook = qof_session_get_book(sess);
+ acc = NULL;
+ equity = get_random_account(openbook);
if (!openbook)
{
failure("book not created");
@@ -107,12 +116,10 @@
tsmiddle = tsfirst;
tsmiddle.tv_sec = (tsfirst.tv_sec + tslast.tv_sec)/2;
-
- // stdout is broken with guile for some reason
- // gnc_set_logfile (stdout);
- // gnc_set_log_level_global (GNC_LOG_INFO);
+ gnc_set_logfile (stdout);
+ gnc_set_log_level_global (GNC_LOG_FATAL);
closedbook = gnc_book_close_period (openbook, tsmiddle,
- NULL, "this is opening balance dude");
+ equity, "this is opening balance dude");
if (!closedbook)
{
@@ -123,18 +130,14 @@
success ("periods lightly tested and seem to work");
}
-static void
-main_helper (void *closure, int argc, char **argv)
-{
- run_test ();
-
- print_test_results();
- exit(get_rv());
-}
-
int
main (int argc, char **argv)
{
- scm_boot_guile(argc, argv, main_helper, NULL);
+ qof_init();
+ if(cashobjects_register()) {
+ run_test ();
+ print_test_results();
+ }
+ qof_close();
return 0;
}
More information about the gnucash-changes
mailing list