28 #include "test-stuff.h" 30 #define TEST_MODULE_NAME "object-test" 31 #define TEST_MODULE_DESC "Test Object" 32 #define DYNAMIC_MOD_NAME "dynamic_test" 33 #define DYNAMIC_MOD_DESC "Full test of adding arbitrary objects" 36 static const gchar *printable (gpointer obj);
37 static void test_printable (
const gchar *name, gpointer obj);
38 static void test_foreach (
QofBook *,
const gchar *);
42 .e_type = TEST_MODULE_NAME,
43 .type_label = TEST_MODULE_DESC,
49 .foreach = obj_foreach,
50 .printable = printable,
54 static G_GNUC_UNUSED
const gchar *
55 test_dyn_printable (gpointer obj)
68 g_return_val_if_fail (book, NULL);
73 all = g_list_prepend (all, inst);
85 do_test (!
safe_strcmp (DYNAMIC_MOD_NAME, ent->e_type),
"e_type check for string");
93 do_test (!
safe_strcmp (DYNAMIC_MOD_NAME, ent->e_type),
"e_type check for int");
101 do_test (!
safe_strcmp (DYNAMIC_MOD_NAME, ent->e_type),
"e_type check for int");
106 add_boolean_param (
void)
111 p->param_name =
"test_boolean";
112 p->param_type = QOF_TYPE_BOOLEAN;
122 do_test (!
safe_strcmp (DYNAMIC_MOD_NAME, ent->e_type),
"e_type check for bool");
123 boolean_getter = (gboolean (*)(QofEntity *,
QofParam *)) p->param_getfcn;
124 b = boolean_getter (ent, (
QofParam*)p);
129 test_class_register (
void)
138 p->param_name =
"test_string";
139 p->param_type = QOF_TYPE_STRING;
143 p->param_name =
"test_int";
144 p->param_type = QOF_TYPE_INT32;
147 list[2] = *add_boolean_param ();
156 test_dynamic_object (
void)
161 const gchar * message;
163 gint t, (*int32_getter) (QofEntity *,
QofParam *);
167 do_test ((NULL != book),
"book null");
170 dynamic->e_type = DYNAMIC_MOD_NAME;
171 dynamic->type_label = DYNAMIC_MOD_DESC;
172 dynamic->
foreach = obj_foreach;
173 dynamic->
create = (gpointer) dyn_create;
177 do_test (check != NULL,
"dynamic object lookup");
179 do_test (!
safe_strcmp(message,
"Full test of adding arbitrary objects"),
180 "dynamic object type_label");
182 do_test (check->
printable != NULL,
"dynamic printable support");
184 do_test (message != NULL,
"dynamic object printable");
186 do_test (message != NULL,
"dynamic direct printable");
191 s = p->param_getfcn (d_ent, p);
192 do_test (!
safe_strcmp(s,
"test_string"),
"get string from dynamic object");
195 int32_getter = (gint32 (*)(QofEntity *,
QofParam *)) p->param_getfcn;
196 t = int32_getter ((QofEntity*)d_ent, (
QofParam*)p);
197 do_test (t == 1,
"get int from dynamic object");
199 do_test (test_boolean_param((QofEntity*)d_ent, p),
200 "get boolean from dynamic object");
208 do_test ((NULL != book),
"book null");
215 "register test object again");
217 "lookup our installed object");
219 "lookup non-existant object object");
223 "test description return");
226 test_foreach (book, TEST_MODULE_NAME);
227 test_printable (TEST_MODULE_NAME, (gpointer) 1);
236 do_test (col != NULL,
"foreach: NULL collection");
237 success (
"called foreach callback");
243 foreachCB (QofEntity * ent __attribute__ ((unused)),
244 gpointer u_d __attribute__ ((unused)))
246 do_test (FALSE,
"FAIL");
250 printable (gpointer obj)
252 do_test (obj != NULL,
"printable: object is NULL");
253 success (
"called printable callback");
254 return ((
const char *) obj);
258 test_foreach (
QofBook * book,
const char *name)
263 do_test (res == 0,
"object: Foreach: NULL, NULL, NULL");
265 do_test (res == 0,
"object: Foreach: NULL, NULL, foreachCB");
268 do_test (res == 0,
"object: Foreach: NULL, book, NULL");
270 do_test (res == 0,
"object: Foreach: NULL, book, foreachCB");
273 do_test (res == 0,
"object: Foreach: name, NULL, NULL");
275 do_test (res == 0,
"object: Foreach: name, NULL, foreachCB");
278 do_test (res != 0,
"object: Foreach: name, book, NULL");
282 do_test (res != 0,
"object: Foreach: name, book, foreachCB");
286 test_printable (
const char *name, gpointer obj)
291 "object: Printable: NULL, NULL");
293 "object: Printable: NULL, object");
295 "object: Printable: mod_name, NULL");
297 do_test (res != NULL,
"object: Printable: mod_name, object");
305 test_dynamic_object ();
306 print_test_results ();
gpointer qof_object_new_instance(QofIdTypeConst type_name, QofBook *book)
QofCollection * qof_book_get_collection(QofBook *book, QofIdType entity_type)
gboolean qof_class_is_registered(QofIdTypeConst obj_name)
#define QOF_OBJECT_VERSION
void qof_object_foreach(QofIdTypeConst type_name, QofBook *book, QofEntityForeachCB cb, gpointer user_data)
const QofObject * qof_object_lookup(QofIdTypeConst name)
void qof_class_register(QofIdTypeConst obj_name, QofSortFunc default_sort_function, const QofParam *params)
registers a new object class with the Qof subsystem.
void(* QofEntityForeachCB)(QofEntity *, gpointer user_data)
QofBook * qof_book_new(void)
gpointer(* create)(QofBook *)
const gchar * qof_object_get_type_label(QofIdTypeConst type_name)
struct QofCollection_s QofCollection
const QofParam * qof_class_get_parameter(QofIdTypeConst obj_name, const gchar *parameter)
const gchar * qof_object_printable(QofIdTypeConst type_name, gpointer obj)
void qof_collection_set_data(QofCollection *col, gpointer user_data)
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
gboolean qof_object_register(const QofObject *object)
void qof_close(void)
Safely close down the Query Object Framework.
gpointer qof_collection_get_data(QofCollection *col)
const gchar *(* printable)(gpointer instance)
void(* foreach)(QofCollection *, QofEntityForeachCB, gpointer)
gint safe_strcmp(const gchar *da, const gchar *db)
void qof_instance_init(QofInstance *inst, QofIdType type, QofBook *book)
void qof_init(void)
Initialise the Query Object Framework.