diff --git a/configure.ac b/configure.ac index 3c8eacae0a..b6150db755 100644 --- a/configure.ac +++ b/configure.ac @@ -1507,6 +1507,7 @@ AC_CONFIG_FILES( src/import-export/log-replay/Makefile src/import-export/aqb/Makefile src/import-export/aqb/gschemas/Makefile + src/import-export/aqb/test/Makefile src/libqof/Makefile src/libqof/qof/Makefile src/libqof/qof/test/Makefile diff --git a/src/import-export/aqb/Makefile.am b/src/import-export/aqb/Makefile.am index ee169c49fe..a79a82be65 100644 --- a/src/import-export/aqb/Makefile.am +++ b/src/import-export/aqb/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = . gschemas +SUBDIRS = . gschemas test pkglib_LTLIBRARIES = libgncmod-aqbanking.la diff --git a/src/import-export/aqb/test/Makefile.am b/src/import-export/aqb/test/Makefile.am new file mode 100644 index 0000000000..e50fbe8360 --- /dev/null +++ b/src/import-export/aqb/test/Makefile.am @@ -0,0 +1,64 @@ +# A template Makefile.am for GLib g_test-based test directories. +# Copyright 2011 John Ralls + +include $(top_srcdir)/test-templates/Makefile.decl + + +#You will only need one of these: It points to the module directory +#after $(top_srcdir) or ${top_builddir}: +MODULEPATH = src/import-export/aqb + +#The test program. You'll need to add to this if you have more than one module above. +TEST_PROGS += test-aqb + +noinst_PROGRAMS = ${TEST_PROGS} + +test_aqbdir = ${top_srcdir}/${MODULEPATH}/test + +#Program files for tests go here. It's probably best to have one for +#each file in the parent directory. Include +#test_foo_support.c if you have one and aren't building the +#support library. +test_aqb_SOURCES = \ + test-aqb.c \ + test-kvp.c + +test_aqb_HEADERSS = + +#The tests might require more libraries, but try to keep them +#as independent as possible. +test_aqb_LDADD = \ + ${top_builddir}/${MODULEPATH}/libgncmod-aqbanking.la \ + ${top_builddir}/src/import-export/libgncmod-generic-import.la \ + ${top_builddir}/src/gnome/libgnc-gnome.la \ + ${top_builddir}/src/gnome-utils/libgncmod-gnome-utils.la \ + ${top_builddir}/src/register/ledger-core/libgncmod-ledger-core.la \ + ${top_builddir}/src/report/report-gnome/libgncmod-report-gnome.la \ + ${top_builddir}/src/app-utils/libgncmod-app-utils.la \ + ${top_builddir}/src/backend/xml/libgncmod-backend-xml.la \ + ${top_builddir}/src/backend/xml/libgnc-backend-xml-utils.la \ + ${top_builddir}/src/engine/libgncmod-engine.la \ + ${top_builddir}/src/core-utils/libgnc-core-utils.la \ + ${top_builddir}/src/gnc-module/libgnc-module.la \ + ${top_builddir}/src/libqof/qof/libgnc-qof.la \ + ${GLIB_LIBS} + +test_aqb_CFLAGS = \ + -DTESTPROG=test_aqb \ + ${DEFAULT_INCLUDES} \ + -I$(top_srcdir)/${MODULEPATH}/ \ + -I${top_srcdir}/src \ + -I${top_srcdir}/src/import-export \ + -I${top_srcdir}/src/gnome \ + -I${top_srcdir}/src/register/ledger-core \ + -I${top_srcdir}/src/register/register-gnome \ + -I${top_srcdir}/src/register/register-core \ + -I${top_srcdir}/src/gnome-utils \ + -I${top_srcdir}/src/app-utils \ + -I${top_srcdir}/src/engine \ + -I${top_srcdir}/src/core-utils \ + -I${top_srcdir}/src/gnc-module \ + -I${top_srcdir}/src/libqof/qof \ + ${GTK_CFLAGS} \ + ${GLIB_CFLAGS} \ + ${AQBANKING_CFLAGS} diff --git a/src/import-export/aqb/test/file-book-hbcislot.gnucash b/src/import-export/aqb/test/file-book-hbcislot.gnucash new file mode 100644 index 0000000000..e7e1309d08 --- /dev/null +++ b/src/import-export/aqb/test/file-book-hbcislot.gnucash @@ -0,0 +1,85 @@ + + + +df401b548fd313dc40a50051277a0ae6 + + + + hbci + + + config-filename + /some/file + + + template-list + + + + amou + 0/1 + + + name + Some Name + + + purc + + + + purp + Some Purpose + + + racc + 1234563065 + + + rbcd + 12310517 + + + rnam + Recipient Name + + + + + + + + + + + + diff --git a/src/import-export/aqb/test/file-book.gnucash b/src/import-export/aqb/test/file-book.gnucash new file mode 100644 index 0000000000..ed662a2f55 --- /dev/null +++ b/src/import-export/aqb/test/file-book.gnucash @@ -0,0 +1,39 @@ + + + +df401b548fd313dc40a50051277a0ae6 + + + + + + diff --git a/src/import-export/aqb/test/test-aqb.c b/src/import-export/aqb/test/test-aqb.c new file mode 100644 index 0000000000..ff96bf60ae --- /dev/null +++ b/src/import-export/aqb/test/test-aqb.c @@ -0,0 +1,60 @@ +/******************************************************************** + * testmain.c: GLib g_test test execution file. * + * Copyright 2011 John Ralls * + * * + * 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@gnu.org * +\********************************************************************/ + + +/* This is a template test program. Copy it to the test sudirectory and rename it test_modulename.c. (Use the same modulename that you gave Makefile.am in the same directory. +Write and link other test files */ +#include +#include "config.h" +#include +#include "backend/xml/gnc-backend-xml.h" +#include "gnc-module/gnc-module.h" +#include "engine/gnc-engine.h" + +GTestSuite* test_suite_kvp ( void ); + +int +main (int argc, + char *argv[]) +{ + qof_init(); /* Initialize the GObject system */ + qof_log_init_filename_special("stderr"); /* Init the log system */ + g_test_init ( &argc, &argv, NULL ); /* initialize test program */ + qof_log_set_level("gnc", G_LOG_LEVEL_DEBUG); + g_test_bug_base("https://bugzilla.gnome.org/show_bug.cgi?id="); /* init the bugzilla URL */ + /* Disable the transaction log */ + xaccLogDisable(); + + gnc_module_system_init(); + gnc_engine_init_static(argc, argv); + gnc_module_init_backend_xml(); // register the file:// handler + + /* Add test functions and suites. See + * http://library.gnome.org/devel/glib/stable/glib-Testing.html for + * details. Unfortunately, GLib-Testing doesn't provide the automatic + * registration features of more sophisitcated frameworks. */ + g_test_add_func ("/AQBANKING/Kvp", test_suite_kvp); + + return g_test_run(); +} + + diff --git a/src/import-export/aqb/test/test-kvp.c b/src/import-export/aqb/test/test-kvp.c new file mode 100644 index 0000000000..8dc7586c30 --- /dev/null +++ b/src/import-export/aqb/test/test-kvp.c @@ -0,0 +1,144 @@ +/******************************************************************** + * test_submodule.c: Example GLib g_test test suite. * + * Copyright 2011 John Ralls * + * * + * 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@gnu.org * +\********************************************************************/ + +#include +#include +/* This is optional; you only need it if you have external fixtures or mocks. */ +//#include "test_module_support.h" +/* Header for this module and any others that you need */ +//#include +#include "gnc-ab-kvp.h" + +/* Declare the test path for the suite. g_test_add_func automatically + * creates a nested set of test suites for us based on this path. */ +static const gchar *suitename = "aqbanking/kvp"; + +/* Test fixture: A struct, a setup function, and a teardown function are passed to g_test_add(); add getters, setters, and whatever other functions you need to call from your test functions. */ +typedef struct +{ + gint foo; + gdouble bar; +} Fixture; + +static void +setup_module_test(Fixture *fixture, gconstpointer pData) +{ + /* Do something useful */ +} + +static void +teardown_module_test(Fixture *fixture, gconstpointer pData) +{ + /* Clean up after ourselves */ +} + +static void +test_function( void ) +{ + /* A simple test function */ +} + +static void +test_function_with_data( gconstpointer data ) +{ + /* a more complicated function that needs arguments at invocation */ +} + +/* Assert macros that you can use in your test functions. "cmp" is a + * comparison operator, one of ==, !=, <, >, <=, >=. + * + * g_assert( boolean_expression ) + * g_assert_not_reached() + * g_assert_cmpstr( gchar *s1, cmp, gchar *s2 ) + * g_assert_cmpint( int s1, cmp, int s2 ) + * g_assert_cmpuint( unsigned int s1, cmp, unsigned int s2 ) + * g_assert_cmphex( unsigned int s1, cmp, unsigned int s2 ) + * g_assert_cmpfloat( double s1, cmp, double s2 ) + * g_assert_no_error( GError *err ) + * g_assert_error( GError *err, GQuark domain, gint code ) + * + * You can also emit arbitrary messages into the test report with + * g_test_message( const char* format, ... ) + */ +GTestSuite* +test_suite_kvp ( void ) +{ +#define TOP_SRCDIR "../../../../../" + /* load the accounts from the users datafile */ + /* but first, check to make sure we've got a session going. */ + QofSession *new_session; + const char* newfile; + QofBackendError io_err; + +#if 0 + // A file with no content at all, but a valid XML file + new_session = qof_session_new (); + newfile = "file://" TOP_SRCDIR "src/import-export/aqb/test/file-book.gnucash"; + qof_session_begin (new_session, newfile, TRUE, FALSE, FALSE); + io_err = qof_session_get_error (new_session); + printf("io_err1 = %d\n", io_err); + g_assert(io_err != ERR_BACKEND_NO_HANDLER); // Do not have no handler + + g_assert(io_err != ERR_BACKEND_NO_SUCH_DB); // DB must exist + g_assert(io_err != ERR_BACKEND_LOCKED); + g_assert(io_err == 0); + + { + GList *mylist = gnc_ab_get_book_template_list(qof_session_get_book(new_session)); + g_assert(mylist == 0); + } +#endif + + //qof_session_destroy(new_session); + +#if 0 + // A file with no content except for the book_template_list kvp + // slot + new_session = qof_session_new (); + newfile = "file://" TOP_SRCDIR "src/import-export/aqb/test/file-book-hbcislot.gnucash"; + qof_session_begin (new_session, newfile, TRUE, FALSE, FALSE); + io_err = qof_session_get_error (new_session); + printf("io_err1 = %d\n", io_err); + g_assert(io_err != ERR_BACKEND_NO_HANDLER); // Do not have no handler + + g_assert(io_err != ERR_BACKEND_NO_SUCH_DB); // DB must exist + g_assert(io_err != ERR_BACKEND_LOCKED); + g_assert(io_err == 0); + + { + GList *mylist = gnc_ab_get_book_template_list(qof_session_get_book(new_session)); + g_assert(mylist != 0); // do we have the slot?! + } + +#endif + +#if 0 + g_test_add_func( suitename, test_function ); + g_test_add_data_func( suitename, (gconstpointer)(&data), + test_function_with_data ); + g_test_add( suitename, Fixture, + data, + setup_module_test, + test_function_with_fixture, + teardown_module_test); +#endif +}