32 #include "test-stuff.h" 35 #define TEST_MODULE_NAME "object_test" 36 #define TEST_MODULE_DESC "Test Object" 37 #define OBJ_AMOUNT "anamount" 59 g_return_val_if_fail (book, NULL);
60 d = g_new0 (dyn_obj, 1);
74 dyn_getAmount (dyn_obj * e)
81 static G_GNUC_UNUSED
const gchar *
82 test_dyn_printable (gpointer obj)
89 .e_type = TEST_MODULE_NAME,
90 .type_label = TEST_MODULE_DESC,
91 .create = (gpointer)dyn_create,
97 .printable = test_dyn_printable,
102 dyn_objRegister (
void)
105 {OBJ_AMOUNT, QOF_TYPE_NUMERIC, (
QofAccessFunc) dyn_getAmount,
113 {NULL, NULL, NULL, NULL, NULL},
122 dyn_foreach (
QofParam * param, gpointer user_data)
124 do_test (param != NULL,
"Fail");
128 dyn_foreach2 (
QofEntity * ent, gpointer user_data)
130 do_test (ent != NULL,
"Fail");
143 gchar * sql_str, * gstr, * test, * err, *rand_str;
149 do_test (inst != NULL,
"object new instance");
150 g_return_if_fail (inst);
152 rand_str = g_strescape (get_random_string (), NULL);
154 do_test (slots != NULL,
"creating some slots");
157 err = g_strdup_printf (
"compare slots: %s", test);
162 do_test (ent != NULL,
"convert to entity");
167 rand_dbl = get_random_double ();
171 test = g_strdup (
"CREATE TABLE object_test ( guid char(32) primary key not null, " 172 "anamount text, dbversion int ); CREATE TABLE sql_kvp (kvp_id int " 173 "primary key not null, guid char(32), path mediumtext, type mediumtext, " 174 "value text, dbversion int );");
176 g_strdup_printf (
"Create table SQL statement:%s:%s", sql_str, test));
185 test = g_strdup_printf (
"INSERT into object_test (guid , anamount) VALUES " 186 "('%s' , '%s'); INSERT into sql_kvp (kvp_id, guid, type, path, value) " 187 "VALUES ('%ld', '%s', 'string', '/debug/test/string', '%s');",
188 gstr, num_str, kvp_id, gstr, rand_str);
189 err = g_strdup_printf (
"Insert entity SQL statement:%s:%s", sql_str, test);
198 do_test (param != NULL,
"no OBJ_AMOUNT parameter");
200 do_test (sql_str != NULL,
"failed to mark instance as dirty");
201 test = g_strdup_printf (
"UPDATE object_test SET anamount = '%s' WHERE " 202 "guid='%s';", num_str, gstr);
203 err = g_strdup_printf (
"Update entity SQL statement: %s", sql_str);
210 test = g_strdup_printf (
"UPDATE sql_kvp SET type='string', value='%s' " 211 "WHERE path='/debug/test/string' and guid='%s';", rand_str, gstr);
212 err = g_strdup_printf (
"Update entity SQL statement: %s", sql_str);
221 test = g_strconcat (
"DELETE from object_test WHERE guid='", gstr,
"';",
222 "DELETE from sql_kvp WHERE kvp_id ='", gstr,
"';", NULL);
223 err = g_strdup_printf (
"DELETE entity SQL statement: %s", sql_str);
230 err = g_strdup_printf (
"DROP TABLE SQL statement: %s", sql_str);
231 do_test (0 ==
safe_strcasecmp (sql_str,
"DROP TABLE object_test;"), err);
244 do_test ((NULL != book),
"book null");
245 do_test (dyn_objRegister() == TRUE,
"register test object");
247 "lookup our installed object");
253 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)
gboolean qof_collection_is_dirty(QofCollection *col)
void qof_class_param_foreach(QofIdTypeConst obj_name, QofParamForeachCB cb, gpointer user_data)
#define QOF_OBJECT_VERSION
gchar * qof_sql_entity_insert(QofEntity *ent)
Build a SQL 'INSERT' statement for this entity.
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.
struct _KvpFrame KvpFrame
QofBook * qof_book_new(void)
gint safe_strcasecmp(const gchar *da, const gchar *db)
gulong qof_sql_entity_get_kvp_id(void)
Get the index value of the KVP table after the operation(s).
QofBook * qof_instance_get_book(QofInstance *inst)
#define GUID_ENCODING_LENGTH
void(* QofSetterFunc)(gpointer, gpointer)
gchar * qof_sql_entity_update(QofEntity *ent)
Build a SQL 'UPDATE' statement for the current entity parameter.
gchar * qof_sql_entity_create_table(QofEntity *ent)
Build a SQL 'CREATE' statement for this entity.
struct QofCollection_s QofCollection
const QofParam * qof_class_get_parameter(QofIdTypeConst obj_name, const gchar *parameter)
const GUID * qof_instance_get_guid(QofInstance *inst)
KvpFrame * qof_instance_get_slots(QofInstance *inst)
void qof_collection_foreach(QofCollection *col, QofEntityForeachCB cb_func, gpointer user_data)
gchar * guid_to_string_buff(const GUID *guid, gchar *buff)
void qof_sql_entity_set_kvp_exists(gboolean exist)
Set or clear a flag that the KVP table exists or not.
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
Private QOF SQL generation routines.
void qof_collection_mark_clean(QofCollection *)
gchar * qof_sql_entity_update_kvp(QofEntity *ent)
Build a SQL 'UPDATE' statement for the KVP data in this entity.
gchar * qof_sql_entity_drop_table(QofEntity *ent)
Build a SQL 'DROP' statement for this entity type.
gchar * qof_numeric_to_string(QofNumeric n)
gboolean qof_object_register(const QofObject *object)
void qof_close(void)
Safely close down the Query Object Framework.
struct QofTime64 QofTime
Use a 64-bit signed int QofTime.
QofNumeric qof_numeric_from_double(gdouble in, gint64 denom, gint how)
static QofNumeric qof_numeric_zero(void)
int qof_instance_version_cmp(QofInstance *left, QofInstance *right)
void qof_instance_init(QofInstance *inst, QofIdType type, QofBook *book)
void qof_init(void)
Initialise the Query Object Framework.
gchar * qof_sql_entity_delete(QofEntity *ent)
Build a SQL 'DELETE' statement for this entity.
void kvp_frame_set_string(KvpFrame *frame, const gchar *path, const gchar *str)
Store a copy of the string at the indicated path.