Work on test infrastructure. Add gnc_book_equal().

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@5452 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas 2001-10-01 08:24:07 +00:00
parent 433e741a51
commit 77913bb212
8 changed files with 58 additions and 52 deletions

View File

@ -2,4 +2,3 @@ Makefile
Makefile.in Makefile.in
gnc_test gnc_test
test-db test-db
test-file-*

View File

@ -32,5 +32,3 @@ INCLUDES = \
EXTRA_DIST = \ EXTRA_DIST = \
db-control.sh db-control.sh
CLEANFILES = test-file-*

View File

@ -17,6 +17,5 @@ diff -u test-file-1 test-file-2 || EXIT_VALUE=1
if test $EXIT_VALUE != 0; then exit $EXIT_VALUE; fi if test $EXIT_VALUE != 0; then exit $EXIT_VALUE; fi
#./db-control.sh destroy #./db-control.sh destroy
rm -f test-file-*
exit $EXIT_VALUE exit $EXIT_VALUE

View File

@ -16,33 +16,12 @@ static void
run_test (void) run_test (void)
{ {
GNCBook *book; GNCBook *book;
GNCBook *book_db;
GNCBackendError io_err; GNCBackendError io_err;
char cwd[1024];
char *filename; char *filename;
book = get_random_book (); book = get_random_book ();
getcwd (cwd, sizeof (cwd));
filename = g_strconcat ("file:/", cwd, "/test-file-1", NULL);
gnc_book_begin (book, filename, FALSE, TRUE);
g_free (filename);
io_err = gnc_book_get_error (book);
if (!do_test (io_err == ERR_BACKEND_NO_ERR, "Beginning test-file-1"))
return;
gnc_book_save (book);
if (!do_test (io_err == ERR_BACKEND_NO_ERR, "Saving test-file-1"))
return;
gnc_book_end (book);
if (!do_test (io_err == ERR_BACKEND_NO_ERR, "Ending test-file-1"))
return;
if (!do_test (gnc_book_get_url (book) == NULL, "book url not NULL"))
return;
filename = g_strdup ("postgres://localhost:7777/gnc_test?mode=single-file"); filename = g_strdup ("postgres://localhost:7777/gnc_test?mode=single-file");
gnc_book_begin (book, filename, FALSE, TRUE); gnc_book_begin (book, filename, FALSE, TRUE);
@ -58,58 +37,48 @@ run_test (void)
if (!do_test (io_err == ERR_BACKEND_NO_ERR, "Ending gnc_test")) if (!do_test (io_err == ERR_BACKEND_NO_ERR, "Ending gnc_test"))
return; return;
gnc_book_destroy (book); if (!do_test (gnc_book_get_url (book) == NULL, "book url not NULL"))
return;
book = gnc_book_new (); book_db = gnc_book_new ();
gnc_book_begin (book, filename, FALSE, FALSE); gnc_book_begin (book_db, filename, FALSE, FALSE);
g_free (filename); g_free (filename);
io_err = gnc_book_get_error (book); io_err = gnc_book_get_error (book_db);
if (!do_test (io_err == ERR_BACKEND_NO_ERR, "Beginning gnc_test load")) if (!do_test (io_err == ERR_BACKEND_NO_ERR, "Beginning gnc_test load"))
return; return;
gnc_book_load (book); gnc_book_load (book_db);
if (!do_test (io_err == ERR_BACKEND_NO_ERR, "Loading gnc_test")) if (!do_test (io_err == ERR_BACKEND_NO_ERR, "Loading gnc_test"))
return; return;
gnc_book_end (book); gnc_book_end (book_db);
if (!do_test (io_err == ERR_BACKEND_NO_ERR, "Ending gnc_test load")) if (!do_test (io_err == ERR_BACKEND_NO_ERR, "Ending gnc_test load"))
return; return;
filename = g_strconcat ("file:/", cwd, "/test-file-2", NULL); do_test (gnc_book_equal (book, book_db), "Books not equal");
gnc_book_begin (book, filename, FALSE, TRUE);
g_free (filename);
io_err = gnc_book_get_error (book);
if (!do_test (io_err == ERR_BACKEND_NO_ERR, "Beginning test-file-2"))
return;
gnc_book_save (book);
if (!do_test (io_err == ERR_BACKEND_NO_ERR, "Saving test-file-2"))
return;
gnc_book_end (book);
if (!do_test (io_err == ERR_BACKEND_NO_ERR, "Ending test-file-2"))
return;
} }
static void static void
guile_main (int argc, char **argv) guile_main (int argc, char **argv)
{ {
GNCBook *book;
gnc_module_system_init (); gnc_module_system_init ();
gnc_module_load ("gnucash/engine", 0); gnc_module_load ("gnucash/engine", 0);
glist_exclude_type (KVP_TYPE_BINARY); glist_exclude_type (KVP_TYPE_BINARY);
glist_exclude_type (KVP_TYPE_GLIST); glist_exclude_type (KVP_TYPE_GLIST);
/* The random double generator is making values /* The random double generator is making values
* that postgres doesn't like. */ * that postgres doesn't like. */
glist_exclude_type (KVP_TYPE_DOUBLE); glist_exclude_type (KVP_TYPE_DOUBLE);
set_max_kvp_depth (3); set_max_kvp_depth (3);
set_max_kvp_frame_elements (3); set_max_kvp_frame_elements (3);
set_max_group_depth (3);
set_max_group_accounts (5);
xaccLogDisable (); xaccLogDisable ();
run_test (); run_test ();
@ -121,7 +90,7 @@ guile_main (int argc, char **argv)
int int
main (int argc, char ** argv) main (int argc, char ** argv)
{ {
getchar (); /* getchar (); */
gh_enter (argc, argv, guile_main); gh_enter (argc, argv, guile_main);

View File

@ -738,6 +738,26 @@ gnc_book_destroy (GNCBook *book)
LEAVE(" "); LEAVE(" ");
} }
gboolean
gnc_book_equal (GNCBook *book_1, GNCBook *book_2)
{
if (book_1 == book_2) return TRUE;
if (!book_1 || !book_2) return FALSE;
if (!xaccGroupEqual (gnc_book_get_group (book_1),
gnc_book_get_group (book_2),
TRUE))
return FALSE;
if (!gnc_pricedb_equal (gnc_book_get_pricedb (book_1),
gnc_book_get_pricedb (book_2)))
return FALSE;
/* FIXME: do scheduled transactions and template group */
return TRUE;
}
gboolean gboolean
gnc_book_events_pending (GNCBook *book) gnc_book_events_pending (GNCBook *book)
{ {

View File

@ -182,6 +182,10 @@ gboolean gnc_book_save_may_clobber_data (GNCBook *book);
void gnc_book_save (GNCBook *book); void gnc_book_save (GNCBook *book);
void gnc_book_end (GNCBook *book); void gnc_book_end (GNCBook *book);
/* The gnc_book_equal() method returns TRUE if the engine data
* in the two given books is equal. */
gboolean gnc_book_equal (GNCBook *book_1, GNCBook *book_2);
/* The gnc_book_events_pending() method will return TRUE if the backend /* The gnc_book_events_pending() method will return TRUE if the backend
* has pending events which must be processed to bring the engine * has pending events which must be processed to bring the engine
* up to date with the backend. * up to date with the backend.

View File

@ -23,12 +23,26 @@ static GHashTable *exclude_kvp_types = NULL;
static gint kvp_max_depth = G_MAXINT; static gint kvp_max_depth = G_MAXINT;
static gint kvp_frame_max_elements = 10; static gint kvp_frame_max_elements = 10;
static gint max_group_depth = 4;
static gint max_group_accounts = 10;
static kvp_value* get_random_kvp_value_depth (int type, gint depth); static kvp_value* get_random_kvp_value_depth (int type, gint depth);
/***********************************************************************/ /***********************************************************************/
void
set_max_group_depth (gint max_group_depth_in)
{
max_group_depth = MAX (max_group_depth_in, 1);
}
void
set_max_group_accounts (gint max_group_accounts_in)
{
max_group_accounts = MAX (max_group_accounts_in, 1);
}
void void
set_max_kvp_depth (gint max_kvp_depth) set_max_kvp_depth (gint max_kvp_depth)
{ {
@ -427,7 +441,8 @@ get_random_group_depth(int depth)
group = xaccMallocAccountGroup (); group = xaccMallocAccountGroup ();
num_accounts = get_random_int_in_range (1, 10); num_accounts = get_random_int_in_range (1, max_group_accounts);
while (num_accounts-- > 0) while (num_accounts-- > 0)
{ {
Account *account = get_random_account (); Account *account = get_random_account ();
@ -445,7 +460,7 @@ get_random_group(void)
{ {
int depth; int depth;
depth = get_random_int_in_range (1, 4); depth = get_random_int_in_range (1, max_group_depth);
return get_random_group_depth (depth); return get_random_group_depth (depth);
} }

View File

@ -34,6 +34,8 @@ void random_glist_strings_only (gboolean strings_only);
void glist_exclude_type (kvp_value_t kvp_type); void glist_exclude_type (kvp_value_t kvp_type);
void set_max_kvp_depth (gint max_kvp_depth); void set_max_kvp_depth (gint max_kvp_depth);
void set_max_kvp_frame_elements (gint max_kvp_frame_elements); void set_max_kvp_frame_elements (gint max_kvp_frame_elements);
void set_max_group_depth (gint max_group_depth);
void set_max_group_accounts (gint max_group_accounts);
GNCPrice * get_random_price(void); GNCPrice * get_random_price(void);
void make_random_pricedb (GNCPriceDB *pdb); void make_random_pricedb (GNCPriceDB *pdb);