mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Fix bugs with new book pointers.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6053 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
8168a283b2
commit
fed69ff72c
@ -230,7 +230,9 @@ pricedb_start_handler(GSList* sibling_data,
|
|||||||
const gchar *tag,
|
const gchar *tag,
|
||||||
gchar **attrs)
|
gchar **attrs)
|
||||||
{
|
{
|
||||||
GNCPriceDB *db = gnc_pricedb_create();
|
gxpf_data *gdata = global_data;
|
||||||
|
GNCBook *book = gdata->bookdata;
|
||||||
|
GNCPriceDB *db = gnc_pricedb_create(book);
|
||||||
g_return_val_if_fail(db, FALSE);
|
g_return_val_if_fail(db, FALSE);
|
||||||
*result = db;
|
*result = db;
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
|
@ -202,7 +202,7 @@ cvt_potential_prices_to_pricedb_and_cleanup(GNCPriceDB **prices,
|
|||||||
{
|
{
|
||||||
GSList *item = potential_quotes;
|
GSList *item = potential_quotes;
|
||||||
|
|
||||||
*prices = gnc_pricedb_create();
|
*prices = gnc_pricedb_create(book);
|
||||||
if (!*prices) return FALSE;
|
if (!*prices) return FALSE;
|
||||||
|
|
||||||
while(item)
|
while(item)
|
||||||
|
@ -404,7 +404,7 @@ gnc_session_load_from_xml_file(GNCSession *session)
|
|||||||
{
|
{
|
||||||
GNCPriceDB *db = gnc_book_get_pricedb(book);
|
GNCPriceDB *db = gnc_book_get_pricedb(book);
|
||||||
|
|
||||||
gnc_book_set_pricedb(book, gnc_pricedb_create());
|
gnc_book_set_pricedb(book, gnc_pricedb_create(book));
|
||||||
|
|
||||||
if(db) gnc_pricedb_destroy(db);
|
if(db) gnc_pricedb_destroy(db);
|
||||||
}
|
}
|
||||||
@ -3711,7 +3711,8 @@ pricedb_start_handler(GSList* sibling_data,
|
|||||||
const gchar *tag,
|
const gchar *tag,
|
||||||
gchar **attrs)
|
gchar **attrs)
|
||||||
{
|
{
|
||||||
GNCPriceDB *db = gnc_pricedb_create();
|
GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
|
||||||
|
GNCPriceDB *db = gnc_pricedb_create(pstatus->book);
|
||||||
g_return_val_if_fail(db, FALSE);
|
g_return_val_if_fail(db, FALSE);
|
||||||
*result = db;
|
*result = db;
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
|
@ -46,7 +46,6 @@
|
|||||||
#include "io-utils.h"
|
#include "io-utils.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define GNC_V2_STRING "gnc-v2"
|
#define GNC_V2_STRING "gnc-v2"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -533,7 +532,7 @@ gnc_session_load_from_xml_file_v2(
|
|||||||
* then the file had no pricedb section. However,
|
* then the file had no pricedb section. However,
|
||||||
* this routine is expected to put one in the book. */
|
* this routine is expected to put one in the book. */
|
||||||
if (!gnc_book_get_pricedb (book))
|
if (!gnc_book_get_pricedb (book))
|
||||||
gnc_book_set_pricedb (book, gnc_pricedb_create ());
|
gnc_book_set_pricedb (book, gnc_pricedb_create (book));
|
||||||
|
|
||||||
/* mark the newly read group as saved, since the act of putting
|
/* mark the newly read group as saved, since the act of putting
|
||||||
* it together will have caused it to be marked up as not-saved.
|
* it together will have caused it to be marked up as not-saved.
|
||||||
|
@ -300,7 +300,7 @@ pgendGetAllPrices (PGBackend *be, GNCPriceDB *prdb)
|
|||||||
ENTER ("be=%p, conn=%p", be, be->connection);
|
ENTER ("be=%p, conn=%p", be, be->connection);
|
||||||
|
|
||||||
if (!prdb) {
|
if (!prdb) {
|
||||||
prdb = gnc_pricedb_create();
|
prdb = gnc_pricedb_create(be->book);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* first, make sure commodities table is up to date */
|
/* first, make sure commodities table is up to date */
|
||||||
|
@ -662,10 +662,7 @@ xaccAccountInsertSubAccount (Account *adult, Account *child)
|
|||||||
|
|
||||||
/* if a container for the children doesn't yet exist, add it */
|
/* if a container for the children doesn't yet exist, add it */
|
||||||
if (adult->children == NULL)
|
if (adult->children == NULL)
|
||||||
{
|
adult->children = xaccMallocAccountGroup (adult->book);
|
||||||
GNCBook *book = xaccGroupGetBook (adult->parent);
|
|
||||||
adult->children = xaccMallocAccountGroup (book);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* set back-pointer to parent */
|
/* set back-pointer to parent */
|
||||||
adult->children->parent = adult;
|
adult->children->parent = adult;
|
||||||
|
@ -78,7 +78,7 @@ gnc_book_init (GNCBook *book)
|
|||||||
|
|
||||||
book->kvp_data = kvp_frame_new ();
|
book->kvp_data = kvp_frame_new ();
|
||||||
book->topgroup = xaccMallocAccountGroup(book);
|
book->topgroup = xaccMallocAccountGroup(book);
|
||||||
book->pricedb = gnc_pricedb_create();
|
book->pricedb = gnc_pricedb_create(book);
|
||||||
|
|
||||||
book->sched_xactions = NULL;
|
book->sched_xactions = NULL;
|
||||||
book->sx_notsaved = FALSE;
|
book->sx_notsaved = FALSE;
|
||||||
@ -238,6 +238,7 @@ gnc_book_set_pricedb(GNCBook *book, GNCPriceDB *db)
|
|||||||
{
|
{
|
||||||
if(!book) return;
|
if(!book) return;
|
||||||
book->pricedb = db;
|
book->pricedb = db;
|
||||||
|
if (db) db->book = book;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
@ -35,8 +35,6 @@ struct gnc_price_s
|
|||||||
{
|
{
|
||||||
/* 'public' data fields */
|
/* 'public' data fields */
|
||||||
GUID guid; /* globally unique price id */
|
GUID guid; /* globally unique price id */
|
||||||
GNCEntityTable *entity_table; /* table in which price is stored */
|
|
||||||
GNCBook *book; /* book to which this price belongs to */
|
|
||||||
|
|
||||||
GNCPriceDB *db;
|
GNCPriceDB *db;
|
||||||
gnc_commodity *commodity;
|
gnc_commodity *commodity;
|
||||||
@ -49,6 +47,8 @@ struct gnc_price_s
|
|||||||
guint32 version_check; /* data aging timestamp */
|
guint32 version_check; /* data aging timestamp */
|
||||||
|
|
||||||
/* 'private' object management fields */
|
/* 'private' object management fields */
|
||||||
|
GNCBook *book; /* book to which this price belongs to */
|
||||||
|
GNCEntityTable *entity_table; /* table in which price is stored */
|
||||||
guint32 refcount; /* garbage collection reference count */
|
guint32 refcount; /* garbage collection reference count */
|
||||||
gint32 editlevel; /* nesting level of begin/end edit calls */
|
gint32 editlevel; /* nesting level of begin/end edit calls */
|
||||||
gboolean not_saved; /* price edit saved flag */
|
gboolean not_saved; /* price edit saved flag */
|
||||||
|
@ -612,10 +612,14 @@ commodity_equal (gconstpointer a, gconstpointer b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
GNCPriceDB *
|
GNCPriceDB *
|
||||||
gnc_pricedb_create(void)
|
gnc_pricedb_create(GNCBook * book)
|
||||||
{
|
{
|
||||||
GNCPriceDB * result = g_new0(GNCPriceDB, 1);
|
GNCPriceDB * result;
|
||||||
result->book = NULL;
|
|
||||||
|
g_return_val_if_fail (book, NULL);
|
||||||
|
|
||||||
|
result = g_new0(GNCPriceDB, 1);
|
||||||
|
result->book = book;
|
||||||
result->commodity_hash = g_hash_table_new(commodity_hash, commodity_equal);
|
result->commodity_hash = g_hash_table_new(commodity_hash, commodity_equal);
|
||||||
g_return_val_if_fail (result->commodity_hash, NULL);
|
g_return_val_if_fail (result->commodity_hash, NULL);
|
||||||
return result;
|
return result;
|
||||||
|
@ -219,7 +219,7 @@ typedef struct gnc_price_db_s GNCPriceDB;
|
|||||||
|
|
||||||
/* gnc_pricedb_create - create a new pricedb. Normally you won't need
|
/* gnc_pricedb_create - create a new pricedb. Normally you won't need
|
||||||
this; you will get the pricedb via gnc_book_get_pricedb. */
|
this; you will get the pricedb via gnc_book_get_pricedb. */
|
||||||
GNCPriceDB * gnc_pricedb_create(void);
|
GNCPriceDB * gnc_pricedb_create(GNCBook *book);
|
||||||
|
|
||||||
/* gnc_pricedb_destroy - destroy the given pricedb and unref all of
|
/* gnc_pricedb_destroy - destroy the given pricedb and unref all of
|
||||||
the prices it contains. This may not deallocate all of those
|
the prices it contains. This may not deallocate all of those
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
#include "date.h"
|
#include "date.h"
|
||||||
#include "Group.h"
|
#include "Group.h"
|
||||||
#include "gnc-book-p.h"
|
|
||||||
#include "gnc-engine.h"
|
#include "gnc-engine.h"
|
||||||
#include "gnc-engine-util.h"
|
#include "gnc-engine-util.h"
|
||||||
#include "test-engine-stuff.h"
|
#include "test-engine-stuff.h"
|
||||||
@ -226,7 +225,7 @@ get_random_pricedb(GNCBook *book)
|
|||||||
{
|
{
|
||||||
GNCPriceDB *db;
|
GNCPriceDB *db;
|
||||||
|
|
||||||
db = gnc_pricedb_create ();
|
db = gnc_pricedb_create (book);
|
||||||
make_random_pricedb (book, db);
|
make_random_pricedb (book, db);
|
||||||
|
|
||||||
return db;
|
return db;
|
||||||
@ -546,16 +545,16 @@ account_add_subaccounts (GNCBook *book, Account *account, int depth)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static AccountGroup *
|
static void
|
||||||
get_random_group_depth(GNCBook *book, int depth)
|
make_random_group_depth (GNCBook *book, AccountGroup *group, int depth)
|
||||||
{
|
{
|
||||||
AccountGroup *group;
|
|
||||||
int num_accounts;
|
int num_accounts;
|
||||||
|
|
||||||
if (depth <= 0)
|
g_return_if_fail (book);
|
||||||
return NULL;
|
g_return_if_fail (group);
|
||||||
|
|
||||||
group = xaccMallocAccountGroup (book);
|
if (depth <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
num_accounts = get_random_int_in_range (1, max_group_accounts);
|
num_accounts = get_random_int_in_range (1, max_group_accounts);
|
||||||
|
|
||||||
@ -567,18 +566,33 @@ get_random_group_depth(GNCBook *book, int depth)
|
|||||||
|
|
||||||
account_add_subaccounts (book, account, depth - 1);
|
account_add_subaccounts (book, account, depth - 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return group;
|
static void
|
||||||
|
make_random_group (GNCBook *book, AccountGroup * group)
|
||||||
|
{
|
||||||
|
int depth;
|
||||||
|
|
||||||
|
g_return_if_fail (book);
|
||||||
|
g_return_if_fail (group);
|
||||||
|
|
||||||
|
depth = get_random_int_in_range (1, max_group_depth);
|
||||||
|
|
||||||
|
make_random_group_depth (book, group, depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
AccountGroup *
|
AccountGroup *
|
||||||
get_random_group (GNCBook *book)
|
get_random_group (GNCBook *book)
|
||||||
{
|
{
|
||||||
int depth;
|
AccountGroup * group;
|
||||||
|
|
||||||
depth = get_random_int_in_range (1, max_group_depth);
|
g_return_val_if_fail (book, NULL);
|
||||||
|
|
||||||
return get_random_group_depth (book, depth);
|
group = xaccMallocAccountGroup (book);
|
||||||
|
|
||||||
|
make_random_group (book, group);
|
||||||
|
|
||||||
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@ -1443,11 +1457,7 @@ get_random_book (void)
|
|||||||
|
|
||||||
book = gnc_book_new ();
|
book = gnc_book_new ();
|
||||||
|
|
||||||
/* XXX fixme -- gnc_book_set_group is a private engine function,
|
make_random_group (book, gnc_book_get_group (book));
|
||||||
* it should not be invoked in ordinary test cases. Its should
|
|
||||||
* be more like make_random_pricedb below... */
|
|
||||||
gnc_book_set_group (book, get_random_group (book));
|
|
||||||
|
|
||||||
make_random_pricedb (book, gnc_book_get_pricedb (book));
|
make_random_pricedb (book, gnc_book_get_pricedb (book));
|
||||||
|
|
||||||
return book;
|
return book;
|
||||||
@ -1463,11 +1473,7 @@ get_random_session (void)
|
|||||||
|
|
||||||
book = gnc_session_get_book (session);
|
book = gnc_session_get_book (session);
|
||||||
|
|
||||||
/* XXX fixme -- gnc_book_set_group is a private engine function,
|
make_random_group (book, gnc_book_get_group (book));
|
||||||
* it should not be invoked in ordinary test cases. Its should
|
|
||||||
* be more like make_random_pricedb below... */
|
|
||||||
gnc_book_set_group (book, get_random_group (book));
|
|
||||||
|
|
||||||
make_random_pricedb (book, gnc_book_get_pricedb (book));
|
make_random_pricedb (book, gnc_book_get_pricedb (book));
|
||||||
|
|
||||||
return session;
|
return session;
|
||||||
|
@ -62,15 +62,18 @@ run_test (void)
|
|||||||
exit(get_rv());
|
exit(get_rv());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!group_has_book (group1, NULL))
|
if (!group_has_book (group1, book))
|
||||||
{
|
{
|
||||||
failure("new group has non-null book");
|
failure("new group has wrong book");
|
||||||
exit(get_rv());
|
exit(get_rv());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ???????? this test seems to be testing routines that
|
/* this test is testing routines that are private
|
||||||
* are private to the engine, not sure why. book_set_group
|
* to the engine. these tests are intended to test
|
||||||
* should not be called publically. */
|
* the engine as a whole, not just the public
|
||||||
|
* interface. the maintenance of the correct
|
||||||
|
* book pointers is important for correct
|
||||||
|
* engine operation. */
|
||||||
gnc_book_set_group (book, group1);
|
gnc_book_set_group (book, group1);
|
||||||
if (!group_has_book (group1, book))
|
if (!group_has_book (group1, book))
|
||||||
{
|
{
|
||||||
|
@ -48,7 +48,7 @@ run_tests (void)
|
|||||||
test_query (q);
|
test_query (q);
|
||||||
xaccFreeQuery (q);
|
xaccFreeQuery (q);
|
||||||
|
|
||||||
for (i = 0; i < 10; i++)
|
for (i = 0; i < 50; i++)
|
||||||
{
|
{
|
||||||
q = get_random_query ();
|
q = get_random_query ();
|
||||||
test_query (q);
|
test_query (q);
|
||||||
|
Loading…
Reference in New Issue
Block a user