r22182 - gnucash/trunk/src/backend/dbi/test - Convert DBI test to utest

Phil Longstaff plongstaff at code.gnucash.org
Sun May 20 17:21:09 EDT 2012


Author: plongstaff
Date: 2012-05-20 17:21:09 -0400 (Sun, 20 May 2012)
New Revision: 22182
Trac: http://svn.gnucash.org/trac/changeset/22182

Added:
   gnucash/trunk/src/backend/dbi/test/test-backend-dbi.c
   gnucash/trunk/src/backend/dbi/test/utest-backend-dbi-basic.c
   gnucash/trunk/src/backend/dbi/test/utest-backend-dbi-business.c
Modified:
   gnucash/trunk/src/backend/dbi/test/Makefile.am
   gnucash/trunk/src/backend/dbi/test/test-dbi-stuff.h
Log:
Convert DBI test to utest


Modified: gnucash/trunk/src/backend/dbi/test/Makefile.am
===================================================================
--- gnucash/trunk/src/backend/dbi/test/Makefile.am	2012-05-20 21:18:45 UTC (rev 22181)
+++ gnucash/trunk/src/backend/dbi/test/Makefile.am	2012-05-20 21:21:09 UTC (rev 22182)
@@ -1,27 +1,39 @@
-SUBDIRS = .
+# Makefile.am for src/backend/dbi/test
 
-check_LTLIBRARIES=libgncmod-test-dbi.la
+include $(top_srcdir)/test-templates/Makefile.decl
 
-libgncmod_test_dbi_la_SOURCES = \
-    test-dbi-stuff.c
-libgncmod_test_dbi_la_LDFLAGS = -module
+AM_CFLAGS = \
+  -I${top_srcdir}/lib/libc \
+  -I${top_srcdir}/src \
+  -I${top_srcdir}/src/core-utils \
+  -I${top_srcdir}/src/gnc-module \
+  -I${top_srcdir}/src/test-core \
+  -I${top_srcdir}/src/engine \
+  -I${top_srcdir}/src/engine/test-core \
+  -I${top_srcdir}/src/libqof/qof \
+  -I${top_srcdir}/src/backend/sql \
+  -DTEST_MYSQL_URL=\"${TEST_MYSQL_URL}\" \
+  -DTEST_PGSQL_URL=\"${TEST_PGSQL_URL}\" \
+  ${GLIB_CFLAGS} \
+  ${GUILE_INCS} \
+  ${GCONF_CFLAGS}
 
-test_dbi_business_SOURCES = \
-  test-dbi-business.c \
-  test-dbi-business-stuff.c
+LDADD = ${top_builddir}/src/test-core/libtest-core.la \
+        ${top_builddir}/src/gnc-module/libgnc-module.la \
+        ${top_builddir}/src/engine/libgncmod-engine.la \
+        ${top_builddir}/src/engine/test-core/libgncmod-test-engine.la \
+        ${top_builddir}/src/core-utils/libgnc-core-utils.la \
+        ${top_builddir}/src/libqof/qof/libgnc-qof.la \
+        ../libgncmod-backend-dbi.la \
+        ${top_builddir}/src/backend/sql/libgnc-backend-sql.la \
+        ${top_builddir}/lib/libc/libc-missing.la
 
-test_dbi_basic_SOURCES = \
-  test-dbi-basic.c
+#TESTS = \
+#  test-dbi-basic \
+#  test-dbi \
+#  test-dbi-business \
+#  test-load-backend
 
-test_dbi_SOURCES = \
-  test-dbi.c
-
-TESTS = \
-  test-dbi-basic \
-  test-dbi \
-  test-dbi-business \
-  test-load-backend
-
 GNC_TEST_DEPS = \
   --gnc-module-dir ${top_builddir}/src/engine \
   --guile-load-dir ${top_builddir}/src/engine \
@@ -30,52 +42,54 @@
   --library-dir    ${top_builddir}/src/gnc-module \
   --library-dir    ${top_builddir}/src/engine
 
