2001-08-20 23:25:39 +00:00
|
|
|
|
|
|
|
|
#include <glib.h>
|
2003-02-22 08:15:53 +00:00
|
|
|
#include <libguile.h>
|
2001-08-20 23:25:39 +00:00
|
|
|
|
2003-06-11 01:23:18 +00:00
|
|
|
#include "Group.h"
|
2001-12-03 01:47:43 +00:00
|
|
|
#include "GroupP.h"
|
2001-08-20 23:25:39 +00:00
|
|
|
#include "GNCIdP.h"
|
2001-11-05 09:18:07 +00:00
|
|
|
#include "TransLog.h"
|
2001-08-20 23:25:39 +00:00
|
|
|
#include "gnc-book.h"
|
2001-11-24 18:22:57 +00:00
|
|
|
#include "gnc-book-p.h"
|
2001-09-29 00:08:44 +00:00
|
|
|
#include "gnc-engine.h"
|
2001-10-03 10:07:45 +00:00
|
|
|
#include "gnc-module.h"
|
2001-08-20 23:25:39 +00:00
|
|
|
#include "test-engine-stuff.h"
|
|
|
|
|
#include "test-stuff.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
group_has_book (AccountGroup *group, GNCBook *book)
|
|
|
|
|
{
|
|
|
|
|
GList *node;
|
|
|
|
|
|
|
|
|
|
if (!group)
|
|
|
|
|
return (book == NULL);
|
|
|
|
|
|
|
|
|
|
if (xaccGroupGetBook (group) != book)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
for (node = xaccGroupGetAccountList (group); node; node = node->next)
|
|
|
|
|
{
|
|
|
|
|
AccountGroup *children = xaccAccountGetChildren (node->data);
|
|
|
|
|
|
|
|
|
|
if (!children)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!group_has_book (children, book))
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
run_test (void)
|
|
|
|
|
{
|
|
|
|
|
AccountGroup *group1;
|
|
|
|
|
AccountGroup *group2;
|
|
|
|
|
Account *account1;
|
|
|
|
|
Account *account2;
|
|
|
|
|
GNCBook *book;
|
|
|
|
|
|
2001-11-24 12:10:42 +00:00
|
|
|
book = gnc_book_new ();
|
|
|
|
|
if (!book)
|
|
|
|
|
{
|
|
|
|
|
failure("book not created");
|
|
|
|
|
exit(get_rv());
|
|
|
|
|
}
|
2001-10-03 10:07:45 +00:00
|
|
|
|
2001-11-24 12:10:42 +00:00
|
|
|
group1 = get_random_group (book);
|
2001-08-20 23:25:39 +00:00
|
|
|
if(!group1)
|
|
|
|
|
{
|
|
|
|
|
failure("group1 not created");
|
|
|
|
|
exit(get_rv());
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-25 09:05:23 +00:00
|
|
|
if (!group_has_book (group1, book))
|
2001-08-20 23:25:39 +00:00
|
|
|
{
|
2001-11-25 09:05:23 +00:00
|
|
|
failure("new group has wrong book");
|
2001-08-20 23:25:39 +00:00
|
|
|
exit(get_rv());
|
|
|
|
|
}
|
|
|
|
|
|
2003-06-10 04:01:16 +00:00
|
|
|
/* This test is testing routines that are private
|
2001-11-25 09:05:23 +00:00
|
|
|
* to the engine. these tests are intended to test
|
|
|
|
|
* the engine as a whole, not just the public
|
|
|
|
|
* interface. the maintenance of the correct
|
|
|
|
|
* book pointers is important for correct
|
|
|
|
|
* engine operation. */
|
2003-06-10 04:01:16 +00:00
|
|
|
xaccSetAccountGroup (book, group1);
|
2001-08-20 23:25:39 +00:00
|
|
|
if (!group_has_book (group1, book))
|
|
|
|
|
{
|
2003-06-10 04:10:54 +00:00
|
|
|
failure("xaccSetAccountGroup didn't take");
|
2001-08-20 23:25:39 +00:00
|
|
|
exit(get_rv());
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-24 12:10:42 +00:00
|
|
|
group2 = get_random_group (book);
|
2001-08-20 23:25:39 +00:00
|
|
|
if(!group2)
|
|
|
|
|
{
|
|
|
|
|
failure("group2 not created");
|
|
|
|
|
exit(get_rv());
|
|
|
|
|
}
|
|
|
|
|
|
2003-06-10 04:01:16 +00:00
|
|
|
xaccSetAccountGroup (book, group2);
|
2001-08-20 23:25:39 +00:00
|
|
|
|
2001-12-04 07:36:45 +00:00
|
|
|
#if 0
|
|
|
|
|
/* a group cannot have a 'null' book; this test is nonsense. */
|
2001-08-20 23:25:39 +00:00
|
|
|
if (!group_has_book (group1, NULL))
|
|
|
|
|
{
|
2003-06-10 04:10:54 +00:00
|
|
|
failure("xaccSetAccountGroup didn't clear old");
|
2001-08-20 23:25:39 +00:00
|
|
|
exit(get_rv());
|
|
|
|
|
}
|
2001-12-04 07:36:45 +00:00
|
|
|
#endif
|
2001-08-20 23:25:39 +00:00
|
|
|
|
|
|
|
|
if (!group_has_book (group2, book))
|
|
|
|
|
{
|
2003-06-10 04:10:54 +00:00
|
|
|
failure("xaccSetAccountGroup didn't take");
|
2001-08-20 23:25:39 +00:00
|
|
|
exit(get_rv());
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-24 12:10:42 +00:00
|
|
|
account1 = get_random_account (book);
|
2001-08-20 23:25:39 +00:00
|
|
|
if(!account1)
|
|
|
|
|
{
|
|
|
|
|
failure("account1 not created");
|
|
|
|
|
exit(get_rv());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xaccGroupInsertAccount (group2, account1);
|
|
|
|
|
if (group2 != xaccAccountGetParent (account1))
|
|
|
|
|
{
|
|
|
|
|
failure("group insert account didn't work");
|
|
|
|
|
exit(get_rv());
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-24 12:10:42 +00:00
|
|
|
account2 = get_random_account (book);
|
2001-08-20 23:25:39 +00:00
|
|
|
if(!account2)
|
|
|
|
|
{
|
|
|
|
|
failure("account2 not created");
|
|
|
|
|
exit(get_rv());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xaccAccountInsertSubAccount (account1, account2);
|
|
|
|
|
if (!group_has_book (xaccAccountGetParent (account2), book))
|
|
|
|
|
{
|
|
|
|
|
failure("account2 has wrong book");
|
|
|
|
|
exit(get_rv());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xaccGroupRemoveAccount (group2, account1);
|
|
|
|
|
if (xaccAccountGetParent (account1) != NULL)
|
|
|
|
|
{
|
|
|
|
|
failure("remove group didn't take");
|
|
|
|
|
exit(get_rv());
|
|
|
|
|
}
|
|
|
|
|
|
2001-12-04 07:36:45 +00:00
|
|
|
#if 0
|
|
|
|
|
/* a group cannot have a 'null' book; this test is nonsense. */
|
2001-08-20 23:25:39 +00:00
|
|
|
if (!group_has_book (xaccAccountGetParent (account2), NULL))
|
|
|
|
|
{
|
|
|
|
|
failure("remove group didn't clear book");
|
|
|
|
|
exit(get_rv());
|
|
|
|
|
}
|
2001-12-04 07:36:45 +00:00
|
|
|
#endif
|
2001-08-20 23:25:39 +00:00
|
|
|
}
|
|
|
|
|
|
2001-10-03 10:07:45 +00:00
|
|
|
static void
|
2003-02-22 08:15:53 +00:00
|
|
|
main_helper (void *closure, int argc, char **argv)
|
2001-08-20 23:25:39 +00:00
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
2001-12-04 22:47:35 +00:00
|
|
|
gnc_module_system_init();
|
|
|
|
|
|
|
|
|
|
if(!gnc_module_load("gnucash/engine", 0))
|
|
|
|
|
{
|
|
|
|
|
failure("couldn't load gnucash/engine");
|
|
|
|
|
exit(get_rv());
|
|
|
|
|
}
|
2001-08-20 23:25:39 +00:00
|
|
|
|
2001-11-05 09:18:07 +00:00
|
|
|
xaccLogDisable ();
|
|
|
|
|
|
2001-08-20 23:25:39 +00:00
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
|
run_test ();
|
|
|
|
|
|
|
|
|
|
success ("group/book stuff seems to work");
|
|
|
|
|
print_test_results();
|
|
|
|
|
exit(get_rv());
|
|
|
|
|
}
|
2001-10-03 10:07:45 +00:00
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main (int argc, char **argv)
|
|
|
|
|
{
|
2003-02-22 08:15:53 +00:00
|
|
|
scm_boot_guile (argc, argv, main_helper, NULL);
|
2001-10-03 10:07:45 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|