gnucash master: Multiple changes pushed

Robert Fewell bobit at code.gnucash.org
Tue Feb 21 05:55:28 EST 2023


Updated	 via  https://github.com/Gnucash/gnucash/commit/c2242f76 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/ec7cc27d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/76f0e3a9 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/e84ecd64 (commit)
	from  https://github.com/Gnucash/gnucash/commit/d6514a47 (commit)



commit c2242f769c1c6c5298dfc15f9669da0ff4fd4320
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Tue Feb 21 10:51:01 2023 +0000

    Add a test for the built in default report invoice define

diff --git a/gnucash/gnome/CMakeLists.txt b/gnucash/gnome/CMakeLists.txt
index e4e1eed18..4a88bb2db 100644
--- a/gnucash/gnome/CMakeLists.txt
+++ b/gnucash/gnome/CMakeLists.txt
@@ -1,4 +1,6 @@
 
+add_subdirectory(test)
+
 set (gnc_gnome_noinst_HEADERS
   assistant-acct-period.h
   assistant-hierarchy.h
diff --git a/gnucash/gnome/test/CMakeLists.txt b/gnucash/gnome/test/CMakeLists.txt
new file mode 100644
index 000000000..89ff09736
--- /dev/null
+++ b/gnucash/gnome/test/CMakeLists.txt
@@ -0,0 +1,35 @@
+set(MODULEPATH ${CMAKE_SOURCE_DIR}/gnucash/gnome/)
+
+set(GNOME_TEST_INCLUDE_DIRS
+  ${CMAKE_BINARY_DIR}/common # for config.h
+  ${CMAKE_SOURCE_DIR}/common/test-core
+  ${CMAKE_SOURCE_DIR}/gnucash/gnome/
+  ${CMAKE_SOURCE_DIR}/gnucash/gnome-utils/
+  ${GUILE_INCLUDE_DIRS}
+  ${GTK3_INCLUDE_DIRS}
+)
+
+set(GNOME_TEST_LIBS
+        gnc-gnome
+        gnc-test-engine
+        test-core
+        ${GUILE_LDFLAGS})
+
+macro(add_gnome_test _TARGET _SOURCE_FILES)
+  gnc_add_test(${_TARGET} "${_SOURCE_FILES}" GNOME_TEST_INCLUDE_DIRS GNOME_TEST_LIBS)
+endmacro()
+
+gnc_add_test_with_guile(test-invoice-report-buitin-default test-invoice-report-buitin-default.cpp
+  GNOME_TEST_INCLUDE_DIRS GNOME_TEST_LIBS
+)
+
+set(GUILE_DEPENDS
+  scm-core-utils
+)
+
+set_dist_list(test_app_utils_DIST
+  CMakeLists.txt
+  test-invoice-buitin-default.cpp
+  ${test_gnome_scheme_SOURCES}
+  ${test_gnome_SOURCES}
+)
diff --git a/gnucash/gnome/test/test-invoice-report-buitin-default.cpp b/gnucash/gnome/test/test-invoice-report-buitin-default.cpp
new file mode 100644
index 000000000..f20edf934
--- /dev/null
+++ b/gnucash/gnome/test/test-invoice-report-buitin-default.cpp
@@ -0,0 +1,110 @@
+/********************************************************************\
+ * 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 <gtk/gtk.h>
+#include <libguile.h>
+
+#include <stdlib.h>
+#include "gnc-ui-util.h"
+
+#include "test-stuff.h"
+
+#include "guile-mappings.h"
+#include "gnc-guile-utils.h"
+
+#include "../business-gnome-utils.h"
+
+static void
+test_basic()
+{
+    do_test(g_strcmp0(gnc_get_builtin_default_invoice_print_report (),
+                      "5123a759ceb9483abf2182d01c140e8d") == 0,
+                      "built in invoice report define does not match guid");
+}
+
+static void
+test_list()
+{
+    GSList *invoice_list = nullptr;
+    SCM template_menu_name = scm_c_eval_string ("gnc:report-template-menu-name/report-guid");
+    SCM get_rpt_guids = scm_c_eval_string ("gnc:custom-report-invoice-template-guids");
+    int number_of_defined_invoice_templates = 5;
+    int i = 0;
+    gboolean printable_found = false;
+    gboolean builtin_default_found = false;
+    const char *builtin_default = gnc_get_builtin_default_invoice_print_report ();
+
+    if (scm_is_procedure (get_rpt_guids))
+    {
+        SCM reportlist = scm_call_0 (get_rpt_guids);
+        SCM rpt_guids = reportlist;
+
+        if (scm_is_list (rpt_guids))
+        {
+            for (i; !scm_is_null (rpt_guids); i++)
+            {
+                gchar *guid_str = scm_to_utf8_string (SCM_CAR(rpt_guids));
+                gchar *name = gnc_scm_to_utf8_string (scm_call_2(template_menu_name,
+                                                      SCM_CAR(rpt_guids), SCM_BOOL_F));
+
+                if (g_strcmp0 (guid_str, builtin_default) == 0)
+                {
+                    if (g_strcmp0 (name, "Printable Invoice") == 0)
+                        printable_found = true;
+
+                    builtin_default_found = true;
+                }
+                g_free (guid_str);
+                g_free (name);
+
+                rpt_guids = SCM_CDR(rpt_guids);
+            }
+        }
+    }
+    do_test(i == number_of_defined_invoice_templates, "number of built in invoice templates does not match");
+    do_test(builtin_default_found == true, "built in default invoice guid not found");
+    do_test(printable_found == true, "built in Printable Invoice not found with default guid");
+}
+
+static void
+real_main(void *closure, int argc, char **argv)
+{
+    g_setenv ("GNC_UNINSTALLED", "1", TRUE);
+    qof_init();
+    gnc_engine_init(0, NULL);
+
+    scm_c_use_module ("gnucash reports");
+    scm_c_use_module ("gnucash report report-core");
+
+    test_basic();
+    test_list();
+
+    print_test_results();
+    exit(get_rv());
+}
+
+int main(int argc, char **argv)
+{
+    /* do things this way so we can test scheme function calls from expressions */
+    scm_boot_guile(argc, argv, real_main, NULL);
+    return 0;
+}

