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,
00082 QofEntityForeachCB cb __attribute__ ((unused)), gpointer u_d)
00083 {
00084 int *foo = u_d;
00085
00086 do_test (col != NULL, "foreach: NULL collection");
00087 success ("called foreach callback");
00088
00089 *foo = 1;
00090 }
00091
00092 static void
00093 foreachCB (QofEntity * ent __attribute__ ((unused)),
00094 gpointer u_d __attribute__ ((unused)))
00095 {
00096 do_test (FALSE, "FAIL");
00097 }
00098
00099 static const char *
00100 printable (gpointer obj)
00101 {
00102 do_test (obj != NULL, "printable: object is NULL");
00103 success ("called printable callback");
00104 return ((const char *) obj);
00105 }
00106
00107 static void
00108 test_foreach (QofBook * book, const char *name)
00109 {
00110 int res = 0;
00111
00112 qof_object_foreach (NULL, NULL, NULL, &res);
00113 do_test (res == 0, "object: Foreach: NULL, NULL, NULL");
00114 qof_object_foreach (NULL, NULL, foreachCB, &res);
00115 do_test (res == 0, "object: Foreach: NULL, NULL, foreachCB");
00116
00117 qof_object_foreach (NULL, book, NULL, &res);
00118 do_test (res == 0, "object: Foreach: NULL, book, NULL");
00119 qof_object_foreach (NULL, book, foreachCB, &res);
00120 do_test (res == 0, "object: Foreach: NULL, book, foreachCB");
00121
00122 qof_object_foreach (name, NULL, NULL, &res);
00123 do_test (res == 0, "object: Foreach: name, NULL, NULL");
00124 qof_object_foreach (name, NULL, foreachCB, &res);
00125 do_test (res == 0, "object: Foreach: name, NULL, foreachCB");
00126
00127 qof_object_foreach (name, book, NULL, &res);
00128 do_test (res != 0, "object: Foreach: name, book, NULL");
00129
00130 res = 0;
00131 qof_object_foreach (name, book, foreachCB, &res);
00132 do_test (res != 0, "object: Foreach: name, book, foreachCB");
00133 }
00134
00135 static void
00136 test_printable (const char *name, gpointer obj)
00137 {
00138 const char *res;
00139
00140 do_test (qof_object_printable (NULL, NULL) == NULL,
00141 "object: Printable: NULL, NULL");
00142 do_test (qof_object_printable (NULL, obj) == NULL,
00143 "object: Printable: NULL, object");
00144 do_test (qof_object_printable (name, NULL) == NULL,
00145 "object: Printable: mod_name, NULL");
00146 res = qof_object_printable (name, obj);
00147 do_test (res != NULL, "object: Printable: mod_name, object");
00148 }
00149
00150 int
00151 main (void)
00152 {
00153 qof_init ();
00154 test_object ();
00155 print_test_results ();
00156 qof_close ();
00157 return get_rv ();
00158 }