gnucash maint: Multiple changes pushed

Geert Janssens gjanssens at code.gnucash.org
Sat Jun 21 17:49:38 EDT 2014


Updated	 via  https://github.com/Gnucash/gnucash/commit/17ed2522 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/031943c5 (commit)
	from  https://github.com/Gnucash/gnucash/commit/f2ffaf23 (commit)



commit 17ed25229f86e60d819ccfc5b0e4110052948272
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Sat Jun 21 23:15:29 2014 +0200

    First unit test for gncEntry and fix first bug it revealed

diff --git a/src/engine/gncEntry.c b/src/engine/gncEntry.c
index 2593bed..f4c1786 100644
--- a/src/engine/gncEntry.c
+++ b/src/engine/gncEntry.c
@@ -535,7 +535,7 @@ void gncEntrySetQuantity (GncEntry *entry, gnc_numeric quantity)
 void gncEntrySetDocQuantity (GncEntry *entry, gnc_numeric quantity, gboolean is_cn)
 {
     if (!entry) return;
-    if (gnc_numeric_eq (entry->quantity, quantity)) return;
+    if (gnc_numeric_eq (entry->quantity, (is_cn ? gnc_numeric_neg (quantity) : quantity))) return;
     gncEntryBeginEdit (entry);
     entry->quantity = (is_cn ? gnc_numeric_neg (quantity) : quantity);
     entry->values_dirty = TRUE;
diff --git a/src/engine/test/Makefile.am b/src/engine/test/Makefile.am
index 12f7929..38fc13a 100644
--- a/src/engine/test/Makefile.am
+++ b/src/engine/test/Makefile.am
@@ -115,6 +115,7 @@ test_engine_SOURCES = \
 	test-engine.c \
 	utest-Account.c \
 	utest-Budget.c \
+	utest-Entry.c \
 	utest-Invoice.c
 
 test_engine_LDADD = \
diff --git a/src/engine/test/test-engine.c b/src/engine/test/test-engine.c
index 508856e..9ef8077 100644
--- a/src/engine/test/test-engine.c
+++ b/src/engine/test/test-engine.c
@@ -28,6 +28,7 @@
 
 extern void test_suite_account();
 extern void test_suite_budget();
+extern void test_suite_gncEntry();
 extern void test_suite_gncInvoice();
 extern void test_suite_transaction();
 extern void test_suite_split();
@@ -46,6 +47,7 @@ main (int   argc,
 
     test_suite_account();
     test_suite_budget();
+    test_suite_gncEntry();
     test_suite_gncInvoice();
     test_suite_transaction();
     test_suite_split();
diff --git a/src/engine/test/utest-Entry.c b/src/engine/test/utest-Entry.c
new file mode 100644
index 0000000..07ec092
--- /dev/null
+++ b/src/engine/test/utest-Entry.c
@@ -0,0 +1,116 @@
+/********************************************************************
+ * utest-Entry.c: GLib g_test test suite for gncEntry.              *
+ * Copyright 2014 Geert Janssens <geert at kobaltwit.be>               *
+ *                                                                  *
+ * 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 <unittest-support.h>
+#include "../gncEntry.h"
+
+static const gchar *suitename = "/engine/gncEntry";
+void test_suite_gncEntry ( void );
+
+typedef struct
+{
+    QofBook *book;
+    Account *account;
+    GncOwner owner;
+    GncCustomer *customer;
+    gnc_commodity *commodity;
+} Fixture;
+
+static void
+setup( Fixture *fixture, gconstpointer pData )
+{
+    fixture->book = qof_book_new();
+
+    fixture->account = xaccMallocAccount(fixture->book);
+    fixture->commodity = gnc_commodity_new(fixture->book, "foo", "bar", "xy", "xy", 100);
+    xaccAccountSetCommodity(fixture->account, fixture->commodity);
+
+}
+
+static void
+teardown( Fixture *fixture, gconstpointer pData )
+{
+    xaccAccountBeginEdit(fixture->account);
+    xaccAccountDestroy(fixture->account);
+    gnc_commodity_destroy(fixture->commodity);
+
+    qof_book_destroy( fixture->book );
+}
+
+
+static void
+test_entry_basics ( Fixture *fixture, gconstpointer pData )
+{
+    Timespec ts1 = timespec_now(), ts2;
+    const char *desc = "Test description with éà unicode chars";
+    const char *action = "Test action with éà unicode chars";
+    const char *note = "Test note with éà unicode chars";
+    gnc_numeric quantity = {500000, 100};
+    gboolean is_cn = FALSE;
+
+    GncEntry *entry = gncEntryCreate(fixture->book);
+    g_assert(entry);
+
+    g_test_message( "Test basic setters/getters" );
+    g_test_message( "  Date" );
+    gncEntrySetDate (entry, ts1);
+    ts2 = gncEntryGetDate (entry);
+    g_assert(timespec_equal (&ts2, &ts1));
+    g_test_message( "  DateEntered" );
+    gncEntrySetDateEntered (entry, ts1);
+    ts2 = gncEntryGetDateEntered (entry);
+    g_assert(timespec_equal (&ts2, &ts1));
+    g_test_message( "  Description" );
+    gncEntrySetDescription (entry, desc);
+    g_assert(g_strcmp0 (gncEntryGetDescription (entry), desc) == 0);
+    g_test_message( "  Action" );
+    gncEntrySetAction (entry, action);
+    g_assert(g_strcmp0 (gncEntryGetAction (entry), action) == 0);
+    g_test_message( "  Notes" );
+    gncEntrySetNotes (entry, note);
+    g_assert(g_strcmp0 (gncEntryGetNotes (entry), note) == 0);
+    g_test_message( "  Quantity" );
+    gncEntrySetQuantity (entry, quantity);
+    g_assert(gnc_numeric_eq (gncEntryGetQuantity (entry), quantity));
+    g_test_message( "  DocQuantity (with is_cn = FALSE)" );
+    gncEntrySetDocQuantity (entry, quantity, is_cn);
+    g_assert(gnc_numeric_eq (gncEntryGetDocQuantity (entry, is_cn), quantity));
+    g_assert(gnc_numeric_eq (gncEntryGetQuantity (entry), quantity));
+    g_test_message( "  DocQuantity (with is_cn = TRUE)");
+    is_cn = TRUE;
+    gncEntrySetDocQuantity (entry, quantity, is_cn);
+    g_assert(gnc_numeric_eq (gncEntryGetDocQuantity (entry, is_cn), quantity));
+    g_assert(gnc_numeric_eq (gncEntryGetQuantity (entry), gnc_numeric_neg (quantity)));
+    g_test_message( "  InvAccount" );
+    gncEntrySetInvAccount (entry, fixture->account);
+    g_assert(gncEntryGetInvAccount (entry) == fixture->account);
+
+}
+
+void
+test_suite_gncEntry ( void )
+{
+    GNC_TEST_ADD( suitename, "basics", Fixture, NULL, setup, test_entry_basics, teardown );
+}

commit 031943c56553eec0fadd6e6c7acfe723006ac015
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Sat Jun 21 23:19:36 2014 +0200

    Fix whitespace

diff --git a/src/engine/test/Makefile.am b/src/engine/test/Makefile.am
index 1a60aee..12f7929 100644
--- a/src/engine/test/Makefile.am
+++ b/src/engine/test/Makefile.am
@@ -114,7 +114,7 @@ noinst_PROGRAMS = ${TEST_PROGS} ${CHECK_PROGS}
 test_engine_SOURCES = \
 	test-engine.c \
 	utest-Account.c \
-    utest-Budget.c \
+	utest-Budget.c \
 	utest-Invoice.c
 
 test_engine_LDADD = \



Summary of changes:
 src/engine/gncEntry.c         |   2 +-
 src/engine/test/Makefile.am   |   3 +-
 src/engine/test/test-engine.c |   2 +
 src/engine/test/utest-Entry.c | 116 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 121 insertions(+), 2 deletions(-)
 create mode 100644 src/engine/test/utest-Entry.c



More information about the gnucash-changes mailing list