mirror of
https://github.com/Gnucash/gnucash.git
synced 2026-09-03 20:53:02 -05:00
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:
+2
-14
@@ -2807,19 +2807,7 @@ xaccAccountFindTransByDesc(Account *account, const char *description)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================================ */
|
/* ================================================================ */
|
||||||
/* gncObject function implementation and registration */
|
/* QofObject 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
static QofObject account_object_def = {
|
static QofObject account_object_def = {
|
||||||
interface_version: QOF_OBJECT_VERSION,
|
interface_version: QOF_OBJECT_VERSION,
|
||||||
@@ -2829,7 +2817,7 @@ static QofObject account_object_def = {
|
|||||||
book_end: NULL,
|
book_end: NULL,
|
||||||
is_dirty: NULL,
|
is_dirty: NULL,
|
||||||
mark_clean: NULL,
|
mark_clean: NULL,
|
||||||
foreach: account_foreach,
|
foreach: qof_collection_foreach,
|
||||||
printable: (const char* (*)(gpointer)) xaccAccountGetName
|
printable: (const char* (*)(gpointer)) xaccAccountGetName
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+33
-15
@@ -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 *
|
AccountGroup *
|
||||||
xaccGetAccountGroup (QofBook *book)
|
xaccGetAccountGroup (QofBook *book)
|
||||||
{
|
{
|
||||||
if (!book) return NULL;
|
QofCollection *col;
|
||||||
return qof_book_get_data (book, GNC_TOP_GROUP);
|
if (!book) return NULL;
|
||||||
|
col = qof_book_get_collection (book, GNC_ID_GROUP);
|
||||||
|
return xaccCollGetAccountGroup (col);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
xaccSetAccountGroup (QofBook *book, AccountGroup *grp)
|
xaccSetAccountGroup (QofBook *book, AccountGroup *grp)
|
||||||
{
|
{
|
||||||
AccountGroup *old_grp;
|
QofCollection *col;
|
||||||
if (!book) return;
|
if (!book) return;
|
||||||
|
|
||||||
old_grp = xaccGetAccountGroup (book);
|
|
||||||
if (old_grp == grp) return;
|
|
||||||
|
|
||||||
if (grp && grp->book != book)
|
if (grp && grp->book != book)
|
||||||
{
|
{
|
||||||
PERR ("cannot mix and match books freely!");
|
PERR ("cannot mix and match books freely!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qof_book_set_data (book, GNC_TOP_GROUP, grp);
|
col = qof_book_get_collection (book, GNC_ID_GROUP);
|
||||||
|
xaccCollSetAccountGroup (col, grp);
|
||||||
xaccAccountGroupBeginEdit (old_grp);
|
|
||||||
xaccAccountGroupDestroy (old_grp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************\
|
/********************************************************************\
|
||||||
@@ -1229,15 +1247,15 @@ group_book_end (QofBook *book)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
group_is_dirty (QofBook *book)
|
group_is_dirty (QofCollection *col)
|
||||||
{
|
{
|
||||||
return xaccGroupNotSaved(xaccGetAccountGroup(book));
|
return xaccGroupNotSaved(xaccCollGetAccountGroup(col));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
group_mark_clean(QofBook *book)
|
group_mark_clean(QofCollection *col)
|
||||||
{
|
{
|
||||||
xaccGroupMarkSaved(xaccGetAccountGroup(book));
|
xaccGroupMarkSaved(xaccCollGetAccountGroup(col));
|
||||||
}
|
}
|
||||||
|
|
||||||
static QofObject group_object_def =
|
static QofObject group_object_def =
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ AccountGroup *xaccMallocAccountGroup (QofBook *book);
|
|||||||
* account group associated with the indicated book.
|
* account group associated with the indicated book.
|
||||||
*/
|
*/
|
||||||
AccountGroup * xaccGetAccountGroup (QofBook *book);
|
AccountGroup * xaccGetAccountGroup (QofBook *book);
|
||||||
|
AccountGroup * xaccCollGetAccountGroup (QofCollection *col);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The xaccAccountDestroy() routine will destroy and free all
|
* The xaccAccountDestroy() routine will destroy and free all
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ void xaccFreeAccountGroup (AccountGroup *account_group);
|
|||||||
|
|
||||||
/* Set the top-level group in the book */
|
/* Set the top-level group in the book */
|
||||||
void xaccSetAccountGroup (QofBook *book, AccountGroup *grp);
|
void xaccSetAccountGroup (QofBook *book, AccountGroup *grp);
|
||||||
|
void xaccCollSetAccountGroup (QofCollection *col, AccountGroup *grp);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The xaccGroupGetBackend() subroutine will find the
|
* The xaccGroupGetBackend() subroutine will find the
|
||||||
|
|||||||
@@ -35,19 +35,23 @@
|
|||||||
#define GNC_SX_BOOK_P_H
|
#define GNC_SX_BOOK_P_H
|
||||||
|
|
||||||
#include "qofbook.h"
|
#include "qofbook.h"
|
||||||
|
#include "qofid.h"
|
||||||
|
|
||||||
/* ====================================================================== */
|
/* ====================================================================== */
|
||||||
|
|
||||||
struct xaccSchedXactionsDef {
|
struct xaccSchedXactionsDef {
|
||||||
QofBook *book;
|
|
||||||
GList *sx_list;
|
GList *sx_list;
|
||||||
gboolean sx_notsaved;
|
gboolean sx_notsaved;
|
||||||
};
|
};
|
||||||
|
|
||||||
void gnc_book_set_schedxactions( QofBook *book, GList *newList );
|
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 */
|
/* Associate the given template group with a book */
|
||||||
void gnc_book_set_template_group (QofBook *book, AccountGroup *templateGroup);
|
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);
|
gboolean gnc_sxtt_register (void);
|
||||||
|
|
||||||
|
|||||||
+131
-74
@@ -54,33 +54,133 @@
|
|||||||
|
|
||||||
static short module = MOD_SX;
|
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"
|
AccountGroup *
|
||||||
SchedXactions *
|
gnc_collection_get_template_group( QofCollection *col )
|
||||||
gnc_book_get_schedxaction_list( QofBook *book )
|
|
||||||
{
|
{
|
||||||
if ( book == NULL ) return NULL;
|
return qof_collection_get_data (col);
|
||||||
return qof_book_get_data (book, GNC_SCHEDXACTIONS);
|
}
|
||||||
|
|
||||||
|
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 *
|
GList *
|
||||||
gnc_book_get_schedxactions( QofBook *book )
|
gnc_book_get_schedxactions( QofBook *book )
|
||||||
{
|
{
|
||||||
SchedXactions *list;
|
QofCollection *col;
|
||||||
if ( book == NULL ) return NULL;
|
col = qof_book_get_collection (book, GNC_ID_SXTT);
|
||||||
list = qof_book_get_data (book, GNC_SCHEDXACTIONS);
|
return gnc_collection_get_schedxactions (col);
|
||||||
if (list) return list->sx_list;
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gnc_book_set_schedxactions( QofBook *book, GList *newList )
|
gnc_collection_set_schedxactions( QofCollection *col, GList *newList )
|
||||||
{
|
{
|
||||||
SchedXactions *old_list, *new_list;
|
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)
|
if (old_list && old_list->sx_list == newList)
|
||||||
{
|
{
|
||||||
/* Assume the worst, that any 'set' means the data has
|
/* 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 = g_new (SchedXactions, 1);
|
||||||
new_list->book = book;
|
|
||||||
new_list->sx_list = newList;
|
new_list->sx_list = newList;
|
||||||
new_list->sx_notsaved = TRUE;
|
new_list->sx_notsaved = TRUE;
|
||||||
if (NULL == newList) new_list->sx_notsaved = FALSE;
|
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);
|
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
|
void
|
||||||
gnc_book_set_template_group (QofBook *book, AccountGroup *templateGroup)
|
gnc_book_set_schedxactions( QofBook *book, GList *newList )
|
||||||
{
|
{
|
||||||
AccountGroup *old_grp;
|
QofCollection *col;
|
||||||
if (!book) return;
|
if ( book == NULL ) return;
|
||||||
|
|
||||||
if (templateGroup && templateGroup->book != book)
|
col = qof_book_get_collection (book, GNC_ID_SXTT);
|
||||||
{
|
gnc_collection_set_schedxactions (col, newList);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ====================================================================== */
|
/* ====================================================================== */
|
||||||
/* gncObject function implementation and registration */
|
/* SX-trans stuff */
|
||||||
/* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sxtt_book_begin (QofBook *book)
|
sxtt_book_begin (QofBook *book)
|
||||||
{
|
{
|
||||||
gnc_book_set_schedxactions (book, NULL);
|
gnc_book_set_schedxactions (book, NULL);
|
||||||
gnc_book_set_template_group (book, xaccMallocAccountGroup(book));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sxtt_book_end (QofBook *book)
|
sxtt_book_end (QofBook *book)
|
||||||
{
|
{
|
||||||
gnc_book_set_template_group (book, NULL);
|
|
||||||
gnc_book_set_schedxactions (book, NULL);
|
gnc_book_set_schedxactions (book, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ====================================================================== */
|
|
||||||
/* dirty flag stuff */
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mark_sx_clean(gpointer data, gpointer user_data)
|
mark_sx_clean(gpointer data, gpointer user_data)
|
||||||
{
|
{
|
||||||
@@ -165,33 +231,31 @@ mark_sx_clean(gpointer data, gpointer user_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
book_sxns_mark_saved(QofBook *book)
|
book_sxns_mark_saved(QofCollection *col)
|
||||||
{
|
{
|
||||||
SchedXactions *sxl;
|
SchedXactions *sxl;
|
||||||
|
|
||||||
sxl = gnc_book_get_schedxaction_list (book);
|
sxl = gnc_collection_get_schedxaction_list (col);
|
||||||
if (sxl) sxl->sx_notsaved = FALSE;
|
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,
|
mark_sx_clean,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
book_sxlist_notsaved(QofBook *book)
|
book_sxlist_notsaved(QofCollection *col)
|
||||||
{
|
{
|
||||||
GList *sxlist;
|
GList *sxlist;
|
||||||
SchedXaction *sx;
|
|
||||||
SchedXactions *sxl;
|
SchedXactions *sxl;
|
||||||
|
|
||||||
sxl = gnc_book_get_schedxaction_list (book);
|
sxl = gnc_collection_get_schedxaction_list (col);
|
||||||
if((sxl && sxl->sx_notsaved)
|
if((sxl && sxl->sx_notsaved)) return TRUE;
|
||||||
||
|
|
||||||
xaccGroupNotSaved(gnc_book_get_template_group(book))) return TRUE;
|
|
||||||
|
|
||||||
for(sxlist = gnc_book_get_schedxactions(book);
|
for(sxlist = gnc_collection_get_schedxactions(col);
|
||||||
sxlist != NULL;
|
sxlist != NULL;
|
||||||
sxlist = g_list_next(sxlist))
|
sxlist = g_list_next(sxlist))
|
||||||
{
|
{
|
||||||
|
SchedXaction *sx;
|
||||||
sx = (SchedXaction *) (sxlist->data);
|
sx = (SchedXaction *) (sxlist->data);
|
||||||
if (xaccSchedXactionIsDirty( sx ))
|
if (xaccSchedXactionIsDirty( sx ))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -200,23 +264,15 @@ book_sxlist_notsaved(QofBook *book)
|
|||||||
return FALSE;
|
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 =
|
static QofObject sxtt_object_def =
|
||||||
{
|
{
|
||||||
interface_version: QOF_OBJECT_VERSION,
|
interface_version: QOF_OBJECT_VERSION,
|
||||||
e_type: GNC_ID_SXTT,
|
e_type: GNC_ID_SXTT,
|
||||||
type_label: "SXTT",
|
type_label: "Scheduled Transaction Templates",
|
||||||
book_begin: sxtt_book_begin,
|
book_begin: sxtt_book_begin,
|
||||||
book_end: sxtt_book_end,
|
book_end: sxtt_book_end,
|
||||||
is_dirty: book_sxlist_notsaved,
|
is_dirty: book_sxlist_notsaved,
|
||||||
mark_clean: sxtt_mark_clean,
|
mark_clean: book_sxns_mark_saved,
|
||||||
foreach: NULL,
|
foreach: NULL,
|
||||||
printable: NULL,
|
printable: NULL,
|
||||||
};
|
};
|
||||||
@@ -224,6 +280,7 @@ static QofObject sxtt_object_def =
|
|||||||
gboolean
|
gboolean
|
||||||
gnc_sxtt_register (void)
|
gnc_sxtt_register (void)
|
||||||
{
|
{
|
||||||
|
return qof_object_register (&sxtg_object_def);
|
||||||
return qof_object_register (&sxtt_object_def);
|
return qof_object_register (&sxtt_object_def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,9 @@
|
|||||||
* @brief Anchor Scheduled Transaction info in a book.
|
* @brief Anchor Scheduled Transaction info in a book.
|
||||||
* See src/doc/books.txt for design overview.
|
* See src/doc/books.txt for design overview.
|
||||||
* @author Copyright (c) 2003 Linas Vepstas <linas@linas.org>
|
* @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
|
#ifndef GNC_SX_BOOK_H
|
||||||
@@ -38,15 +41,19 @@
|
|||||||
|
|
||||||
#include "gnc-engine.h"
|
#include "gnc-engine.h"
|
||||||
#include "qofbook.h"
|
#include "qofbook.h"
|
||||||
|
#include "qofid.h"
|
||||||
|
|
||||||
typedef struct xaccSchedXactionsDef SchedXactions;
|
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 );
|
GList * gnc_book_get_schedxactions( QofBook *book );
|
||||||
|
|
||||||
/** Returns the template group from the book.
|
/** Returns the template group from the book.
|
||||||
**/
|
**/
|
||||||
AccountGroup * gnc_book_get_template_group (QofBook *book);
|
AccountGroup * gnc_book_get_template_group (QofBook *book);
|
||||||
|
AccountGroup * gnc_collection_get_template_group( QofCollection *col );
|
||||||
|
|
||||||
|
|
||||||
#endif /* GNC_SX_BOOK_H */
|
#endif /* GNC_SX_BOOK_H */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|||||||
@@ -3179,18 +3179,9 @@ xaccTransReverse (Transaction *trans)
|
|||||||
|
|
||||||
/********************************************************************\
|
/********************************************************************\
|
||||||
\********************************************************************/
|
\********************************************************************/
|
||||||
/* gncObject function implementation */
|
/* QofObject function implementation */
|
||||||
|
|
||||||
static void
|
/* Hook into the QofObject registry */
|
||||||
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 */
|
|
||||||
|
|
||||||
static QofObject split_object_def = {
|
static QofObject split_object_def = {
|
||||||
interface_version: QOF_OBJECT_VERSION,
|
interface_version: QOF_OBJECT_VERSION,
|
||||||
@@ -3200,7 +3191,7 @@ static QofObject split_object_def = {
|
|||||||
book_end: NULL,
|
book_end: NULL,
|
||||||
is_dirty: NULL,
|
is_dirty: NULL,
|
||||||
mark_clean: NULL,
|
mark_clean: NULL,
|
||||||
foreach: split_foreach,
|
foreach: qof_collection_foreach,
|
||||||
printable: (const char* (*)(gpointer)) xaccSplitGetMemo
|
printable: (const char* (*)(gpointer)) xaccSplitGetMemo
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -3284,15 +3275,6 @@ gboolean xaccSplitRegister (void)
|
|||||||
return qof_object_register (&split_object_def);
|
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 = {
|
static QofObject trans_object_def = {
|
||||||
interface_version: QOF_OBJECT_VERSION,
|
interface_version: QOF_OBJECT_VERSION,
|
||||||
e_type: GNC_ID_TRANS,
|
e_type: GNC_ID_TRANS,
|
||||||
@@ -3301,7 +3283,7 @@ static QofObject trans_object_def = {
|
|||||||
book_end: NULL,
|
book_end: NULL,
|
||||||
is_dirty: NULL,
|
is_dirty: NULL,
|
||||||
mark_clean: NULL,
|
mark_clean: NULL,
|
||||||
foreach: trans_foreach,
|
foreach: qof_collection_foreach,
|
||||||
printable: (const char* (*)(gpointer)) xaccTransGetDescription
|
printable: (const char* (*)(gpointer)) xaccTransGetDescription
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -40,9 +40,11 @@
|
|||||||
|
|
||||||
#define SAFE_STRCMP_REAL(fcn,da,db) { \
|
#define SAFE_STRCMP_REAL(fcn,da,db) { \
|
||||||
if ((da) && (db)) { \
|
if ((da) && (db)) { \
|
||||||
int retval = fcn ((da), (db)); \
|
if ((da) != (db)) { \
|
||||||
/* if strings differ, return */ \
|
int retval = fcn ((da), (db)); \
|
||||||
if (retval) return retval; \
|
/* if strings differ, return */ \
|
||||||
|
if (retval) return retval; \
|
||||||
|
} \
|
||||||
} else \
|
} else \
|
||||||
if ((!(da)) && (db)) { \
|
if ((!(da)) && (db)) { \
|
||||||
return -1; \
|
return -1; \
|
||||||
|
|||||||
@@ -68,7 +68,8 @@
|
|||||||
#define GNC_ID_PRICEDB "PriceDB"
|
#define GNC_ID_PRICEDB "PriceDB"
|
||||||
#define GNC_ID_SPLIT "Split"
|
#define GNC_ID_SPLIT "Split"
|
||||||
#define GNC_ID_SCHEDXACTION "SchedXaction"
|
#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"
|
#define GNC_ID_TRANS "Trans"
|
||||||
|
|
||||||
/* TYPES **********************************************************/
|
/* TYPES **********************************************************/
|
||||||
|
|||||||
@@ -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))
|
#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_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_mark_clean(GNCPriceDB *db);
|
||||||
void gnc_pricedb_substitute_commodity(GNCPriceDB *db,
|
void gnc_pricedb_substitute_commodity(GNCPriceDB *db,
|
||||||
|
|||||||
+31
-17
@@ -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 *
|
GNCPriceDB *
|
||||||
gnc_pricedb_get_db(QofBook *book)
|
gnc_pricedb_get_db(QofBook *book)
|
||||||
{
|
{
|
||||||
|
QofCollection *col;
|
||||||
if (!book) return NULL;
|
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
|
void
|
||||||
gnc_pricedb_set_db(QofBook *book, GNCPriceDB *db)
|
gnc_pricedb_set_db(QofBook *book, GNCPriceDB *db)
|
||||||
{
|
{
|
||||||
GNCPriceDB *old_db;
|
QofCollection *col;
|
||||||
|
|
||||||
if(!book) return;
|
if(!book) return;
|
||||||
|
col = qof_book_get_collection (book, GNC_ID_PRICE);
|
||||||
old_db = gnc_pricedb_get_db (book);
|
gnc_collection_set_pricedb (col, db);
|
||||||
if (db == old_db) return;
|
|
||||||
|
|
||||||
qof_book_set_data (book, GNC_PRICEDB, db);
|
|
||||||
if (db) db->book = book;
|
if (db) db->book = book;
|
||||||
|
|
||||||
gnc_pricedb_destroy (old_db);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ==================================================================== */
|
/* ==================================================================== */
|
||||||
@@ -1942,15 +1956,15 @@ pricedb_book_end (QofBook *book)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
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
|
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
|
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_unstable_price_traversal(db,
|
||||||
(void (*)(GNCPrice *, gpointer)) cb,
|
(void (*)(GNCPrice *, gpointer)) cb,
|
||||||
data);
|
data);
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include "gnc-numeric.h"
|
#include "gnc-numeric.h"
|
||||||
#include "guid.h"
|
#include "guid.h"
|
||||||
#include "qofbook.h"
|
#include "qofbook.h"
|
||||||
|
#include "qofid.h"
|
||||||
#include "qofinstance.h"
|
#include "qofinstance.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -239,6 +240,7 @@ GNCPriceDB * gnc_pricedb_create(QofBook *book);
|
|||||||
|
|
||||||
/** return the pricedb associated with the book */
|
/** return the pricedb associated with the book */
|
||||||
GNCPriceDB * gnc_pricedb_get_db(QofBook *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
|
/** 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
|
||||||
|
|||||||
@@ -43,6 +43,18 @@
|
|||||||
* manipulated by GnuCash. This is the top-most structure
|
* manipulated by GnuCash. This is the top-most structure
|
||||||
* used for anchoring data.
|
* 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;
|
typedef struct _QofBook QofBook;
|
||||||
|
|
||||||
/** GList of QofBook */
|
/** GList of QofBook */
|
||||||
|
|||||||
@@ -42,5 +42,8 @@ void qof_entity_set_guid (QofEntity *ent, const GUID *guid);
|
|||||||
*/
|
*/
|
||||||
void qof_collection_insert_entity (QofCollection *, QofEntity *);
|
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 */
|
#endif /* QOF_ID_P_H */
|
||||||
|
|||||||
+44
-2
@@ -39,10 +39,11 @@ static short module = MOD_ENGINE;
|
|||||||
|
|
||||||
struct QofCollection_s
|
struct QofCollection_s
|
||||||
{
|
{
|
||||||
QofIdType e_type;
|
QofIdType e_type;
|
||||||
gboolean is_dirty;
|
gboolean is_dirty;
|
||||||
|
|
||||||
GHashTable * hash_of_entities;
|
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 = g_new0(QofCollection, 1);
|
||||||
col->e_type = CACHE_INSERT (type);
|
col->e_type = CACHE_INSERT (type);
|
||||||
col->hash_of_entities = g_hash_table_new (id_hash, id_compare);
|
col->hash_of_entities = g_hash_table_new (id_hash, id_compare);
|
||||||
|
col->data = NULL;
|
||||||
return col;
|
return col;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,6 +164,7 @@ qof_collection_destroy (QofCollection *col)
|
|||||||
g_hash_table_destroy(col->hash_of_entities);
|
g_hash_table_destroy(col->hash_of_entities);
|
||||||
col->e_type = NULL;
|
col->e_type = NULL;
|
||||||
col->hash_of_entities = NULL;
|
col->hash_of_entities = NULL;
|
||||||
|
col->data = NULL; /** XXX there should be a destroy notifier for this */
|
||||||
g_free (col);
|
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 {
|
struct _iterate {
|
||||||
QofEntityForeachCB fcn;
|
QofEntityForeachCB fcn;
|
||||||
gpointer data;
|
gpointer data;
|
||||||
|
|||||||
@@ -52,6 +52,7 @@
|
|||||||
* type of the identifier.
|
* type of the identifier.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
#include "guid.h"
|
#include "guid.h"
|
||||||
|
|
||||||
typedef const char * QofIdType;
|
typedef const char * QofIdType;
|
||||||
@@ -65,6 +66,37 @@ typedef const char * QofIdTypeConst;
|
|||||||
/* simple,cheesy cast but holds water for now */
|
/* simple,cheesy cast but holds water for now */
|
||||||
#define QOF_ENTITY(object) ((QofEntity *)(object))
|
#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 QofEntity_s QofEntity;
|
||||||
typedef struct QofCollection_s QofCollection;
|
typedef struct QofCollection_s QofCollection;
|
||||||
|
|
||||||
@@ -102,6 +134,12 @@ typedef void (*QofEntityForeachCB) (QofEntity *, gpointer user_data);
|
|||||||
void qof_collection_foreach (QofCollection *,
|
void qof_collection_foreach (QofCollection *,
|
||||||
QofEntityForeachCB, gpointer user_data);
|
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 */
|
#endif /* QOF_ID_H */
|
||||||
|
|||||||
+26
-11
@@ -75,29 +75,40 @@ void qof_object_book_end (QofBook *book)
|
|||||||
LEAVE (" ");
|
LEAVE (" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean qof_object_is_dirty (QofBook *book)
|
gboolean
|
||||||
|
qof_object_is_dirty (QofBook *book)
|
||||||
{
|
{
|
||||||
GList *l;
|
GList *l;
|
||||||
|
|
||||||
if (!book) return FALSE;
|
if (!book) return FALSE;
|
||||||
for (l = object_modules; l; l = l->next) {
|
for (l = object_modules; l; l = l->next)
|
||||||
|
{
|
||||||
QofObject *obj = l->data;
|
QofObject *obj = l->data;
|
||||||
if (obj->is_dirty)
|
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;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void qof_object_mark_clean (QofBook *book)
|
void
|
||||||
|
qof_object_mark_clean (QofBook *book)
|
||||||
{
|
{
|
||||||
GList *l;
|
GList *l;
|
||||||
|
|
||||||
if (!book) return;
|
if (!book) return;
|
||||||
for (l = object_modules; l; l = l->next) {
|
for (l = object_modules; l; l = l->next)
|
||||||
|
{
|
||||||
QofObject *obj = l->data;
|
QofObject *obj = l->data;
|
||||||
if (obj->mark_clean)
|
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,
|
void
|
||||||
QofForeachCB cb, gpointer user_data)
|
qof_object_foreach (QofIdTypeConst type_name, QofBook *book,
|
||||||
|
QofEntityForeachCB cb, gpointer user_data)
|
||||||
{
|
{
|
||||||
|
QofCollection *col;
|
||||||
const QofObject *obj;
|
const QofObject *obj;
|
||||||
|
|
||||||
if (!book || !type_name) return;
|
if (!book || !type_name) return;
|
||||||
ENTER ("type=%s", type_name);
|
ENTER ("type=%s", type_name);
|
||||||
|
|
||||||
obj = qof_object_lookup (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);
|
PINFO ("lookup obj=%p for type=%s", obj, type_name);
|
||||||
if (!obj) return;
|
if (!obj) return;
|
||||||
|
|
||||||
PINFO ("type=%s foreach=%p", type_name, obj->foreach);
|
PINFO ("type=%s foreach=%p", type_name, obj->foreach);
|
||||||
if (obj->foreach) {
|
if (obj->foreach)
|
||||||
obj->foreach (book, cb, user_data);
|
{
|
||||||
|
obj->foreach (col, cb, user_data);
|
||||||
}
|
}
|
||||||
LEAVE ("type=%s", type_name);
|
LEAVE ("type=%s", type_name);
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#define QOF_OBJECT_H_
|
#define QOF_OBJECT_H_
|
||||||
|
|
||||||
#include "qofbook.h"
|
#include "qofbook.h"
|
||||||
|
#include "qofid.h"
|
||||||
|
|
||||||
/* Defines the version of the core object object registration
|
/* Defines the version of the core object object registration
|
||||||
* interface. Only object modules compiled against this version
|
* interface. Only object modules compiled against this version
|
||||||
@@ -46,7 +47,10 @@ typedef void (*QofForeachBackendTypeCB) (QofIdTypeConst type,
|
|||||||
gpointer backend_data,
|
gpointer backend_data,
|
||||||
gpointer user_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
|
struct _QofObject
|
||||||
{
|
{
|
||||||
gint interface_version; /* of this object interface */
|
gint interface_version; /* of this object interface */
|
||||||
@@ -62,15 +66,15 @@ struct _QofObject
|
|||||||
void (*book_end)(QofBook *);
|
void (*book_end)(QofBook *);
|
||||||
|
|
||||||
/* Determine if there are any dirty items in this book */
|
/* 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) */
|
/* 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
|
/* foreach() is used to execute a callback over each object
|
||||||
* stored in the particular book
|
* stored in the particular book
|
||||||
*/
|
*/
|
||||||
void (*foreach)(QofBook *, QofForeachCB, gpointer);
|
void (*foreach)(QofCollection *, QofEntityForeachCB, gpointer);
|
||||||
|
|
||||||
/* Given a particular object, return a printable string */
|
/* Given a particular object, return a printable string */
|
||||||
/* Argument should really be QofInstance not gpointer.. */
|
/* 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_type (QofForeachTypeCB cb, gpointer user_data);
|
||||||
|
|
||||||
void qof_object_foreach (QofIdTypeConst type_name, QofBook *book,
|
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);
|
const char * qof_object_printable (QofIdTypeConst type_name, gpointer obj);
|
||||||
|
|
||||||
|
|||||||
@@ -743,7 +743,7 @@ GList * qof_query_run (QofQuery *q)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* and then iterate over all the objects */
|
/* 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;
|
matching_objects = qcb.list;
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
|
|
||||||
#include "gnc-engine-util.h"
|
#include "gnc-engine-util.h"
|
||||||
|
|
||||||
#include "gnc-book.h"
|
|
||||||
#include "gnc-commodity.h"
|
#include "gnc-commodity.h"
|
||||||
#include "gnc-engine.h"
|
#include "gnc-engine.h"
|
||||||
#include "gnc-module.h"
|
#include "gnc-module.h"
|
||||||
|
#include "qofbook.h"
|
||||||
#include "test-engine-stuff.h"
|
#include "test-engine-stuff.h"
|
||||||
#include "test-stuff.h"
|
#include "test-stuff.h"
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ test_commodity(void)
|
|||||||
gnc_commodity *coms[20];
|
gnc_commodity *coms[20];
|
||||||
QofBook *book;
|
QofBook *book;
|
||||||
|
|
||||||
book = gnc_book_new ();
|
book = qof_book_new ();
|
||||||
tbl = gnc_commodity_table_new ();
|
tbl = gnc_commodity_table_new ();
|
||||||
|
|
||||||
do_test(gnc_commodity_table_get_size(tbl) == 0,
|
do_test(gnc_commodity_table_get_size(tbl) == 0,
|
||||||
|
|||||||
+422
-422
@@ -15,542 +15,542 @@
|
|||||||
#include "FreqSpec.h"
|
#include "FreqSpec.h"
|
||||||
#include "gnc-engine.h"
|
#include "gnc-engine.h"
|
||||||
#include "gnc-module.h"
|
#include "gnc-module.h"
|
||||||
#include "gnc-book.h"
|
#include "qofbook.h"
|
||||||
|
|
||||||
static QofBook *book;
|
static QofBook *book;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_once (void)
|
test_once (void)
|
||||||
{
|
{
|
||||||
FreqSpec *fs;
|
FreqSpec *fs;
|
||||||
guint32 i, start_julian;
|
guint32 i, start_julian;
|
||||||
GDate date1, date2, next_date;
|
GDate date1, date2, next_date;
|
||||||
|
|
||||||
fs = xaccFreqSpecMalloc(book);
|
fs = xaccFreqSpecMalloc(book);
|
||||||
|
|
||||||
for( start_julian = 1; start_julian < 1000; ++start_julian ) {
|
for( start_julian = 1; start_julian < 1000; ++start_julian ) {
|
||||||
g_date_set_julian( &date1, start_julian );
|
g_date_set_julian( &date1, start_julian );
|
||||||
|
|
||||||
xaccFreqSpecSetOnceDate( fs, &date1 );
|
xaccFreqSpecSetOnceDate( fs, &date1 );
|
||||||
for( i = 0; i <= 2 * start_julian; ++i ) {
|
for( i = 0; i <= 2 * start_julian; ++i ) {
|
||||||
g_date_set_julian( &date2, start_julian + i );
|
g_date_set_julian( &date2, start_julian + i );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
||||||
do_test( (g_date_compare( &date2, &date1 ) >= 0 &&
|
do_test( (g_date_compare( &date2, &date1 ) >= 0 &&
|
||||||
!g_date_valid( &next_date ) ) ||
|
!g_date_valid( &next_date ) ) ||
|
||||||
g_date_compare( &date1, &next_date ) == 0,
|
g_date_compare( &date1, &next_date ) == 0,
|
||||||
"once off" );
|
"once off" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xaccFreqSpecFree(fs);
|
xaccFreqSpecFree(fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_daily (void)
|
test_daily (void)
|
||||||
{
|
{
|
||||||
guint32 interval, i, start_julian, j;
|
guint32 interval, i, start_julian, j;
|
||||||
FreqSpec *fs;
|
FreqSpec *fs;
|
||||||
GDate date1, date2, next_date;
|
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 );
|
start_julian = g_date_julian( &date1 );
|
||||||
for( interval = 1; interval < 400; ++interval ) {
|
for( interval = 1; interval < 400; ++interval ) {
|
||||||
xaccFreqSpecSetDaily( fs, &date1, interval );
|
xaccFreqSpecSetDaily( fs, &date1, interval );
|
||||||
for( i = 0; i <= 2 * interval; ++i ) {
|
for( i = 0; i <= 2 * interval; ++i ) {
|
||||||
g_date_set_julian( &date2, start_julian + i );
|
g_date_set_julian( &date2, start_julian + i );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
||||||
do_test_args(
|
do_test_args(
|
||||||
g_date_julian( &next_date ) - g_date_julian( &date2 ) ==
|
g_date_julian( &next_date ) - g_date_julian( &date2 ) ==
|
||||||
interval - (i%interval),
|
interval - (i%interval),
|
||||||
"daily repeats",
|
"daily repeats",
|
||||||
__FILE__, __LINE__,
|
__FILE__, __LINE__,
|
||||||
"interval = %d days, days from start = %d",
|
"interval = %d days, days from start = %d",
|
||||||
interval, i );
|
interval, i );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This tests whether we can correctly generate a sequence of dates,
|
/* This tests whether we can correctly generate a sequence of dates,
|
||||||
* and end up in the right place. */
|
* and end up in the right place. */
|
||||||
g_date_set_dmy( &date1, 25, 3, 2001 );
|
g_date_set_dmy( &date1, 25, 3, 2001 );
|
||||||
for( interval = 1; interval < 20; ++interval ) {
|
for( interval = 1; interval < 20; ++interval ) {
|
||||||
xaccFreqSpecSetDaily( fs, &date1, interval );
|
xaccFreqSpecSetDaily( fs, &date1, interval );
|
||||||
for( j = 0; j < 20; ++j ) {
|
for( j = 0; j < 20; ++j ) {
|
||||||
date2 = date1;
|
date2 = date1;
|
||||||
for( i = 0; i < j; ++i ) {
|
for( i = 0; i < j; ++i ) {
|
||||||
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
||||||
date2 = next_date;
|
date2 = next_date;
|
||||||
}
|
}
|
||||||
do_test_args( g_date_julian( &date2 ) - g_date_julian( &date1 ) == interval*j,
|
do_test_args( g_date_julian( &date2 ) - g_date_julian( &date1 ) == interval*j,
|
||||||
"daily repeats end up in the right place",
|
"daily repeats end up in the right place",
|
||||||
__FILE__, __LINE__, "interval = %d days, iters = %d",
|
__FILE__, __LINE__, "interval = %d days, iters = %d",
|
||||||
interval, j );
|
interval, j );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xaccFreqSpecFree(fs);
|
xaccFreqSpecFree(fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_weekly (void)
|
test_weekly (void)
|
||||||
{
|
{
|
||||||
guint32 interval, i, start_julian, weekday, j;
|
guint32 interval, i, start_julian, weekday, j;
|
||||||
FreqSpec *fs;
|
FreqSpec *fs;
|
||||||
GDate date1, date2, next_date;
|
GDate date1, date2, next_date;
|
||||||
|
|
||||||
fs = xaccFreqSpecMalloc(book);
|
fs = xaccFreqSpecMalloc(book);
|
||||||
|
|
||||||
/* Use this to test any specific cases which fail,
|
/* Use this to test any specific cases which fail,
|
||||||
* for easy access in the debugger. */
|
* for easy access in the debugger. */
|
||||||
/*
|
/*
|
||||||
g_date_set_dmy( &date1, 2, 1, 1 );
|
g_date_set_dmy( &date1, 2, 1, 1 );
|
||||||
xaccFreqSpecSetWeekly( fs, &date1, 1 );
|
xaccFreqSpecSetWeekly( fs, &date1, 1 );
|
||||||
start_julian = g_date_julian( &date1 );
|
start_julian = g_date_julian( &date1 );
|
||||||
g_date_set_julian( &date2, start_julian + 6 );
|
g_date_set_julian( &date2, start_julian + 6 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
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 ) {
|
for( weekday = 1; weekday <= 7; ++weekday ) {
|
||||||
g_date_set_dmy( &date1, weekday, 1, 1 );
|
g_date_set_dmy( &date1, weekday, 1, 1 );
|
||||||
start_julian = g_date_julian( &date1 );
|
start_julian = g_date_julian( &date1 );
|
||||||
for( interval = 1; interval <= 52; ++interval ) {
|
for( interval = 1; interval <= 52; ++interval ) {
|
||||||
xaccFreqSpecSetWeekly( fs, &date1, interval );
|
xaccFreqSpecSetWeekly( fs, &date1, interval );
|
||||||
for( i = 0; i <= 2 * 7 * interval; ++i ) {
|
for( i = 0; i <= 2 * 7 * interval; ++i ) {
|
||||||
g_date_set_julian( &date2, start_julian + i );
|
g_date_set_julian( &date2, start_julian + i );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
||||||
do_test_args(
|
do_test_args(
|
||||||
g_date_julian( &next_date ) - g_date_julian( &date2 ) ==
|
g_date_julian( &next_date ) - g_date_julian( &date2 ) ==
|
||||||
interval*7 - (i%(interval*7)),
|
interval*7 - (i%(interval*7)),
|
||||||
"weekly repeats",
|
"weekly repeats",
|
||||||
__FILE__, __LINE__,
|
__FILE__, __LINE__,
|
||||||
"weekday = %d, interval = %d weeks, days from start = %d",
|
"weekday = %d, interval = %d weeks, days from start = %d",
|
||||||
weekday, interval, i );
|
weekday, interval, i );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This tests whether we can correctly generate a sequence of dates,
|
/* This tests whether we can correctly generate a sequence of dates,
|
||||||
* and end up in the right place. */
|
* and end up in the right place. */
|
||||||
g_date_set_dmy( &date1, 25, 3, 2001 );
|
g_date_set_dmy( &date1, 25, 3, 2001 );
|
||||||
for( interval = 1; interval < 20; ++interval ) {
|
for( interval = 1; interval < 20; ++interval ) {
|
||||||
xaccFreqSpecSetWeekly( fs, &date1, interval );
|
xaccFreqSpecSetWeekly( fs, &date1, interval );
|
||||||
for( j = 0; j < 2*53; ++j ) {
|
for( j = 0; j < 2*53; ++j ) {
|
||||||
date2 = date1;
|
date2 = date1;
|
||||||
for( i = 0; i < j; ++i ) {
|
for( i = 0; i < j; ++i ) {
|
||||||
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
||||||
date2 = next_date;
|
date2 = next_date;
|
||||||
}
|
}
|
||||||
do_test_args( g_date_julian( &date2 ) - g_date_julian( &date1 ) == interval*7*j,
|
do_test_args( g_date_julian( &date2 ) - g_date_julian( &date1 ) == interval*7*j,
|
||||||
"weekly repeats end up in the right place",
|
"weekly repeats end up in the right place",
|
||||||
__FILE__, __LINE__, "interval = %d weeks, iters = %d",
|
__FILE__, __LINE__, "interval = %d weeks, iters = %d",
|
||||||
interval, j );
|
interval, j );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xaccFreqSpecFree(fs);
|
xaccFreqSpecFree(fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_monthly (void)
|
test_monthly (void)
|
||||||
{
|
{
|
||||||
guint32 interval, i, start_julian, monthday, month, j, day_of_year;
|
guint32 interval, i, start_julian, monthday, month, j, day_of_year;
|
||||||
FreqSpec *fs;
|
FreqSpec *fs;
|
||||||
GDate date0, date1, date2, next_date;
|
GDate date0, date1, date2, next_date;
|
||||||
|
|
||||||
fs = xaccFreqSpecMalloc(book);
|
fs = xaccFreqSpecMalloc(book);
|
||||||
|
|
||||||
/* Use this to test any specific cases which fail,
|
/* Use this to test any specific cases which fail,
|
||||||
* for easy access in the debugger. */
|
* for easy access in the debugger. */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
g_date_set_dmy( &date1, 1, 1, 1 );
|
g_date_set_dmy( &date1, 1, 1, 1 );
|
||||||
xaccFreqSpecSetMonthly( fs, &date1, 2 );
|
xaccFreqSpecSetMonthly( fs, &date1, 2 );
|
||||||
start_julian = g_date_julian( &date1 );
|
start_julian = g_date_julian( &date1 );
|
||||||
g_date_set_julian( &date2, start_julian + 0 );
|
g_date_set_julian( &date2, start_julian + 0 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for( monthday = 1; monthday <= 28; ++monthday ) {
|
for( monthday = 1; monthday <= 28; ++monthday ) {
|
||||||
for( month = 1; month <= 12; ++month ) {
|
for( month = 1; month <= 12; ++month ) {
|
||||||
g_date_set_dmy( &date1, monthday, month, 1 );
|
g_date_set_dmy( &date1, monthday, month, 1 );
|
||||||
start_julian = g_date_julian( &date1 );
|
start_julian = g_date_julian( &date1 );
|
||||||
for( interval = 1; interval <= 24; ++interval ) {
|
for( interval = 1; interval <= 24; ++interval ) {
|
||||||
xaccFreqSpecSetMonthly( fs, &date1, interval );
|
xaccFreqSpecSetMonthly( fs, &date1, interval );
|
||||||
for( i = 0; i <= 2 * 31 * interval; ++i ) {
|
for( i = 0; i <= 2 * 31 * interval; ++i ) {
|
||||||
g_date_set_julian( &date2, start_julian + i );
|
g_date_set_julian( &date2, start_julian + i );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
||||||
do_test_args(
|
do_test_args(
|
||||||
g_date_day( &next_date ) == g_date_day( &date1 ),
|
g_date_day( &next_date ) == g_date_day( &date1 ),
|
||||||
"monthly repeats - check day",
|
"monthly repeats - check day",
|
||||||
__FILE__, __LINE__,
|
__FILE__, __LINE__,
|
||||||
"monthday = %d, month = %d, interval = %d months, days from start = %d",
|
"monthday = %d, month = %d, interval = %d months, days from start = %d",
|
||||||
monthday, month, interval, i );
|
monthday, month, interval, i );
|
||||||
do_test_args(
|
do_test_args(
|
||||||
( g_date_month( &next_date ) + 12 * (g_date_year( &next_date )-1) - 1) %
|
( g_date_month( &next_date ) + 12 * (g_date_year( &next_date )-1) - 1) %
|
||||||
interval == (month-1) % interval,
|
interval == (month-1) % interval,
|
||||||
"monthly repeats - check month",
|
"monthly repeats - check month",
|
||||||
__FILE__, __LINE__,
|
__FILE__, __LINE__,
|
||||||
"monthday = %d, month = %d, interval = %d months, days from start = %d",
|
"monthday = %d, month = %d, interval = %d months, days from start = %d",
|
||||||
monthday, month, interval, i );
|
monthday, month, interval, i );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This tests whether we can correctly generate a sequence of dates,
|
/* This tests whether we can correctly generate a sequence of dates,
|
||||||
* and end up in the right place. */
|
* and end up in the right place. */
|
||||||
g_date_set_dmy( &date0, 1, 1, 2000 );
|
g_date_set_dmy( &date0, 1, 1, 2000 );
|
||||||
for( day_of_year = 1; day_of_year <= 365*5; ++day_of_year ) {
|
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 );
|
g_date_set_julian( &date1, g_date_julian( &date0 ) + day_of_year-1 );
|
||||||
for( interval = 1; interval < 20; ++interval ) {
|
for( interval = 1; interval < 20; ++interval ) {
|
||||||
xaccFreqSpecSetMonthly( fs, &date1, interval );
|
xaccFreqSpecSetMonthly( fs, &date1, interval );
|
||||||
for( j = 1; j < 20; ++j ) {
|
for( j = 1; j < 20; ++j ) {
|
||||||
date2 = date1;
|
date2 = date1;
|
||||||
for( i = 0; i < j; ++i ) {
|
for( i = 0; i < j; ++i ) {
|
||||||
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
||||||
date2 = next_date;
|
date2 = next_date;
|
||||||
}
|
}
|
||||||
date2 = date1;
|
date2 = date1;
|
||||||
g_date_add_months( &date2, interval * j );
|
g_date_add_months( &date2, interval * j );
|
||||||
do_test_args( g_date_compare( &date2, &next_date ) == 0,
|
do_test_args( g_date_compare( &date2, &next_date ) == 0,
|
||||||
"monthly repeats end up in the right place",
|
"monthly repeats end up in the right place",
|
||||||
__FILE__, __LINE__, "interval = %d months, iters = %d, day_of_year = %d",
|
__FILE__, __LINE__, "interval = %d months, iters = %d, day_of_year = %d",
|
||||||
interval, j, day_of_year );
|
interval, j, day_of_year );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xaccFreqSpecFree(fs);
|
xaccFreqSpecFree(fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_month_relative (void)
|
test_month_relative (void)
|
||||||
{
|
{
|
||||||
guint32 interval, i, start_julian, monthday, month, j;
|
guint32 interval, i, start_julian, monthday, month, j;
|
||||||
FreqSpec *fs;
|
FreqSpec *fs;
|
||||||
GDate date0, date1, date2, next_date;
|
GDate date0, date1, date2, next_date;
|
||||||
|
|
||||||
fs = xaccFreqSpecMalloc(book);
|
fs = xaccFreqSpecMalloc(book);
|
||||||
|
|
||||||
/* Use this to test any specific cases which fail,
|
/* Use this to test any specific cases which fail,
|
||||||
* for easy access in the debugger. */
|
* for easy access in the debugger. */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
g_date_set_dmy( &date1, 1, 1, 1 );
|
g_date_set_dmy( &date1, 1, 1, 1 );
|
||||||
xaccFreqSpecSetMonthRelative( fs, &date1, 2 );
|
xaccFreqSpecSetMonthRelative( fs, &date1, 2 );
|
||||||
start_julian = g_date_julian( &date1 );
|
start_julian = g_date_julian( &date1 );
|
||||||
g_date_set_julian( &date2, start_julian + 0 );
|
g_date_set_julian( &date2, start_julian + 0 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* This loop does not test for days/occurences which can
|
/* This loop does not test for days/occurences which can
|
||||||
* fail to fall in the same month. */
|
* fail to fall in the same month. */
|
||||||
for( monthday = 1; monthday <= 28; ++monthday ) {
|
for( monthday = 1; monthday <= 28; ++monthday ) {
|
||||||
for( month = 1; month <= 12; ++month ) {
|
for( month = 1; month <= 12; ++month ) {
|
||||||
g_date_set_dmy( &date1, monthday, month, 1 );
|
g_date_set_dmy( &date1, monthday, month, 1 );
|
||||||
start_julian = g_date_julian( &date1 );
|
start_julian = g_date_julian( &date1 );
|
||||||
for( interval = 1; interval <= 24; ++interval ) {
|
for( interval = 1; interval <= 24; ++interval ) {
|
||||||
xaccFreqSpecSetMonthRelative( fs, &date1, interval );
|
xaccFreqSpecSetMonthRelative( fs, &date1, interval );
|
||||||
for( i = 0; i <= 2 * 31 * interval; ++i ) {
|
for( i = 0; i <= 2 * 31 * interval; ++i ) {
|
||||||
g_date_set_julian( &date2, start_julian + i );
|
g_date_set_julian( &date2, start_julian + i );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
||||||
do_test_args(
|
do_test_args(
|
||||||
g_date_weekday( &next_date ) == g_date_weekday( &date1 ),
|
g_date_weekday( &next_date ) == g_date_weekday( &date1 ),
|
||||||
"month relative repeats - check weekday",
|
"month relative repeats - check weekday",
|
||||||
__FILE__, __LINE__,
|
__FILE__, __LINE__,
|
||||||
"monthday = %d, month = %d, interval = %d months, days from start = %d, weekday = %d",
|
"monthday = %d, month = %d, interval = %d months, days from start = %d, weekday = %d",
|
||||||
monthday, month, interval, i, g_date_weekday( &date1 ) );
|
monthday, month, interval, i, g_date_weekday( &date1 ) );
|
||||||
do_test_args(
|
do_test_args(
|
||||||
(g_date_day( &next_date )-1)/7 == (g_date_day( &date1 )-1)/7,
|
(g_date_day( &next_date )-1)/7 == (g_date_day( &date1 )-1)/7,
|
||||||
"month relative repeats - check occurrence",
|
"month relative repeats - check occurrence",
|
||||||
__FILE__, __LINE__,
|
__FILE__, __LINE__,
|
||||||
"monthday = %d, month = %d, interval = %d months, days from start = %d, occurrence = %d",
|
"monthday = %d, month = %d, interval = %d months, days from start = %d, occurrence = %d",
|
||||||
monthday, month, interval, i, (g_date_day( &date1 )-1)/7 );
|
monthday, month, interval, i, (g_date_day( &date1 )-1)/7 );
|
||||||
do_test_args(
|
do_test_args(
|
||||||
( g_date_month( &next_date ) + 12 * (g_date_year( &next_date )-1) - 1) %
|
( g_date_month( &next_date ) + 12 * (g_date_year( &next_date )-1) - 1) %
|
||||||
interval == (month-1) % interval,
|
interval == (month-1) % interval,
|
||||||
"month relative repeats - check month",
|
"month relative repeats - check month",
|
||||||
__FILE__, __LINE__,
|
__FILE__, __LINE__,
|
||||||
"monthday = %d, month = %d, interval = %d months, days from start = %d",
|
"monthday = %d, month = %d, interval = %d months, days from start = %d",
|
||||||
monthday, month, interval, i );
|
monthday, month, interval, i );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This tests whether we can correctly generate a sequence of dates,
|
/* This tests whether we can correctly generate a sequence of dates,
|
||||||
* and end up in the right place. */
|
* and end up in the right place. */
|
||||||
/* Unfortunately, I think that this is going to require specifically
|
/* Unfortunately, I think that this is going to require specifically
|
||||||
* written test cases, for the case where the repeat falls in the next
|
* written test cases, for the case where the repeat falls in the next
|
||||||
* (or subsequent) month in the cycle.... */
|
* (or subsequent) month in the cycle.... */
|
||||||
|
|
||||||
g_date_set_dmy( &date1, 1, 1, 2000 );
|
g_date_set_dmy( &date1, 1, 1, 2000 );
|
||||||
for( interval = 1; interval < 20; ++interval ) {
|
for( interval = 1; interval < 20; ++interval ) {
|
||||||
xaccFreqSpecSetMonthRelative( fs, &date1, interval );
|
xaccFreqSpecSetMonthRelative( fs, &date1, interval );
|
||||||
for( j = 1; j < 20; ++j ) {
|
for( j = 1; j < 20; ++j ) {
|
||||||
date2 = date1;
|
date2 = date1;
|
||||||
for( i = 0; i < j; ++i ) {
|
for( i = 0; i < j; ++i ) {
|
||||||
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
||||||
date2 = next_date;
|
date2 = next_date;
|
||||||
}
|
}
|
||||||
date2 = date1;
|
date2 = date1;
|
||||||
g_date_add_months( &date2, interval * j );
|
g_date_add_months( &date2, interval * j );
|
||||||
do_test_args( g_date_month( &date2 ) == g_date_month( &next_date ),
|
do_test_args( g_date_month( &date2 ) == g_date_month( &next_date ),
|
||||||
"month_relative repeats end up in the right place - month",
|
"month_relative repeats end up in the right place - month",
|
||||||
__FILE__, __LINE__, "interval = %d months, iters = %d, weekday = %d",
|
__FILE__, __LINE__, "interval = %d months, iters = %d, weekday = %d",
|
||||||
interval, j, g_date_weekday( &date1 ) );
|
interval, j, g_date_weekday( &date1 ) );
|
||||||
do_test_args( g_date_weekday( &date1 ) == g_date_weekday( &next_date ),
|
do_test_args( g_date_weekday( &date1 ) == g_date_weekday( &next_date ),
|
||||||
"month_relative repeats end up in the right place - weekday",
|
"month_relative repeats end up in the right place - weekday",
|
||||||
__FILE__, __LINE__, "interval = %d months, iters = %d, weekday = %d",
|
__FILE__, __LINE__, "interval = %d months, iters = %d, weekday = %d",
|
||||||
interval, j, g_date_weekday( &date1 ) );
|
interval, j, g_date_weekday( &date1 ) );
|
||||||
do_test_args( (g_date_day( &date2 )-1)/7 == (g_date_day( &next_date )-1)/7,
|
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",
|
"month_relative repeats end up in the right place - occurrence",
|
||||||
__FILE__, __LINE__, "interval = %d months, iters = %d, weekday = %d",
|
__FILE__, __LINE__, "interval = %d months, iters = %d, weekday = %d",
|
||||||
interval, j, g_date_weekday( &date1 ) );
|
interval, j, g_date_weekday( &date1 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* also test oddball cases */
|
/* also test oddball cases */
|
||||||
/* This is the fifth Sunday of a five Sunday month. */
|
/* This is the fifth Sunday of a five Sunday month. */
|
||||||
g_date_set_dmy( &date0, 29, 4, 2001 );
|
g_date_set_dmy( &date0, 29, 4, 2001 );
|
||||||
xaccFreqSpecSetMonthRelative( fs, &date0, 1 );
|
xaccFreqSpecSetMonthRelative( fs, &date0, 1 );
|
||||||
|
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &next_date );
|
xaccFreqSpecGetNextInstance( fs, &date0, &next_date );
|
||||||
g_date_set_dmy( &date1, 29, 7, 2001 );
|
g_date_set_dmy( &date1, 29, 7, 2001 );
|
||||||
do_test( g_date_compare( &next_date, &date1 ) == 0, "find five-sunday months" );
|
do_test( g_date_compare( &next_date, &date1 ) == 0, "find five-sunday months" );
|
||||||
date2 = next_date;
|
date2 = next_date;
|
||||||
|
|
||||||
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
||||||
g_date_set_dmy( &date1, 30, 9, 2001 );
|
g_date_set_dmy( &date1, 30, 9, 2001 );
|
||||||
do_test( g_date_compare( &next_date, &date1 ) == 0, "find five-sunday months" );
|
do_test( g_date_compare( &next_date, &date1 ) == 0, "find five-sunday months" );
|
||||||
date2 = next_date;
|
date2 = next_date;
|
||||||
|
|
||||||
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
||||||
g_date_set_dmy( &date1, 30, 12, 2001 );
|
g_date_set_dmy( &date1, 30, 12, 2001 );
|
||||||
do_test( g_date_compare( &next_date, &date1 ) == 0, "find five-sunday months" );
|
do_test( g_date_compare( &next_date, &date1 ) == 0, "find five-sunday months" );
|
||||||
date2 = next_date;
|
date2 = next_date;
|
||||||
|
|
||||||
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
||||||
g_date_set_dmy( &date1, 31, 3, 2002 );
|
g_date_set_dmy( &date1, 31, 3, 2002 );
|
||||||
do_test( g_date_compare( &next_date, &date1 ) == 0, "find five-sunday months" );
|
do_test( g_date_compare( &next_date, &date1 ) == 0, "find five-sunday months" );
|
||||||
date2 = next_date;
|
date2 = next_date;
|
||||||
|
|
||||||
xaccFreqSpecFree(fs);
|
xaccFreqSpecFree(fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_composite (void)
|
test_composite (void)
|
||||||
{
|
{
|
||||||
FreqSpec *fs, *fs2;
|
FreqSpec *fs, *fs2;
|
||||||
GDate date0, date1, date2;
|
GDate date0, date1, date2;
|
||||||
|
|
||||||
fs = xaccFreqSpecMalloc(book);
|
fs = xaccFreqSpecMalloc(book);
|
||||||
|
|
||||||
/* Use this to test any specific cases which fail,
|
/* Use this to test any specific cases which fail,
|
||||||
* for easy access in the debugger. */
|
* for easy access in the debugger. */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
g_date_set_dmy( &date1, 1, 1, 1 );
|
g_date_set_dmy( &date1, 1, 1, 1 );
|
||||||
xaccFreqSpecSetMonthly( fs, &date1, 2 );
|
xaccFreqSpecSetMonthly( fs, &date1, 2 );
|
||||||
start_julian = g_date_julian( &date1 );
|
start_julian = g_date_julian( &date1 );
|
||||||
g_date_set_julian( &date2, start_julian + 0 );
|
g_date_set_julian( &date2, start_julian + 0 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* I have not tested this type as thoroughly
|
/* I have not tested this type as thoroughly
|
||||||
* because I expect that the elements from which it
|
* because I expect that the elements from which it
|
||||||
* has been constructed have been pretty much tortured
|
* has been constructed have been pretty much tortured
|
||||||
* in the previous tests. I don't expect anything strange
|
* in the previous tests. I don't expect anything strange
|
||||||
* to go on here, at least for now... Maybe I'll put
|
* to go on here, at least for now... Maybe I'll put
|
||||||
* in more extensive tests later. */
|
* in more extensive tests later. */
|
||||||
|
|
||||||
xaccFreqSpecSetComposite( fs );
|
xaccFreqSpecSetComposite( fs );
|
||||||
|
|
||||||
fs2 = xaccFreqSpecMalloc(book);
|
fs2 = xaccFreqSpecMalloc(book);
|
||||||
g_date_set_dmy( &date0, 29, 3, 2001 ); /* Wednesday */
|
g_date_set_dmy( &date0, 29, 3, 2001 ); /* Wednesday */
|
||||||
xaccFreqSpecSetWeekly( fs2, &date0, 2 );
|
xaccFreqSpecSetWeekly( fs2, &date0, 2 );
|
||||||
xaccFreqSpecCompositeAdd( fs, fs2 );
|
xaccFreqSpecCompositeAdd( fs, fs2 );
|
||||||
|
|
||||||
fs2 = xaccFreqSpecMalloc(book);
|
fs2 = xaccFreqSpecMalloc(book);
|
||||||
g_date_set_dmy( &date0, 3, 4, 2001 ); /* Tuesday */
|
g_date_set_dmy( &date0, 3, 4, 2001 ); /* Tuesday */
|
||||||
xaccFreqSpecSetWeekly( fs2, &date0, 2 );
|
xaccFreqSpecSetWeekly( fs2, &date0, 2 );
|
||||||
xaccFreqSpecCompositeAdd( fs, fs2 );
|
xaccFreqSpecCompositeAdd( fs, fs2 );
|
||||||
|
|
||||||
fs2 = xaccFreqSpecMalloc(book);
|
fs2 = xaccFreqSpecMalloc(book);
|
||||||
g_date_set_dmy( &date0, 7, 4, 2001 ); /* Saturday */
|
g_date_set_dmy( &date0, 7, 4, 2001 ); /* Saturday */
|
||||||
xaccFreqSpecSetWeekly( fs2, &date0, 2 );
|
xaccFreqSpecSetWeekly( fs2, &date0, 2 );
|
||||||
xaccFreqSpecCompositeAdd( fs, fs2 );
|
xaccFreqSpecCompositeAdd( fs, fs2 );
|
||||||
|
|
||||||
fs2 = 0;
|
fs2 = 0;
|
||||||
|
|
||||||
/* OK - now let's iterate it and see if we get the right sequence of dates. */
|
/* OK - now let's iterate it and see if we get the right sequence of dates. */
|
||||||
g_date_set_dmy( &date0, 26, 3, 2001 );
|
g_date_set_dmy( &date0, 26, 3, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 29, 3, 2001 );
|
g_date_set_dmy( &date2, 29, 3, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0,
|
do_test( g_date_compare( &date1, &date2 ) == 0,
|
||||||
"first date in sequence" );
|
"first date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 27, 3, 2001 );
|
g_date_set_dmy( &date0, 27, 3, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 29, 3, 2001 );
|
g_date_set_dmy( &date2, 29, 3, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0,
|
do_test( g_date_compare( &date1, &date2 ) == 0,
|
||||||
"first date in sequence" );
|
"first date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 28, 3, 2001 );
|
g_date_set_dmy( &date0, 28, 3, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 29, 3, 2001 );
|
g_date_set_dmy( &date2, 29, 3, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "first date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "first date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 29, 3, 2001 );
|
g_date_set_dmy( &date0, 29, 3, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 3, 4, 2001 );
|
g_date_set_dmy( &date2, 3, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "second date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "second date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 30, 3, 2001 );
|
g_date_set_dmy( &date0, 30, 3, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 3, 4, 2001 );
|
g_date_set_dmy( &date2, 3, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "second date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "second date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 31, 3, 2001 );
|
g_date_set_dmy( &date0, 31, 3, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 3, 4, 2001 );
|
g_date_set_dmy( &date2, 3, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "second date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "second date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 1, 4, 2001 );
|
g_date_set_dmy( &date0, 1, 4, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 3, 4, 2001 );
|
g_date_set_dmy( &date2, 3, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "second date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "second date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 2, 4, 2001 );
|
g_date_set_dmy( &date0, 2, 4, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 3, 4, 2001 );
|
g_date_set_dmy( &date2, 3, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "second date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "second date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 3, 4, 2001 );
|
g_date_set_dmy( &date0, 3, 4, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 7, 4, 2001 );
|
g_date_set_dmy( &date2, 7, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "third date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "third date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 4, 4, 2001 );
|
g_date_set_dmy( &date0, 4, 4, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 7, 4, 2001 );
|
g_date_set_dmy( &date2, 7, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "third date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "third date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 5, 4, 2001 );
|
g_date_set_dmy( &date0, 5, 4, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 7, 4, 2001 );
|
g_date_set_dmy( &date2, 7, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "third date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "third date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 6, 4, 2001 );
|
g_date_set_dmy( &date0, 6, 4, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 7, 4, 2001 );
|
g_date_set_dmy( &date2, 7, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "third date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "third date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 7, 4, 2001 );
|
g_date_set_dmy( &date0, 7, 4, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 12, 4, 2001 );
|
g_date_set_dmy( &date2, 12, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "fourth date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "fourth date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 8, 4, 2001 );
|
g_date_set_dmy( &date0, 8, 4, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 12, 4, 2001 );
|
g_date_set_dmy( &date2, 12, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "fourth date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "fourth date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 9, 4, 2001 );
|
g_date_set_dmy( &date0, 9, 4, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 12, 4, 2001 );
|
g_date_set_dmy( &date2, 12, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "fourth date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "fourth date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 10, 4, 2001 );
|
g_date_set_dmy( &date0, 10, 4, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 12, 4, 2001 );
|
g_date_set_dmy( &date2, 12, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "fourth date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "fourth date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 11, 4, 2001 );
|
g_date_set_dmy( &date0, 11, 4, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 12, 4, 2001 );
|
g_date_set_dmy( &date2, 12, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "fourth date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "fourth date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 12, 4, 2001 );
|
g_date_set_dmy( &date0, 12, 4, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 17, 4, 2001 );
|
g_date_set_dmy( &date2, 17, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "fifth date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "fifth date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 13, 4, 2001 );
|
g_date_set_dmy( &date0, 13, 4, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 17, 4, 2001 );
|
g_date_set_dmy( &date2, 17, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "fifth date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "fifth date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 14, 4, 2001 );
|
g_date_set_dmy( &date0, 14, 4, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 17, 4, 2001 );
|
g_date_set_dmy( &date2, 17, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "fifth date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "fifth date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 15, 4, 2001 );
|
g_date_set_dmy( &date0, 15, 4, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 17, 4, 2001 );
|
g_date_set_dmy( &date2, 17, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "fifth date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "fifth date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 16, 4, 2001 );
|
g_date_set_dmy( &date0, 16, 4, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 17, 4, 2001 );
|
g_date_set_dmy( &date2, 17, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "fifth date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "fifth date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 17, 4, 2001 );
|
g_date_set_dmy( &date0, 17, 4, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 21, 4, 2001 );
|
g_date_set_dmy( &date2, 21, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "sixth date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "sixth date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 18, 4, 2001 );
|
g_date_set_dmy( &date0, 18, 4, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 21, 4, 2001 );
|
g_date_set_dmy( &date2, 21, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "sixth date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "sixth date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 19, 4, 2001 );
|
g_date_set_dmy( &date0, 19, 4, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 21, 4, 2001 );
|
g_date_set_dmy( &date2, 21, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "sixth date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "sixth date in sequence" );
|
||||||
|
|
||||||
g_date_set_dmy( &date0, 20, 4, 2001 );
|
g_date_set_dmy( &date0, 20, 4, 2001 );
|
||||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||||
g_date_set_dmy( &date2, 21, 4, 2001 );
|
g_date_set_dmy( &date2, 21, 4, 2001 );
|
||||||
do_test( g_date_compare( &date1, &date2 ) == 0, "sixth date in sequence" );
|
do_test( g_date_compare( &date1, &date2 ) == 0, "sixth date in sequence" );
|
||||||
|
|
||||||
xaccFreqSpecFree(fs);
|
xaccFreqSpecFree(fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
guile_main ( void *closure, int argc, char* argv[] )
|
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
|
#if 0
|
||||||
set_success_print(TRUE);
|
set_success_print(TRUE);
|
||||||
#endif
|
#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();
|
print_test_results();
|
||||||
exit (get_rv());
|
exit (get_rv());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,14 +6,14 @@
|
|||||||
#include "gnc-engine-util.h"
|
#include "gnc-engine-util.h"
|
||||||
#include "messages.h"
|
#include "messages.h"
|
||||||
#include "qofbook.h"
|
#include "qofbook.h"
|
||||||
|
#include "qofobject.h"
|
||||||
|
|
||||||
#include "gncObject.h"
|
|
||||||
#include "test-stuff.h"
|
#include "test-stuff.h"
|
||||||
|
|
||||||
#define TEST_MODULE_NAME "object-test"
|
#define TEST_MODULE_NAME "object-test"
|
||||||
#define TEST_MODULE_DESC "Test Object"
|
#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 const char * printable (gpointer obj);
|
||||||
static void test_printable (const char *name, gpointer obj);
|
static void test_printable (const char *name, gpointer obj);
|
||||||
static void test_foreach (QofBook *, const char *);
|
static void test_foreach (QofBook *, const char *);
|
||||||
@@ -26,7 +26,7 @@ static QofObject bus_obj = {
|
|||||||
NULL, /* destroy */
|
NULL, /* destroy */
|
||||||
NULL, /* is dirty */
|
NULL, /* is dirty */
|
||||||
NULL, /* mark_clean */
|
NULL, /* mark_clean */
|
||||||
foreach,
|
obj_foreach,
|
||||||
printable,
|
printable,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -34,15 +34,15 @@ static void test_object (void)
|
|||||||
{
|
{
|
||||||
/* Test the global registration and lookup functions */
|
/* Test the global registration and lookup functions */
|
||||||
{
|
{
|
||||||
do_test (!gncObjectRegister (NULL), "register NULL");
|
do_test (!qof_object_register (NULL), "register NULL");
|
||||||
do_test (gncObjectRegister (&bus_obj), "register test object");
|
do_test (qof_object_register (&bus_obj), "register test object");
|
||||||
do_test (!gncObjectRegister (&bus_obj), "register test object again");
|
do_test (!qof_object_register (&bus_obj), "register test object again");
|
||||||
do_test (gncObjectLookup (TEST_MODULE_NAME) == &bus_obj,
|
do_test (qof_object_lookup (TEST_MODULE_NAME) == &bus_obj,
|
||||||
"lookup our installed object");
|
"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");
|
"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_MODULE_DESC)),
|
||||||
"test description return");
|
"test description return");
|
||||||
}
|
}
|
||||||
@@ -52,17 +52,17 @@ static void test_object (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
foreach (QofBook *book, QofForeachCB cb, gpointer u_d)
|
obj_foreach (QofCollection *col, QofEntityForeachCB cb, gpointer u_d)
|
||||||
{
|
{
|
||||||
int *foo = u_d;
|
int *foo = u_d;
|
||||||
|
|
||||||
do_test (book != NULL, "foreach: NULL object");
|
do_test (col != NULL, "foreach: NULL collection");
|
||||||
success ("called foreach callback");
|
success ("called foreach callback");
|
||||||
|
|
||||||
*foo = 1;
|
*foo = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void foreachCB (gpointer obj, gpointer u_d)
|
static void foreachCB (QofEntity *ent, gpointer u_d)
|
||||||
{
|
{
|
||||||
do_test (FALSE, "FAIL");
|
do_test (FALSE, "FAIL");
|
||||||
}
|
}
|
||||||
@@ -80,26 +80,26 @@ test_foreach (QofBook *book, const char *name)
|
|||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
gncObjectForeach (NULL, NULL, NULL, &res);
|
qof_object_foreach (NULL, NULL, NULL, &res);
|
||||||
do_test (res == 0, "object: Foreach: NULL, NULL, NULL");
|
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");
|
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");
|
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");
|
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");
|
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");
|
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");
|
do_test (res != 0, "object: Foreach: name, book, NULL");
|
||||||
|
|
||||||
res = 0;
|
res = 0;
|
||||||
gncObjectForeach (name, book, foreachCB, &res);
|
qof_object_foreach (name, book, foreachCB, &res);
|
||||||
do_test (res != 0, "object: Foreach: name, book, foreachCB");
|
do_test (res != 0, "object: Foreach: name, book, foreachCB");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,13 +108,13 @@ test_printable (const char *name, gpointer obj)
|
|||||||
{
|
{
|
||||||
const char *res;
|
const char *res;
|
||||||
|
|
||||||
do_test (gncObjectPrintable (NULL, NULL) == NULL,
|
do_test (qof_object_printable (NULL, NULL) == NULL,
|
||||||
"object: Printable: NULL, NULL");
|
"object: Printable: NULL, NULL");
|
||||||
do_test (gncObjectPrintable (NULL, obj) == NULL,
|
do_test (qof_object_printable (NULL, obj) == NULL,
|
||||||
"object: Printable: NULL, object");
|
"object: Printable: NULL, object");
|
||||||
do_test (gncObjectPrintable (name, NULL) == NULL,
|
do_test (qof_object_printable (name, NULL) == NULL,
|
||||||
"object: Printable: mod_name, 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");
|
do_test (res != NULL, "object: Printable: mod_name, object");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user