Replace C qofsession struct with c++ qofsession struct

This commit is contained in:
lmat
2016-06-05 13:14:45 -04:00
committed by John Ralls
parent 557a5e2f2d
commit 3063c87346
12 changed files with 662 additions and 668 deletions

View File

@@ -84,9 +84,9 @@ gnc_state_set_base (const QofSession *session)
state_file_name = NULL;
state_file_name_pre_241 = NULL;
uri = qof_session_get_url(session);
uri = qof_session_get_url (session);
ENTER("session %p (%s)", session, uri ? uri : "(null)");
if (!uri)
if (!strlen (uri))
{
LEAVE("no uri, nothing to do");
return;
@@ -228,7 +228,7 @@ void gnc_state_save (const QofSession *session)
{
GError *error = NULL;
if (!qof_session_get_url(session))
if (!strlen (qof_session_get_url(session)))
{
DEBUG("No file associated with session - skip state saving");
return;

View File

@@ -51,7 +51,6 @@ extern "C"
#include "gncInvoice.h"
/* For version_control */
#include <gnc-prefs.h>
#include <qofsession-p.h>
}
/* For test_conn_index_functions */
#include "test-dbi-stuff.h"

View File

@@ -26,7 +26,6 @@ extern "C"
{
#include <config.h>
#include <qof.h>
#include <qofsession-p.h>
#include <cashobjects.h>
#include <test-dbi-stuff.h>
#include <unittest-support.h>

View File

@@ -492,7 +492,7 @@ gnc_add_history (QofSession * session)
if (!session) return;
url = qof_session_get_url ( session );
if ( !url )
if ( !strlen (url) )
return;
if ( gnc_uri_is_file_uri ( url ) )
@@ -1188,7 +1188,7 @@ gnc_file_do_export(const char * filename)
* file. If so, prevent the export from happening to avoid killing this file */
current_session = gnc_get_current_session ();
oldfile = qof_session_get_url(current_session);
if (oldfile && (strcmp(oldfile, newfile) == 0))
if (strlen (oldfile) && (strcmp(oldfile, newfile) == 0))
{
g_free (newfile);
show_session_error (ERR_FILEIO_WRITE_ERROR, filename,
@@ -1271,7 +1271,7 @@ gnc_file_save (void)
/* If we don't have a filename/path to save to get one. */
session = gnc_get_current_session ();
if (!qof_session_get_url(session))
if (!strlen (qof_session_get_url (session)))
{
gnc_file_save_as ();
return;
@@ -1420,7 +1420,7 @@ gnc_file_do_save_as (const char* filename)
* file. If so, then just do a simple save, instead of a full save as */
session = gnc_get_current_session ();
oldfile = qof_session_get_url(session);
if (oldfile && (strcmp(oldfile, newfile) == 0))
if (strlen (oldfile) && (strcmp(oldfile, newfile) == 0))
{
g_free (newfile);
gnc_file_save ();
@@ -1578,7 +1578,7 @@ gnc_file_revert (void)
session = gnc_get_current_session();
fileurl = qof_session_get_url(session);
if (fileurl == NULL)
if (!strlen (fileurl))
fileurl = _("<unknown>");
if ((tmp = strrchr(fileurl, '/')) != NULL)
filename = tmp + 1;

View File

@@ -1216,7 +1216,7 @@ gnc_main_window_prompt_for_save (GtkWidget *window)
session = gnc_get_current_session();
book = qof_session_get_book(session);
filename = qof_session_get_url(session);
if (filename == NULL)
if (!strlen (filename))
filename = _("<unknown>");
if ((tmp = strrchr(filename, '/')) != NULL)
filename = tmp + 1;
@@ -1626,7 +1626,7 @@ static gchar *generate_statusbar_lastmodified_message()
book_id = qof_session_get_url (gnc_get_current_session ());
}
if (!book_id)
if (!strlen (book_id))
return NULL;
else
{

View File

@@ -77,6 +77,7 @@ qofinclude_HEADERS = \
qofquery.h \
qofquerycore.h \
qofsession.h \
qofsession.hpp \
qof-string-cache.h \
qofutil.h \
qof-gobject.h
@@ -89,8 +90,7 @@ noinst_HEADERS = \
gnc-int128.hpp \
qofobject-p.h \
qofquery-p.h \
qofquerycore-p.h \
qofsession-p.h
qofquerycore-p.h
if OS_WIN32
libgnc_qof_la_SOURCES += qof-win32.cpp

View File

@@ -78,4 +78,6 @@ using QofBackendProvider_ptr = std::unique_ptr<QofBackendProvider>;
*/
void qof_backend_register_provider (QofBackendProvider_ptr&&);
void qof_backend_unregister_all_providers ();
#endif // __GNC_BACKEND_PROV_HPP__

File diff suppressed because it is too large Load Diff

View File

@@ -112,7 +112,7 @@ extern "C"
/* PROTOTYPES ******************************************************/
typedef struct _QofSession QofSession;
typedef struct QofSessionImpl QofSession;
QofSession * qof_session_new (void);
void qof_session_destroy (QofSession *session);
@@ -156,7 +156,6 @@ void qof_session_begin (QofSession *session, const char * book_id,
gboolean ignore_lock, gboolean create,
gboolean force);
/**
* The qof_session_load() method causes the QofBook to be made ready to
* to use with this URL/datastore. When the URL points at a file,
@@ -195,7 +194,6 @@ const char * qof_session_get_error_message(const QofSession *session);
QofBackendError qof_session_pop_error (QofSession *session);
/** @} */
/** Returns the QofBook of this session. */
QofBook * qof_session_get_book (const QofSession *session);
@@ -224,6 +222,11 @@ const char * qof_session_get_url (const QofSession *session);
/* gboolean qof_session_not_saved(const QofSession *session); <- unimplemented */
gboolean qof_session_save_in_progress(const QofSession *session);
/**
* Returns the qof session's backend.
*/
QofBackend * qof_session_get_backend(const QofSession *session);
/** The qof_session_save() method will commit all changes that have been
* made to the session. For the file backend, this is nothing
* more than a write to the file of the current Accounts & etc.

View File

@@ -1,5 +1,5 @@
/********************************************************************\
* qofsession-p.h -- private functions for QOF sessions. *
* qofsession.hpp -- declarations for QOF sessions. *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
@@ -31,23 +31,70 @@
#include "qofbook.h"
#include "qofsession.h"
#include <utility>
#include <string>
struct _QofSession
struct QofSessionImpl
{
/* This is just a "fake" entry point to allow me to pass a Session as
* an Entity. NOTE: THIS IS NOT AN ENTITY! THE ONLY PART OF ENTITY
* THAT IS VALID IS E_TYPE!
QofSessionImpl () noexcept;
/* Ends the current session, destroys the backend, and destroys the book. */
~QofSessionImpl () noexcept;
/** Begin this session. */
void begin (std::string book_id, bool ignore_lock, bool create, bool force) noexcept;
/** Swap books with another session */
void swap_books (QofSessionImpl &) noexcept;
void ensure_all_data_loaded () noexcept;
void load (QofPercentageFunc) noexcept;
void save (QofPercentageFunc) noexcept;
void safe_save (QofPercentageFunc) noexcept;
bool save_in_progress () const noexcept;
bool export_session (QofSessionImpl & real_session, QofPercentageFunc) noexcept;
bool events_pending () const noexcept;
bool process_events () const noexcept;
void clear_error () noexcept;
QofBackendError pop_error () noexcept;
/**
* We return by reference so that a pointer to the data of the string lives
* long enough to make it back to C code.
*/
QofInstance entity;
std::string const & get_book_id () const noexcept;
/**
* Returns and clears the local cached error. If there is no local error, we check
* for an error in the backend.
*/
QofBackendError get_error () noexcept;
std::string get_error_message () const noexcept;
QofBook * get_book () const noexcept;
QofBackend * get_backend () const noexcept;
std::string get_file_path () const noexcept;
bool is_saving () const noexcept;
/**
* Terminates the current backend.
*/
void end () noexcept;
void destroy_backend () noexcept;
private:
void push_error (QofBackendError const err, std::string message) noexcept;
void load_backend (std::string access_method) noexcept;
/* A book holds pointers to the various types of datasets.
* A session has exactly one book. */
QofBook *book;
QofBook * m_book;
/* The requested book id, in the form or a URI, such as
* file:/some/where, or sql:server.host.com:555
*/
char *book_id;
std::string m_book_id;
bool m_saving;
/* If any book subroutine failed, this records the failure reason
* (file not found, etc).
@@ -56,14 +103,14 @@ struct _QofSession
* and the backends should all be using (or making it look like)
* there is only one stack.
*/
QofBackendError last_err;
char *error_message;
QofBackendError m_last_err;
std::string m_error_message;
/* ---------------------------------------------------- */
/* Pointer to the backend that is actually used to move data
* between the persistant store and the local engine. */
QofBackend *backend;
gint lock;
/* These functions support the old testing infrastructure and should
* be removed when they are no longer necessary.*/
friend void qof_session_load_backend (QofSession *, const char *);
friend char const * qof_session_get_book_id (QofSession *);
friend void qof_session_set_book_id (QofSession *, char const *);
};
typedef struct qof_instance_copy_data
@@ -84,8 +131,6 @@ extern "C"
QofBackend * qof_session_get_backend (const QofSession *session);
void qof_session_push_error (QofSession *session, QofBackendError err,
const char *message);
#ifdef __cplusplus
}
#endif

View File

@@ -14,7 +14,7 @@ test_qof_SOURCES = \
test-qofbook.c \
test-qofinstance.cpp \
test-qofobject.c \
test-qofsession.cpp \
test-qofsession-old.cpp \
test-qof-string-cache.c \
test-gnc-guid.cpp \
${top_srcdir}/src/test-core/unittest-support.c

View File

@@ -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);
}