mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Replace in-test setup and teardown with a fixture.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22463 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
6f66fa8993
commit
2bca864ddf
@ -219,8 +219,6 @@ test_dbi_business_store_and_reload( const gchar* driver, QofSession* session_1,
|
|||||||
|
|
||||||
// Compare with the original data
|
// Compare with the original data
|
||||||
compare_books( qof_session_get_book( session_2 ), qof_session_get_book( session_3 ) );
|
compare_books( qof_session_get_book( session_2 ), qof_session_get_book( session_3 ) );
|
||||||
qof_session_end( session_1 );
|
|
||||||
qof_session_destroy( session_1 );
|
|
||||||
qof_session_end( session_2 );
|
qof_session_end( session_2 );
|
||||||
qof_session_destroy( session_2 );
|
qof_session_destroy( session_2 );
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <glib/gstdio.h>
|
||||||
|
|
||||||
#include "unittest-support.h"
|
#include "unittest-support.h"
|
||||||
#include "test-stuff.h"
|
#include "test-stuff.h"
|
||||||
@ -21,67 +21,66 @@ void do_test_mysql(void);
|
|||||||
void do_test_pgsql(void);
|
void do_test_pgsql(void);
|
||||||
|
|
||||||
#define DBI_TEST_XML_FILENAME "test-dbi.xml"
|
#define DBI_TEST_XML_FILENAME "test-dbi.xml"
|
||||||
#define FILE_NAME "sqlite3:///tmp/test-sqlite3-file"
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
QofSession *session;
|
QofSession *session;
|
||||||
|
gchar *filename;
|
||||||
|
} Fixture;
|
||||||
|
|
||||||
void
|
static void
|
||||||
do_test_sqlite(void)
|
setup (Fixture *fixture, gconstpointer pData)
|
||||||
{
|
{
|
||||||
gchar* filename;
|
fixture->session = qof_session_new();
|
||||||
QofSession* session_1;
|
qof_session_begin( fixture->session, DBI_TEST_XML_FILENAME, FALSE,
|
||||||
|
FALSE, FALSE );
|
||||||
|
g_assert_cmpint (qof_session_get_error (fixture->session), ==,
|
||||||
|
ERR_BACKEND_NO_ERR);
|
||||||
|
qof_session_load( fixture->session, NULL );
|
||||||
|
|
||||||
g_test_log_set_fatal_handler(handler, 0);
|
fixture->filename = tempnam( "/tmp", "test-sqlite3-" );
|
||||||
|
g_test_message ( "Using filename: %s\n", fixture->filename );
|
||||||
// Create a session with data
|
|
||||||
session_1 = qof_session_new();
|
|
||||||
qof_session_begin( session_1, DBI_TEST_XML_FILENAME, FALSE, FALSE, FALSE );
|
|
||||||
qof_session_load( session_1, NULL );
|
|
||||||
|
|
||||||
filename = tempnam( "/tmp", "test-sqlite3-" );
|
|
||||||
g_test_message ( "Using filename: %s\n", filename );
|
|
||||||
test_dbi_store_and_reload( "sqlite3", session_1, filename );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
do_test_mysql(void)
|
teardown (Fixture *fixture, gconstpointer pData)
|
||||||
{
|
{
|
||||||
gchar* filename;
|
qof_session_end (fixture->session);
|
||||||
QofSession* session_1;
|
qof_session_destroy (fixture->session);
|
||||||
|
g_unlink (fixture->filename);
|
||||||
|
|
||||||
// Create a session with data
|
|
||||||
session_1 = qof_session_new();
|
|
||||||
qof_session_begin( session_1, DBI_TEST_XML_FILENAME, FALSE, FALSE, FALSE );
|
|
||||||
qof_session_load( session_1, NULL );
|
|
||||||
|
|
||||||
g_test_message ( "Using database: %s\n", TEST_MYSQL_URL );
|
|
||||||
test_dbi_store_and_reload( "mysql", session_1, TEST_MYSQL_URL );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
do_test_pgsql(void)
|
static void
|
||||||
|
test_sqlite_store_and_reload (Fixture *fixture, gconstpointer pData)
|
||||||
{
|
{
|
||||||
gchar* filename;
|
|
||||||
QofSession* session_1;
|
|
||||||
|
|
||||||
// Create a session with data
|
// Create a session with data
|
||||||
session_1 = qof_session_new();
|
test_dbi_store_and_reload( "sqlite3", fixture->session, fixture->filename );
|
||||||
qof_session_begin( session_1, DBI_TEST_XML_FILENAME, FALSE, FALSE, FALSE );
|
}
|
||||||
qof_session_load( session_1, NULL );
|
|
||||||
|
|
||||||
g_test_message ( "Using database: %s\n", TEST_PGSQL_URL );
|
static void
|
||||||
test_dbi_store_and_reload( "postgres", session_1, TEST_PGSQL_URL );
|
test_mysql_store_and_reload (Fixture *fixture, gconstpointer pData)
|
||||||
|
{
|
||||||
|
g_assert (strlen (TEST_MYSQL_URL) > 0);
|
||||||
|
test_dbi_store_and_reload( TEST_MYSQL_URL, fixture->session,
|
||||||
|
fixture->filename );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_pgsql_store_and_reload (Fixture *fixture, gconstpointer pData)
|
||||||
|
{
|
||||||
|
g_assert (strlen (TEST_PGSQL_URL) > 0);
|
||||||
|
test_dbi_store_and_reload( TEST_PGSQL_URL, fixture->session,
|
||||||
|
fixture->filename );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
test_suite_gnc_backend_dbi_basic(void)
|
test_suite_gnc_backend_dbi_basic(void)
|
||||||
{
|
{
|
||||||
GNC_TEST_ADD_FUNC(suitename, "gnc dbi test sqlite", do_test_sqlite);
|
GNC_TEST_ADD (suitename, "store_and_reload/sqlite", Fixture, NULL, setup, test_sqlite_store_and_reload, teardown);
|
||||||
if ( strlen( TEST_MYSQL_URL ) > 0 )
|
if (strlen (TEST_MYSQL_URL) > 0)
|
||||||
GNC_TEST_ADD_FUNC(suitename, "gnc dbi test mysql", do_test_mysql);
|
GNC_TEST_ADD (suitename, "store_and_reload/mysql", Fixture, NULL, setup, test_mysql_store_and_reload, teardown);
|
||||||
if ( strlen( TEST_PGSQL_URL ) > 0 )
|
if (strlen (TEST_PGSQL_URL) > 0)
|
||||||
GNC_TEST_ADD_FUNC(suitename, "gnc dbi test pgsql", do_test_pgsql);
|
GNC_TEST_ADD (suitename, "store_and_reload/postgres", Fixture, NULL, setup, test_pgsql_store_and_reload, teardown);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user