r22082 - gnucash/trunk/src/engine - Add some unittest for GncInvoice and posting/unposting an invoice.

Christian Stimming cstim at code.gnucash.org
Wed Mar 14 18:26:54 EDT 2012


Author: cstim
Date: 2012-03-14 18:26:54 -0400 (Wed, 14 Mar 2012)
New Revision: 22082
Trac: http://svn.gnucash.org/trac/changeset/22082

Added:
   gnucash/trunk/src/engine/test/utest-Invoice.c
Modified:
   gnucash/trunk/src/engine/gncInvoice.c
   gnucash/trunk/src/engine/test/Makefile.am
   gnucash/trunk/src/engine/test/test-engine.c
Log:
Add some unittest for GncInvoice and posting/unposting an invoice.

I thought this would reproduce the crash when unposting a real invoice
with G_SLICE=always-malloc set. However, apparently this test case isn't
complete enough and does not crash. Maybe one needs to add further GncEntries?

Modified: gnucash/trunk/src/engine/gncInvoice.c
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.c	2012-03-14 22:26:42 UTC (rev 22081)
+++ gnucash/trunk/src/engine/gncInvoice.c	2012-03-14 22:26:54 UTC (rev 22082)
@@ -1537,7 +1537,6 @@
     {
         Split *split = lot_split_iter->data;
         GList *other_split_list, *list_iter;
-        GNCLot *other_lot;
         Transaction *other_txn = xaccSplitGetParent (split);
         GList *lot_list = NULL;
 
@@ -1567,6 +1566,7 @@
         xaccTransBeginEdit (other_txn);
         xaccTransDestroy (other_txn);
         xaccTransCommitEdit (other_txn);
+        g_assert(lot_split_list == gnc_lot_get_split_list (lot));
 
         /* Re-balance the saved lots as well as is possible */
         gncOwnerAutoApplyPaymentsWithLots (&invoice->owner, lot_list);

Modified: gnucash/trunk/src/engine/test/Makefile.am
===================================================================
--- gnucash/trunk/src/engine/test/Makefile.am	2012-03-14 22:26:42 UTC (rev 22081)
+++ gnucash/trunk/src/engine/test/Makefile.am	2012-03-14 22:26:54 UTC (rev 22082)
@@ -112,6 +112,7 @@
 
 test_engine_SOURCES = \
 	test-engine.c \
+	utest-Invoice.c \
 	utest-Account.c
 
 test_engine_HEADERS = \

Modified: gnucash/trunk/src/engine/test/test-engine.c
===================================================================
--- gnucash/trunk/src/engine/test/test-engine.c	2012-03-14 22:26:42 UTC (rev 22081)
+++ gnucash/trunk/src/engine/test/test-engine.c	2012-03-14 22:26:54 UTC (rev 22082)
@@ -26,6 +26,7 @@
 #include "qof.h"
 
 extern void test_suite_account();
+extern void test_suite_gncInvoice();
 //extern void test_suite_transaction();
 //extern void test_suite_split();
 
@@ -36,9 +37,11 @@
     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 */
+    //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 */
 
     test_suite_account();
+    test_suite_gncInvoice();
 //    test_suite_transaction();
 //    test_suite_split();
 

Added: gnucash/trunk/src/engine/test/utest-Invoice.c
===================================================================
--- gnucash/trunk/src/engine/test/utest-Invoice.c	                        (rev 0)
+++ gnucash/trunk/src/engine/test/utest-Invoice.c	2012-03-14 22:26:54 UTC (rev 22082)
@@ -0,0 +1,97 @@
+/********************************************************************
+ * test_qofbook.c: GLib g_test test suite for qofbook.		    *
+ * 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 <string.h>
+#include <glib.h>
+#include "qof.h"
+#include "test-stuff.h"
+#include "../gncInvoice.h"
+
+static const gchar *suitename = "/engine/gncInvoice";
+void test_suite_gncInvoice ( void );
+
+typedef struct
+{
+    QofBook *book;
+    Account *account;
+    GncOwner owner;
+    GncCustomer *customer;
+    gnc_commodity *commodity;
+} Fixture;
+
+static void
+setup( Fixture *fixture, gconstpointer pData )
+{
+    Account *root;
+    fixture->book = qof_book_new();
+    root = gnc_account_create_root (fixture->book);
+
+    fixture->account = xaccMallocAccount(fixture->book);
+    fixture->commodity = gnc_commodity_new(fixture->book, "foo", "bar", "xy", "xy", 100);
+    xaccAccountSetCommodity(fixture->account, fixture->commodity);
+
+    fixture->customer = gncCustomerCreate(fixture->book);
+    gncOwnerInitCustomer(&fixture->owner, fixture->customer);
+}
+
+static void
+teardown( Fixture *fixture, gconstpointer pData )
+{
+    gncCustomerBeginEdit(fixture->customer);
+    gncCustomerDestroy(fixture->customer);
+
+    xaccAccountBeginEdit(fixture->account);
+    xaccAccountDestroy(fixture->account);
+    gnc_commodity_destroy(fixture->commodity);
+
+    qof_book_destroy( fixture->book );
+}
+
+
+static void
+test_invoice_post ( Fixture *fixture, gconstpointer pData )
+{
+    GncInvoice *invoice = gncInvoiceCreate(fixture->book);
+    Timespec ts1 = timespec_now(), ts2 = ts1;
+    g_assert(invoice);
+    g_assert(!gncInvoiceGetIsCreditNote(invoice));
+    g_assert(gncInvoiceGetActive(invoice));
+    g_assert(gncInvoiceGetPostedAcc(invoice) == NULL);
+
+    gncInvoiceSetCurrency(invoice, fixture->commodity);
+
+    gncInvoiceSetOwner(invoice, &fixture->owner);
+
+    g_test_message( "Will now post the invoice" );
+    g_assert(!gncInvoiceIsPosted(invoice));
+    gncInvoicePostToAccount(invoice, fixture->account, &ts1, &ts2, "memo", TRUE);
+    g_assert(gncInvoiceIsPosted(invoice));
+
+    gncInvoiceUnpost(invoice, TRUE);
+    g_assert(!gncInvoiceIsPosted(invoice));
+}
+
+void
+test_suite_gncInvoice ( void )
+{
+    GNC_TEST_ADD( suitename, "post", Fixture, NULL, setup, test_invoice_post, teardown );
+}


Property changes on: gnucash/trunk/src/engine/test/utest-Invoice.c
___________________________________________________________________
Added: svn:eol-style
   + LF



More information about the gnucash-changes mailing list