commit ec7cc27d6d64b92e6a2297659c8882b1d3228234
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Tue Feb 21 10:48:34 2023 +0000

    Add tests for default invoice report book property

diff --git a/libgnucash/engine/test/test-qofbook.c b/libgnucash/engine/test/test-qofbook.c
index 9691dfa12..c33d7a0ad 100644
--- a/libgnucash/engine/test/test-qofbook.c
+++ b/libgnucash/engine/test/test-qofbook.c
@@ -425,6 +425,116 @@ test_book_increment_and_format_counter ( Fixture *fixture, gconstpointer pData )
     g_free( r );
 }
 
+static void
+test_book_get_default_report_guid ( Fixture *fixture, gconstpointer pData )
+{
+    const char *err_no_book = "No book";
+    const char *r;
+
+    /* need this as long as we have fatal warnings enabled */
+    g_test_log_set_fatal_handler ( ( GTestLogFatalFunc )handle_faults, NULL );
+
+    g_test_message( "Testing default report guid when book is null" );
+    r = qof_book_get_default_invoice_report_guid ( NULL );
+    g_assert_cmpstr( r, == , NULL );
+    g_assert( g_strrstr( test_struct.msg, err_no_book ) != NULL );
+    g_free( test_struct.msg );
+
+    g_test_message( "Testing default report guid for default value" );
+    r = qof_book_get_default_invoice_report_guid ( fixture->book );
+    g_assert_cmpstr( r, == , NULL );
+}
+
+static void
+test_book_get_default_report_name ( Fixture *fixture, gconstpointer pData )
+{
+    const char *err_no_book = "No book";
+    const char *r;
+
+    /* need this as long as we have fatal warnings enabled */
+    g_test_log_set_fatal_handler ( ( GTestLogFatalFunc )handle_faults, NULL );
+
+    g_test_message( "Testing default report name when book is null" );
+    r = qof_book_get_default_invoice_report_name ( NULL );
+    g_assert_cmpstr( r, == , NULL );
+    g_assert( g_strrstr( test_struct.msg, err_no_book ) != NULL );
+    g_free( test_struct.msg );
+
+    g_test_message( "Testing default report name for default value" );
+    r = qof_book_get_default_invoice_report_name ( fixture->book );
+    g_assert_cmpstr( r, == , NULL );
+}
+
+static void
+test_book_get_default_report_timeout ( Fixture *fixture, gconstpointer pData )
+{
+    const char *err_no_book = "No book";
+    int r;
+
+    /* need this as long as we have fatal warnings enabled */
+    g_test_log_set_fatal_handler ( ( GTestLogFatalFunc )handle_faults, NULL );
+
+    g_test_message( "Testing default report timeout when book is null" );
+    r = qof_book_get_default_invoice_report_timeout ( NULL );
+    g_assert_cmpint( r, == , 0 );
+    g_assert( g_strrstr( test_struct.msg, err_no_book ) != NULL );
+    g_free( test_struct.msg );
+
+    g_test_message( "Testing default report timeout for default value" );
+    r = qof_book_get_default_invoice_report_timeout ( fixture->book );
+    g_assert_cmpint( r, == , 0 );
+}
+
+static void
+test_book_set_default_report ( Fixture *fixture, gconstpointer pData )
+{
+    const char *err_no_book = "No book";
+    const char *err_no_guid = "No guid";
+    const char *err_no_name = "No name";
+    const char *test_guid1 = "5123a759ceb9483abf2182d01c140eff";
+    const char *test_guid2 = "5123a759ceb9483abf2182d01c140eee";
+    const char *test_name = "My Invoice Report";
+    const char *r;
+
+    /* need this as long as we have fatal warnings enabled */
+    g_test_log_set_fatal_handler ( ( GTestLogFatalFunc )handle_faults, NULL );
+
+    g_test_message( "Testing setting default report when book is null" );
+    qof_book_set_default_invoice_report ( NULL, test_guid1, test_name );
+    r = qof_book_get_default_invoice_report_guid ( fixture->book );
+    g_assert_cmpstr( r, == , NULL );
+    g_assert( g_strrstr( test_struct.msg, err_no_book ) != NULL );
+    g_free( test_struct.msg );
+
+    g_test_message( "Testing setting default report when guid is null" );
+    qof_book_set_default_invoice_report ( fixture->book, NULL, test_name );
+    r = qof_book_get_default_invoice_report_guid ( fixture->book );
+    g_assert_cmpstr( r, == , NULL );
+    g_assert( g_strrstr( test_struct.msg, err_no_guid ) != NULL );
+    g_free( test_struct.msg );
+
+    g_test_message( "Testing setting default report when name is null" );
+    qof_book_set_default_invoice_report ( fixture->book, test_guid1, NULL );
+    r = qof_book_get_default_invoice_report_guid ( fixture->book );
+    g_assert_cmpstr( r, == , NULL );
+    g_assert( g_strrstr( test_struct.msg, err_no_name ) != NULL );
+    g_free( test_struct.msg );
+
+    g_test_message( "Testing setting default report when name is empty string" );
+    qof_book_set_default_invoice_report ( fixture->book, test_guid1, "" );
+    r = qof_book_get_default_invoice_report_guid ( fixture->book );
+    g_assert_cmpstr( r, == , test_guid1 );
+    r = qof_book_get_default_invoice_report_name ( fixture->book );
+    g_assert_cmpstr( r, == , "" );
+
+    g_test_message( "Testing setting default report with guid and name" );
+    qof_book_set_default_invoice_report ( fixture->book, test_guid2, test_name );
+    r = qof_book_get_default_invoice_report_guid ( fixture->book );
+    g_assert_cmpstr( r, == , test_guid2 );
+    r = qof_book_get_default_invoice_report_name ( fixture->book );
+    g_assert_cmpstr( r, == , test_name );
+}
+
 static void
 test_book_use_trading_accounts( Fixture *fixture, gconstpointer pData )
 {
@@ -850,6 +960,10 @@ test_suite_qofbook ( void )
     GNC_TEST_ADD( suitename, "get counter", Fixture, NULL, setup, test_book_get_counter, teardown );
     GNC_TEST_ADD( suitename, "get counter format", Fixture, NULL, setup, test_book_get_counter_format, teardown );
     GNC_TEST_ADD( suitename, "increment and format counter", Fixture, NULL, setup, test_book_increment_and_format_counter, teardown );
+    GNC_TEST_ADD( suitename, "get default report guid", Fixture, NULL, setup, test_book_get_default_report_guid, teardown );
+    GNC_TEST_ADD( suitename, "get default report name", Fixture, NULL, setup, test_book_get_default_report_name, teardown );
+    GNC_TEST_ADD( suitename, "get default report timeout", Fixture, NULL, setup, test_book_get_default_report_timeout, teardown );
+    GNC_TEST_ADD( suitename, "set default report", Fixture, NULL, setup, test_book_set_default_report, teardown );
     GNC_TEST_ADD( suitename, "use trading accounts", Fixture, NULL, setup, test_book_use_trading_accounts, teardown );
     GNC_TEST_ADD( suitename, "get autofreeze days", Fixture, NULL, setup, test_book_get_num_days_autofreeze, teardown );
     GNC_TEST_ADD( suitename, "use split action for num field", Fixture, NULL, setup, test_book_use_split_action_for_num_field, teardown );

commit 76f0e3a97e863977652337637ebc2eae4c072d3e
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Tue Feb 21 10:44:07 2023 +0000

    Add some PWARN messages to the default invoice report
     book functions

diff --git a/libgnucash/engine/qofbook.cpp b/libgnucash/engine/qofbook.cpp
index 127adecc4..be5cc4691 100644
--- a/libgnucash/engine/qofbook.cpp
+++ b/libgnucash/engine/qofbook.cpp
@@ -1026,8 +1026,23 @@ qof_book_set_default_invoice_report (QofBook *book, const gchar *guid,
     const gchar *existing_guid_name = nullptr;
     gchar *new_guid_name;
 
+    if (!book)
+    {
+        PWARN ("No book!!!");
+        return;
+    }
+
     if (!guid)
+    {
+        PWARN ("No guid!!!");
+        return;
+    }
+
+    if (!name)
+    {
+        PWARN ("No name!!!");
         return;
+    }
 
     KvpValue *value = get_option_default_invoice_report_value (book);
 
@@ -1053,9 +1068,16 @@ qof_book_set_default_invoice_report (QofBook *book, const gchar *guid,
 gchar *
 qof_book_get_default_invoice_report_guid (const QofBook *book)
 {
-    KvpValue *value = get_option_default_invoice_report_value (const_cast<QofBook*>(book));
     gchar *report_guid = nullptr;
 
+    if (!book)
+    {
+        PWARN ("No book!!!");
+        return report_guid;
+    }
+
+    KvpValue *value = get_option_default_invoice_report_value (const_cast<QofBook*>(book));
+
     if (value)
     {
         auto str {value->get<const char*>()};
@@ -1064,7 +1086,7 @@ qof_book_get_default_invoice_report_guid (const QofBook *book)
         {
             if (ptr - str == GUID_ENCODING_LENGTH)
             {
-                if (strlen (str) > GUID_ENCODING_LENGTH + 1)
+                if (strlen (str) > GUID_ENCODING_LENGTH)
                     report_guid = g_strndup (&str[0], GUID_ENCODING_LENGTH);
             }
         }
@@ -1075,9 +1097,16 @@ qof_book_get_default_invoice_report_guid (const QofBook *book)
 gchar *
 qof_book_get_default_invoice_report_name (const QofBook *book)
 {
-    KvpValue *value = get_option_default_invoice_report_value (const_cast<QofBook*>(book));
     gchar *report_name = nullptr;
 
+    if (!book)
+    {
+        PWARN ("No book!!!");
+        return report_name;
+    }
+
+    KvpValue *value = get_option_default_invoice_report_value (const_cast<QofBook*>(book));
+
     if (value)
     {
         auto str {value->get<const char*>()};
@@ -1088,6 +1117,8 @@ qof_book_get_default_invoice_report_name (const QofBook *book)
             {
                 if (strlen (str) > GUID_ENCODING_LENGTH + 1)
                     report_name = g_strdup (&str[GUID_ENCODING_LENGTH + 1]);
+                else
+                    report_name = g_strdup ("");
             }
         }
     }
@@ -1098,6 +1129,13 @@ gdouble
 qof_book_get_default_invoice_report_timeout (const QofBook *book)
 {
     double ret = 0;
+
+    if (!book)
+    {
+        PWARN ("No book!!!");
+        return ret;
+    }
+
     KvpFrame *root = qof_instance_get_slots (QOF_INSTANCE(book));
     KvpValue *value = root->get_slot ({KVP_OPTION_PATH,
                                        OPTION_SECTION_BUSINESS,

commit e84ecd64a0137d71a1647ca3a5dbe8c6e9109a55
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Tue Feb 21 10:40:33 2023 +0000

    Remove leftover function from business-gnome-utils.h

diff --git a/gnucash/gnome/business-gnome-utils.h b/gnucash/gnome/business-gnome-utils.h
index 96fef1be5..d050d0a30 100644
--- a/gnucash/gnome/business-gnome-utils.h
+++ b/gnucash/gnome/business-gnome-utils.h
@@ -62,15 +62,6 @@ const char * gnc_migrate_default_invoice_print_report (void);
  */
 char *gnc_get_default_invoice_print_report (void);
 
-/** Setup a combo used for displaying list of Invoice Reports.
- *
- *  @param combo The GtkComboBox that presents the list.
- *
- *  @param warning The warning image, displayed if the default guid is
- *                 not in the Invoice list.
- */
-void gnc_default_print_report_list (GtkWidget *combo, GtkWidget *warning);
-
 /** Create a report combo to show a list of Invoice reports so that
  *  a default Invoice Report can be selected.
  *



Summary of changes:
 gnucash/gnome/CMakeLists.txt                       |   2 +
 gnucash/gnome/business-gnome-utils.h               |   9 --
 gnucash/gnome/test/CMakeLists.txt                  |  35 +++++++
 .../test/test-invoice-report-buitin-default.cpp    | 110 ++++++++++++++++++++
 libgnucash/engine/qofbook.cpp                      |  44 +++++++-
 libgnucash/engine/test/test-qofbook.c              | 114 +++++++++++++++++++++
 6 files changed, 302 insertions(+), 12 deletions(-)
 create mode 100644 gnucash/gnome/test/CMakeLists.txt
 create mode 100644 gnucash/gnome/test/test-invoice-report-buitin-default.cpp



More information about the gnucash-changes mailing list