-if CUSTOM_GNC_DBD_DIR
-gnc_dbd_dir_override = GNC_DBD_DIR="@GNC_DBD_DIR@"
-endif
-
 TESTS_ENVIRONMENT = \
   GNC_ACCOUNT_PATH=${top_srcdir}/accounts/C \
   SRCDIR=${srcdir} \
   ${gnc_dbd_dir_override} \
   $(shell ${top_srcdir}/src/gnc-test-env --no-exports ${GNC_TEST_DEPS})
 
-check_PROGRAMS = \
-  test-dbi-basic \
-  test-dbi \
-  test-dbi-business \
-  test-load-backend
+#check_PROGRAMS = \
+#  test-dbi-basic \
+#  test-dbi \
+#  test-dbi-business \
+#  test-load-backend
 
-EXTRA_DIST = \
+EXTRA_DIST += \
     test-dbi-stuff.h \
     test-dbi-business-stuff.h
 
-LDADD = ${top_builddir}/src/test-core/libtest-core.la \
-        ${top_builddir}/src/gnc-module/libgnc-module.la \
-        ${top_builddir}/src/engine/libgncmod-engine.la \
-        ${top_builddir}/src/engine/test-core/libgncmod-test-engine.la \
-        ${top_builddir}/src/core-utils/libgnc-core-utils.la \
-        ${top_builddir}/src/libqof/qof/libgnc-qof.la \
-        ${top_builddir}/src/backend/dbi/test/libgncmod-test-dbi.la \
-        ${top_builddir}/src/backend/sql/libgnc-backend-sql.la \
-        ${top_builddir}/lib/libc/libc-missing.la
+TEST_PROGS += \
+    test-backend-dbi
 
-AM_CFLAGS = \
-  -I${top_srcdir}/lib/libc \
-  -I${top_srcdir}/src \
-  -I${top_srcdir}/src/core-utils \
-  -I${top_srcdir}/src/gnc-module \
-  -I${top_srcdir}/src/test-core \
-  -I${top_srcdir}/src/engine \
-  -I${top_srcdir}/src/engine/test-core \
-  -I${top_srcdir}/src/libqof/qof \
-  -I${top_srcdir}/src/backend/sql \
-  -DTEST_MYSQL_URL=\"${TEST_MYSQL_URL}\" \
-  -DTEST_PGSQL_URL=\"${TEST_PGSQL_URL}\" \
-  ${GLIB_CFLAGS} \
-  ${GUILE_INCS} \
-  ${GCONF_CFLAGS}
+noinst_PROGRAMS = ${TEST_PROGS} ${CHECK_PROGS}
 
+#check_LTLIBRARIES=libgncmod-test-dbi.la
+
+#libgncmod_test_dbi_la_SOURCES = \
+#    test-dbi-stuff.c
+libgncmod_test_dbi_la_LDFLAGS = -module
+
+test_dbi_business_SOURCES = \
+  test-dbi-business.c \
+  test-dbi-business-stuff.c
+
+test_dbi_basic_SOURCES = \
+  test-dbi-basic.c
+
+test_dbi_SOURCES = \
+  test-dbi.c
+
+if CUSTOM_GNC_DBD_DIR
+gnc_dbd_dir_override = GNC_DBD_DIR="@GNC_DBD_DIR@"
+endif
+
+test_backend_dbi_SOURCES = \
+    test-backend-dbi.c \
+    utest-backend-dbi-basic.c \
+    utest-backend-dbi-business.c \
+    test-dbi-stuff.c \
+    test-dbi-business-stuff.c
+
 INCLUDES = -DG_LOG_DOMAIN=\"gnc.backend.dbi\"
 
 # If you let make run parallel builds it complains that there is no rule to make

