|
|
|
|
@@ -29,7 +29,7 @@ extern "C"
|
|
|
|
|
|
|
|
|
|
#include "../qof.h"
|
|
|
|
|
#include "../qofbackend-p.h"
|
|
|
|
|
#include "../qofsession-p.h"
|
|
|
|
|
#include "../qofsession.h"
|
|
|
|
|
#include "../qofclass-p.h"
|
|
|
|
|
#include "../gnc-backend-prov.hpp"
|
|
|
|
|
#include <vector>
|
|
|
|
|
@@ -37,16 +37,16 @@ extern "C"
|
|
|
|
|
static const gchar *suitename = "/qof/qofsession";
|
|
|
|
|
extern "C" void test_suite_qofsession ( void );
|
|
|
|
|
|
|
|
|
|
extern void (*p_qof_session_load_backend) (QofSession * session, const char * access_method);
|
|
|
|
|
extern void (*p_qof_session_clear_error) (QofSession * session);
|
|
|
|
|
extern void (*p_qof_session_destroy_backend) (QofSession * session);
|
|
|
|
|
extern void (*p_qof_session_load_backend) (QofSession *, const char * access_method);
|
|
|
|
|
extern void (*p_qof_session_clear_error) (QofSession *);
|
|
|
|
|
extern void (*p_qof_session_destroy_backend) (QofSession *);
|
|
|
|
|
extern void (*p_qof_session_set_book_id) (QofSession *, const char * book_id);
|
|
|
|
|
|
|
|
|
|
void init_static_qofsession_pointers (void);
|
|
|
|
|
|
|
|
|
|
using ProviderVec = std::vector<QofBackendProvider_ptr>;
|
|
|
|
|
extern ProviderVec& get_providers (void);
|
|
|
|
|
extern bool get_providers_initialized (void);
|
|
|
|
|
extern void unregister_all_providers (void);
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
@@ -92,14 +92,13 @@ test_qof_session_new_destroy (void)
|
|
|
|
|
g_test_message ("Test session initialization");
|
|
|
|
|
session = qof_session_new ();
|
|
|
|
|
g_assert (session);
|
|
|
|
|
g_assert_cmpstr (session->entity.e_type, == , QOF_ID_SESSION);
|
|
|
|
|
g_assert (session->book);
|
|
|
|
|
book = (QofBook*) session->book;
|
|
|
|
|
g_assert (qof_session_get_book (session));
|
|
|
|
|
book = (QofBook*) qof_session_get_book (session);
|
|
|
|
|
g_assert (book);
|
|
|
|
|
g_assert (QOF_IS_BOOK (book));
|
|
|
|
|
g_assert (!session->book_id);
|
|
|
|
|
g_assert (!session->backend);
|
|
|
|
|
g_assert_cmpint (session->lock, == , 1);
|
|
|
|
|
g_assert (!strlen (qof_session_get_url (session)));
|
|
|
|
|
g_assert (!qof_session_get_backend (session));
|
|
|
|
|
g_assert (!qof_session_save_in_progress (session));
|
|
|
|
|
g_assert_cmpint (qof_session_get_error (session), == , ERR_BACKEND_NO_ERR);
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test session destroy");
|
|
|
|
|
@@ -112,12 +111,12 @@ test_qof_session_new_destroy (void)
|
|
|
|
|
static void
|
|
|
|
|
test_session_safe_save( Fixture *fixture, gconstpointer pData )
|
|
|
|
|
{
|
|
|
|
|
fixture->session->backend = g_new0 (QofBackend, 1);
|
|
|
|
|
fixture->session->backend->safe_sync = safe_sync;
|
|
|
|
|
qof_book_set_backend (qof_session_get_book (fixture->session), g_new0 (QofBackend, 1));
|
|
|
|
|
qof_book_get_backend (qof_session_get_book (fixture->session))->safe_sync = safe_sync;
|
|
|
|
|
qof_session_safe_save( fixture->session, percentage_fn );
|
|
|
|
|
g_assert_cmpint( ERR_BACKEND_DATA_CORRUPT, == ,
|
|
|
|
|
qof_session_get_error( fixture->session ));
|
|
|
|
|
g_assert( NULL == qof_session_get_url( fixture->session ));
|
|
|
|
|
g_assert (!strlen (qof_session_get_url (fixture->session)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct
|
|
|
|
|
@@ -170,7 +169,6 @@ test_qof_session_load_backend (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
p_qof_session_load_backend (fixture->session, "file");
|
|
|
|
|
g_assert (!get_providers_initialized ());
|
|
|
|
|
g_assert_cmpint (qof_session_get_error (fixture->session), == , ERR_BACKEND_NO_HANDLER);
|
|
|
|
|
g_assert_cmpstr (qof_session_get_error_message (fixture->session), == , "Failed to load 'file' using access_method");
|
|
|
|
|
p_qof_session_clear_error (fixture->session);
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test with provider registered but access method not supported");
|
|
|
|
|
@@ -180,7 +178,6 @@ test_qof_session_load_backend (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
g_assert_cmpint (get_providers().size(), == , 1);
|
|
|
|
|
p_qof_session_load_backend (fixture->session, "file");
|
|
|
|
|
g_assert_cmpint (qof_session_get_error (fixture->session), == , ERR_BACKEND_NO_HANDLER);
|
|
|
|
|
g_assert_cmpstr (qof_session_get_error_message (fixture->session), == , "Failed to load 'file' using access_method");
|
|
|
|
|
p_qof_session_clear_error (fixture->session);
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test with access method supported but type incompatible");
|
|
|
|
|
@@ -189,11 +186,10 @@ test_qof_session_load_backend (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
qof_backend_register_provider (std::move(prov));
|
|
|
|
|
load_backend_struct.data_compatible = FALSE;
|
|
|
|
|
load_backend_struct.check_data_type_called = FALSE;
|
|
|
|
|
fixture->session->book_id = g_strdup ("my book");
|
|
|
|
|
p_qof_session_set_book_id (fixture->session, "my book");
|
|
|
|
|
p_qof_session_load_backend (fixture->session, "file");
|
|
|
|
|
g_assert (load_backend_struct.check_data_type_called);
|
|
|
|
|
g_assert_cmpint (qof_session_get_error (fixture->session), == , ERR_BACKEND_NO_HANDLER);
|
|
|
|
|
g_assert_cmpstr (qof_session_get_error_message (fixture->session), == , "Failed to load 'file' using access_method");
|
|
|
|
|
p_qof_session_clear_error (fixture->session);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -202,7 +198,7 @@ test_qof_session_load_backend (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
load_backend_struct.data_compatible = TRUE;
|
|
|
|
|
load_backend_struct.check_data_type_called = FALSE;
|
|
|
|
|
load_backend_struct.backend_new_called = FALSE;
|
|
|
|
|
g_assert (fixture->session->backend == NULL);
|
|
|
|
|
g_assert (qof_book_get_backend (qof_session_get_book (fixture->session)) == NULL);
|
|
|
|
|
book = qof_session_get_book (fixture->session);
|
|
|
|
|
g_assert (book);
|
|
|
|
|
g_assert (qof_book_get_backend (book) == NULL);
|
|
|
|
|
@@ -210,11 +206,11 @@ test_qof_session_load_backend (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
g_assert (load_backend_struct.check_data_type_called);
|
|
|
|
|
g_assert (load_backend_struct.backend_new_called);
|
|
|
|
|
g_assert (load_backend_struct.be);
|
|
|
|
|
g_assert (load_backend_struct.be == fixture->session->backend);
|
|
|
|
|
g_assert (load_backend_struct.be == qof_book_get_backend (qof_session_get_book (fixture->session)));
|
|
|
|
|
g_assert (qof_book_get_backend (book) == load_backend_struct.be);
|
|
|
|
|
g_assert_cmpint (qof_session_get_error (fixture->session), == , ERR_BACKEND_NO_ERR);
|
|
|
|
|
|
|
|
|
|
unregister_all_providers ();
|
|
|
|
|
qof_backend_unregister_all_providers ();
|
|
|
|
|
g_assert_cmpint (get_providers().size(), == , 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -249,36 +245,36 @@ test_qof_session_load (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
QofBook *newbook = NULL;
|
|
|
|
|
|
|
|
|
|
/* init */
|
|
|
|
|
fixture->session->book_id = g_strdup ("my book");
|
|
|
|
|
p_qof_session_set_book_id (fixture->session, "my book");
|
|
|
|
|
be = g_new0 (QofBackend, 1);
|
|
|
|
|
g_assert (be);
|
|
|
|
|
fixture->session->backend = be;
|
|
|
|
|
qof_book_set_backend (qof_session_get_book (fixture->session), be);
|
|
|
|
|
be->load = mock_load;
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test when no error is produced");
|
|
|
|
|
g_assert (be->percentage == NULL);
|
|
|
|
|
load_session_struct.be = be;
|
|
|
|
|
load_session_struct.oldbook = qof_session_get_book (fixture->session);
|
|
|
|
|
g_assert (fixture->session->book);
|
|
|
|
|
g_assert (qof_session_get_book (fixture->session));
|
|
|
|
|
load_session_struct.error = FALSE;
|
|
|
|
|
load_session_struct.load_called = FALSE;
|
|
|
|
|
qof_session_load (fixture->session, percentage_fn);
|
|
|
|
|
newbook = qof_session_get_book (fixture->session);
|
|
|
|
|
g_assert (newbook);
|
|
|
|
|
g_assert (load_session_struct.oldbook != newbook);
|
|
|
|
|
g_assert (fixture->session->book);
|
|
|
|
|
g_assert (qof_session_get_book (fixture->session));
|
|
|
|
|
g_assert (load_session_struct.load_called);
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test when no is produced");
|
|
|
|
|
load_session_struct.oldbook = qof_session_get_book (fixture->session);
|
|
|
|
|
g_assert (fixture->session->book);
|
|
|
|
|
g_assert (qof_session_get_book (fixture->session));
|
|
|
|
|
load_session_struct.error = TRUE;
|
|
|
|
|
load_session_struct.load_called = FALSE;
|
|
|
|
|
qof_session_load (fixture->session, percentage_fn);
|
|
|
|
|
newbook = qof_session_get_book (fixture->session);
|
|
|
|
|
g_assert (newbook);
|
|
|
|
|
g_assert (load_session_struct.oldbook == newbook);
|
|
|
|
|
g_assert (fixture->session->book);
|
|
|
|
|
g_assert (qof_session_get_book (fixture->session));
|
|
|
|
|
g_assert (load_session_struct.load_called);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -357,16 +353,15 @@ test_qof_session_begin (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
|
|
|
|
|
/* run tests */
|
|
|
|
|
g_test_message ("Test when book_id is set backend is not changed");
|
|
|
|
|
fixture->session->backend = be;
|
|
|
|
|
fixture->session->book_id = g_strdup ("my book");
|
|
|
|
|
qof_book_set_backend (qof_session_get_book (fixture->session), be);
|
|
|
|
|
p_qof_session_set_book_id (fixture->session, "my book");
|
|
|
|
|
qof_session_begin (fixture->session, "my book", ignore_lock, create, force);
|
|
|
|
|
g_assert (fixture->session->backend == be);
|
|
|
|
|
g_assert (qof_book_get_backend (qof_session_get_book (fixture->session)) == be);
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test when session book_id is not set and book_id passed is null backend is not changed");
|
|
|
|
|
g_free (fixture->session->book_id);
|
|
|
|
|
fixture->session->book_id = NULL;
|
|
|
|
|
p_qof_session_set_book_id (fixture->session, NULL);
|
|
|
|
|
qof_session_begin (fixture->session, NULL, ignore_lock, create, force);
|
|
|
|
|
g_assert (fixture->session->backend == be);
|
|
|
|
|
g_assert (qof_book_get_backend (qof_session_get_book (fixture->session)) == be);
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test default access_method parsing");
|
|
|
|
|
/* routine will destroy old backend
|
|
|
|
|
@@ -374,17 +369,15 @@ test_qof_session_begin (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
* as there is no backend registered error will be raised
|
|
|
|
|
*/
|
|
|
|
|
qof_session_begin (fixture->session, "default_should_be_file", ignore_lock, create, force);
|
|
|
|
|
g_assert (fixture->session->backend == NULL);
|
|
|
|
|
g_assert (fixture->session->book_id == NULL);
|
|
|
|
|
g_assert (qof_book_get_backend (qof_session_get_book (fixture->session)) == NULL);
|
|
|
|
|
g_assert (!strlen (qof_session_get_url (fixture->session)));
|
|
|
|
|
g_assert_cmpint (qof_session_get_error (fixture->session), == , ERR_BACKEND_NO_HANDLER);
|
|
|
|
|
g_assert_cmpstr (qof_session_get_error_message (fixture->session), == , "Failed to load 'file' using access_method");
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test access_method parsing");
|
|
|
|
|
qof_session_begin (fixture->session, "postgres://localhost:8080", ignore_lock, create, force);
|
|
|
|
|
g_assert (fixture->session->backend == NULL);
|
|
|
|
|
g_assert (fixture->session->book_id == NULL);
|
|
|
|
|
g_assert (qof_book_get_backend (qof_session_get_book (fixture->session)) == NULL);
|
|
|
|
|
g_assert (!strlen (qof_session_get_url (fixture->session)));
|
|
|
|
|
g_assert_cmpint (qof_session_get_error (fixture->session), == , ERR_BACKEND_NO_HANDLER);
|
|
|
|
|
g_assert_cmpstr (qof_session_get_error_message (fixture->session), == , "Failed to load 'postgres' using access_method");
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test with valid backend returned and session begin set; error is produced");
|
|
|
|
|
session_begin_struct.session = fixture->session;
|
|
|
|
|
@@ -397,11 +390,11 @@ test_qof_session_begin (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
qof_backend_register_provider (std::move(prov));
|
|
|
|
|
|
|
|
|
|
qof_session_begin (fixture->session, "postgres://localhost:8080", ignore_lock, create, force);
|
|
|
|
|
g_assert (fixture->session->backend);
|
|
|
|
|
g_assert (session_begin_struct.be == fixture->session->backend);
|
|
|
|
|
g_assert (qof_book_get_backend (qof_session_get_book (fixture->session)));
|
|
|
|
|
g_assert (session_begin_struct.be == qof_book_get_backend (qof_session_get_book (fixture->session)));
|
|
|
|
|
g_assert (session_begin_struct.backend_new_called == TRUE);
|
|
|
|
|
g_assert (session_begin_struct.session_begin_called == TRUE);
|
|
|
|
|
g_assert (fixture->session->book_id == NULL);
|
|
|
|
|
g_assert (!strlen (qof_session_get_url (fixture->session)));
|
|
|
|
|
g_assert_cmpint (qof_session_get_error (fixture->session), == , ERR_BACKEND_DATA_CORRUPT);
|
|
|
|
|
g_assert_cmpstr (qof_session_get_error_message (fixture->session), == , "push any error");
|
|
|
|
|
|
|
|
|
|
@@ -410,15 +403,15 @@ test_qof_session_begin (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
session_begin_struct.session_begin_called = FALSE;
|
|
|
|
|
session_begin_struct.produce_error = FALSE;
|
|
|
|
|
qof_session_begin (fixture->session, "postgres://localhost:8080", ignore_lock, create, force);
|
|
|
|
|
g_assert (fixture->session->backend);
|
|
|
|
|
g_assert (session_begin_struct.be == fixture->session->backend);
|
|
|
|
|
g_assert (qof_book_get_backend (qof_session_get_book (fixture->session)));
|
|
|
|
|
g_assert (session_begin_struct.be == qof_book_get_backend (qof_session_get_book (fixture->session)));
|
|
|
|
|
g_assert (session_begin_struct.backend_new_called == TRUE);
|
|
|
|
|
g_assert (session_begin_struct.session_begin_called == TRUE);
|
|
|
|
|
g_assert (fixture->session->book_id);
|
|
|
|
|
g_assert_cmpstr (fixture->session->book_id, == , "postgres://localhost:8080");
|
|
|
|
|
g_assert (strlen (qof_session_get_url (fixture->session)));
|
|
|
|
|
g_assert_cmpstr (qof_session_get_url (fixture->session), == , "postgres://localhost:8080");
|
|
|
|
|
g_assert_cmpint (qof_session_get_error (fixture->session), == , ERR_BACKEND_NO_ERR);
|
|
|
|
|
|
|
|
|
|
unregister_all_providers ();
|
|
|
|
|
qof_backend_unregister_all_providers ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct
|
|
|
|
|
@@ -450,22 +443,21 @@ test_qof_session_save (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
QofBackendProvider *prov = NULL;
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test when backend not set");
|
|
|
|
|
g_assert (fixture->session->backend == NULL);
|
|
|
|
|
g_assert (qof_book_get_backend (qof_session_get_book (fixture->session)) == NULL);
|
|
|
|
|
book = qof_session_get_book (fixture->session);
|
|
|
|
|
g_assert (book);
|
|
|
|
|
qof_session_push_error (fixture->session, ERR_BACKEND_DATA_CORRUPT, "push any error");
|
|
|
|
|
g_assert_cmpint (fixture->session->lock, == , 1);
|
|
|
|
|
g_assert_cmpint (qof_session_get_error (fixture->session), !=, ERR_BACKEND_NO_HANDLER);
|
|
|
|
|
g_assert (!qof_session_save_in_progress (fixture->session));
|
|
|
|
|
qof_session_save (fixture->session, NULL);
|
|
|
|
|
g_assert_cmpint (qof_session_get_error (fixture->session), == , ERR_BACKEND_NO_HANDLER);
|
|
|
|
|
g_assert_cmpstr (qof_session_get_error_message (fixture->session), == , "failed to load backend");
|
|
|
|
|
g_assert_cmpint (fixture->session->lock, == , 1);
|
|
|
|
|
g_assert (!qof_session_save_in_progress (fixture->session));
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test when backend set; imitate error");
|
|
|
|
|
be = g_new0 (QofBackend, 1);
|
|
|
|
|
g_assert (be);
|
|
|
|
|
be->sync = mock_sync;
|
|
|
|
|
fixture->session->backend = be;
|
|
|
|
|
g_assert_cmpint (fixture->session->lock, == , 1);
|
|
|
|
|
qof_book_set_backend (qof_session_get_book (fixture->session), be);
|
|
|
|
|
g_assert (!qof_session_save_in_progress (fixture->session));
|
|
|
|
|
session_save_struct.sync_called = FALSE;
|
|
|
|
|
session_save_struct.be = be;
|
|
|
|
|
session_save_struct.book = book;
|
|
|
|
|
@@ -475,18 +467,18 @@ test_qof_session_save (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
g_assert (qof_book_get_backend (book) == be);
|
|
|
|
|
g_assert (be->percentage == percentage_fn);
|
|
|
|
|
g_assert (session_save_struct.sync_called);
|
|
|
|
|
g_assert_cmpint (fixture->session->lock, == , 1);
|
|
|
|
|
g_assert (!qof_session_save_in_progress (fixture->session));
|
|
|
|
|
g_assert_cmpint (qof_session_get_error (fixture->session), == , ERR_BACKEND_DATA_CORRUPT);
|
|
|
|
|
g_assert_cmpstr (qof_session_get_error_message (fixture->session), == , "");
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test when backend set; successful save");
|
|
|
|
|
g_assert_cmpint (fixture->session->lock, == , 1);
|
|
|
|
|
g_assert (!qof_session_save_in_progress (fixture->session));
|
|
|
|
|
session_save_struct.sync_called = FALSE;
|
|
|
|
|
qof_session_save (fixture->session, percentage_fn);
|
|
|
|
|
g_assert (qof_book_get_backend (book) == be);
|
|
|
|
|
g_assert (be->percentage == percentage_fn);
|
|
|
|
|
g_assert (session_save_struct.sync_called);
|
|
|
|
|
g_assert_cmpint (fixture->session->lock, == , 1);
|
|
|
|
|
g_assert (!qof_session_save_in_progress (fixture->session));
|
|
|
|
|
g_assert_cmpint (qof_session_get_error (fixture->session), == , ERR_BACKEND_NO_ERR);
|
|
|
|
|
|
|
|
|
|
/* change backend testing
|
|
|
|
|
@@ -494,7 +486,7 @@ test_qof_session_save (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
* for example: qof_session_load_backend
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
unregister_all_providers ();
|
|
|
|
|
qof_backend_unregister_all_providers ();
|
|
|
|
|
g_free (prov);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -520,19 +512,19 @@ test_qof_session_destroy_backend (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
g_test_message ("Test with destroy backend callback not set");
|
|
|
|
|
be = g_new0 (QofBackend, 1);
|
|
|
|
|
g_assert (be);
|
|
|
|
|
fixture->session->backend = be;
|
|
|
|
|
qof_book_set_backend (qof_session_get_book (fixture->session), be);
|
|
|
|
|
p_qof_session_destroy_backend (fixture->session);
|
|
|
|
|
g_assert (!fixture->session->backend);
|
|
|
|
|
g_assert (!qof_book_get_backend (qof_session_get_book (fixture->session)));
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test with destroy backend callback set");
|
|
|
|
|
be = g_new0 (QofBackend, 1);
|
|
|
|
|
g_assert (be);
|
|
|
|
|
be->destroy_backend = mock_destroy_backend;
|
|
|
|
|
fixture->session->backend = be;
|
|
|
|
|
qof_book_set_backend (qof_session_get_book (fixture->session), be);
|
|
|
|
|
destroy_backend_struct.called = FALSE;
|
|
|
|
|
destroy_backend_struct.be = be;
|
|
|
|
|
p_qof_session_destroy_backend (fixture->session);
|
|
|
|
|
g_assert (!fixture->session->backend);
|
|
|
|
|
g_assert (!qof_book_get_backend (qof_session_get_book (fixture->session)));
|
|
|
|
|
g_assert (destroy_backend_struct.called);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -559,15 +551,16 @@ test_qof_session_end (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
be = g_new0 (QofBackend, 1);
|
|
|
|
|
g_assert (be);
|
|
|
|
|
be->session_end = mock_session_end;
|
|
|
|
|
fixture->session->backend = be;
|
|
|
|
|
qof_session_push_error (fixture->session, ERR_BACKEND_DATA_CORRUPT, "push any error");
|
|
|
|
|
fixture->session->book_id = g_strdup ("my book");
|
|
|
|
|
be->last_err = ERR_BACKEND_DATA_CORRUPT;
|
|
|
|
|
be->error_msg = g_strdup("push any error");
|
|
|
|
|
qof_book_set_backend (qof_session_get_book (fixture->session), be);
|
|
|
|
|
p_qof_session_set_book_id (fixture->session, "my book");
|
|
|
|
|
session_end_struct.called = FALSE;
|
|
|
|
|
session_end_struct.be = be;
|
|
|
|
|
qof_session_end (fixture->session);
|
|
|
|
|
g_assert (session_end_struct.called);
|
|
|
|
|
g_assert_cmpint (qof_session_get_error (fixture->session), == , ERR_BACKEND_NO_ERR);
|
|
|
|
|
g_assert (!fixture->session->book_id);
|
|
|
|
|
g_assert (!strlen (qof_session_get_url (fixture->session)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct
|
|
|
|
|
@@ -611,7 +604,7 @@ test_qof_session_export (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
g_test_message ("Test with backend set");
|
|
|
|
|
be = g_new0 (QofBackend, 1);
|
|
|
|
|
g_assert (be);
|
|
|
|
|
fixture->session->backend = be;
|
|
|
|
|
qof_book_set_backend (qof_session_get_book (fixture->session), be);
|
|
|
|
|
qof_book_set_backend (tmp_book, be);
|
|
|
|
|
g_assert (!be->percentage);
|
|
|
|
|
g_assert (qof_session_export (fixture->session, real_session, percentage_fn));
|
|
|
|
|
@@ -654,20 +647,20 @@ test_qof_session_swap_data (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
g_assert (be1);
|
|
|
|
|
be2 = g_new0 (QofBackend, 1);
|
|
|
|
|
g_assert (be2);
|
|
|
|
|
fixture->session->backend = be1;
|
|
|
|
|
session2->backend = be2;
|
|
|
|
|
book1 = fixture->session->book;
|
|
|
|
|
book2 = session2->book;
|
|
|
|
|
qof_book_set_backend (qof_session_get_book (fixture->session), be1);
|
|
|
|
|
qof_book_set_backend (qof_session_get_book (session2), be2);
|
|
|
|
|
book1 = qof_session_get_book (fixture->session);
|
|
|
|
|
book2 = qof_session_get_book (session2);
|
|
|
|
|
g_assert (book1);
|
|
|
|
|
g_assert (book2);
|
|
|
|
|
qof_book_set_backend (book1, fixture->session->backend);
|
|
|
|
|
qof_book_set_backend (book2, session2->backend);
|
|
|
|
|
qof_book_set_backend (book1, qof_book_get_backend (qof_session_get_book (fixture->session)));
|
|
|
|
|
qof_book_set_backend (book2, qof_book_get_backend (qof_session_get_book (session2)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test book lists are swapped and backend for each book is swapped");
|
|
|
|
|
qof_session_swap_data (fixture->session, session2);
|
|
|
|
|
g_assert (fixture->session->book == book2);
|
|
|
|
|
g_assert (session2->book == book1);
|
|
|
|
|
g_assert (qof_session_get_book (fixture->session) == book2);
|
|
|
|
|
g_assert (qof_session_get_book (session2) == book1);
|
|
|
|
|
|
|
|
|
|
qof_session_destroy (session2);
|
|
|
|
|
}
|
|
|
|
|
@@ -694,12 +687,12 @@ test_qof_session_events (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test pending events null checks");
|
|
|
|
|
g_assert (!qof_session_events_pending (NULL));
|
|
|
|
|
g_assert (!fixture->session->backend);
|
|
|
|
|
g_assert (!qof_book_get_backend (qof_session_get_book (fixture->session)));
|
|
|
|
|
g_assert (!qof_session_events_pending (fixture->session));
|
|
|
|
|
be = g_new0 (QofBackend, 1);
|
|
|
|
|
g_assert (be);
|
|
|
|
|
be->events_pending = NULL;
|
|
|
|
|
fixture->session->backend = be;
|
|
|
|
|
qof_book_set_backend (qof_session_get_book (fixture->session), be);
|
|
|
|
|
g_assert (!qof_session_events_pending (fixture->session));
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test pending events callback");
|
|
|
|
|
@@ -711,10 +704,10 @@ test_qof_session_events (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test process events null checks");
|
|
|
|
|
g_assert (!qof_session_process_events (NULL));
|
|
|
|
|
fixture->session->backend = NULL;
|
|
|
|
|
qof_book_set_backend (qof_session_get_book (fixture->session), NULL);
|
|
|
|
|
g_assert (!qof_session_process_events (fixture->session));
|
|
|
|
|
be->process_events = NULL;
|
|
|
|
|
fixture->session->backend = be;
|
|
|
|
|
qof_book_set_backend (qof_session_get_book (fixture->session), be);
|
|
|
|
|
g_assert (!qof_session_process_events (fixture->session));
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test process events callback");
|
|
|
|
|
@@ -752,7 +745,7 @@ test_qof_session_data_loaded (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
be = g_new0 (QofBackend, 1);
|
|
|
|
|
g_assert (be);
|
|
|
|
|
be->load = mock_all_data_load;
|
|
|
|
|
fixture->session->backend = be;
|
|
|
|
|
qof_book_set_backend (qof_session_get_book (fixture->session), be);
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test load callback and artificial error");
|
|
|
|
|
data_load_struct.be = be;
|
|
|
|
|
@@ -773,7 +766,7 @@ test_qof_session_get_book (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
g_assert (!qof_session_get_book (NULL));
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test open book is returned");
|
|
|
|
|
g_assert (fixture->session->book);
|
|
|
|
|
g_assert (qof_session_get_book (fixture->session));
|
|
|
|
|
book = qof_session_get_book (fixture->session);
|
|
|
|
|
g_assert (book);
|
|
|
|
|
g_assert_cmpuint (book->book_open, == , 'y');
|
|
|
|
|
@@ -792,20 +785,11 @@ test_qof_session_get_error (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
g_test_message ("Test if session is null");
|
|
|
|
|
g_assert_cmpint (qof_session_get_error (NULL), == , ERR_BACKEND_NO_BACKEND);
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test when there is a local error");
|
|
|
|
|
fixture->session->last_err = ERR_BACKEND_DATA_CORRUPT; /* just any error */
|
|
|
|
|
g_assert_cmpint (qof_session_get_error (fixture->session), == , ERR_BACKEND_DATA_CORRUPT);
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test if session backend is null");
|
|
|
|
|
g_assert (!fixture->session->backend);
|
|
|
|
|
fixture->session->last_err = ERR_BACKEND_NO_ERR;
|
|
|
|
|
g_assert_cmpint (qof_session_get_error (fixture->session), == , ERR_BACKEND_NO_ERR);
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test for backend error");
|
|
|
|
|
be = g_new0 (QofBackend, 1);
|
|
|
|
|
g_assert (be);
|
|
|
|
|
qof_backend_set_error (be, ERR_BACKEND_CANT_CONNECT);
|
|
|
|
|
fixture->session->backend = be;
|
|
|
|
|
qof_book_set_backend (qof_session_get_book (fixture->session), be);
|
|
|
|
|
g_assert_cmpint (qof_session_get_error (fixture->session), == , ERR_BACKEND_CANT_CONNECT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -818,13 +802,14 @@ test_qof_session_clear_error (Fixture *fixture, gconstpointer pData)
|
|
|
|
|
g_assert (be);
|
|
|
|
|
|
|
|
|
|
g_test_message ("Test session and backend errors are cleared");
|
|
|
|
|
qof_session_push_error (fixture->session, ERR_BACKEND_NO_SUCH_DB, "push any error");
|
|
|
|
|
fixture->session->backend = be;
|
|
|
|
|
be->last_err = ERR_BACKEND_NO_SUCH_DB;
|
|
|
|
|
be->error_msg = g_strdup ("push any error");
|
|
|
|
|
qof_book_set_backend (qof_session_get_book (fixture->session), be);
|
|
|
|
|
qof_backend_set_error (be, ERR_BACKEND_CANT_CONNECT);
|
|
|
|
|
p_qof_session_clear_error (fixture->session);
|
|
|
|
|
g_assert_cmpint (qof_session_get_error (fixture->session), == , ERR_BACKEND_NO_ERR);
|
|
|
|
|
g_assert_cmpstr (qof_session_get_error_message (fixture->session), == , "");
|
|
|
|
|
g_assert (!fixture->session->error_message);
|
|
|
|
|
g_assert (!strlen (qof_session_get_error_message (fixture->session)));
|
|
|
|
|
g_assert_cmpint (qof_backend_get_error (be), == , ERR_BACKEND_NO_ERR);
|
|
|
|
|
}
|
|
|
|
|
|