gnucash master: Add some initial aqbanking test with example file that should demonstrate the hbci template kvp problem.

Christian Stimming cstim at code.gnucash.org
Fri Aug 29 17:35:16 EDT 2014


Updated	 via  https://github.com/Gnucash/gnucash/commit/5b653811 (commit)
	from  https://github.com/Gnucash/gnucash/commit/0871df56 (commit)



commit 5b653811f80385b76dc23f21c389ba5208aaa972
Author: Christian Stimming <christian at cstimming.de>
Date:   Fri Aug 29 23:32:40 2014 +0200

    Add some initial aqbanking test with example file that should demonstrate the hbci template kvp problem.
    
    Not yet working, though - the test, I mean.

diff --git a/configure.ac b/configure.ac
index 3c8eaca..b6150db 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 ee169c4..a79a82b 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 0000000..e50fbe8
--- /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 <jralls at ceridwen.us>
+
+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 0000000..e7e1309
--- /dev/null
+++ b/src/import-export/aqb/test/file-book-hbcislot.gnucash
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<gnc-v2
+     xmlns:gnc="http://www.gnucash.org/XML/gnc"
+     xmlns:act="http://www.gnucash.org/XML/act"
+     xmlns:book="http://www.gnucash.org/XML/book"
+     xmlns:cd="http://www.gnucash.org/XML/cd"
+     xmlns:cmdty="http://www.gnucash.org/XML/cmdty"
+     xmlns:price="http://www.gnucash.org/XML/price"
+     xmlns:slot="http://www.gnucash.org/XML/slot"
+     xmlns:split="http://www.gnucash.org/XML/split"
+     xmlns:sx="http://www.gnucash.org/XML/sx"
+     xmlns:trn="http://www.gnucash.org/XML/trn"
+     xmlns:ts="http://www.gnucash.org/XML/ts"
+     xmlns:fs="http://www.gnucash.org/XML/fs"
+     xmlns:bgt="http://www.gnucash.org/XML/bgt"
+     xmlns:recurrence="http://www.gnucash.org/XML/recurrence"
+     xmlns:lot="http://www.gnucash.org/XML/lot"
+     xmlns:addr="http://www.gnucash.org/XML/addr"
+     xmlns:owner="http://www.gnucash.org/XML/owner"
+     xmlns:billterm="http://www.gnucash.org/XML/billterm"
+     xmlns:bt-days="http://www.gnucash.org/XML/bt-days"
+     xmlns:bt-prox="http://www.gnucash.org/XML/bt-prox"
+     xmlns:cust="http://www.gnucash.org/XML/cust"
+     xmlns:employee="http://www.gnucash.org/XML/employee"
+     xmlns:entry="http://www.gnucash.org/XML/entry"
+     xmlns:invoice="http://www.gnucash.org/XML/invoice"
+     xmlns:job="http://www.gnucash.org/XML/job"
+     xmlns:order="http://www.gnucash.org/XML/order"
+     xmlns:taxtable="http://www.gnucash.org/XML/taxtable"
+     xmlns:tte="http://www.gnucash.org/XML/tte"
+     xmlns:vendor="http://www.gnucash.org/XML/vendor">
+<gnc:book version="2.0.0">
+<book:id type="guid">df401b548fd313dc40a50051277a0ae6</book:id>
+</gnc:book>
+<book:slots>
+  <slot>
+    <slot:key>hbci</slot:key>
+    <slot:value type="frame">
+      <slot>
+        <slot:key>config-filename</slot:key>
+        <slot:value type="string">/some/file</slot:value>
+      </slot>
+      <slot>
+        <slot:key>template-list</slot:key>
+        <slot:value type="list">
+          <slot:value type="frame">
+            <slot>
+              <slot:key>amou</slot:key>
+              <slot:value type="numeric">0/1</slot:value>
+            </slot>
+            <slot>
+              <slot:key>name</slot:key>
+              <slot:value type="string">Some Name</slot:value>
+            </slot>
+            <slot>
+              <slot:key>purc</slot:key>
+              <slot:value type="string"></slot:value>
+            </slot>
+            <slot>
+              <slot:key>purp</slot:key>
+              <slot:value type="string">Some Purpose</slot:value>
+            </slot>
+            <slot>
+              <slot:key>racc</slot:key>
+              <slot:value type="string">1234563065</slot:value>
+            </slot>
+            <slot>
+              <slot:key>rbcd</slot:key>
+              <slot:value type="string">12310517</slot:value>
+            </slot>
+            <slot>
+              <slot:key>rnam</slot:key>
+              <slot:value type="string">Recipient Name</slot:value>
+            </slot>
+          </slot:value>
+        </slot:value>
+      </slot>
+    </slot:value>
+  </slot>
+</book:slots>
+</gnc-v2>
+
+<!-- Local variables: -->
+<!-- mode: xml        -->
+<!-- End:             -->
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 0000000..ed662a2
--- /dev/null
+++ b/src/import-export/aqb/test/file-book.gnucash
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<gnc-v2
+     xmlns:gnc="http://www.gnucash.org/XML/gnc"
+     xmlns:act="http://www.gnucash.org/XML/act"
+     xmlns:book="http://www.gnucash.org/XML/book"
+     xmlns:cd="http://www.gnucash.org/XML/cd"
+     xmlns:cmdty="http://www.gnucash.org/XML/cmdty"
+     xmlns:price="http://www.gnucash.org/XML/price"
+     xmlns:slot="http://www.gnucash.org/XML/slot"
+     xmlns:split="http://www.gnucash.org/XML/split"
+     xmlns:sx="http://www.gnucash.org/XML/sx"
+     xmlns:trn="http://www.gnucash.org/XML/trn"
+     xmlns:ts="http://www.gnucash.org/XML/ts"
+     xmlns:fs="http://www.gnucash.org/XML/fs"
+     xmlns:bgt="http://www.gnucash.org/XML/bgt"
+     xmlns:recurrence="http://www.gnucash.org/XML/recurrence"
+     xmlns:lot="http://www.gnucash.org/XML/lot"
+     xmlns:addr="http://www.gnucash.org/XML/addr"
+     xmlns:owner="http://www.gnucash.org/XML/owner"
+     xmlns:billterm="http://www.gnucash.org/XML/billterm"
+     xmlns:bt-days="http://www.gnucash.org/XML/bt-days"
+     xmlns:bt-prox="http://www.gnucash.org/XML/bt-prox"
+     xmlns:cust="http://www.gnucash.org/XML/cust"
+     xmlns:employee="http://www.gnucash.org/XML/employee"
+     xmlns:entry="http://www.gnucash.org/XML/entry"
+     xmlns:invoice="http://www.gnucash.org/XML/invoice"
+     xmlns:job="http://www.gnucash.org/XML/job"
+     xmlns:order="http://www.gnucash.org/XML/order"
+     xmlns:taxtable="http://www.gnucash.org/XML/taxtable"
+     xmlns:tte="http://www.gnucash.org/XML/tte"
+     xmlns:vendor="http://www.gnucash.org/XML/vendor">
+<gnc:book version="2.0.0">
+<book:id type="guid">df401b548fd313dc40a50051277a0ae6</book:id>
+</gnc:book>
+</gnc-v2>
+
+<!-- Local variables: -->
+<!-- mode: xml        -->
+<!-- End:             -->
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 0000000..ff96bf6
--- /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 <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                   *
+\********************************************************************/
+
+
+/* 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 <glib.h>
+#include "config.h"
+#include <qof.h>
+#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 0000000..8dc7586
--- /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 <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>
+/* 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 <module_1.h>
+#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
+}



Summary of changes:
 configure.ac                                       |  1 +
 src/import-export/aqb/Makefile.am                  |  2 +-
 src/import-export/aqb/test/Makefile.am             | 64 ++++++++++++++++
 .../aqb/test/file-book-hbcislot.gnucash            | 85 ++++++++++++++++++++++
 src/import-export/aqb/test/file-book.gnucash       | 39 ++++++++++
 .../import-export/aqb/test/test-aqb.c              | 30 ++++++--
 .../import-export/aqb/test/test-kvp.c              | 81 ++++++++++++++-------
 7 files changed, 268 insertions(+), 34 deletions(-)
 create mode 100644 src/import-export/aqb/test/Makefile.am
 create mode 100644 src/import-export/aqb/test/file-book-hbcislot.gnucash
 create mode 100644 src/import-export/aqb/test/file-book.gnucash
 copy test-templates/testmain.c => src/import-export/aqb/test/test-aqb.c (71%)
 copy test-templates/test-suite.c => src/import-export/aqb/test/test-kvp.c (65%)



More information about the gnucash-changes mailing list