Added: gnucash/trunk/src/backend/dbi/test/test-backend-dbi.c
===================================================================
--- gnucash/trunk/src/backend/dbi/test/test-backend-dbi.c	                        (rev 0)
+++ gnucash/trunk/src/backend/dbi/test/test-backend-dbi.c	2012-05-20 21:21:09 UTC (rev 22182)
@@ -0,0 +1,50 @@
+/********************************************************************
+ * test-backend-dbi.c: GLib test execution file for backend/dbi     *
+ * Copyright 2011 John Ralls <jralls at ceridwen.us>		            *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+\********************************************************************/
+
+
+#include "config.h"
+#include <glib.h>
+#include "qof.h"
+#include "cashobjects.h"
+
+extern void test_suite_gnc_backend_dbi_basic();
+extern void test_suite_gnc_backend_dbi_business();
+
+#define GNC_LIB_NAME "gncmod-backend-dbi"
+
+int
+main (int   argc,
+      char *argv[])
+{
+    g_type_init(); 			/* Initialize the GObject system */
+    g_test_init ( &argc, &argv, NULL ); 	/* initialize test program */
+    qof_log_init_filename_special("stderr"); /* Init the log system */
+    g_test_bug_base("https://bugzilla.gnome.org/show_bug.cgi?id="); /* init the bugzilla URL */
+    qof_init();
+    cashobjects_register();
+    qof_load_backend_library ("../.libs/", GNC_LIB_NAME);
+
+    test_suite_gnc_backend_dbi_basic();
+    test_suite_gnc_backend_dbi_business();
+
+    return g_test_run( );
+}

Modified: gnucash/trunk/src/backend/dbi/test/test-dbi-stuff.h
===================================================================
--- gnucash/trunk/src/backend/dbi/test/test-dbi-stuff.h	2012-05-20 21:18:45 UTC (rev 22181)
+++ gnucash/trunk/src/backend/dbi/test/test-dbi-stuff.h	2012-05-20 21:21:09 UTC (rev 22182)
@@ -26,6 +26,8 @@
 #ifndef _TEST_DBI_STUFF_H_
 #define _TEST_DBI_STUFF_H_
 
