Get "make check" to work with the gobjectified objects.

- fix a bunch of tests to use the new gobject defs
- make sure we initialize g_type_init() in qof_init()
- fix qofbook's destruction sequence (I broke it earlier)
- use dispose() in QofInstance
- use qof_init() for the business tests.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/branches/gobject-engine-dev-warlord@15826 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Derek Atkins 2007-04-05 02:44:47 +00:00
parent 4c64b3e9a0
commit b4323dbfcf
10 changed files with 193 additions and 51 deletions

View File

@ -110,6 +110,8 @@ qof_book_finalize_real (GObject *bookp)
void
qof_book_destroy (QofBook *book)
{
GHashTable* cols;
if (!book) return;
ENTER ("book=%p", book);
@ -130,10 +132,16 @@ qof_book_destroy (QofBook *book)
/* qof_instance_release (&book->inst); */
g_hash_table_destroy (book->hash_of_collections);
/* Note: we need to save this hashtable until after we remove ourself
* from it, otherwise we'll crash in our dispose() function when we
* DO remove ourself from the collection but the collection had already
* been destroyed.
*/
cols = book->hash_of_collections;
g_object_unref (book);
g_hash_table_destroy (cols);
book->hash_of_collections = NULL;
g_object_unref (book);
LEAVE ("book=%p", book);
}

View File

@ -39,7 +39,16 @@ static QofLogModule log_module = QOF_MOD_ENGINE;
/* ========================================================== */
QOF_GOBJECT_IMPL(qof_instance, QofInstance, G_TYPE_OBJECT);
QOF_GOBJECT_GET_TYPE(QofInstance, qof_instance, G_TYPE_OBJECT, {});
QOF_GOBJECT_FINALIZE(qof_instance);
static void qof_instance_dispose(GObject*);
static void qof_instance_class_init(QofInstanceClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
object_class->finalize = qof_instance_finalize;
object_class->dispose = qof_instance_dispose;
}
static void
qof_instance_init (QofInstance *inst)
@ -66,6 +75,14 @@ qof_instance_init_data (QofInstance *inst, QofIdType type, QofBook *book)
qof_entity_init (inst, type, col);
}
static void
qof_instance_dispose (GObject *instp)
{
QofInstance* inst = QOF_INSTANCE(instp);
qof_entity_release (inst);
G_OBJECT_CLASS(qof_instance_parent_class)->dispose(instp);
}
static void
qof_instance_finalize_real (GObject *instp)
{
@ -76,7 +93,6 @@ qof_instance_finalize_real (GObject *instp)
inst->editlevel = 0;
inst->do_free = FALSE;
inst->dirty = FALSE;
qof_entity_release (inst);
}
const GUID *

View File

