00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <glib.h>
00026
00027 #include "qof.h"
00028
00029 #include "test-stuff.h"
00030
00031 #define TEST_MODULE_NAME "object-test"
00032 #define TEST_MODULE_DESC "Test Object"
00033
00034 static void obj_foreach (QofCollection *, QofEntityForeachCB, gpointer);
00035 static const char *printable (gpointer obj);
00036 static void test_printable (const char *name, gpointer obj);
00037 static void test_foreach (QofBook *, const char *);
00038
00039 static QofObject bus_obj = {
00040 interface_version:QOF_OBJECT_VERSION,
00041 e_type:TEST_MODULE_NAME,
00042 type_label:TEST_MODULE_DESC,
00043 create:NULL,
00044 book_begin:NULL,
00045 book_end:NULL,
00046 is_dirty:NULL,
00047 mark_clean:NULL,
00048 foreach:obj_foreach,
00049 printable:printable,
00050 version_cmp:NULL,
00051 };
00052
00053 static void
00054 test_object (void)
00055 {
00056 QofBook *book = qof_book_new ();
00057
00058 do_test ((NULL != book), "book null");
00059
00060
00061 {
00062 do_test (!qof_object_register (NULL), "register NULL");
00063 do_test (qof_object_register (&bus_obj), "register test object");
00064 do_test (!qof_object_register (&bus_obj),
00065 "register test object again");
00066 do_test (qof_object_lookup (TEST_MODULE_NAME) == &bus_obj,
00067 "lookup our installed object");
00068 do_test (qof_object_lookup ("snm98sn snml say dyikh9y9ha") == NULL,
00069 "lookup non-existant object object");
00070
00071 do_test (!safe_strcmp (qof_object_get_type_label (TEST_MODULE_NAME),
00072 (TEST_MODULE_DESC)),
00073 "test description return");
00074 }
00075
00076 test_foreach (book, TEST_MODULE_NAME);
00077 test_printable (TEST_MODULE_NAME, (gpointer) 1);
00078 }
00079
00080 static void
00081 obj_foreach (QofCollection * col, QofEntityForeachCB cb, gpointer u_d)
00082 {
00083 int *foo = u_d;
00084
00085 do_test (col != NULL, "foreach: NULL collection");
00086 success ("called foreach callback");
00087
00088 *foo = 1;
00089 }
00090
00091 static void
00092 foreachCB (QofEntity * ent, gpointer u_d)
00093 {
00094 do_test (FALSE, "FAIL");
00095 }
00096
00097 static const char *
00098 printable (gpointer obj)
00099 {
00100 do_test (obj != NULL, "printable: object is NULL");
00101 success ("called printable callback");
00102 return ((const char *) obj);
00103 }
00104
00105 static void
00106 test_foreach (QofBook * book, const char *name)
00107 {
00108 int res = 0;
00109
00110 qof_object_foreach (NULL, NULL, NULL, &res);
00111 do_test (res == 0, "object: Foreach: NULL, NULL, NULL");
00112 qof_object_foreach (NULL, NULL, foreachCB, &res);
00113 do_test (res == 0, "object: Foreach: NULL, NULL, foreachCB");
00114
00115 qof_object_foreach (NULL, book, NULL, &res);
00116 do_test (res == 0, "object: Foreach: NULL, book, NULL");
00117 qof_object_foreach (NULL, book, foreachCB, &res);
00118 do_test (res == 0, "object: Foreach: NULL, book, foreachCB");
00119
00120 qof_object_foreach (name, NULL, NULL, &res);
00121 do_test (res == 0, "object: Foreach: name, NULL, NULL");
00122 qof_object_foreach (name, NULL, foreachCB, &res);
00123 do_test (res == 0, "object: Foreach: name, NULL, foreachCB");
00124
00125 qof_object_foreach (name, book, NULL, &res);
00126 do_test (res != 0, "object: Foreach: name, book, NULL");
00127
00128 res = 0;
00129 qof_object_foreach (name, book, foreachCB, &res);
00130 do_test (res != 0, "object: Foreach: name, book, foreachCB");
00131 }
00132
00133 static void
00134 test_printable (const char *name, gpointer obj)
00135 {
00136 const char *res;
00137
00138 do_test (qof_object_printable (NULL, NULL) == NULL,
00139 "object: Printable: NULL, NULL");
00140 do_test (qof_object_printable (NULL, obj) == NULL,
00141 "object: Printable: NULL, object");
00142 do_test (qof_object_printable (name, NULL) == NULL,
00143 "object: Printable: mod_name, NULL");
00144 res = qof_object_printable (name, obj);
00145 do_test (res != NULL, "object: Printable: mod_name, object");
00146 }
00147
00148 int
00149 main (int argc, char **argv)
00150 {
00151 qof_init ();
00152 test_object ();
00153 print_test_results ();
00154 qof_close ();
00155 return get_rv ();
00156 }