+#include "qof.h"
+
 typedef struct
 {
     QofBook* book_1;

Added: gnucash/trunk/src/backend/dbi/test/utest-backend-dbi-basic.c
===================================================================
--- gnucash/trunk/src/backend/dbi/test/utest-backend-dbi-basic.c	                        (rev 0)
+++ gnucash/trunk/src/backend/dbi/test/utest-backend-dbi-basic.c	2012-05-20 21:21:09 UTC (rev 22182)
@@ -0,0 +1,52 @@
+/*
+ * utest-gnc-prefs-gconf.c
+ *
+ *  Created on: 2011-04-23
+ *      Author: phil
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+
+#include "unittest-support.h"
+#include "test-stuff.h"
+#include "test-dbi-stuff.h"
+
+static const gchar* suitename = "/backend/dbi";
+void test_suite_gnc_backend_dbi_basic(void);
+
+void do_test_sqlite(void);
+
+#define DBI_TEST_XML_FILENAME "test-dbi.xml"
+#define FILE_NAME "sqlite3:///tmp/test-sqlite3-file"
+
+static gboolean handler(const gchar* log_domain, GLogLevelFlags log_level, const gchar* message, gpointer user_data)
+{
+    printf("domain=%s level=%d message=%s\n", log_domain, log_level, message);
+    return FALSE;
+}
+
+void
+do_test_sqlite(void)
+{
+    gchar* filename;
+    QofSession* session_1;
+
+    g_test_log_set_fatal_handler(handler, 0);
+
+    // 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
+test_suite_gnc_backend_dbi_basic(void)
+{
+    GNC_TEST_ADD_FUNC(suitename, "gnc dbi test sqlite", do_test_sqlite);
+}

Added: gnucash/trunk/src/backend/dbi/test/utest-backend-dbi-business.c
===================================================================
--- gnucash/trunk/src/backend/dbi/test/utest-backend-dbi-business.c	                        (rev 0)
+++ gnucash/trunk/src/backend/dbi/test/utest-backend-dbi-business.c	2012-05-20 21:21:09 UTC (rev 22182)
@@ -0,0 +1,205 @@
+/***************************************************************************
+ *            test-dbi-business.c
+ *
+ *  Tests saving and loading business objects to a dbi/sqlite3 db
+ *
+ *  Copyright (C) 2010  Phil Longstaff <plongstaff at rogers.com>
+ ****************************************************************************/
+
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ *  02110-1301, USA.
+ */
+
+/*
+ * utest-gnc-prefs-gconf.c
+ *
+ *  Created on: 2011-04-23
+ *      Author: phil
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+
+#include "unittest-support.h"
+#include "test-stuff.h"
+#include "test-dbi-stuff.h"
+
+static const gchar* suitename = "/backend/dbi";
+void test_suite_gnc_backend_dbi_business(void);
+
+void do_test_business_sqlite(void);
+
+#define DBI_TEST_XML_FILENAME "test-dbi.xml"
+#define FILE_NAME "sqlite3:///tmp/test-sqlite3-file"
+#define GNC_LIB_NAME "gncmod-backend-dbi"
+#include "config.h"
+#include "qof.h"
+#include "cashobjects.h"
+#include "test-engine-stuff.h"
+#include "test-stuff.h"
+#include "test-dbi-business-stuff.h"
+
+#include "Account.h"
+#include <TransLog.h>
+#include "Transaction.h"
+#include "Split.h"
+#include "gnc-commodity.h"
+#include "gncAddress.h"
+#include "gncCustomer.h"
+#include "gncInvoice.h"
+
+#include "gnc-backend-sql.h"
+
+#include "gnc-address-sql.h"
+#include "gnc-bill-term-sql.h"
+#include "gnc-customer-sql.h"
+#include "gnc-employee-sql.h"
+#include "gnc-entry-sql.h"
+#include "gnc-invoice-sql.h"
+#include "gnc-job-sql.h"
+#include "gnc-order-sql.h"
+#include "gnc-owner-sql.h"
+#include "gnc-tax-table-sql.h"
+#include "gnc-vendor-sql.h"
+
+#define FILE_NAME "sqlite3:///tmp/test-sqlite3-file"
+#define GNC_LIB_NAME "gncmod-backend-dbi"
+
+static QofSession*
+create_business_session(void)
+{
+    QofSession* session = qof_session_new();
+    QofBook* book = qof_session_get_book( session );
+    Account* root = gnc_book_get_root_account( book );
+    Account* acct1;
+    Account* acct2;
+    gnc_commodity_table* table;
+    gnc_commodity* currency;
+    GncAddress* addr;
+    GncCustomer* cust;
+    GncEmployee* emp;
+    GncVendor* v;
+    GncInvoice* inv;
+    GncJob* job;
+    GncTaxTable* tt;
+    GncTaxTableEntry* tte;
+
+    table = gnc_commodity_table_get_table( book );
+    currency = gnc_commodity_table_lookup( table, GNC_COMMODITY_NS_CURRENCY, "CAD" );
+
+    acct1 = xaccMallocAccount( book );
+    xaccAccountSetType( acct1, ACCT_TYPE_BANK );
+    xaccAccountSetName( acct1, "Bank 1" );
+    xaccAccountSetCommodity( acct1, currency );
+    xaccAccountSetHidden( acct1, FALSE );
+    xaccAccountSetPlaceholder( acct1, FALSE );
+    gnc_account_append_child( root, acct1 );
+
+    acct2 = xaccMallocAccount( book );
+    xaccAccountSetType( acct2, ACCT_TYPE_BANK );
+    xaccAccountSetName( acct2, "Bank 2" );
+    xaccAccountSetCommodity( acct2, currency );
+    xaccAccountSetHidden( acct2, FALSE );
+    xaccAccountSetPlaceholder( acct2, FALSE );
+    gnc_account_append_child( root, acct2 );
+
+    tt = gncTaxTableCreate( book );
+    gncTaxTableSetName( tt, "tt" );
+    tte = gncTaxTableEntryCreate();
+    gncTaxTableEntrySetAccount( tte, acct1 );
+    gncTaxTableEntrySetType( tte, GNC_AMT_TYPE_VALUE );
+    gncTaxTableEntrySetAmount( tte, gnc_numeric_zero() );
+    gncTaxTableAddEntry( tt, tte );
+    tte = gncTaxTableEntryCreate();
+    gncTaxTableEntrySetAccount( tte, acct2 );
+    gncTaxTableEntrySetType( tte, GNC_AMT_TYPE_PERCENT );
+    gncTaxTableEntrySetAmount( tte, gnc_numeric_zero() );
+    gncTaxTableAddEntry( tt, tte );
+
+    cust = gncCustomerCreate( book );
+    gncCustomerSetID( cust, "0001" );
+    gncCustomerSetName( cust, "MyCustomer" );
+    gncCustomerSetNotes( cust, "Here are some notes" );
+    gncCustomerSetCurrency( cust, currency );
+    addr = gncAddressCreate( book, QOF_INSTANCE(cust) );
+    gncAddressSetName( addr, "theAddress" );
+    gncAddressSetAddr1( addr, "Address line #1" );
+    gncAddressSetAddr2( addr, "Address line #2" );
+    gncAddressSetAddr3( addr, "Address line #3" );
+    gncAddressSetAddr4( addr, "Address line #4" );
+    gncAddressSetPhone( addr, "(123) 555-1212" );
+    gncAddressSetPhone( addr, "(123) 555-2121" );
+    gncAddressSetEmail( addr, "cust at mycustomer.com" );
+
+    emp = gncEmployeeCreate( book );
+    gncEmployeeSetID( emp, "0001" );
+    gncEmployeeSetUsername( emp, "gnucash" );
+    gncEmployeeSetLanguage( emp, "english" );
+    gncEmployeeSetCurrency( emp, currency );
+
+    return session;
+}
+
+/* Order in which business objects need to be loaded */
+static const gchar* fixed_load_order[] =
+{ GNC_ID_BILLTERM, GNC_ID_TAXTABLE, NULL };
+
+static void
+init_business_sql(void)
+{
+    /* Initialize our pointers into the backend subsystem */
+    gnc_address_sql_initialize();
+    gnc_billterm_sql_initialize();
+    gnc_customer_sql_initialize();
+    gnc_employee_sql_initialize();
+    gnc_entry_sql_initialize();
+    gnc_invoice_sql_initialize();
+    gnc_job_sql_initialize();
+    gnc_order_sql_initialize();
+    gnc_owner_sql_initialize();
+    gnc_taxtable_sql_initialize();
+    gnc_vendor_sql_initialize();
+
+    gnc_sql_set_load_order( fixed_load_order );
+}
+
+static gboolean handler(const gchar* log_domain, GLogLevelFlags log_level, const gchar* message, gpointer user_data)
+{
+    printf("domain=%s level=%d message=%s\n", log_domain, log_level, message);
+    return FALSE;
+}
+
+void
+do_test_business_sqlite(void)
+{
+    gchar* filename;
+    QofSession* session_1;
+
+    g_test_log_set_fatal_handler(handler, 0);
+
+    // Create a session with data
+    session_1 = create_business_session();
+    filename = tempnam( "/tmp", "test-sqlite3-" );
+    g_test_message ( "Using filename: %s\n", filename );
+    test_dbi_business_store_and_reload( "sqlite3", session_1, filename );
+}
+
+void
+test_suite_gnc_backend_dbi_business(void)
+{
+    GNC_TEST_ADD_FUNC(suitename, "gnc dbi test sqlite (business)", do_test_business_sqlite);
+}



More information about the gnucash-changes mailing list