@ -545,7 +545,8 @@ qof_util_param_as_string(QofInstance *ent, QofParam *param)
void
qof_init (void)
{
qof_log_init();
g_type_init();
qof_log_init();
qof_util_get_string_cache ();
guid_init ();
qof_object_initialize ();

View File

@ -208,19 +208,13 @@ test_bool_fcn (QofBook *book, const char *message,
int
main (int argc, char **argv)
{
qof_log_init();
guid_init ();
qof_query_init ();
qof_object_initialize ();
qof_book_register ();
qof_init();
do_test (cashobjects_register(), "Cannot register cash objects");
do_test (gncInvoiceRegister(), "Cannot register GncInvoice");
do_test (gncJobRegister (), "Cannot register GncJob");
do_test (gncCustomerRegister(), "Cannot register GncCustomer");
test_customer();
print_test_results();
qof_query_shutdown();
guid_shutdown();
qof_object_shutdown ();
qof_close ();
return 0;
}

View File

@ -218,19 +218,13 @@ test_gint_fcn (QofBook *book, const char *message,
int
main (int argc, char **argv)
{
qof_log_init();
guid_init ();
qof_query_init ();
qof_object_initialize ();
qof_book_register ();
qof_init();
do_test (gncInvoiceRegister(), "Cannot register GncInvoice");
do_test (gncJobRegister (), "Cannot register GncJob");
do_test (gncCustomerRegister(), "Cannot register GncCustomer");
do_test (gncEmployeeRegister(), "Cannot register GncEmployee");
test_employee();
print_test_results();
qof_query_shutdown();
guid_shutdown();
qof_object_shutdown ();
qof_close();
return 0;
}

View File

@ -235,19 +235,13 @@ test_gint_fcn (QofBook *book, const char *message,
int
main (int argc, char **argv)
{
qof_log_init();
guid_init ();
qof_query_init ();
qof_object_initialize ();
qof_book_register ();
qof_init();
do_test (gncInvoiceRegister(), "Cannot register GncInvoice");
do_test (gncJobRegister (), "Cannot register GncJob");
do_test (gncCustomerRegister(), "Cannot register GncCustomer");
test_job();
print_test_results();
qof_query_shutdown();
guid_shutdown();
qof_object_shutdown ();
qof_close();
return 0;
}

View File

@ -216,19 +216,13 @@ test_gint_fcn (QofBook *book, const char *message,
int
main (int argc, char **argv)
{
qof_log_init();
guid_init ();
qof_query_init ();
qof_object_initialize ();
qof_book_register ();
qof_init();
do_test (gncInvoiceRegister(), "Cannot register GncInvoice");
do_test (gncJobRegister (), "Cannot register GncJob");
do_test (gncCustomerRegister(), "Cannot register GncCustomer");
do_test (gncVendorRegister(), "Cannot register GncVendor");
test_vendor();
print_test_results();
qof_query_shutdown();
guid_shutdown();
qof_object_shutdown ();
qof_close();
return 0;
}

View File

@ -1533,6 +1533,19 @@ gnc_commodity_table_get_quotable_commodities(const gnc_commodity_table * table)
* add an empty namespace if it does not exist
********************************************************************/
/* GObject Initialization */
QOF_GOBJECT_IMPL(gnc_commodity_namespace, gnc_commodity_namespace, QOF_TYPE_INSTANCE);
static void
gnc_commodity_namespace_init(gnc_commodity_namespace* ns)
{
}
static void
gnc_commodity_namespace_finalize_real(GObject* nsp)
{
}
gnc_commodity_namespace *
gnc_commodity_table_add_namespace(gnc_commodity_table * table,
const char * namespace,

View File

@ -58,6 +58,11 @@ typedef struct obj_s
gint64 minor;
}myobj;
typedef struct objclass_s
{
QofInstanceClass parent_class;
} myobjClass;
myobj* obj_create(QofBook*);
/* obvious setter functions */
@ -80,13 +85,40 @@ gboolean obj_getActive(myobj*);
gint32 obj_getVersion(myobj*);
gint64 obj_getMinor(myobj*);
/* --- type macros --- */
#define GNC_TYPE_MYOBJ (gnc_myobj_get_type ())
#define GNC_MYOBJ(o) \
(G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_MYOBJ, myobj))
#define GNC_MYOBJ_CLASS(k) \
(G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_MYOBJ, myobjClass))
#define GNC_IS_MYOBJ(o) \
(G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_MYOBJ))
#define GNC_IS_MYOBJ_CLASS(k) \
(G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_MYOBJ))
#define GNC_MYOBJ_GET_CLASS(o) \
(G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_MYOBJ, myobjClass))
GType gnc_myobj_get_type(void);
/* GObject Initialization */
QOF_GOBJECT_IMPL(gnc_myobj, myobj, QOF_TYPE_INSTANCE);
static void
gnc_myobj_init(myobj* obj)
{
}
static void
gnc_myobj_finalize_real(GObject* objp)
{
}
myobj*
obj_create(QofBook *book)
{
myobj *g;
g_return_val_if_fail(book, NULL);
g = g_new(myobj, 1);
qof_instance_init (&g->inst, TEST_MODULE_NAME, book);
g = g_object_new(GNC_TYPE_MYOBJ, NULL);
qof_instance_init_data (&g->inst, TEST_MODULE_NAME, book);
obj_setGUID(g,qof_instance_get_guid(&g->inst));
g->date.tv_nsec = 0;
g->date.tv_sec = 0;
@ -279,9 +311,9 @@ test_merge (void)
/* import book objects - tests used */
do_test ((NULL != import), "#2 import book is NULL");
import_obj = g_new(myobj, 1);
import_obj = g_object_new(GNC_TYPE_MYOBJ, NULL);
do_test ((NULL != import_obj), "#3 new object create");
qof_instance_init (&import_obj->inst, TEST_MODULE_NAME, import);
qof_instance_init_data (&import_obj->inst, TEST_MODULE_NAME, import);
do_test ((NULL != &import_obj->inst), "#4 instance init");
obj_setGUID(import_obj,qof_instance_get_guid(&import_obj->inst));
do_test ((NULL != &import_obj->obj_guid), "#5 guid set");
@ -310,8 +342,8 @@ test_merge (void)
minor = 3;
/* second import object - test results would be the same, so not tested. */
new_obj = g_new(myobj, 1);
qof_instance_init (&new_obj->inst, TEST_MODULE_NAME, import);
new_obj = g_object_new(GNC_TYPE_MYOBJ, NULL);
qof_instance_init_data (&new_obj->inst, TEST_MODULE_NAME, import);
obj_setGUID(new_obj,qof_instance_get_guid(&new_obj->inst));
qof_event_gen (&new_obj->inst, QOF_EVENT_CREATE, NULL);
obj_setName(new_obj, import_init);
@ -330,8 +362,8 @@ test_merge (void)
tc.tv_nsec = 0;
/* target object - test results would be the same, so not tested. */
target_obj = g_new(myobj, 1);
qof_instance_init (&target_obj->inst, TEST_MODULE_NAME, target);
target_obj = g_object_new(GNC_TYPE_MYOBJ, NULL);
qof_instance_init_data (&target_obj->inst, TEST_MODULE_NAME, target);
obj_setGUID(target_obj,qof_instance_get_guid(&target_obj->inst));
qof_event_gen (&target_obj->inst, QOF_EVENT_CREATE, NULL);
obj_setName(target_obj, target_init);

View File

@ -65,6 +65,11 @@ typedef struct child_s
gint64 minor;
}mychild;
typedef struct childClass_s
{
QofInstanceClass parent_class;
} mychildClass;
/* simple object structure */
typedef struct parent_s
{
@ -80,6 +85,11 @@ typedef struct parent_s
gint64 minor;
}myparent;
typedef struct parentClass_s
{
QofInstanceClass parent_class;
} myparentClass;
/* simple object structure */
typedef struct grand_s
{
@ -96,6 +106,11 @@ typedef struct grand_s
gint64 minor;
}mygrand;
typedef struct grandClass_s
{
QofInstanceClass parent_class;
} mygrandClass;
mygrand* grand_create(QofBook*);
myparent* parent_create(QofBook*);
mychild* child_create(QofBook*);
@ -164,14 +179,95 @@ gint32 child_getVersion(mychild*);
gint64 child_getMinor(mychild*);
gchar child_getFlag(mychild*);
/* --- type macros --- */
#define GNC_TYPE_MYCHILD (gnc_mychild_get_type ())
#define GNC_MYCHILD(o) \
(G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_MYCHILD, mychild))
#define GNC_MYCHILD_CLASS(k) \
(G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_MYCHILD, mychildClass))
#define GNC_IS_MYCHILD(o) \
(G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_MYCHILD))
#define GNC_IS_MYCHILD_CLASS(k) \
(G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_MYCHILD))
#define GNC_MYCHILD_GET_CLASS(o) \
(G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_MYCHILD, mychildClass))
GType gnc_mychild_get_type(void);
/* --- type macros --- */
#define GNC_TYPE_MYPARENT (gnc_myparent_get_type ())
#define GNC_MYPARENT(o) \
(G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_MYPARENT, myparent))
#define GNC_MYPARENT_CLASS(k) \
(G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_MYPARENT, myparentClass))
#define GNC_IS_MYPARENT(o) \
(G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_MYPARENT))
#define GNC_IS_MYPARENT_CLASS(k) \
(G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_MYPARENT))
#define GNC_MYPARENT_GET_CLASS(o) \
(G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_MYPARENT, myparentClass))
GType gnc_myparent_get_type(void);
/* --- type macros --- */
#define GNC_TYPE_MYGRAND (gnc_mygrand_get_type ())
#define GNC_MYGRAND(o) \
(G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_MYGRAND, mygrand))
#define GNC_MYGRAND_CLASS(k) \
(G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_MYGRAND, mygrandClass))
#define GNC_IS_MYGRAND(o) \
(G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_MYGRAND))
#define GNC_IS_MYGRAND_CLASS(k) \
(G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_MYGRAND))
#define GNC_MYGRAND_GET_CLASS(o) \
(G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_MYGRAND, mygrandClass))
GType gnc_mygrand_get_type(void);
/* GObject Initialization */
QOF_GOBJECT_IMPL(gnc_mychild, mychild, QOF_TYPE_INSTANCE);
static void
gnc_mychild_init(mychild* obj)
{
}
static void
gnc_mychild_finalize_real(GObject* objp)
{
}
/* GObject Initialization */
QOF_GOBJECT_IMPL(gnc_myparent, myparent, QOF_TYPE_INSTANCE);
static void
gnc_myparent_init(myparent* obj)
{
}
static void
gnc_myparent_finalize_real(GObject* objp)
{
}
/* GObject Initialization */
QOF_GOBJECT_IMPL(gnc_mygrand, mygrand, QOF_TYPE_INSTANCE);
static void
gnc_mygrand_init(mygrand* obj)
{
}
static void
gnc_mygrand_finalize_real(GObject* objp)
{
}
mygrand*
grand_create(QofBook *book)
{
mygrand *g;
g_return_val_if_fail(book, NULL);
g = g_new0(mygrand, 1);
qof_instance_init (&g->inst, GRAND_MODULE_NAME, book);
g = g_object_new(GNC_TYPE_MYGRAND, NULL);
qof_instance_init_data (&g->inst, GRAND_MODULE_NAME, book);
g->date = *get_random_timespec();
g->discount = get_random_double();;
g->active = get_random_boolean();
@ -192,8 +288,8 @@ parent_create(QofBook *book)
myparent *g;
g_return_val_if_fail(book, NULL);
g = g_new0(myparent, 1);
qof_instance_init (&g->inst, PARENT_MODULE_NAME, book);
g = g_object_new(GNC_TYPE_MYPARENT, NULL);
qof_instance_init_data (&g->inst, PARENT_MODULE_NAME, book);
g->date = *get_random_timespec();
g->discount = get_random_double();
g->active = get_random_boolean();
@ -213,8 +309,8 @@ child_create(QofBook *book)
mychild *g;
g_return_val_if_fail(book, NULL);
g = g_new0(mychild, 1);
qof_instance_init (&g->inst, CHILD_MODULE_NAME, book);
g = g_object_new(GNC_TYPE_MYCHILD, NULL);
qof_instance_init_data (&g->inst, CHILD_MODULE_NAME, book);
g->date = *get_random_timespec();
g->discount = get_random_double();
g->active = get_random_boolean();