2005-11-02 03:32:36 +00:00
|
|
|
/***************************************************************************
|
|
|
|
|
* test-group-vs-book.c
|
|
|
|
|
*
|
|
|
|
|
* Tue Sep 27 19:32:31 2005
|
|
|
|
|
* Copyright 2005 Gnucash team
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
/*
|
|
|
|
|
* 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
|
2005-11-17 05:35:02 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
|
* 02110-1301, USA.
|
2005-11-02 03:32:36 +00:00
|
|
|
*/
|
2001-08-20 23:25:39 +00:00
|
|
|
|
2006-09-05 18:00:11 +00:00
|
|
|
#include "config.h"
|
2001-08-20 23:25:39 +00:00
|
|
|
#include <glib.h>
|
2005-11-02 03:32:36 +00:00
|
|
|
#include "qof.h"
|
|
|
|
|
#include "cashobjects.h"
|
2003-06-11 01:23:18 +00:00
|
|
|
#include "Group.h"
|
2001-12-03 01:47:43 +00:00
|
|
|
#include "GroupP.h"
|
2001-11-05 09:18:07 +00:00
|
|
|
#include "TransLog.h"
|
2001-09-29 00:08:44 +00:00
|
|
|
#include "gnc-engine.h"
|
2001-08-20 23:25:39 +00:00
|
|
|
#include "test-engine-stuff.h"
|
|
|
|
|
#include "test-stuff.h"
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2003-06-25 00:52:46 +00:00
|
|
|
group_has_book (AccountGroup *group, QofBook *book)
|
2001-08-20 23:25:39 +00:00
|
|
|
{
|
|
|
|
|
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;
|
2003-06-25 00:52:46 +00:00
|
|
|
QofBook *book;
|
2001-08-20 23:25:39 +00:00
|
|
|
|
2003-06-25 00:52:46 +00:00
|
|
|
book = qof_book_new ();
|
2001-11-24 12:10:42 +00:00
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-11-02 03:32:36 +00:00
|
|
|
int
|
|
|
|
|
main (int argc, char **argv)
|
2001-08-20 23:25:39 +00:00
|
|
|
{
|
2005-11-02 03:32:36 +00:00
|
|
|
gint i;
|
|
|
|
|
qof_init();
|
|
|
|
|
if(cashobjects_register()) {
|
2001-11-05 09:18:07 +00:00
|
|
|
xaccLogDisable ();
|
2001-08-20 23:25:39 +00:00
|
|
|
for (i = 0; i < 10; i++)
|
2005-11-02 03:32:36 +00:00
|
|
|
{
|
2001-08-20 23:25:39 +00:00
|
|
|
run_test ();
|
2005-11-02 03:32:36 +00:00
|
|
|
}
|
2001-08-20 23:25:39 +00:00
|
|
|
success ("group/book stuff seems to work");
|
|
|
|
|
print_test_results();
|
2005-11-02 03:32:36 +00:00
|
|
|
}
|
|
|
|
|
qof_close();
|
2007-01-03 10:53:05 +00:00
|
|
|
return get_rv();
|
2001-10-03 10:07:45 +00:00
|
|
|
}
|