QofSession, QofBackend: Change book_id to uri.

It's more descriptive and less likely to be confused with the book:id value
in XML files that is the book's GUID.
Also changed the QofSessionImpl::begin new_uri parameter from std::string to
const char*. There's no point in allocating a string just to call
new_uri.c_str() all over the place.
This commit is contained in:
John Ralls
2020-06-02 11:48:33 -07:00
parent 65e2639de4
commit a320035f42
9 changed files with 89 additions and 90 deletions

View File

@@ -1499,7 +1499,7 @@ gnc_main_window_generate_title (GncMainWindow *window)
QofBook *book; QofBook *book;
gboolean immutable; gboolean immutable;
gchar *filename = NULL; gchar *filename = NULL;
const gchar *book_id = NULL; const gchar *uri = NULL;
const gchar *dirty = ""; const gchar *dirty = "";
const gchar *readonly_text = NULL; const gchar *readonly_text = NULL;
gchar *readonly; gchar *readonly;
@@ -1507,7 +1507,7 @@ gnc_main_window_generate_title (GncMainWindow *window)
if (gnc_current_session_exist()) if (gnc_current_session_exist())
{ {
book_id = qof_session_get_url (gnc_get_current_session ()); uri = qof_session_get_url (gnc_get_current_session ());
book = gnc_get_current_book(); book = gnc_get_current_book();
if (qof_book_session_not_saved (book)) if (qof_book_session_not_saved (book))
dirty = "*"; dirty = "*";
@@ -1522,15 +1522,15 @@ gnc_main_window_generate_title (GncMainWindow *window)
? g_strdup_printf(" %s", readonly_text) ? g_strdup_printf(" %s", readonly_text)
: g_strdup(""); : g_strdup("");
if (!book_id || g_strcmp0 (book_id, "") == 0) if (!uri || g_strcmp0 (uri, "") == 0)
filename = g_strdup(_("Unsaved Book")); filename = g_strdup(_("Unsaved Book"));
else else
{ {
if (gnc_uri_targets_local_fs (book_id)) if (gnc_uri_targets_local_fs (uri))
{ {
/* The filename is a true file. /* The filename is a true file.
* The Gnome HIG 2.0 recommends only the file name (no path) be used. (p15) */ * The Gnome HIG 2.0 recommends only the file name (no path) be used. (p15) */
gchar *path = gnc_uri_get_path ( book_id ); gchar *path = gnc_uri_get_path ( uri );
filename = g_path_get_basename ( path ); filename = g_path_get_basename ( path );
g_free ( path ); g_free ( path );
} }
@@ -1538,7 +1538,7 @@ gnc_main_window_generate_title (GncMainWindow *window)
{ {
/* The filename is composed of database connection parameters. /* The filename is composed of database connection parameters.
* For this we will show access_method://username@database[:port] */ * For this we will show access_method://username@database[:port] */
filename = gnc_uri_normalize_uri (book_id, FALSE); filename = gnc_uri_normalize_uri (uri, FALSE);
} }
} }
@@ -1654,22 +1654,22 @@ static gboolean statusbar_notification_off(gpointer user_data_unused)
static gchar *generate_statusbar_lastmodified_message() static gchar *generate_statusbar_lastmodified_message()
{ {
gchar *message = NULL; gchar *message = NULL;
const gchar *book_id = NULL; const gchar *uri = NULL;
if (gnc_current_session_exist()) if (gnc_current_session_exist())
{ {
book_id = qof_session_get_url (gnc_get_current_session ()); uri = qof_session_get_url (gnc_get_current_session ());
} }
if (!(book_id && strlen (book_id))) if (!(uri && strlen (uri)))
return NULL; return NULL;
else else
{ {
if (gnc_uri_targets_local_fs (book_id)) if (gnc_uri_targets_local_fs (uri))
{ {
#ifdef HAVE_SYS_STAT_H #ifdef HAVE_SYS_STAT_H
/* The filename is a true file. */ /* The filename is a true file. */
gchar *filepath = gnc_uri_get_path ( book_id ); gchar *filepath = gnc_uri_get_path ( uri );
gchar *filename = g_path_get_basename ( filepath ); gchar *filename = g_path_get_basename ( filepath );
{ {
// Access the mtime information through stat(2) // Access the mtime information through stat(2)

View File

@@ -376,7 +376,7 @@ error_handler<DbType::DBI_SQLITE> (dbi_conn conn, void* user_data)
template <> void template <> void
GncDbiBackend<DbType::DBI_SQLITE>::session_begin(QofSession* session, GncDbiBackend<DbType::DBI_SQLITE>::session_begin(QofSession* session,
const char* book_id, const char* new_uri,
bool ignore_lock, bool ignore_lock,
bool create, bool force) bool create, bool force)
{ {
@@ -384,12 +384,12 @@ GncDbiBackend<DbType::DBI_SQLITE>::session_begin(QofSession* session,
PairVec options; PairVec options;
g_return_if_fail (session != nullptr); g_return_if_fail (session != nullptr);
g_return_if_fail (book_id != nullptr); g_return_if_fail (new_uri != nullptr);
ENTER (" "); ENTER (" ");
/* Remove uri type if present */ /* Remove uri type if present */
auto path = gnc_uri_get_path (book_id); auto path = gnc_uri_get_path (new_uri);
std::string filepath{path}; std::string filepath{path};
g_free(path); g_free(path);
GFileTest ftest = static_cast<decltype (ftest)> ( GFileTest ftest = static_cast<decltype (ftest)> (
@@ -441,7 +441,7 @@ GncDbiBackend<DbType::DBI_SQLITE>::session_begin(QofSession* session,
if (result < 0) if (result < 0)
{ {
dbi_conn_close(conn); dbi_conn_close(conn);
PERR ("Unable to connect to %s: %d\n", book_id, result); PERR ("Unable to connect to %s: %d\n", new_uri, result);
set_error (ERR_BACKEND_BAD_URL); set_error (ERR_BACKEND_BAD_URL);
LEAVE("Error"); LEAVE("Error");
return; return;
@@ -611,21 +611,21 @@ adjust_sql_options (dbi_conn connection)
template <DbType Type> void template <DbType Type> void
GncDbiBackend<Type>::session_begin (QofSession* session, const char* book_id, GncDbiBackend<Type>::session_begin (QofSession* session, const char* new_uri,
bool ignore_lock, bool create, bool force) bool ignore_lock, bool create, bool force)
{ {
GncDbiTestResult dbi_test_result = GNC_DBI_PASS; GncDbiTestResult dbi_test_result = GNC_DBI_PASS;
PairVec options; PairVec options;
g_return_if_fail (session != nullptr); g_return_if_fail (session != nullptr);
g_return_if_fail (book_id != nullptr); g_return_if_fail (new_uri != nullptr);
ENTER (" "); ENTER (" ");
/* Split the book-id /* Split the book-id
* Format is protocol://username:password@hostname:port/dbname * Format is protocol://username:password@hostname:port/dbname
where username, password and port are optional) */ where username, password and port are optional) */
UriStrings uri(book_id); UriStrings uri(new_uri);
if (Type == DbType::DBI_PGSQL) if (Type == DbType::DBI_PGSQL)
{ {

View File

@@ -106,11 +106,11 @@ GncXmlBackend::check_path (const char* fullpath, bool create)
} }
void void
GncXmlBackend::session_begin(QofSession* session, const char* book_id, GncXmlBackend::session_begin(QofSession* session, const char* new_uri,
bool ignore_lock, bool create, bool force) bool ignore_lock, bool create, bool force)
{ {
/* Make sure the directory is there */ /* Make sure the directory is there */
m_fullpath = gnc_uri_get_path (book_id); m_fullpath = gnc_uri_get_path (new_uri);
if (m_fullpath.empty()) if (m_fullpath.empty())
{ {

View File

@@ -35,7 +35,7 @@ public:
GncXmlBackend(const GncXmlBackend&&) = delete; GncXmlBackend(const GncXmlBackend&&) = delete;
GncXmlBackend operator=(const GncXmlBackend&&) = delete; GncXmlBackend operator=(const GncXmlBackend&&) = delete;
~GncXmlBackend() = default; ~GncXmlBackend() = default;
void session_begin(QofSession* session, const char* book_id, void session_begin(QofSession* session, const char* new_uri,
bool ignore_lock, bool create, bool force) override; bool ignore_lock, bool create, bool force) override;
void session_end() override; void session_end() override;
void load(QofBook* book, QofBackendLoadType loadType) override; void load(QofBook* book, QofBackendLoadType loadType) override;

View File

@@ -185,7 +185,7 @@ public:
/** /**
* Open the file or connect to the server. * Open the file or connect to the server.
* @param session The QofSession that will control the backend. * @param session The QofSession that will control the backend.
* @param book_id The book's string identifier. * @param new_uri The location of the data store that the backend will use.
* @param ignore_lock indicates whether the single-user lock on the backend * @param ignore_lock indicates whether the single-user lock on the backend
* should be cleared. The typical GUI sequence leading to this is: * should be cleared. The typical GUI sequence leading to this is:
* (1) GUI attempts to open the backend by calling this routine with * (1) GUI attempts to open the backend by calling this routine with
@@ -203,7 +203,7 @@ public:
* @param force works with create to force creating a new database even if * @param force works with create to force creating a new database even if
* one already exists at the same URI. * one already exists at the same URI.
*/ */
virtual void session_begin(QofSession *session, const char* book_id, virtual void session_begin(QofSession *session, const char* new_uri,
bool ignore_lock, bool create, bool force) = 0; bool ignore_lock, bool create, bool force) = 0;
virtual void session_end() = 0; virtual void session_end() = 0;
/** /**

View File

@@ -121,7 +121,7 @@ qof_backend_get_registered_access_method_list(void)
QofSessionImpl::QofSessionImpl (QofBook* book) noexcept QofSessionImpl::QofSessionImpl (QofBook* book) noexcept
: m_backend {}, : m_backend {},
m_book {book}, m_book {book},
m_book_id {}, m_uri {},
m_saving {false}, m_saving {false},
m_last_err {}, m_last_err {},
m_error_message {} m_error_message {}
@@ -130,7 +130,7 @@ QofSessionImpl::QofSessionImpl (QofBook* book) noexcept
QofSessionImpl::~QofSessionImpl () noexcept QofSessionImpl::~QofSessionImpl () noexcept
{ {
ENTER ("sess=%p book_id=%s", this, m_book_id.c_str ()); ENTER ("sess=%p uri=%s", this, m_uri.c_str ());
end (); end ();
destroy_backend (); destroy_backend ();
qof_book_set_backend (m_book, nullptr); qof_book_set_backend (m_book, nullptr);
@@ -182,10 +182,10 @@ QofSessionImpl::load_backend (std::string access_method) noexcept
PINFO (" Selected provider %s", prov->provider_name); PINFO (" Selected provider %s", prov->provider_name);
// Only do a type check when trying to open an existing file // Only do a type check when trying to open an existing file
// When saving over an existing file the contents of the original file don't matter // When saving over an existing file the contents of the original file don't matter
if (!m_creating && !prov->type_check (m_book_id.c_str ())) if (!m_creating && !prov->type_check (m_uri.c_str ()))
{ {
PINFO("Provider, %s, reported not being usable for book, %s.", PINFO("Provider, %s, reported not being usable for book, %s.",
prov->provider_name, m_book_id.c_str ()); prov->provider_name, m_uri.c_str ());
continue; continue;
} }
m_backend = prov->create_backend(); m_backend = prov->create_backend();
@@ -203,8 +203,8 @@ QofSessionImpl::load (QofPercentageFunc percentage_func) noexcept
/* We must have an empty book to load into or bad things will happen. */ /* We must have an empty book to load into or bad things will happen. */
g_return_if_fail(m_book && qof_book_empty(m_book)); g_return_if_fail(m_book && qof_book_empty(m_book));
if (!m_book_id.size ()) return; if (!m_uri.size ()) return;
ENTER ("sess=%p book_id=%s", this, m_book_id.c_str ()); ENTER ("sess=%p uri=%s", this, m_uri.c_str ());
/* At this point, we should are supposed to have a valid book /* At this point, we should are supposed to have a valid book
* id and a lock on the file. */ * id and a lock on the file. */
@@ -246,18 +246,18 @@ QofSessionImpl::load (QofPercentageFunc percentage_func) noexcept
return; return;
} }
LEAVE ("sess = %p, book_id=%s", this, m_book_id.c_str ()); LEAVE ("sess = %p, uri=%s", this, m_uri.c_str ());
} }
void void
QofSessionImpl::begin (std::string new_book_id, bool ignore_lock, QofSessionImpl::begin (const char* new_uri, bool ignore_lock,
bool create, bool force) noexcept bool create, bool force) noexcept
{ {
ENTER (" sess=%p ignore_lock=%d, book-id=%s", ENTER (" sess=%p ignore_lock=%d, book-id=%s",
this, ignore_lock, new_book_id.c_str ()); this, ignore_lock, new_uri);
clear_error (); clear_error ();
/* Check to see if this session is already open */ /* Check to see if this session is already open */
if (m_book_id.size ()) if (m_uri.size ())
{ {
if (ERR_BACKEND_NO_ERR != get_error ()) if (ERR_BACKEND_NO_ERR != get_error ())
push_error (ERR_BACKEND_LOCKED, {}); push_error (ERR_BACKEND_LOCKED, {});
@@ -266,20 +266,20 @@ QofSessionImpl::begin (std::string new_book_id, bool ignore_lock,
} }
/* seriously invalid */ /* seriously invalid */
if (!new_book_id.size ()) if (!new_uri)
{ {
if (ERR_BACKEND_NO_ERR != get_error ()) if (ERR_BACKEND_NO_ERR != get_error ())
push_error (ERR_BACKEND_BAD_URL, {}); push_error (ERR_BACKEND_BAD_URL, {});
LEAVE("push error missing new_book_id"); LEAVE("push error missing new_uri");
return; return;
} }
char * scheme {g_uri_parse_scheme (new_book_id.c_str ())}; char * scheme {g_uri_parse_scheme (new_uri)};
char * filename {nullptr}; char * filename {nullptr};
if (g_strcmp0 (scheme, "file") == 0) if (g_strcmp0 (scheme, "file") == 0)
filename = g_filename_from_uri (new_book_id.c_str (), nullptr, nullptr); filename = g_filename_from_uri (new_uri, nullptr, nullptr);
else if (!scheme) else if (!scheme)
filename = g_strdup (new_book_id.c_str ()); filename = g_strdup (new_uri);
if (filename && g_file_test (filename, G_FILE_TEST_IS_DIR)) if (filename && g_file_test (filename, G_FILE_TEST_IS_DIR))
{ {
@@ -293,7 +293,7 @@ QofSessionImpl::begin (std::string new_book_id, bool ignore_lock,
/* destroy the old backend */ /* destroy the old backend */
destroy_backend (); destroy_backend ();
/* Store the session URL */ /* Store the session URL */
m_book_id = new_book_id; m_uri = new_uri;
m_creating = create; m_creating = create;
if (filename) if (filename)
load_backend ("file"); load_backend ("file");
@@ -305,23 +305,23 @@ QofSessionImpl::begin (std::string new_book_id, bool ignore_lock,
/* No backend was found. That's bad. */ /* No backend was found. That's bad. */
if (m_backend == nullptr) if (m_backend == nullptr)
{ {
m_book_id = {}; m_uri = {};
if (ERR_BACKEND_NO_ERR == get_error ()) if (ERR_BACKEND_NO_ERR == get_error ())
push_error (ERR_BACKEND_BAD_URL, {}); push_error (ERR_BACKEND_BAD_URL, {});
LEAVE (" BAD: no backend: sess=%p book-id=%s", LEAVE (" BAD: no backend: sess=%p book-id=%s",
this, new_book_id.c_str ()); this, new_uri);
return; return;
} }
/* If there's a begin method, call that. */ /* If there's a begin method, call that. */
m_backend->session_begin(this, m_book_id.c_str(), m_backend->session_begin(this, m_uri.c_str(),
ignore_lock, create, force); ignore_lock, create, force);
PINFO ("Done running session_begin on backend"); PINFO ("Done running session_begin on backend");
QofBackendError const err {m_backend->get_error()}; QofBackendError const err {m_backend->get_error()};
auto msg (m_backend->get_message()); auto msg (m_backend->get_message());
if (err != ERR_BACKEND_NO_ERR) if (err != ERR_BACKEND_NO_ERR)
{ {
m_book_id = {}; m_uri = {};
push_error (err, msg); push_error (err, msg);
LEAVE (" backend error %d %s", err, msg.empty() ? "(null)" : msg.c_str()); LEAVE (" backend error %d %s", err, msg.empty() ? "(null)" : msg.c_str());
return; return;
@@ -331,19 +331,19 @@ QofSessionImpl::begin (std::string new_book_id, bool ignore_lock,
PWARN("%s", msg.c_str()); PWARN("%s", msg.c_str());
} }
LEAVE (" sess=%p book-id=%s", this, new_book_id.c_str ()); LEAVE (" sess=%p book-id=%s", this, new_uri);
} }
void void
QofSessionImpl::end () noexcept QofSessionImpl::end () noexcept
{ {
ENTER ("sess=%p book_id=%s", this, m_book_id.c_str ()); ENTER ("sess=%p uri=%s", this, m_uri.c_str ());
auto backend = qof_book_get_backend (m_book); auto backend = qof_book_get_backend (m_book);
if (backend != nullptr) if (backend != nullptr)
backend->session_end(); backend->session_end();
clear_error (); clear_error ();
m_book_id.clear(); m_uri.clear();
LEAVE ("sess=%p book_id=%s", this, m_book_id.c_str ()); LEAVE ("sess=%p uri=%s", this, m_uri.c_str ());
} }
/* error handling functions --------------------------------*/ /* error handling functions --------------------------------*/
@@ -424,9 +424,9 @@ QofSessionImpl::get_file_path () const noexcept
} }
std::string const & std::string const &
QofSessionImpl::get_book_id () const noexcept QofSessionImpl::get_uri () const noexcept
{ {
return m_book_id; return m_uri;
} }
bool bool
@@ -443,7 +443,7 @@ QofSessionImpl::save (QofPercentageFunc percentage_func) noexcept
if (!qof_book_session_not_saved (m_book)) //Clean book, nothing to do. if (!qof_book_session_not_saved (m_book)) //Clean book, nothing to do.
return; return;
m_saving = true; m_saving = true;
ENTER ("sess=%p book_id=%s", this, m_book_id.c_str ()); ENTER ("sess=%p uri=%s", this, m_uri.c_str ());
/* If there is a backend, the book is dirty, and the backend is reachable /* If there is a backend, the book is dirty, and the backend is reachable
* (i.e. we can communicate with it), then synchronize with the backend. If * (i.e. we can communicate with it), then synchronize with the backend. If
@@ -490,7 +490,7 @@ QofSessionImpl::safe_save (QofPercentageFunc percentage_func) noexcept
auto msg = m_backend->get_message(); auto msg = m_backend->get_message();
if (err != ERR_BACKEND_NO_ERR) if (err != ERR_BACKEND_NO_ERR)
{ {
m_book_id = nullptr; m_uri = "";
push_error (err, msg); push_error (err, msg);
} }
} }
@@ -540,8 +540,8 @@ QofSessionImpl::export_session (QofSessionImpl & real_session,
QofPercentageFunc percentage_func) noexcept QofPercentageFunc percentage_func) noexcept
{ {
auto real_book = real_session.get_book (); auto real_book = real_session.get_book ();
ENTER ("tmp_session=%p real_session=%p book=%p book_id=%s", ENTER ("tmp_session=%p real_session=%p book=%p uri=%s",
this, &real_session, real_book, m_book_id.c_str ()); this, &real_session, real_book, m_uri.c_str ());
/* There must be a backend or else. (It should always be the file /* There must be a backend or else. (It should always be the file
* backend too.) * backend too.)
@@ -599,7 +599,7 @@ const char *
qof_session_get_url (const QofSession *session) qof_session_get_url (const QofSession *session)
{ {
if (!session) return NULL; if (!session) return NULL;
return session->get_book_id ().c_str (); return session->get_uri ().c_str ();
} }
QofBackend * QofBackend *
@@ -610,11 +610,11 @@ qof_session_get_backend (const QofSession *session)
} }
void void
qof_session_begin (QofSession *session, const char * book_id, qof_session_begin (QofSession *session, const char * new_uri,
gboolean ignore_lock, gboolean create, gboolean force) gboolean ignore_lock, gboolean create, gboolean force)
{ {
if (!session) return; if (!session) return;
session->begin((book_id ? book_id : ""), ignore_lock, create, force); session->begin((new_uri ? new_uri : ""), ignore_lock, create, force);
} }
void void
@@ -706,18 +706,18 @@ qof_session_destroy_backend (QofSession * session)
session->destroy_backend (); session->destroy_backend ();
} }
void qof_session_set_book_id (QofSession * session, char const * book_id) void qof_session_set_uri (QofSession * session, char const * uri)
{ {
if (!book_id) if (!uri)
session->m_book_id = ""; session->m_uri = "";
else else
session->m_book_id = book_id; session->m_uri = uri;
} }
void (*p_qof_session_load_backend) (QofSession *, const char * access_method); void (*p_qof_session_load_backend) (QofSession *, const char * access_method);
void (*p_qof_session_clear_error) (QofSession *); void (*p_qof_session_clear_error) (QofSession *);
void (*p_qof_session_destroy_backend) (QofSession *); void (*p_qof_session_destroy_backend) (QofSession *);
void (*p_qof_session_set_book_id) (QofSession *, char const * book_id); void (*p_qof_session_set_uri) (QofSession *, char const * uri);
void void
init_static_qofsession_pointers (void) init_static_qofsession_pointers (void)
@@ -725,7 +725,7 @@ init_static_qofsession_pointers (void)
p_qof_session_load_backend = &qof_session_load_backend; p_qof_session_load_backend = &qof_session_load_backend;
p_qof_session_clear_error = &qof_session_clear_error; p_qof_session_clear_error = &qof_session_clear_error;
p_qof_session_destroy_backend = &qof_session_destroy_backend; p_qof_session_destroy_backend = &qof_session_destroy_backend;
p_qof_session_set_book_id = &qof_session_set_book_id; p_qof_session_set_uri = &qof_session_set_uri;
} }
QofBackendError QofBackendError

View File

@@ -152,7 +152,7 @@ void qof_session_swap_data (QofSession *session_1, QofSession *session_2);
* If an error occurs, it will be pushed onto the session error * If an error occurs, it will be pushed onto the session error
* stack, and that is where it should be examined. * stack, and that is where it should be examined.
*/ */
void qof_session_begin (QofSession *session, const char * book_id, void qof_session_begin (QofSession *session, const char * new_uri,
gboolean ignore_lock, gboolean create, gboolean ignore_lock, gboolean create,
gboolean force); gboolean force);

View File

@@ -41,7 +41,7 @@ struct QofSessionImpl
~QofSessionImpl () noexcept; ~QofSessionImpl () noexcept;
/** Begin this session. */ /** Begin this session. */
void begin (std::string book_id, bool ignore_lock, bool create, bool force) noexcept; void begin (const char* new_uri, bool ignore_lock, bool create, bool force) noexcept;
/** Swap books with another session */ /** Swap books with another session */
void swap_books (QofSessionImpl &) noexcept; void swap_books (QofSessionImpl &) noexcept;
@@ -62,7 +62,7 @@ struct QofSessionImpl
* We return by reference so that a pointer to the data of the string lives * We return by reference so that a pointer to the data of the string lives
* long enough to make it back to C code. * long enough to make it back to C code.
*/ */
std::string const & get_book_id () const noexcept; std::string const & get_uri () const noexcept;
/** /**
* Returns and clears the local cached error. If there is no local error, we check * Returns and clears the local cached error. If there is no local error, we check
* for an error in the backend. * for an error in the backend.
@@ -92,10 +92,10 @@ private:
/* A book holds pointers to the various types of datasets. /* A book holds pointers to the various types of datasets.
* A session has exactly one book. */ * A session has exactly one book. */
QofBook * m_book; QofBook * m_book;
/* The requested book id, in the form or a URI, such as /* The requested URI, such as
* file:/some/where, or sql:server.host.com:555 * file://some/where, or sql:server.host.com:555
*/ */
std::string m_book_id; std::string m_uri;
bool m_saving; bool m_saving;
bool m_creating; bool m_creating;
@@ -113,8 +113,8 @@ private:
/* These functions support the old testing infrastructure and should /* These functions support the old testing infrastructure and should
* be removed when they are no longer necessary.*/ * be removed when they are no longer necessary.*/
friend void qof_session_load_backend (QofSession *, const char *); friend void qof_session_load_backend (QofSession *, const char *);
friend char const * qof_session_get_book_id (QofSession *); friend char const * qof_session_get_uri (QofSession *);
friend void qof_session_set_book_id (QofSession *, char const *); friend void qof_session_set_uri (QofSession *, char const *);
}; };
typedef struct qof_instance_copy_data typedef struct qof_instance_copy_data

View File

@@ -41,7 +41,6 @@ extern "C" void test_suite_qofsession ( void );
extern void (*p_qof_session_load_backend) (QofSession *, const char * access_method); 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_clear_error) (QofSession *);
extern void (*p_qof_session_destroy_backend) (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); void init_static_qofsession_pointers (void);
@@ -134,10 +133,10 @@ struct QofMockLoadBackendProvider : public QofBackendProvider
}; };
bool bool
QofMockLoadBackendProvider::type_check (const char* book_id) QofMockLoadBackendProvider::type_check (const char* uri)
{ {
g_assert (book_id); g_assert (uri);
g_assert_cmpstr (book_id, ==, "my book"); g_assert_cmpstr (uri, ==, "my book");
load_backend_struct.check_data_type_called = true; load_backend_struct.check_data_type_called = true;
return load_backend_struct.data_compatible; return load_backend_struct.data_compatible;
} }
@@ -184,7 +183,7 @@ test_qof_session_load_backend (Fixture *fixture, gconstpointer pData)
qof_backend_register_provider (std::move(prov)); qof_backend_register_provider (std::move(prov));
load_backend_struct.data_compatible = FALSE; load_backend_struct.data_compatible = FALSE;
load_backend_struct.check_data_type_called = FALSE; load_backend_struct.check_data_type_called = FALSE;
p_qof_session_set_book_id (fixture->session, "my book"); p_qof_session_set_uri (fixture->session, "my book");
p_qof_session_load_backend (fixture->session, "file"); p_qof_session_load_backend (fixture->session, "file");
g_assert (load_backend_struct.check_data_type_called); g_assert (load_backend_struct.check_data_type_called);
g_assert_cmpint (qof_session_get_error (fixture->session), == , ERR_BACKEND_NO_HANDLER); g_assert_cmpint (qof_session_get_error (fixture->session), == , ERR_BACKEND_NO_HANDLER);
@@ -243,7 +242,7 @@ test_qof_session_load (Fixture *fixture, gconstpointer pData)
QofBook *newbook = NULL; QofBook *newbook = NULL;
/* init */ /* init */
p_qof_session_set_book_id (fixture->session, "my book"); p_qof_session_set_uri (fixture->session, "my book");
be = g_new0 (QofBackend, 1); be = g_new0 (QofBackend, 1);
g_assert (be); g_assert (be);
qof_book_set_backend (qof_session_get_book (fixture->session), be); qof_book_set_backend (qof_session_get_book (fixture->session), be);
@@ -280,22 +279,22 @@ static struct
{ {
QofBackend *be; QofBackend *be;
QofSession *session; QofSession *session;
const char *book_id; const char *uri;
gboolean backend_new_called; gboolean backend_new_called;
gboolean session_begin_called; gboolean session_begin_called;
gboolean produce_error; gboolean produce_error;
} session_begin_struct; } session_begin_struct;
static void static void
mock_session_begin (QofBackend *be, QofSession *session, const char *book_id, mock_session_begin (QofBackend *be, QofSession *session, const char *uri,
gboolean ignore_lock, gboolean create, gboolean force) gboolean ignore_lock, gboolean create, gboolean force)
{ {
g_assert (be); g_assert (be);
g_assert (be == session_begin_struct.be); g_assert (be == session_begin_struct.be);
g_assert (session); g_assert (session);
g_assert (session == session_begin_struct.session); g_assert (session == session_begin_struct.session);
g_assert (book_id); g_assert (uri);
g_assert_cmpstr (book_id, == , session_begin_struct.book_id); g_assert_cmpstr (uri, == , session_begin_struct.uri);
g_assert (ignore_lock); g_assert (ignore_lock);
g_assert (!create); g_assert (!create);
g_assert (force); g_assert (force);
@@ -315,9 +314,9 @@ struct QofMockSessBackendProvider : public QofBackendProvider
}; };
bool bool
QofMockSessBackendProvider::type_check (const char* book_id) QofMockSessBackendProvider::type_check (const char* uri)
{ {
g_assert (book_id); g_assert (uri);
return true; return true;
} }
@@ -350,14 +349,14 @@ test_qof_session_begin (Fixture *fixture, gconstpointer pData)
g_assert_cmpint (get_providers().size(), == , 0); g_assert_cmpint (get_providers().size(), == , 0);
/* run tests */ /* run tests */
g_test_message ("Test when book_id is set backend is not changed"); g_test_message ("Test when uri is set backend is not changed");
qof_book_set_backend (qof_session_get_book (fixture->session), be); qof_book_set_backend (qof_session_get_book (fixture->session), be);
p_qof_session_set_book_id (fixture->session, "my book"); p_qof_session_set_uri (fixture->session, "my book");
qof_session_begin (fixture->session, "my book", ignore_lock, create, force); qof_session_begin (fixture->session, "my book", ignore_lock, create, force);
g_assert (qof_book_get_backend (qof_session_get_book (fixture->session)) == 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_test_message ("Test when session uri is not set and uri passed is null backend is not changed");
p_qof_session_set_book_id (fixture->session, NULL); p_qof_session_set_uri (fixture->session, NULL);
qof_session_begin (fixture->session, NULL, ignore_lock, create, force); qof_session_begin (fixture->session, NULL, ignore_lock, create, force);
g_assert (qof_book_get_backend (qof_session_get_book (fixture->session)) == be); g_assert (qof_book_get_backend (qof_session_get_book (fixture->session)) == be);
@@ -379,7 +378,7 @@ test_qof_session_begin (Fixture *fixture, gconstpointer pData)
g_test_message ("Test with valid backend returned and session begin set; error is produced"); g_test_message ("Test with valid backend returned and session begin set; error is produced");
session_begin_struct.session = fixture->session; session_begin_struct.session = fixture->session;
session_begin_struct.book_id = "postgres://localhost:8080"; session_begin_struct.uri = "postgres://localhost:8080";
session_begin_struct.backend_new_called = FALSE; session_begin_struct.backend_new_called = FALSE;
session_begin_struct.session_begin_called = FALSE; session_begin_struct.session_begin_called = FALSE;
session_begin_struct.produce_error = TRUE; session_begin_struct.produce_error = TRUE;
@@ -417,7 +416,7 @@ static struct
QofBackend *be; QofBackend *be;
QofBook *book; QofBook *book;
QofSession *session; QofSession *session;
const char *book_id; const char *uri;
gboolean sync_called; gboolean sync_called;
gboolean backend_new_called; gboolean backend_new_called;
gboolean session_begin_called; gboolean session_begin_called;
@@ -545,14 +544,14 @@ test_qof_session_end (Fixture *fixture, gconstpointer pData)
{ {
QofBackend *be = NULL; QofBackend *be = NULL;
g_test_message ("Test backend is closed, errors cleared and book_id removed"); g_test_message ("Test backend is closed, errors cleared and uri removed");
be = g_new0 (QofBackend, 1); be = g_new0 (QofBackend, 1);
g_assert (be); g_assert (be);
be->session_end = mock_session_end; be->session_end = mock_session_end;
be->last_err = ERR_BACKEND_DATA_CORRUPT; be->last_err = ERR_BACKEND_DATA_CORRUPT;
be->error_msg = g_strdup("push any error"); be->error_msg = g_strdup("push any error");
qof_book_set_backend (qof_session_get_book (fixture->session), be); qof_book_set_backend (qof_session_get_book (fixture->session), be);
p_qof_session_set_book_id (fixture->session, "my book"); p_qof_session_set_uri (fixture->session, "my book");
session_end_struct.called = FALSE; session_end_struct.called = FALSE;
session_end_struct.be = be; session_end_struct.be = be;
qof_session_end (fixture->session); qof_session_end (fixture->session);