static void test_qof_object_compliance( Fixture *fixture, gconstpointer pData ) { g_assert( qof_object_register( fixture->qofobject ) ); g_test_message( "Test when neither create nor foreach set" ); g_assert( qof_object_compliance( fixture->qofobject->e_type, FALSE ) == FALSE ); g_assert( qof_object_compliance( fixture->qofobject->e_type, TRUE ) == FALSE ); g_test_message( "Test when only create set" ); fixture->qofobject->create = mock_object_create; g_assert( qof_object_compliance( fixture->qofobject->e_type, FALSE ) == FALSE ); g_assert( qof_object_compliance( fixture->qofobject->e_type, TRUE ) == FALSE ); g_test_message( "Test when only foreach set" ); fixture->qofobject->create = NULL; fixture->qofobject->foreach = mock_object_foreach; g_assert( qof_object_compliance( fixture->qofobject->e_type, FALSE ) == FALSE ); g_assert( qof_object_compliance( fixture->qofobject->e_type, TRUE ) == FALSE ); g_test_message( "Test when both set" ); fixture->qofobject->create = mock_object_create; fixture->qofobject->foreach = mock_object_foreach; g_assert( qof_object_compliance( fixture->qofobject->e_type, FALSE ) == TRUE ); g_assert( qof_object_compliance( fixture->qofobject->e_type, TRUE ) == TRUE ); }
static void qof_instance_coll_copy(QofInstance *original, gpointer user_data) { QofInstanceCopyData *qecd; QofBook *book; QofInstance *inst; const GncGUID *g; g_return_if_fail(original != NULL); g_return_if_fail(user_data != NULL); qecd = (QofInstanceCopyData*)user_data; book = qof_session_get_book(qecd->new_session); if (!qof_object_compliance(original->e_type, TRUE)) { return; } inst = (QofInstance*)qof_object_new_instance(original->e_type, book); qecd->to = inst; qecd->from = original; g = qof_instance_get_guid(original); qof_instance_set_guid(qecd->to, g); qof_begin_edit(inst); g_slist_foreach(qecd->param_list, qof_instance_foreach_copy, qecd); qof_commit_edit(inst); }
static void qof_instance_list_foreach(gpointer data, gpointer user_data) { QofInstanceCopyData *qecd; QofInstance *original; QofInstance *inst; QofBook *book; const GncGUID *g; g_return_if_fail(data != NULL); original = QOF_INSTANCE(data); g_return_if_fail(user_data != NULL); qecd = (QofInstanceCopyData*)user_data; if (qof_instance_guid_match(qecd->new_session, original)) { return; } qecd->from = original; if (!qof_object_compliance(original->e_type, FALSE)) { qecd->error = TRUE; return; } book = qof_session_get_book(qecd->new_session); inst = (QofInstance*)qof_object_new_instance(original->e_type, book); if (!inst) { PERR (" failed to create new entity type=%s.", original->e_type); qecd->error = TRUE; return; } qecd->to = inst; g = qof_instance_get_guid(original); qof_instance_set_guid(qecd->to, g); if (qecd->param_list != NULL) { g_slist_free(qecd->param_list); qecd->param_list = NULL; } qof_class_param_foreach(original->e_type, qof_instance_param_cb, qecd); qof_begin_edit(inst); g_slist_foreach(qecd->param_list, qof_instance_foreach_copy, qecd); qof_commit_edit(inst); }
gboolean qof_instance_copy_to_session(QofSession* new_session, QofInstance* original) { QofInstanceCopyData qecd; QofInstance *inst; QofBook *book; if (!new_session || !original) { return FALSE; } if (qof_instance_guid_match(new_session, original)) { return FALSE; } if (!qof_object_compliance(original->e_type, TRUE)) { return FALSE; } qof_event_suspend(); qecd.param_list = NULL; book = qof_session_get_book(new_session); qecd.new_session = new_session; qof_book_set_partial(book); inst = (QofInstance*)qof_object_new_instance(original->e_type, book); qecd.to = inst; qecd.from = original; qof_instance_set_guid(qecd.to, qof_instance_get_guid(original)); qof_begin_edit(inst); qof_class_param_foreach(original->e_type, qof_instance_param_cb, &qecd); qof_commit_edit(inst); if (g_slist_length(qecd.param_list) == 0) { return FALSE; } g_slist_foreach(qecd.param_list, qof_instance_foreach_copy, &qecd); g_slist_free(qecd.param_list); qof_event_resume(); return TRUE; }