27 #include "qofinstance-p.h" 28 #include "qofevent-p.h" 29 #include "test-stuff.h" 31 #define TEST_MODULE_NAME "book-merge-test" 32 #define TEST_MODULE_DESC "Test Book Merge" 33 #define OBJ_NAME "somename" 34 #define OBJ_AMOUNT "anamount" 35 #define OBJ_DATE "nottoday" 36 #define OBJ_GUID "unique" 37 #define OBJ_DISCOUNT "hefty" 38 #define OBJ_VERSION "early" 39 #define OBJ_MINOR "tiny" 40 #define OBJ_ACTIVE "ofcourse" 41 #define OBJ_FLAG "tiny_flag" 45 static void test_merge (
void);
46 gboolean myobjRegister (
void);
67 obj_setGUID (myobj * g,
const GUID * h)
78 g_return_val_if_fail (book, NULL);
92 obj_setFlag (myobj * g,
char f)
99 obj_getFlag (myobj * g)
101 g_return_val_if_fail (g,
'n');
106 obj_setMinor (myobj * g, gint64 h)
108 g_return_if_fail (g != NULL);
113 obj_getMinor (myobj * g)
115 g_return_val_if_fail ((g != NULL), 0);
120 obj_setVersion (myobj * g, gint32 h)
122 g_return_if_fail (g != NULL);
127 obj_getVersion (myobj * g)
135 obj_setActive (myobj * g, gboolean h)
143 obj_getActive (myobj * g)
151 obj_setDiscount (myobj * g, gdouble h)
159 obj_getDiscount (myobj * g)
167 obj_setDate (myobj * g,
QofTime *h)
171 do_test ((h != NULL),
"passed a NULL time");
172 do_test ((qof_time_is_valid (h) == TRUE),
173 "passed an invalid time");
178 obj_getDate (myobj * g)
182 do_test ((g->date != NULL),
"stored time is NULL");
183 do_test ((qof_time_is_valid (g->date) == TRUE),
184 "stored time is invalid");
189 obj_getGUID (myobj * g)
197 obj_setName (myobj * g,
char *h)
201 g->Name = strdup (h);
205 obj_getName (myobj * g)
221 obj_getAmount (myobj * g)
230 .e_type = TEST_MODULE_NAME,
231 .type_label = TEST_MODULE_DESC,
232 .create = (gpointer) obj_create,
239 .version_cmp = (gint (*)(gpointer, gpointer))
249 {OBJ_AMOUNT, QOF_TYPE_NUMERIC, (
QofAccessFunc) obj_getAmount,
255 {OBJ_DISCOUNT, QOF_TYPE_DOUBLE, (
QofAccessFunc) obj_getDiscount,
257 {OBJ_ACTIVE, QOF_TYPE_BOOLEAN, (
QofAccessFunc) obj_getActive,
259 {OBJ_VERSION, QOF_TYPE_INT32, (
QofAccessFunc) obj_getVersion,
269 {NULL, NULL, NULL, NULL, NULL},
281 gdouble init_value, discount;
282 myobj *import_obj, *target_obj, *new_obj;
283 QofTime *base_time, *temp_time;
287 gchar *import_init, *target_init;
288 gchar flag, flag_check;
295 flag = get_random_character ();
298 version = get_random_int_in_range (0, 10000);
299 minor = get_random_int_in_range (1000001, 2000000);
300 import_init =
"test";
301 target_init =
"testing";
303 do_test ((TRUE == qof_time_is_valid (base_time)),
304 "invalid init time");
312 "2006-07-19 11:39:54.568714241 +0000", str)),
313 "failed to compare base_time correctly.");
318 do_test ((NULL != target),
"#1 target book is NULL");
319 do_test ((NULL !=
import),
"#2 import book is NULL");
322 import_obj = g_new (myobj, 1);
323 do_test ((NULL != import_obj),
"#3 new object create");
325 do_test ((NULL != &import_obj->inst),
"#4 instance init");
327 do_test ((NULL != &import_obj->obj_guid),
"#5 guid set");
329 do_test ((NULL != &import_obj->inst.entity),
"#6 gnc event create");
330 obj_setName (import_obj, import_init);
331 do_test ((NULL != &import_obj->Name),
"#7 string set");
333 obj_setAmount (import_obj, obj_amount);
335 "#8 gnc_numeric set");
336 obj_setActive (import_obj, active);
337 do_test ((FALSE != &import_obj->active),
"#9 gboolean set");
338 obj_setDiscount (import_obj, discount);
339 obj_setVersion (import_obj, version);
340 do_test ((version == import_obj->version),
"#11 gint32 set");
341 obj_setMinor (import_obj, minor);
342 do_test ((minor == import_obj->minor),
"#12 gint64 set");
343 do_test ((TRUE == qof_time_is_valid (base_time)),
344 "invalid import time ts");
352 "2006-07-19 11:39:54.568714241 +0000", str)),
353 "failed to compare base_time correctly.");
357 obj_setDate (import_obj, base_time);
358 do_test ((TRUE == qof_time_is_valid (import_obj->date)),
359 "invalid import time");
360 do_test ((
qof_time_cmp (base_time, import_obj->date) == 0),
361 "test #13 date set");
362 obj_setFlag (import_obj, flag);
363 do_test ((flag == obj_getFlag (import_obj)),
"#14 flag set");
367 discount = get_random_double ();
372 new_obj = g_new (myobj, 1);
376 obj_setName (new_obj, import_init);
377 obj_setAmount (new_obj, obj_amount);
378 obj_setActive (new_obj, active);
379 obj_setDiscount (new_obj, discount);
380 obj_setVersion (new_obj, version);
381 obj_setMinor (new_obj, minor);
382 do_test ((TRUE == qof_time_is_valid (base_time)),
383 "second import time invalid");
391 "2006-07-19 11:39:54.568714241 +0000", str)),
392 "failed to compare base_time correctly.");
396 obj_setDate (new_obj, base_time);
397 obj_setFlag (new_obj, flag);
401 discount = get_random_double ();
407 target_obj = g_new (myobj, 1);
411 obj_setName (target_obj, target_init);
412 obj_setAmount (target_obj, obj_amount);
413 obj_setActive (target_obj, active);
414 obj_setDiscount (target_obj, discount);
415 obj_setVersion (target_obj, version);
416 obj_setMinor (target_obj, minor);
424 "2006-07-19 11:39:54.568714241 +0000", str)),
425 "failed to compare base_time correctly.");
430 do_test ((TRUE == qof_time_is_valid (temp_time)),
431 "time add secs returned invalid");
432 obj_setDate (target_obj, temp_time);
433 obj_setFlag (target_obj, flag);
434 do_test ((flag == obj_getFlag (target_obj)),
"#15 flag set");
437 do_test (mergeData != NULL,
438 "FATAL: Merge could not be initialised!\t aborting . . ");
439 g_return_if_fail (mergeData != NULL);
449 obj_getName (target_obj))) != 0),
450 "Init value test #1");
456 do_test (((
safe_strcmp (import_init, obj_getName (target_obj))) == 0),
457 "Merged value test #1");
461 (obj_getName (target_obj), obj_getName (import_obj))) == 0),
462 "Merged value test #2");
466 "import gnc_numeric check");
468 "target gnc_numeric check");
480 temp_time = target_obj->date;
488 "2006-07-19 11:39:54.568714241 +0000", str)),
489 "failed to compare base_time after merge.");
500 "2006-07-19 11:39:54.568714241 +0000", str)),
501 "failed to compare target time after merge.");
506 "date value check: 1");
508 DEBUG (
" import<->target=%d\n",
515 DEBUG (
" base_time=%" G_GINT64_FORMAT
518 DEBUG (
" import:\nyear=%" G_GINT64_FORMAT
519 " month=%ld day=%ld hour=%ld min=%ld sec=%" 520 G_GINT64_FORMAT
"nsecs=%ld\n",
524 DEBUG (
" import=%s\n", check);
529 DEBUG (
" target:\nyear=%" G_GINT64_FORMAT
530 " month=%ld day=%ld hour=%ld min=%ld sec=%" 531 G_GINT64_FORMAT
"nsecs=%ld\n",
535 DEBUG (
" target=%s\n", check);
542 flag_check = obj_getFlag (target_obj);
543 do_test ((flag_check == obj_getFlag (import_obj)),
"flag value check: 1");
544 do_test ((obj_getFlag (import_obj) == obj_getFlag (target_obj)),
545 "flag value check: 2");
556 gboolean skip_target;
562 do_test ((rule != NULL),
"loop:#1 Rule is NULL");
563 do_test (remainder > 0,
"loop:#2 remainder error.");
565 "loop:#3 object label\n");
567 "loop:#4 empty import entity");
577 "loop: entity type mismatch");
580 "loop: empty parameter list");
583 while (testing != NULL)
585 eachParam = testing->data;
586 do_test ((eachParam != NULL),
"loop:#8 no QofParam data");
587 do_test ((eachParam->param_name != NULL),
588 "loop:#9 no parameter name");
589 do_test ((eachParam->param_getfcn != NULL),
590 "loop:#10 no get function");
591 do_test ((eachParam->param_setfcn != NULL),
592 "loop:#11 no set function");
594 if (
safe_strcmp (eachParam->param_type, QOF_TYPE_STRING) == 0)
597 g_strdup (eachParam->
598 param_getfcn (rule->
importEnt, eachParam));
599 do_test ((importstring != NULL),
600 "loop:#12 direct get_fcn import");
601 do_test ((
safe_strcmp (importstring,
"test") == 0),
602 "loop:#13 direct import comparison");
606 eachParam->param_getfcn (rule->
targetEnt, eachParam);
607 do_test ((targetstring != NULL),
608 "loop:#14 direct get_fcn target");
609 do_test ((
safe_strcmp (targetstring,
"testing") == 0),
610 "loop:#15 direct target comparison");
616 do_test ((importstring != NULL),
617 "loop:#16 import param_as_string is null");
621 do_test ((targetstring != NULL),
622 "loop:#17 target param_as_string is null");
624 testing = g_slist_next (testing);
630 "update result fail");
639 print_test_results ();
QofNumericErrorCode qof_numeric_check(QofNumeric in)
gint64 qd_year
Extended version to cope with full range of dates.
#define PERR(format, args...)
gint qof_numeric_compare(QofNumeric a, QofNumeric b)
void qof_date_free(QofDate *date)
QofDate * qof_date_from_qtime(const QofTime *qt)
#define QOF_OBJECT_VERSION
gint qof_book_merge_commit(QofBookMergeData *mergeData)
Commits the import data to the target book.
QofTime * qof_time_add_secs_copy(QofTime *qt, QofTimeSecs secs)
Create a new QofTime, secs different to an original.
QofTimeSecs qof_time_get_secs(const QofTime *qt)
Get the number of seconds.
void qof_class_register(QofIdTypeConst obj_name, QofSortFunc default_sort_function, const QofParam *params)
registers a new object class with the Qof subsystem.
QofBook * qof_book_new(void)
gchar * qof_date_print(const QofDate *date, QofDateFormat df)
Convert a QofDate to a timestamp according to the specified date format.
glong qof_time_get_nanosecs(const QofTime *qt)
Get the number of seconds.
QofBook * qof_instance_get_book(QofInstance *inst)
Full range replacement for struct tm.
void qof_event_gen(QofEntity *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
void(* QofSetterFunc)(gpointer, gpointer)
const GUID * qof_instance_get_guid(QofInstance *inst)
glong qd_hour
Signed replacement of struct tm.tm_hour.
QofBookMergeResult mergeResult
void qof_time_free(QofTime *qt)
Free a QofTime when no longer required.
glong qd_min
Signed replacement of struct tm.tm_min.
void qof_collection_foreach(QofCollection *col, QofEntityForeachCB cb_func, gpointer user_data)
gint qof_time_cmp(const QofTime *ta, const QofTime *tb)
glong qd_mon
Signed replacement of struct tm.tm_mon.
void qof_book_merge_rule_foreach(QofBookMergeData *mergeData, QofBookMergeRuleForeachCB cb, QofBookMergeResult mergeResult)
Dialogue Control Callback.
#define DEBUG(format, args...)
gchar * qof_util_param_to_string(QofEntity *ent, const QofParam *param)
Converts a parameter to a string for storage or display.
#define QOF_DATE_FORMAT_ISO8601
One rule per entity, built into a single GList for the entire merge.
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
QofTime * qof_time_set(QofTimeSecs t, glong nanosecs)
QofBookMergeData * qof_book_merge_init(QofBook *importBook, QofBook *targetBook)
Initialise the QofBookMerge process.
QofBookMergeRule * currentRule
gboolean qof_object_register(const QofObject *object)
void qof_close(void)
Safely close down the Query Object Framework.
QofNumeric qof_numeric_add(QofNumeric a, QofNumeric b, gint64 denom, gint how)
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)
gint safe_strcmp(const gchar *da, const gchar *db)
QofBookMergeData * qof_book_merge_update_result(QofBookMergeData *mergeData, QofBookMergeResult tag)
called by dialogue callback to set the result of user intervention
int qof_instance_version_cmp(QofInstance *left, QofInstance *right)
void qof_instance_init(QofInstance *inst, QofIdType type, QofBook *book)
glong qd_mday
Signed replacement of struct tm.tm_mday.
void qof_init(void)
Initialise the Query Object Framework.
const gchar * QofLogModule
mergeData contains the essential context data for any merge.