changes to use more generic 'collection of entities' functions

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9568 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2003-10-19 05:11:07 +00:00
parent 8c8871f65d
commit b10828a439
23 changed files with 808 additions and 615 deletions

View File

@ -2807,19 +2807,7 @@ xaccAccountFindTransByDesc(Account *account, const char *description)
}
/* ================================================================ */
/* gncObject function implementation and registration */
static void
account_foreach (QofBook *book, QofForeachCB cb, gpointer ud)
{
QofCollection *col;
g_return_if_fail (book);
g_return_if_fail (cb);
col = qof_book_get_collection (book, GNC_ID_ACCOUNT);
qof_collection_foreach (col, (QofEntityForeachCB) cb, ud);
}
/* QofObject function implementation and registration */
static QofObject account_object_def = {
interface_version: QOF_OBJECT_VERSION,
@ -2829,7 +2817,7 @@ static QofObject account_object_def = {
book_end: NULL,
is_dirty: NULL,
mark_clean: NULL,
foreach: account_foreach,
foreach: qof_collection_foreach,
printable: (const char* (*)(gpointer)) xaccAccountGetName
};

View File

@ -84,33 +84,51 @@ xaccMallocAccountGroup (QofBook *book)
/********************************************************************\
\********************************************************************/
#define GNC_TOP_GROUP "gnc_top_group"
AccountGroup *
xaccCollGetAccountGroup (QofCollection *col)
{
if (!col) return NULL;
return qof_collection_get_data (col);
}
void
xaccCollSetAccountGroup (QofCollection *col, AccountGroup *grp)
{
AccountGroup *old_grp;
if (!col) return;
old_grp = xaccCollGetAccountGroup (col);
if (old_grp == grp) return;
qof_collection_set_data (col, grp);
xaccAccountGroupBeginEdit (old_grp);
xaccAccountGroupDestroy (old_grp);
}
AccountGroup *
xaccGetAccountGroup (QofBook *book)
{
if (!book) return NULL;
return qof_book_get_data (book, GNC_TOP_GROUP);
QofCollection *col;
if (!book) return NULL;
col = qof_book_get_collection (book, GNC_ID_GROUP);
return xaccCollGetAccountGroup (col);
}
void
xaccSetAccountGroup (QofBook *book, AccountGroup *grp)
{
AccountGroup *old_grp;
QofCollection *col;
if (!book) return;
old_grp = xaccGetAccountGroup (book);
if (old_grp == grp) return;
if (grp && grp->book != book)
{
PERR ("cannot mix and match books freely!");
return;
}
qof_book_set_data (book, GNC_TOP_GROUP, grp);
xaccAccountGroupBeginEdit (old_grp);
xaccAccountGroupDestroy (old_grp);
col = qof_book_get_collection (book, GNC_ID_GROUP);
xaccCollSetAccountGroup (col, grp);
}
/********************************************************************\
@ -1229,15 +1247,15 @@ group_book_end (QofBook *book)
}
static gboolean
group_is_dirty (QofBook *book)
group_is_dirty (QofCollection *col)
{
return xaccGroupNotSaved(xaccGetAccountGroup(book));
return xaccGroupNotSaved(xaccCollGetAccountGroup(col));
}
static void
group_mark_clean(QofBook *book)
group_mark_clean(QofCollection *col)
{
xaccGroupMarkSaved(xaccGetAccountGroup(book));
xaccGroupMarkSaved(xaccCollGetAccountGroup(col));
}
static QofObject group_object_def =

View File

@ -46,6 +46,7 @@ AccountGroup *xaccMallocAccountGroup (QofBook *book);
* account group associated with the indicated book.
*/
AccountGroup * xaccGetAccountGroup (QofBook *book);
AccountGroup * xaccCollGetAccountGroup (QofCollection *col);
/*
* The xaccAccountDestroy() routine will destroy and free all

View File

@ -95,6 +95,7 @@ void xaccFreeAccountGroup (AccountGroup *account_group);
/* Set the top-level group in the book */
void xaccSetAccountGroup (QofBook *book, AccountGroup *grp);
void xaccCollSetAccountGroup (QofCollection *col, AccountGroup *grp);
/*
* The xaccGroupGetBackend() subroutine will find the

View File

@ -35,19 +35,23 @@
#define GNC_SX_BOOK_P_H
#include "qofbook.h"
#include "qofid.h"
/* ====================================================================== */
struct xaccSchedXactionsDef {
QofBook *book;
GList *sx_list;
gboolean sx_notsaved;
};
void gnc_book_set_schedxactions( QofBook *book, GList *newList );
void gnc_collection_set_schedxactions( QofCollection *col, GList *newList );
/* Associate the given template group with a book */
void gnc_book_set_template_group (QofBook *book, AccountGroup *templateGroup);
void gnc_collection_set_template_group (QofCollection *col, AccountGroup *templateGroup);
gboolean gnc_sxtt_register (void);

View File

@ -54,33 +54,133 @@
static short module = MOD_SX;
/* XXX this whole file is crufty, it doesn't really use entities
* in the most efficient/best way */
/* ====================================================================== */
#define GNC_SCHEDXACTIONS "gnc_schedxactions"
SchedXactions *
gnc_book_get_schedxaction_list( QofBook *book )
AccountGroup *
gnc_collection_get_template_group( QofCollection *col )
{
if ( book == NULL ) return NULL;
return qof_book_get_data (book, GNC_SCHEDXACTIONS);
return qof_collection_get_data (col);
}
AccountGroup *
gnc_book_get_template_group( QofBook *book )
{
QofCollection *col;
if (!book) return NULL;
col = qof_book_get_collection (book, GNC_ID_SXTG);
return gnc_collection_get_template_group (col);
}
void
gnc_collection_set_template_group (QofCollection *col, AccountGroup *templateGroup)
{
AccountGroup *old_grp;
if (!col) return;
old_grp = gnc_collection_get_template_group (col);
if (old_grp == templateGroup) return;
qof_collection_set_data (col, templateGroup);
xaccAccountGroupBeginEdit (old_grp);
xaccAccountGroupDestroy (old_grp);
}
void
gnc_book_set_template_group (QofBook *book, AccountGroup *templateGroup)
{
QofCollection *col;
if (!book) return;
if (templateGroup && templateGroup->book != book)
{
PERR ("cannot mix and match books freely!");
return;
}
col = qof_book_get_collection (book, GNC_ID_SXTG);
gnc_collection_set_template_group (col, templateGroup);
}
/* ====================================================================== */
/* gncObject function implementation and registration */
static void
sxtg_book_begin (QofBook *book)
{
gnc_book_set_template_group (book, xaccMallocAccountGroup(book));
}
static void
sxtg_book_end (QofBook *book)
{
gnc_book_set_template_group (book, NULL);
}
static gboolean
sxtg_is_dirty(QofCollection *col)
{
return xaccGroupNotSaved(gnc_collection_get_template_group(col));
}
static void
sxtg_mark_clean(QofCollection *col)
{
xaccGroupMarkSaved(gnc_collection_get_template_group(col));
}
static QofObject sxtg_object_def =
{
interface_version: QOF_OBJECT_VERSION,
e_type: GNC_ID_SXTG,
type_label: "Scheduled Transaction Templates",
book_begin: sxtg_book_begin,
book_end: sxtg_book_end,
is_dirty: sxtg_is_dirty,
mark_clean: sxtg_mark_clean,
foreach: NULL,
printable: NULL,
};
/* ====================================================================== */
SchedXactions *
gnc_collection_get_schedxaction_list( QofCollection *col)
{
return qof_collection_get_data (col);
}
GList *
gnc_collection_get_schedxactions( QofCollection *col)
{
SchedXactions *list;
list = qof_collection_get_data (col);
if (list) return list->sx_list;
return NULL;
}
GList *
gnc_book_get_schedxactions( QofBook *book )
{
SchedXactions *list;
if ( book == NULL ) return NULL;
list = qof_book_get_data (book, GNC_SCHEDXACTIONS);
if (list) return list->sx_list;
return NULL;
QofCollection *col;
col = qof_book_get_collection (book, GNC_ID_SXTT);
return gnc_collection_get_schedxactions (col);
}
void
gnc_book_set_schedxactions( QofBook *book, GList *newList )
gnc_collection_set_schedxactions( QofCollection *col, GList *newList )
{
SchedXactions *old_list, *new_list;
if ( book == NULL ) return;
if ( col == NULL ) return;
old_list = qof_book_get_data (book, GNC_SCHEDXACTIONS);
old_list = qof_collection_get_data (col);
if (old_list && old_list->sx_list == newList)
{
/* Assume the worst, that any 'set' means the data has
@ -90,73 +190,39 @@ gnc_book_set_schedxactions( QofBook *book, GList *newList )
}
new_list = g_new (SchedXactions, 1);
new_list->book = book;
new_list->sx_list = newList;
new_list->sx_notsaved = TRUE;
if (NULL == newList) new_list->sx_notsaved = FALSE;
qof_book_set_data (book, GNC_SCHEDXACTIONS, new_list);
qof_collection_set_data (col, new_list);
g_free (old_list);
}
/* ====================================================================== */
#define GNC_TEMPLATE_GROUP "gnc_template_group"
AccountGroup *
gnc_book_get_template_group( QofBook *book )
{
if (!book) return NULL;
return qof_book_get_data (book, GNC_TEMPLATE_GROUP);
}
void
gnc_book_set_template_group (QofBook *book, AccountGroup *templateGroup)
gnc_book_set_schedxactions( QofBook *book, GList *newList )
{
AccountGroup *old_grp;
if (!book) return;
QofCollection *col;
if ( book == NULL ) return;
if (templateGroup && templateGroup->book != book)
{
PERR ("cannot mix and match books freely!");
return;
}
old_grp = gnc_book_get_template_group (book);
if (old_grp == templateGroup) return;
qof_book_set_data (book, GNC_TEMPLATE_GROUP, templateGroup);
xaccAccountGroupBeginEdit (old_grp);
xaccAccountGroupDestroy (old_grp);
col = qof_book_get_collection (book, GNC_ID_SXTT);
gnc_collection_set_schedxactions (col, newList);
}
/* ====================================================================== */
/* gncObject function implementation and registration */
/* XXX Its not clear to me if the template group and the sched xactions
* should be treated together or not. I got lazy, and mashed them together.
* For right now, this works. If you feel you need to slit this up into
* two separate gnc Objects, that's OK with me.
*/
/* SX-trans stuff */
static void
sxtt_book_begin (QofBook *book)
{
gnc_book_set_schedxactions (book, NULL);
gnc_book_set_template_group (book, xaccMallocAccountGroup(book));
}
static void
sxtt_book_end (QofBook *book)
{
gnc_book_set_template_group (book, NULL);
gnc_book_set_schedxactions (book, NULL);
}
/* ====================================================================== */
/* dirty flag stuff */
static void
mark_sx_clean(gpointer data, gpointer user_data)
{
@ -165,33 +231,31 @@ mark_sx_clean(gpointer data, gpointer user_data)
}
static void
book_sxns_mark_saved(QofBook *book)
book_sxns_mark_saved(QofCollection *col)
{
SchedXactions *sxl;
sxl = gnc_book_get_schedxaction_list (book);
sxl = gnc_collection_get_schedxaction_list (col);
if (sxl) sxl->sx_notsaved = FALSE;
g_list_foreach(gnc_book_get_schedxactions(book),
g_list_foreach(gnc_collection_get_schedxactions(col),
mark_sx_clean,
NULL);
}
static gboolean
book_sxlist_notsaved(QofBook *book)
book_sxlist_notsaved(QofCollection *col)
{
GList *sxlist;
SchedXaction *sx;
SchedXactions *sxl;
sxl = gnc_book_get_schedxaction_list (book);
if((sxl && sxl->sx_notsaved)
||
xaccGroupNotSaved(gnc_book_get_template_group(book))) return TRUE;
sxl = gnc_collection_get_schedxaction_list (col);
if((sxl && sxl->sx_notsaved)) return TRUE;
for(sxlist = gnc_book_get_schedxactions(book);
for(sxlist = gnc_collection_get_schedxactions(col);
sxlist != NULL;
sxlist = g_list_next(sxlist))
{
SchedXaction *sx;
sx = (SchedXaction *) (sxlist->data);
if (xaccSchedXactionIsDirty( sx ))
return TRUE;
@ -200,23 +264,15 @@ book_sxlist_notsaved(QofBook *book)
return FALSE;
}
static void
sxtt_mark_clean(QofBook *book)
{
xaccGroupMarkSaved(gnc_book_get_template_group(book));
book_sxns_mark_saved(book);
}
static QofObject sxtt_object_def =
{
interface_version: QOF_OBJECT_VERSION,
e_type: GNC_ID_SXTT,
type_label: "SXTT",
type_label: "Scheduled Transaction Templates",
book_begin: sxtt_book_begin,
book_end: sxtt_book_end,
is_dirty: book_sxlist_notsaved,
mark_clean: sxtt_mark_clean,
mark_clean: book_sxns_mark_saved,
foreach: NULL,
printable: NULL,
};
@ -224,6 +280,7 @@ static QofObject sxtt_object_def =
gboolean
gnc_sxtt_register (void)
{
return qof_object_register (&sxtg_object_def);
return qof_object_register (&sxtt_object_def);
}

View File

@ -27,6 +27,9 @@
* @brief Anchor Scheduled Transaction info in a book.
* See src/doc/books.txt for design overview.
* @author Copyright (c) 2003 Linas Vepstas <linas@linas.org>
*
* XXX currently, this is crufty, it should be modified to use
* entities a bit more whole-heartedly than it does.
**/
#ifndef GNC_SX_BOOK_H
@ -38,15 +41,19 @@
#include "gnc-engine.h"
#include "qofbook.h"
#include "qofid.h"
typedef struct xaccSchedXactionsDef SchedXactions;
SchedXactions * gnc_book_get_schedxaction_list( QofBook *book );
SchedXactions * gnc_collection_get_schedxaction_list( QofCollection *col);
GList * gnc_collection_get_schedxactions( QofCollection *col);
GList * gnc_book_get_schedxactions( QofBook *book );
/** Returns the template group from the book.
**/
AccountGroup * gnc_book_get_template_group (QofBook *book);
AccountGroup * gnc_collection_get_template_group( QofCollection *col );
#endif /* GNC_SX_BOOK_H */
/** @} */

View File

@ -3179,18 +3179,9 @@ xaccTransReverse (Transaction *trans)
/********************************************************************\
\********************************************************************/
/* gncObject function implementation */
/* QofObject function implementation */
static void
split_foreach (QofBook *book, QofForeachCB fcn, gpointer user_data)
{
QofCollection *col;
g_return_if_fail (book);
col = qof_book_get_collection (book, GNC_ID_SPLIT);
qof_collection_foreach (col, (QofEntityForeachCB) fcn, user_data);
}
/* Hook into the gncObject registry */
/* Hook into the QofObject registry */
static QofObject split_object_def = {
interface_version: QOF_OBJECT_VERSION,
@ -3200,7 +3191,7 @@ static QofObject split_object_def = {
book_end: NULL,
is_dirty: NULL,
mark_clean: NULL,
foreach: split_foreach,
foreach: qof_collection_foreach,
printable: (const char* (*)(gpointer)) xaccSplitGetMemo
};
@ -3284,15 +3275,6 @@ gboolean xaccSplitRegister (void)
return qof_object_register (&split_object_def);
}
static void
trans_foreach (QofBook *book, QofForeachCB fcn, gpointer user_data)
{
QofCollection *col;
g_return_if_fail (book);
col = qof_book_get_collection (book, GNC_ID_TRANS);
qof_collection_foreach (col, (QofEntityForeachCB) fcn, user_data);
}
static QofObject trans_object_def = {
interface_version: QOF_OBJECT_VERSION,
e_type: GNC_ID_TRANS,
@ -3301,7 +3283,7 @@ static QofObject trans_object_def = {
book_end: NULL,
is_dirty: NULL,
mark_clean: NULL,
foreach: trans_foreach,
foreach: qof_collection_foreach,
printable: (const char* (*)(gpointer)) xaccTransGetDescription
};

View File

@ -40,9 +40,11 @@
#define SAFE_STRCMP_REAL(fcn,da,db) { \
if ((da) && (db)) { \
int retval = fcn ((da), (db)); \
/* if strings differ, return */ \
if (retval) return retval; \
if ((da) != (db)) { \
int retval = fcn ((da), (db)); \
/* if strings differ, return */ \
if (retval) return retval; \
} \
} else \
if ((!(da)) && (db)) { \
return -1; \

View File

@ -68,7 +68,8 @@
#define GNC_ID_PRICEDB "PriceDB"
#define GNC_ID_SPLIT "Split"
#define GNC_ID_SCHEDXACTION "SchedXaction"
#define GNC_ID_SXTT "SXTT"
#define GNC_ID_SXTG "SXTGroup"
#define GNC_ID_SXTT "SXTTrans"
#define GNC_ID_TRANS "Trans"
/* TYPES **********************************************************/

View File

@ -100,6 +100,8 @@ typedef struct gnc_price_lookup_helper_s
#define gnc_price_set_guid(P,G) qof_entity_set_guid(QOF_ENTITY(P),(G))
void gnc_pricedb_set_db(QofBook *book, GNCPriceDB *db);
void gnc_collection_set_pricedb(QofCollection *col, GNCPriceDB *db);
void gnc_pricedb_mark_clean(GNCPriceDB *db);
void gnc_pricedb_substitute_commodity(GNCPriceDB *db,

View File

@ -678,29 +678,43 @@ gnc_pricedb_destroy(GNCPriceDB *db)
/* ==================================================================== */
#define GNC_PRICEDB "gnc_pricedb"
GNCPriceDB *
gnc_collection_get_pricedb(QofCollection *col)
{
return qof_collection_get_data (col);
}
GNCPriceDB *
gnc_pricedb_get_db(QofBook *book)
{
QofCollection *col;
if (!book) return NULL;
return qof_book_get_data (book, GNC_PRICEDB);
col = qof_book_get_collection (book, GNC_ID_PRICE);
return gnc_collection_get_pricedb (col);
}
void
gnc_collection_set_pricedb(QofCollection *col, GNCPriceDB *db)
{
GNCPriceDB *old_db;
if(!col) return;
old_db = qof_collection_get_data (col);
if (db == old_db) return;
qof_collection_set_data (col, db);
gnc_pricedb_destroy (old_db);
}
void
gnc_pricedb_set_db(QofBook *book, GNCPriceDB *db)
{
GNCPriceDB *old_db;
QofCollection *col;
if(!book) return;
old_db = gnc_pricedb_get_db (book);
if (db == old_db) return;
qof_book_set_data (book, GNC_PRICEDB, db);
col = qof_book_get_collection (book, GNC_ID_PRICE);
gnc_collection_set_pricedb (col, db);
if (db) db->book = book;
gnc_pricedb_destroy (old_db);
}
/* ==================================================================== */
@ -1942,15 +1956,15 @@ pricedb_book_end (QofBook *book)
}
static gboolean
pricedb_is_dirty (QofBook *book)
pricedb_is_dirty (QofCollection *col)
{
return gnc_pricedb_dirty(gnc_pricedb_get_db(book));
return gnc_pricedb_dirty(gnc_collection_get_pricedb(col));
}
static void
pricedb_mark_clean(QofBook *book)
pricedb_mark_clean(QofCollection *col)
{
gnc_pricedb_mark_clean(gnc_pricedb_get_db(book));
gnc_pricedb_mark_clean(gnc_collection_get_pricedb(col));
}
/* ==================================================================== */
@ -2002,9 +2016,9 @@ void_unstable_price_traversal(GNCPriceDB *db,
}
static void
pricedb_foreach(QofBook *book, QofForeachCB cb, gpointer data)
pricedb_foreach(QofCollection *col, QofEntityForeachCB cb, gpointer data)
{
GNCPriceDB *db = gnc_pricedb_get_db(book);
GNCPriceDB *db = gnc_collection_get_pricedb(col);
void_unstable_price_traversal(db,
(void (*)(GNCPrice *, gpointer)) cb,
data);

View File

@ -31,6 +31,7 @@
#include "gnc-numeric.h"
#include "guid.h"
#include "qofbook.h"
#include "qofid.h"
#include "qofinstance.h"
@ -239,6 +240,7 @@ GNCPriceDB * gnc_pricedb_create(QofBook *book);
/** return the pricedb associated with the book */
GNCPriceDB * gnc_pricedb_get_db(QofBook *book);
GNCPriceDB * gnc_collection_get_pricedb(QofCollection *col);
/** gnc_pricedb_destroy - destroy the given pricedb and unref all of
the prices it contains. This may not deallocate all of those

View File

@ -43,6 +43,18 @@
* manipulated by GnuCash. This is the top-most structure
* used for anchoring data.
*/
/** Lookup an entity by guid, returning pointer to the entity */
#define QOF_BOOK_LOOKUP_ENTITY(book,guid,e_type,c_type) ({ \
QofEntity *val = NULL; \
if (guid && book) { \
QofCollection *col; \
col = qof_book_get_collection (book, e_type); \
val = qof_collection_lookup_entity (col, guid); \
} \
(c_type *) val; \
})
typedef struct _QofBook QofBook;
/** GList of QofBook */

View File

@ -42,5 +42,8 @@ void qof_entity_set_guid (QofEntity *ent, const GUID *guid);
*/
void qof_collection_insert_entity (QofCollection *, QofEntity *);
/* reset value of dirty flag */
void qof_collection_mark_clean (QofCollection *);
void qof_collection_mark_dirty (QofCollection *);
#endif /* QOF_ID_P_H */

View File

@ -39,10 +39,11 @@ static short module = MOD_ENGINE;
struct QofCollection_s
{
QofIdType e_type;
gboolean is_dirty;
QofIdType e_type;
gboolean is_dirty;
GHashTable * hash_of_entities;
gpointer data; /* place where object class can hang arbitrari data */
};
/* =============================================================== */
@ -152,6 +153,7 @@ qof_collection_new (QofIdType type)
col = g_new0(QofCollection, 1);
col->e_type = CACHE_INSERT (type);
col->hash_of_entities = g_hash_table_new (id_hash, id_compare);
col->data = NULL;
return col;
}
@ -162,6 +164,7 @@ qof_collection_destroy (QofCollection *col)
g_hash_table_destroy(col->hash_of_entities);
col->e_type = NULL;
col->hash_of_entities = NULL;
col->data = NULL; /** XXX there should be a destroy notifier for this */
g_free (col);
}
@ -207,6 +210,45 @@ qof_collection_lookup_entity (QofCollection *col, const GUID * guid)
/* =============================================================== */
gboolean
qof_collection_is_dirty (QofCollection *col)
{
if (!col) return FALSE;
return col->is_dirty;
}
void
qof_collection_mark_clean (QofCollection *col)
{
if (!col) return;
col->is_dirty = FALSE;
}
void
qof_collection_mark_dirty (QofCollection *col)
{
if (!col) return;
col->is_dirty = TRUE;
}
/* =============================================================== */
gpointer
qof_collection_get_data (QofCollection *col)
{
if (!col) return NULL;
return col->data;
}
void
qof_collection_set_data (QofCollection *col, gpointer user_data)
{
if (!col) return;
col->data = user_data;
}
/* =============================================================== */
struct _iterate {
QofEntityForeachCB fcn;
gpointer data;

View File

@ -52,6 +52,7 @@
* type of the identifier.
*/
#include <string.h>
#include "guid.h"
typedef const char * QofIdType;
@ -65,6 +66,37 @@ typedef const char * QofIdTypeConst;
/* simple,cheesy cast but holds water for now */
#define QOF_ENTITY(object) ((QofEntity *)(object))
/* Inline string comparision; compiler will optimize away most of this */
#define QSTRCMP(da,db) ({ \
int val = 0; \
if ((da) && (db)) { \
if ((da) != (db)) { \
val = strcmp ((da), (db)); \
} \
} else \
if ((!(da)) && (db)) { \
val = -1; \
} else \
if ((da) && (!(db))) { \
val = 1; \
} \
val; /* block assumes value of last statment */ \
})
/** return TRUE if object is of the given type */
#define QOF_CHECK_TYPE(obj,type) (0 == QSTRCMP((type),(((QofEntity *)(obj))->e_type)))
/** cast object to the indicated type, print error message if its bad */
#define QOF_CHECK_CAST(obj,e_type,c_type) ( \
QOF_CHECK_TYPE((obj),(e_type)) ? \
(c_type *) (obj) : \
(c_type *) ({ \
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, \
"Error: Bad QofEntity at %s:%d", __FILE__, __LINE__); \
(obj); \
}))
typedef struct QofEntity_s QofEntity;
typedef struct QofCollection_s QofCollection;
@ -102,6 +134,12 @@ typedef void (*QofEntityForeachCB) (QofEntity *, gpointer user_data);
void qof_collection_foreach (QofCollection *,
QofEntityForeachCB, gpointer user_data);
/** store and retreive arbitrary object-defined data */
gpointer qof_collection_get_data (QofCollection *col);
void qof_collection_set_data (QofCollection *col, gpointer user_data);
/* Return value of 'dirty' flag on collection */
gboolean qof_collection_is_dirty (QofCollection *col);
#endif /* QOF_ID_H */

View File

@ -75,29 +75,40 @@ void qof_object_book_end (QofBook *book)
LEAVE (" ");
}
gboolean qof_object_is_dirty (QofBook *book)
gboolean
qof_object_is_dirty (QofBook *book)
{
GList *l;
if (!book) return FALSE;
for (l = object_modules; l; l = l->next) {
for (l = object_modules; l; l = l->next)
{
QofObject *obj = l->data;
if (obj->is_dirty)
if (obj->is_dirty (book))
return TRUE;
{
QofCollection *col;
col = qof_book_get_collection (book, obj->e_type);
if (obj->is_dirty (col)) return TRUE;
}
}
return FALSE;
}
void qof_object_mark_clean (QofBook *book)
void
qof_object_mark_clean (QofBook *book)
{
GList *l;
if (!book) return;
for (l = object_modules; l; l = l->next) {
for (l = object_modules; l; l = l->next)
{
QofObject *obj = l->data;
if (obj->mark_clean)
(obj->mark_clean) (book);
{
QofCollection *col;
col = qof_book_get_collection (book, obj->e_type);
(obj->mark_clean) (col);
}
}
}
@ -113,21 +124,25 @@ void qof_object_foreach_type (QofForeachTypeCB cb, gpointer user_data)
}
}
void qof_object_foreach (QofIdTypeConst type_name, QofBook *book,
QofForeachCB cb, gpointer user_data)
void
qof_object_foreach (QofIdTypeConst type_name, QofBook *book,
QofEntityForeachCB cb, gpointer user_data)
{
QofCollection *col;
const QofObject *obj;
if (!book || !type_name) return;
ENTER ("type=%s", type_name);
obj = qof_object_lookup (type_name);
col = qof_book_get_collection (book, obj->e_type);
PINFO ("lookup obj=%p for type=%s", obj, type_name);
if (!obj) return;
PINFO ("type=%s foreach=%p", type_name, obj->foreach);
if (obj->foreach) {
obj->foreach (book, cb, user_data);
if (obj->foreach)
{
obj->foreach (col, cb, user_data);
}
LEAVE ("type=%s", type_name);

View File

@ -31,6 +31,7 @@
#define QOF_OBJECT_H_
#include "qofbook.h"
#include "qofid.h"
/* Defines the version of the core object object registration
* interface. Only object modules compiled against this version
@ -46,7 +47,10 @@ typedef void (*QofForeachBackendTypeCB) (QofIdTypeConst type,
gpointer backend_data,
gpointer user_data);
/** This is the QofObject Class descriptor */
/** This is the QofObject Class descriptor
*
* XXX Hmm, should we add an object factory to this?
*/
struct _QofObject
{
gint interface_version; /* of this object interface */
@ -62,15 +66,15 @@ struct _QofObject
void (*book_end)(QofBook *);
/* Determine if there are any dirty items in this book */
gboolean (*is_dirty)(QofBook *);
gboolean (*is_dirty)(QofCollection *);
/* Mark this object's book clean (for after a load) */
void (*mark_clean)(QofBook *);
void (*mark_clean)(QofCollection *);
/* foreach() is used to execute a callback over each object
* stored in the particular book
*/
void (*foreach)(QofBook *, QofForeachCB, gpointer);
void (*foreach)(QofCollection *, QofEntityForeachCB, gpointer);
/* Given a particular object, return a printable string */
/* Argument should really be QofInstance not gpointer.. */
@ -87,7 +91,7 @@ void qof_object_shutdown (void);
void qof_object_foreach_type (QofForeachTypeCB cb, gpointer user_data);
void qof_object_foreach (QofIdTypeConst type_name, QofBook *book,
QofForeachCB cb, gpointer user_data);
QofEntityForeachCB cb, gpointer user_data);
const char * qof_object_printable (QofIdTypeConst type_name, gpointer obj);

View File

@ -743,7 +743,7 @@ GList * qof_query_run (QofQuery *q)
}
/* and then iterate over all the objects */
qof_object_foreach (q->search_for, book, check_item_cb, &qcb);
qof_object_foreach (q->search_for, book, (QofEntityForeachCB) check_item_cb, &qcb);
}
matching_objects = qcb.list;

View File

@ -3,10 +3,10 @@
#include "gnc-engine-util.h"
#include "gnc-book.h"
#include "gnc-commodity.h"
#include "gnc-engine.h"
#include "gnc-module.h"
#include "qofbook.h"
#include "test-engine-stuff.h"
#include "test-stuff.h"
@ -108,7 +108,7 @@ test_commodity(void)
gnc_commodity *coms[20];
QofBook *book;
book = gnc_book_new ();
book = qof_book_new ();
tbl = gnc_commodity_table_new ();
do_test(gnc_commodity_table_get_size(tbl) == 0,

View File

@ -15,542 +15,542 @@
#include "FreqSpec.h"
#include "gnc-engine.h"
#include "gnc-module.h"
#include "gnc-book.h"
#include "qofbook.h"
static QofBook *book;
static void
test_once (void)
{
FreqSpec *fs;
guint32 i, start_julian;
GDate date1, date2, next_date;
FreqSpec *fs;
guint32 i, start_julian;
GDate date1, date2, next_date;
fs = xaccFreqSpecMalloc(book);
fs = xaccFreqSpecMalloc(book);
for( start_julian = 1; start_julian < 1000; ++start_julian ) {
g_date_set_julian( &date1, start_julian );
for( start_julian = 1; start_julian < 1000; ++start_julian ) {
g_date_set_julian( &date1, start_julian );
xaccFreqSpecSetOnceDate( fs, &date1 );
for( i = 0; i <= 2 * start_julian; ++i ) {
g_date_set_julian( &date2, start_julian + i );
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
do_test( (g_date_compare( &date2, &date1 ) >= 0 &&
!g_date_valid( &next_date ) ) ||
g_date_compare( &date1, &next_date ) == 0,
"once off" );
}
}
xaccFreqSpecSetOnceDate( fs, &date1 );
for( i = 0; i <= 2 * start_julian; ++i ) {
g_date_set_julian( &date2, start_julian + i );
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
do_test( (g_date_compare( &date2, &date1 ) >= 0 &&
!g_date_valid( &next_date ) ) ||
g_date_compare( &date1, &next_date ) == 0,
"once off" );
}
}
xaccFreqSpecFree(fs);
xaccFreqSpecFree(fs);
}
static void
test_daily (void)
{
guint32 interval, i, start_julian, j;
FreqSpec *fs;
GDate date1, date2, next_date;
guint32 interval, i, start_julian, j;
FreqSpec *fs;
GDate date1, date2, next_date;
fs = xaccFreqSpecMalloc(book);
fs = xaccFreqSpecMalloc(book);
g_date_set_dmy( &date1, 1, 1, 2000 );
g_date_set_dmy( &date1, 1, 1, 2000 );
start_julian = g_date_julian( &date1 );
for( interval = 1; interval < 400; ++interval ) {
xaccFreqSpecSetDaily( fs, &date1, interval );
for( i = 0; i <= 2 * interval; ++i ) {
g_date_set_julian( &date2, start_julian + i );
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
do_test_args(
g_date_julian( &next_date ) - g_date_julian( &date2 ) ==
interval - (i%interval),
"daily repeats",
__FILE__, __LINE__,
"interval = %d days, days from start = %d",
interval, i );
}
}
start_julian = g_date_julian( &date1 );
for( interval = 1; interval < 400; ++interval ) {
xaccFreqSpecSetDaily( fs, &date1, interval );
for( i = 0; i <= 2 * interval; ++i ) {
g_date_set_julian( &date2, start_julian + i );
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
do_test_args(
g_date_julian( &next_date ) - g_date_julian( &date2 ) ==
interval - (i%interval),
"daily repeats",
__FILE__, __LINE__,
"interval = %d days, days from start = %d",
interval, i );
}
}
/* This tests whether we can correctly generate a sequence of dates,
* and end up in the right place. */
g_date_set_dmy( &date1, 25, 3, 2001 );
for( interval = 1; interval < 20; ++interval ) {
xaccFreqSpecSetDaily( fs, &date1, interval );
for( j = 0; j < 20; ++j ) {
date2 = date1;
for( i = 0; i < j; ++i ) {
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
date2 = next_date;
}
do_test_args( g_date_julian( &date2 ) - g_date_julian( &date1 ) == interval*j,
"daily repeats end up in the right place",
__FILE__, __LINE__, "interval = %d days, iters = %d",
interval, j );
}
}
/* This tests whether we can correctly generate a sequence of dates,
* and end up in the right place. */
g_date_set_dmy( &date1, 25, 3, 2001 );
for( interval = 1; interval < 20; ++interval ) {
xaccFreqSpecSetDaily( fs, &date1, interval );
for( j = 0; j < 20; ++j ) {
date2 = date1;
for( i = 0; i < j; ++i ) {
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
date2 = next_date;
}
do_test_args( g_date_julian( &date2 ) - g_date_julian( &date1 ) == interval*j,
"daily repeats end up in the right place",
__FILE__, __LINE__, "interval = %d days, iters = %d",
interval, j );
}
}
xaccFreqSpecFree(fs);
xaccFreqSpecFree(fs);
}
static void
test_weekly (void)
{
guint32 interval, i, start_julian, weekday, j;
FreqSpec *fs;
GDate date1, date2, next_date;
guint32 interval, i, start_julian, weekday, j;
FreqSpec *fs;
GDate date1, date2, next_date;
fs = xaccFreqSpecMalloc(book);
fs = xaccFreqSpecMalloc(book);
/* Use this to test any specific cases which fail,
* for easy access in the debugger. */
/* Use this to test any specific cases which fail,
* for easy access in the debugger. */
/*
g_date_set_dmy( &date1, 2, 1, 1 );
xaccFreqSpecSetWeekly( fs, &date1, 1 );
start_julian = g_date_julian( &date1 );
g_date_set_julian( &date2, start_julian + 6 );
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
g_date_set_dmy( &date1, 2, 1, 1 );
xaccFreqSpecSetWeekly( fs, &date1, 1 );
start_julian = g_date_julian( &date1 );
g_date_set_julian( &date2, start_julian + 6 );
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
*/
/* date2 should now be 9/1/1, julian date 9. */
/* date2 should now be 9/1/1, julian date 9. */
for( weekday = 1; weekday <= 7; ++weekday ) {
g_date_set_dmy( &date1, weekday, 1, 1 );
start_julian = g_date_julian( &date1 );
for( interval = 1; interval <= 52; ++interval ) {
xaccFreqSpecSetWeekly( fs, &date1, interval );
for( i = 0; i <= 2 * 7 * interval; ++i ) {
g_date_set_julian( &date2, start_julian + i );
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
do_test_args(
g_date_julian( &next_date ) - g_date_julian( &date2 ) ==
interval*7 - (i%(interval*7)),
"weekly repeats",
__FILE__, __LINE__,
"weekday = %d, interval = %d weeks, days from start = %d",
weekday, interval, i );
}
}
}
for( weekday = 1; weekday <= 7; ++weekday ) {
g_date_set_dmy( &date1, weekday, 1, 1 );
start_julian = g_date_julian( &date1 );
for( interval = 1; interval <= 52; ++interval ) {
xaccFreqSpecSetWeekly( fs, &date1, interval );
for( i = 0; i <= 2 * 7 * interval; ++i ) {
g_date_set_julian( &date2, start_julian + i );
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
do_test_args(
g_date_julian( &next_date ) - g_date_julian( &date2 ) ==
interval*7 - (i%(interval*7)),
"weekly repeats",
__FILE__, __LINE__,
"weekday = %d, interval = %d weeks, days from start = %d",
weekday, interval, i );
}
}
}
/* This tests whether we can correctly generate a sequence of dates,
* and end up in the right place. */
g_date_set_dmy( &date1, 25, 3, 2001 );
for( interval = 1; interval < 20; ++interval ) {
xaccFreqSpecSetWeekly( fs, &date1, interval );
for( j = 0; j < 2*53; ++j ) {
date2 = date1;
for( i = 0; i < j; ++i ) {
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
date2 = next_date;
}
do_test_args( g_date_julian( &date2 ) - g_date_julian( &date1 ) == interval*7*j,
"weekly repeats end up in the right place",
__FILE__, __LINE__, "interval = %d weeks, iters = %d",
interval, j );
}
}
/* This tests whether we can correctly generate a sequence of dates,
* and end up in the right place. */
g_date_set_dmy( &date1, 25, 3, 2001 );
for( interval = 1; interval < 20; ++interval ) {
xaccFreqSpecSetWeekly( fs, &date1, interval );
for( j = 0; j < 2*53; ++j ) {
date2 = date1;
for( i = 0; i < j; ++i ) {
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
date2 = next_date;
}
do_test_args( g_date_julian( &date2 ) - g_date_julian( &date1 ) == interval*7*j,
"weekly repeats end up in the right place",
__FILE__, __LINE__, "interval = %d weeks, iters = %d",
interval, j );
}
}
xaccFreqSpecFree(fs);
xaccFreqSpecFree(fs);
}
static void
test_monthly (void)
{
guint32 interval, i, start_julian, monthday, month, j, day_of_year;
FreqSpec *fs;
GDate date0, date1, date2, next_date;
guint32 interval, i, start_julian, monthday, month, j, day_of_year;
FreqSpec *fs;
GDate date0, date1, date2, next_date;
fs = xaccFreqSpecMalloc(book);
fs = xaccFreqSpecMalloc(book);
/* Use this to test any specific cases which fail,
* for easy access in the debugger. */
/* Use this to test any specific cases which fail,
* for easy access in the debugger. */
/*
g_date_set_dmy( &date1, 1, 1, 1 );
xaccFreqSpecSetMonthly( fs, &date1, 2 );
start_julian = g_date_julian( &date1 );
g_date_set_julian( &date2, start_julian + 0 );
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
g_date_set_dmy( &date1, 1, 1, 1 );
xaccFreqSpecSetMonthly( fs, &date1, 2 );
start_julian = g_date_julian( &date1 );
g_date_set_julian( &date2, start_julian + 0 );
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
*/
for( monthday = 1; monthday <= 28; ++monthday ) {
for( month = 1; month <= 12; ++month ) {
g_date_set_dmy( &date1, monthday, month, 1 );
start_julian = g_date_julian( &date1 );
for( interval = 1; interval <= 24; ++interval ) {
xaccFreqSpecSetMonthly( fs, &date1, interval );
for( i = 0; i <= 2 * 31 * interval; ++i ) {
g_date_set_julian( &date2, start_julian + i );
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
do_test_args(
g_date_day( &next_date ) == g_date_day( &date1 ),
"monthly repeats - check day",
__FILE__, __LINE__,
"monthday = %d, month = %d, interval = %d months, days from start = %d",
monthday, month, interval, i );
do_test_args(
( g_date_month( &next_date ) + 12 * (g_date_year( &next_date )-1) - 1) %
interval == (month-1) % interval,
"monthly repeats - check month",
__FILE__, __LINE__,
"monthday = %d, month = %d, interval = %d months, days from start = %d",
monthday, month, interval, i );
}
}
}
}
for( monthday = 1; monthday <= 28; ++monthday ) {
for( month = 1; month <= 12; ++month ) {
g_date_set_dmy( &date1, monthday, month, 1 );
start_julian = g_date_julian( &date1 );
for( interval = 1; interval <= 24; ++interval ) {
xaccFreqSpecSetMonthly( fs, &date1, interval );
for( i = 0; i <= 2 * 31 * interval; ++i ) {
g_date_set_julian( &date2, start_julian + i );
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
do_test_args(
g_date_day( &next_date ) == g_date_day( &date1 ),
"monthly repeats - check day",
__FILE__, __LINE__,
"monthday = %d, month = %d, interval = %d months, days from start = %d",
monthday, month, interval, i );
do_test_args(
( g_date_month( &next_date ) + 12 * (g_date_year( &next_date )-1) - 1) %
interval == (month-1) % interval,
"monthly repeats - check month",
__FILE__, __LINE__,
"monthday = %d, month = %d, interval = %d months, days from start = %d",
monthday, month, interval, i );
}
}
}
}
/* This tests whether we can correctly generate a sequence of dates,
* and end up in the right place. */
g_date_set_dmy( &date0, 1, 1, 2000 );
for( day_of_year = 1; day_of_year <= 365*5; ++day_of_year ) {
g_date_set_julian( &date1, g_date_julian( &date0 ) + day_of_year-1 );
for( interval = 1; interval < 20; ++interval ) {
xaccFreqSpecSetMonthly( fs, &date1, interval );
for( j = 1; j < 20; ++j ) {
date2 = date1;
for( i = 0; i < j; ++i ) {
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
date2 = next_date;
}
date2 = date1;
g_date_add_months( &date2, interval * j );
do_test_args( g_date_compare( &date2, &next_date ) == 0,
"monthly repeats end up in the right place",
__FILE__, __LINE__, "interval = %d months, iters = %d, day_of_year = %d",
interval, j, day_of_year );
}
}
}
/* This tests whether we can correctly generate a sequence of dates,
* and end up in the right place. */
g_date_set_dmy( &date0, 1, 1, 2000 );
for( day_of_year = 1; day_of_year <= 365*5; ++day_of_year ) {
g_date_set_julian( &date1, g_date_julian( &date0 ) + day_of_year-1 );
for( interval = 1; interval < 20; ++interval ) {
xaccFreqSpecSetMonthly( fs, &date1, interval );
for( j = 1; j < 20; ++j ) {
date2 = date1;
for( i = 0; i < j; ++i ) {
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
date2 = next_date;
}
date2 = date1;
g_date_add_months( &date2, interval * j );
do_test_args( g_date_compare( &date2, &next_date ) == 0,
"monthly repeats end up in the right place",
__FILE__, __LINE__, "interval = %d months, iters = %d, day_of_year = %d",
interval, j, day_of_year );
}
}
}
xaccFreqSpecFree(fs);
xaccFreqSpecFree(fs);
}
static void
test_month_relative (void)
{
guint32 interval, i, start_julian, monthday, month, j;
FreqSpec *fs;
GDate date0, date1, date2, next_date;
guint32 interval, i, start_julian, monthday, month, j;
FreqSpec *fs;
GDate date0, date1, date2, next_date;
fs = xaccFreqSpecMalloc(book);
fs = xaccFreqSpecMalloc(book);
/* Use this to test any specific cases which fail,
* for easy access in the debugger. */
/* Use this to test any specific cases which fail,
* for easy access in the debugger. */
/*
g_date_set_dmy( &date1, 1, 1, 1 );
xaccFreqSpecSetMonthRelative( fs, &date1, 2 );
start_julian = g_date_julian( &date1 );
g_date_set_julian( &date2, start_julian + 0 );
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
g_date_set_dmy( &date1, 1, 1, 1 );
xaccFreqSpecSetMonthRelative( fs, &date1, 2 );
start_julian = g_date_julian( &date1 );
g_date_set_julian( &date2, start_julian + 0 );
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
*/
/* This loop does not test for days/occurences which can
* fail to fall in the same month. */
for( monthday = 1; monthday <= 28; ++monthday ) {
for( month = 1; month <= 12; ++month ) {
g_date_set_dmy( &date1, monthday, month, 1 );
start_julian = g_date_julian( &date1 );
for( interval = 1; interval <= 24; ++interval ) {
xaccFreqSpecSetMonthRelative( fs, &date1, interval );
for( i = 0; i <= 2 * 31 * interval; ++i ) {
g_date_set_julian( &date2, start_julian + i );
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
do_test_args(
g_date_weekday( &next_date ) == g_date_weekday( &date1 ),
"month relative repeats - check weekday",
__FILE__, __LINE__,
"monthday = %d, month = %d, interval = %d months, days from start = %d, weekday = %d",
monthday, month, interval, i, g_date_weekday( &date1 ) );
do_test_args(
(g_date_day( &next_date )-1)/7 == (g_date_day( &date1 )-1)/7,
"month relative repeats - check occurrence",
__FILE__, __LINE__,
"monthday = %d, month = %d, interval = %d months, days from start = %d, occurrence = %d",
monthday, month, interval, i, (g_date_day( &date1 )-1)/7 );
do_test_args(
( g_date_month( &next_date ) + 12 * (g_date_year( &next_date )-1) - 1) %
interval == (month-1) % interval,
"month relative repeats - check month",
__FILE__, __LINE__,
"monthday = %d, month = %d, interval = %d months, days from start = %d",
monthday, month, interval, i );
}
}
}
}
/* This loop does not test for days/occurences which can
* fail to fall in the same month. */
for( monthday = 1; monthday <= 28; ++monthday ) {
for( month = 1; month <= 12; ++month ) {
g_date_set_dmy( &date1, monthday, month, 1 );
start_julian = g_date_julian( &date1 );
for( interval = 1; interval <= 24; ++interval ) {
xaccFreqSpecSetMonthRelative( fs, &date1, interval );
for( i = 0; i <= 2 * 31 * interval; ++i ) {
g_date_set_julian( &date2, start_julian + i );
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
do_test_args(
g_date_weekday( &next_date ) == g_date_weekday( &date1 ),
"month relative repeats - check weekday",
__FILE__, __LINE__,
"monthday = %d, month = %d, interval = %d months, days from start = %d, weekday = %d",
monthday, month, interval, i, g_date_weekday( &date1 ) );
do_test_args(
(g_date_day( &next_date )-1)/7 == (g_date_day( &date1 )-1)/7,
"month relative repeats - check occurrence",
__FILE__, __LINE__,
"monthday = %d, month = %d, interval = %d months, days from start = %d, occurrence = %d",
monthday, month, interval, i, (g_date_day( &date1 )-1)/7 );
do_test_args(
( g_date_month( &next_date ) + 12 * (g_date_year( &next_date )-1) - 1) %
interval == (month-1) % interval,
"month relative repeats - check month",
__FILE__, __LINE__,
"monthday = %d, month = %d, interval = %d months, days from start = %d",
monthday, month, interval, i );
}
}
}
}
/* This tests whether we can correctly generate a sequence of dates,
* and end up in the right place. */
/* Unfortunately, I think that this is going to require specifically
* written test cases, for the case where the repeat falls in the next
* (or subsequent) month in the cycle.... */
g_date_set_dmy( &date1, 1, 1, 2000 );
for( interval = 1; interval < 20; ++interval ) {
xaccFreqSpecSetMonthRelative( fs, &date1, interval );
for( j = 1; j < 20; ++j ) {
date2 = date1;
for( i = 0; i < j; ++i ) {
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
date2 = next_date;
}
date2 = date1;
g_date_add_months( &date2, interval * j );
do_test_args( g_date_month( &date2 ) == g_date_month( &next_date ),
"month_relative repeats end up in the right place - month",
__FILE__, __LINE__, "interval = %d months, iters = %d, weekday = %d",
interval, j, g_date_weekday( &date1 ) );
do_test_args( g_date_weekday( &date1 ) == g_date_weekday( &next_date ),
"month_relative repeats end up in the right place - weekday",
__FILE__, __LINE__, "interval = %d months, iters = %d, weekday = %d",
interval, j, g_date_weekday( &date1 ) );
do_test_args( (g_date_day( &date2 )-1)/7 == (g_date_day( &next_date )-1)/7,
"month_relative repeats end up in the right place - occurrence",
__FILE__, __LINE__, "interval = %d months, iters = %d, weekday = %d",
interval, j, g_date_weekday( &date1 ) );
}
}
/* also test oddball cases */
/* This is the fifth Sunday of a five Sunday month. */
g_date_set_dmy( &date0, 29, 4, 2001 );
xaccFreqSpecSetMonthRelative( fs, &date0, 1 );
xaccFreqSpecGetNextInstance( fs, &date0, &next_date );
g_date_set_dmy( &date1, 29, 7, 2001 );
do_test( g_date_compare( &next_date, &date1 ) == 0, "find five-sunday months" );
date2 = next_date;
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
g_date_set_dmy( &date1, 30, 9, 2001 );
do_test( g_date_compare( &next_date, &date1 ) == 0, "find five-sunday months" );
date2 = next_date;
/* This tests whether we can correctly generate a sequence of dates,
* and end up in the right place. */
/* Unfortunately, I think that this is going to require specifically
* written test cases, for the case where the repeat falls in the next
* (or subsequent) month in the cycle.... */
g_date_set_dmy( &date1, 1, 1, 2000 );
for( interval = 1; interval < 20; ++interval ) {
xaccFreqSpecSetMonthRelative( fs, &date1, interval );
for( j = 1; j < 20; ++j ) {
date2 = date1;
for( i = 0; i < j; ++i ) {
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
date2 = next_date;
}
date2 = date1;
g_date_add_months( &date2, interval * j );
do_test_args( g_date_month( &date2 ) == g_date_month( &next_date ),
"month_relative repeats end up in the right place - month",
__FILE__, __LINE__, "interval = %d months, iters = %d, weekday = %d",
interval, j, g_date_weekday( &date1 ) );
do_test_args( g_date_weekday( &date1 ) == g_date_weekday( &next_date ),
"month_relative repeats end up in the right place - weekday",
__FILE__, __LINE__, "interval = %d months, iters = %d, weekday = %d",
interval, j, g_date_weekday( &date1 ) );
do_test_args( (g_date_day( &date2 )-1)/7 == (g_date_day( &next_date )-1)/7,
"month_relative repeats end up in the right place - occurrence",
__FILE__, __LINE__, "interval = %d months, iters = %d, weekday = %d",
interval, j, g_date_weekday( &date1 ) );
}
}
/* also test oddball cases */
/* This is the fifth Sunday of a five Sunday month. */
g_date_set_dmy( &date0, 29, 4, 2001 );
xaccFreqSpecSetMonthRelative( fs, &date0, 1 );
xaccFreqSpecGetNextInstance( fs, &date0, &next_date );
g_date_set_dmy( &date1, 29, 7, 2001 );
do_test( g_date_compare( &next_date, &date1 ) == 0, "find five-sunday months" );
date2 = next_date;
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
g_date_set_dmy( &date1, 30, 9, 2001 );
do_test( g_date_compare( &next_date, &date1 ) == 0, "find five-sunday months" );
date2 = next_date;
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
g_date_set_dmy( &date1, 30, 12, 2001 );
do_test( g_date_compare( &next_date, &date1 ) == 0, "find five-sunday months" );
date2 = next_date;
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
g_date_set_dmy( &date1, 31, 3, 2002 );
do_test( g_date_compare( &next_date, &date1 ) == 0, "find five-sunday months" );
date2 = next_date;
xaccFreqSpecFree(fs);
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
g_date_set_dmy( &date1, 30, 12, 2001 );
do_test( g_date_compare( &next_date, &date1 ) == 0, "find five-sunday months" );
date2 = next_date;
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
g_date_set_dmy( &date1, 31, 3, 2002 );
do_test( g_date_compare( &next_date, &date1 ) == 0, "find five-sunday months" );
date2 = next_date;
xaccFreqSpecFree(fs);
}
static void
test_composite (void)
{
FreqSpec *fs, *fs2;
GDate date0, date1, date2;
FreqSpec *fs, *fs2;
GDate date0, date1, date2;
fs = xaccFreqSpecMalloc(book);
fs = xaccFreqSpecMalloc(book);
/* Use this to test any specific cases which fail,
* for easy access in the debugger. */
/* Use this to test any specific cases which fail,
* for easy access in the debugger. */
/*
g_date_set_dmy( &date1, 1, 1, 1 );
xaccFreqSpecSetMonthly( fs, &date1, 2 );
start_julian = g_date_julian( &date1 );
g_date_set_julian( &date2, start_julian + 0 );
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
g_date_set_dmy( &date1, 1, 1, 1 );
xaccFreqSpecSetMonthly( fs, &date1, 2 );
start_julian = g_date_julian( &date1 );
g_date_set_julian( &date2, start_julian + 0 );
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
*/
/* I have not tested this type as thoroughly
* because I expect that the elements from which it
* has been constructed have been pretty much tortured
* in the previous tests. I don't expect anything strange
* to go on here, at least for now... Maybe I'll put
* in more extensive tests later. */
xaccFreqSpecSetComposite( fs );
/* I have not tested this type as thoroughly
* because I expect that the elements from which it
* has been constructed have been pretty much tortured
* in the previous tests. I don't expect anything strange
* to go on here, at least for now... Maybe I'll put
* in more extensive tests later. */
xaccFreqSpecSetComposite( fs );
fs2 = xaccFreqSpecMalloc(book);
g_date_set_dmy( &date0, 29, 3, 2001 ); /* Wednesday */
xaccFreqSpecSetWeekly( fs2, &date0, 2 );
xaccFreqSpecCompositeAdd( fs, fs2 );
fs2 = xaccFreqSpecMalloc(book);
g_date_set_dmy( &date0, 3, 4, 2001 ); /* Tuesday */
xaccFreqSpecSetWeekly( fs2, &date0, 2 );
xaccFreqSpecCompositeAdd( fs, fs2 );
fs2 = xaccFreqSpecMalloc(book);
g_date_set_dmy( &date0, 7, 4, 2001 ); /* Saturday */
xaccFreqSpecSetWeekly( fs2, &date0, 2 );
xaccFreqSpecCompositeAdd( fs, fs2 );
fs2 = 0;
fs2 = xaccFreqSpecMalloc(book);
g_date_set_dmy( &date0, 29, 3, 2001 ); /* Wednesday */
xaccFreqSpecSetWeekly( fs2, &date0, 2 );
xaccFreqSpecCompositeAdd( fs, fs2 );
fs2 = xaccFreqSpecMalloc(book);
g_date_set_dmy( &date0, 3, 4, 2001 ); /* Tuesday */
xaccFreqSpecSetWeekly( fs2, &date0, 2 );
xaccFreqSpecCompositeAdd( fs, fs2 );
fs2 = xaccFreqSpecMalloc(book);
g_date_set_dmy( &date0, 7, 4, 2001 ); /* Saturday */
xaccFreqSpecSetWeekly( fs2, &date0, 2 );
xaccFreqSpecCompositeAdd( fs, fs2 );
fs2 = 0;
/* OK - now let's iterate it and see if we get the right sequence of dates. */
g_date_set_dmy( &date0, 26, 3, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 29, 3, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0,
/* OK - now let's iterate it and see if we get the right sequence of dates. */
g_date_set_dmy( &date0, 26, 3, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 29, 3, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0,
"first date in sequence" );
g_date_set_dmy( &date0, 27, 3, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 29, 3, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0,
g_date_set_dmy( &date0, 27, 3, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 29, 3, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0,
"first date in sequence" );
g_date_set_dmy( &date0, 28, 3, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 29, 3, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "first date in sequence" );
g_date_set_dmy( &date0, 29, 3, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 3, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "second date in sequence" );
g_date_set_dmy( &date0, 28, 3, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 29, 3, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "first date in sequence" );
g_date_set_dmy( &date0, 29, 3, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 3, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "second date in sequence" );
g_date_set_dmy( &date0, 30, 3, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 3, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "second date in sequence" );
g_date_set_dmy( &date0, 30, 3, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 3, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "second date in sequence" );
g_date_set_dmy( &date0, 31, 3, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 3, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "second date in sequence" );
g_date_set_dmy( &date0, 31, 3, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 3, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "second date in sequence" );
g_date_set_dmy( &date0, 1, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 3, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "second date in sequence" );
g_date_set_dmy( &date0, 1, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 3, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "second date in sequence" );
g_date_set_dmy( &date0, 2, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 3, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "second date in sequence" );
g_date_set_dmy( &date0, 2, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 3, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "second date in sequence" );
g_date_set_dmy( &date0, 3, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 7, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "third date in sequence" );
g_date_set_dmy( &date0, 3, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 7, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "third date in sequence" );
g_date_set_dmy( &date0, 4, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 7, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "third date in sequence" );
g_date_set_dmy( &date0, 4, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 7, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "third date in sequence" );
g_date_set_dmy( &date0, 5, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 7, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "third date in sequence" );
g_date_set_dmy( &date0, 5, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 7, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "third date in sequence" );
g_date_set_dmy( &date0, 6, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 7, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "third date in sequence" );
g_date_set_dmy( &date0, 6, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 7, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "third date in sequence" );
g_date_set_dmy( &date0, 7, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 12, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "fourth date in sequence" );
g_date_set_dmy( &date0, 7, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 12, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "fourth date in sequence" );
g_date_set_dmy( &date0, 8, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 12, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "fourth date in sequence" );
g_date_set_dmy( &date0, 8, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 12, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "fourth date in sequence" );
g_date_set_dmy( &date0, 9, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 12, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "fourth date in sequence" );
g_date_set_dmy( &date0, 9, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 12, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "fourth date in sequence" );
g_date_set_dmy( &date0, 10, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 12, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "fourth date in sequence" );
g_date_set_dmy( &date0, 10, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 12, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "fourth date in sequence" );
g_date_set_dmy( &date0, 11, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 12, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "fourth date in sequence" );
g_date_set_dmy( &date0, 11, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 12, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "fourth date in sequence" );
g_date_set_dmy( &date0, 12, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 17, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "fifth date in sequence" );
g_date_set_dmy( &date0, 12, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 17, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "fifth date in sequence" );
g_date_set_dmy( &date0, 13, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 17, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "fifth date in sequence" );
g_date_set_dmy( &date0, 13, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 17, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "fifth date in sequence" );
g_date_set_dmy( &date0, 14, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 17, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "fifth date in sequence" );
g_date_set_dmy( &date0, 14, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 17, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "fifth date in sequence" );
g_date_set_dmy( &date0, 15, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 17, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "fifth date in sequence" );
g_date_set_dmy( &date0, 15, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 17, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "fifth date in sequence" );
g_date_set_dmy( &date0, 16, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 17, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "fifth date in sequence" );
g_date_set_dmy( &date0, 16, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 17, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "fifth date in sequence" );
g_date_set_dmy( &date0, 17, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 21, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "sixth date in sequence" );
g_date_set_dmy( &date0, 17, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 21, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "sixth date in sequence" );
g_date_set_dmy( &date0, 18, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 21, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "sixth date in sequence" );
g_date_set_dmy( &date0, 18, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 21, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "sixth date in sequence" );
g_date_set_dmy( &date0, 19, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 21, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "sixth date in sequence" );
g_date_set_dmy( &date0, 19, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 21, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "sixth date in sequence" );
g_date_set_dmy( &date0, 20, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 21, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "sixth date in sequence" );
g_date_set_dmy( &date0, 20, 4, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 21, 4, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "sixth date in sequence" );
xaccFreqSpecFree(fs);
xaccFreqSpecFree(fs);
}
static void
guile_main ( void *closure, int argc, char* argv[] )
{
gnc_module_load("gnucash/engine", 0);
gnc_module_load("gnucash/engine", 0);
g_log_set_always_fatal( G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING );
g_log_set_always_fatal( G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING );
#if 0
set_success_print(TRUE);
set_success_print(TRUE);
#endif
book = gnc_book_new ();
book = qof_book_new ();
test_once();
test_once();
test_daily();
test_daily();
test_weekly();
test_weekly();
test_monthly();
test_monthly();
test_month_relative();
test_month_relative();
test_composite();
test_composite();
gnc_book_destroy (book);
qof_book_destroy (book);
print_test_results();
exit (get_rv());
print_test_results();
exit (get_rv());
}

View File

@ -6,14 +6,14 @@
#include "gnc-engine-util.h"
#include "messages.h"
#include "qofbook.h"
#include "qofobject.h"
#include "gncObject.h"
#include "test-stuff.h"
#define TEST_MODULE_NAME "object-test"
#define TEST_MODULE_DESC "Test Object"
static void foreach (QofBook *, QofForeachCB, gpointer);
static void obj_foreach (QofCollection *, QofEntityForeachCB, gpointer);
static const char * printable (gpointer obj);
static void test_printable (const char *name, gpointer obj);
static void test_foreach (QofBook *, const char *);
@ -26,7 +26,7 @@ static QofObject bus_obj = {
NULL, /* destroy */
NULL, /* is dirty */
NULL, /* mark_clean */
foreach,
obj_foreach,
printable,
};
@ -34,15 +34,15 @@ static void test_object (void)
{
/* Test the global registration and lookup functions */
{
do_test (!gncObjectRegister (NULL), "register NULL");
do_test (gncObjectRegister (&bus_obj), "register test object");
do_test (!gncObjectRegister (&bus_obj), "register test object again");
do_test (gncObjectLookup (TEST_MODULE_NAME) == &bus_obj,
do_test (!qof_object_register (NULL), "register NULL");
do_test (qof_object_register (&bus_obj), "register test object");
do_test (!qof_object_register (&bus_obj), "register test object again");
do_test (qof_object_lookup (TEST_MODULE_NAME) == &bus_obj,
"lookup our installed object");
do_test (gncObjectLookup ("snm98sn snml say dyikh9y9ha") == NULL,
do_test (qof_object_lookup ("snm98sn snml say dyikh9y9ha") == NULL,
"lookup non-existant object object");
do_test (!safe_strcmp (gncObjectGetTypeLabel (TEST_MODULE_NAME),
do_test (!safe_strcmp (qof_object_get_type_label (TEST_MODULE_NAME),
_(TEST_MODULE_DESC)),
"test description return");
}
@ -52,17 +52,17 @@ static void test_object (void)
}
static void
foreach (QofBook *book, QofForeachCB cb, gpointer u_d)
obj_foreach (QofCollection *col, QofEntityForeachCB cb, gpointer u_d)
{
int *foo = u_d;
do_test (book != NULL, "foreach: NULL object");
do_test (col != NULL, "foreach: NULL collection");
success ("called foreach callback");
*foo = 1;
}
static void foreachCB (gpointer obj, gpointer u_d)
static void foreachCB (QofEntity *ent, gpointer u_d)
{
do_test (FALSE, "FAIL");
}
@ -80,26 +80,26 @@ test_foreach (QofBook *book, const char *name)
{
int res = 0;
gncObjectForeach (NULL, NULL, NULL, &res);
qof_object_foreach (NULL, NULL, NULL, &res);
do_test (res == 0, "object: Foreach: NULL, NULL, NULL");
gncObjectForeach (NULL, NULL, foreachCB, &res);
qof_object_foreach (NULL, NULL, foreachCB, &res);
do_test (res == 0, "object: Foreach: NULL, NULL, foreachCB");
gncObjectForeach (NULL, book, NULL, &res);
qof_object_foreach (NULL, book, NULL, &res);
do_test (res == 0, "object: Foreach: NULL, book, NULL");
gncObjectForeach (NULL, book, foreachCB, &res);
qof_object_foreach (NULL, book, foreachCB, &res);
do_test (res == 0, "object: Foreach: NULL, book, foreachCB");
gncObjectForeach (name, NULL, NULL, &res);
qof_object_foreach (name, NULL, NULL, &res);
do_test (res == 0, "object: Foreach: name, NULL, NULL");
gncObjectForeach (name, NULL, foreachCB, &res);
qof_object_foreach (name, NULL, foreachCB, &res);
do_test (res == 0, "object: Foreach: name, NULL, foreachCB");
gncObjectForeach (name, book, NULL, &res);
qof_object_foreach (name, book, NULL, &res);
do_test (res != 0, "object: Foreach: name, book, NULL");
res = 0;
gncObjectForeach (name, book, foreachCB, &res);
qof_object_foreach (name, book, foreachCB, &res);
do_test (res != 0, "object: Foreach: name, book, foreachCB");
}
@ -108,13 +108,13 @@ test_printable (const char *name, gpointer obj)
{
const char *res;
do_test (gncObjectPrintable (NULL, NULL) == NULL,
do_test (qof_object_printable (NULL, NULL) == NULL,
"object: Printable: NULL, NULL");
do_test (gncObjectPrintable (NULL, obj) == NULL,
do_test (qof_object_printable (NULL, obj) == NULL,
"object: Printable: NULL, object");
do_test (gncObjectPrintable (name, NULL) == NULL,
do_test (qof_object_printable (name, NULL) == NULL,
"object: Printable: mod_name, NULL");
res = gncObjectPrintable (name, obj);
res = qof_object_printable (name, obj);
do_test (res != NULL, "object: Printable: mod_name, object");
}