diff --git a/0001-Change-gtkmacintegration-gtk2-include-directory-back.patch b/0001-Change-gtkmacintegration-gtk2-include-directory-back.patch new file mode 100644 index 0000000000..74774cf779 --- /dev/null +++ b/0001-Change-gtkmacintegration-gtk2-include-directory-back.patch @@ -0,0 +1,41 @@ +From b9de55c8711b07c0fdf83d9838c8a5d65222e887 Mon Sep 17 00:00:00 2001 +From: John Ralls +Date: Sun, 24 May 2015 18:05:04 -0700 +Subject: [PATCH] Change gtkmacintegration-gtk2 include directory back to + gtkmacintegration. + +As of gtk-mac-integration-2.0.8. +--- + src/core-utils/binreloc.c | 2 +- + src/gnome-utils/gnc-main-window.c | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/core-utils/binreloc.c b/src/core-utils/binreloc.c +index 6a2a55f..4e72494 100644 +--- a/src/core-utils/binreloc.c ++++ b/src/core-utils/binreloc.c +@@ -24,7 +24,7 @@ + #include + #include + #ifdef MAC_INTEGRATION +-#include ++#include + #endif + #endif /* ENABLE_BINRELOC */ + #include +diff --git a/src/gnome-utils/gnc-main-window.c b/src/gnome-utils/gnc-main-window.c +index 89462ef..c77637d 100644 +--- a/src/gnome-utils/gnc-main-window.c ++++ b/src/gnome-utils/gnc-main-window.c +@@ -70,7 +70,7 @@ + #include "gnc-autosave.h" + #include "print-session.h" + #ifdef MAC_INTEGRATION +-#include ++#include + #endif + #ifdef HAVE_SYS_STAT_H + # include +-- +2.2.2 + diff --git a/src/app-utils/test/Makefile.am b/src/app-utils/test/Makefile.am index 4000490d74..c0cf529317 100644 --- a/src/app-utils/test/Makefile.am +++ b/src/app-utils/test/Makefile.am @@ -67,11 +67,10 @@ AM_CPPFLAGS = \ test_app_utils_SOURCES = \ test-app-utils.c \ - test-option-util.c \ + test-option-util.cpp \ test-gnc-ui-util.c - -test_app_utils_CFLAGS = \ +test_app_utils_CXXFLAGS = \ ${DEFAULT_INCLUDES} \ -I${top_srcdir}/${MODULEPATH}/ \ -DTESTPROG=test_app_utils \ diff --git a/src/app-utils/test/test-option-util.c b/src/app-utils/test/test-option-util.cpp similarity index 92% rename from src/app-utils/test/test-option-util.c rename to src/app-utils/test/test-option-util.cpp index 3a261c21aa..16f0f35247 100644 --- a/src/app-utils/test/test-option-util.c +++ b/src/app-utils/test/test-option-util.cpp @@ -21,17 +21,19 @@ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 * * Boston, MA 02110-1301, USA gnu@gnu.org * ********************************************************************/ - +#include +#include +extern "C" +{ #include #include #include #include -#include - #include "../option-util.h" +} static const gchar *suitename = "/app-utils/option-util"; -void test_suite_option_util (void); +extern "C" void test_suite_option_util (void); typedef struct { @@ -42,7 +44,7 @@ typedef struct /* Expose a mostly-private QofInstance function to load options into * the Book. */ -extern KvpFrame *qof_instance_get_slots (const QofInstance*); +extern "C" KvpFrame *qof_instance_get_slots (const QofInstance*); static void setup (Fixture *fixture, gconstpointer pData) @@ -66,8 +68,8 @@ setup_kvp (Fixture *fixture, gconstpointer pData) "autoreadonly-days", (double)21, NULL); - kvp_frame_set_string (slots, "options/Business/Company Name", - "Bogus Company"); + slots->set_path("options/Business/Company Name", + new KvpValue("Bogus Company")); qof_commit_edit (QOF_INSTANCE (book)); } @@ -205,10 +207,10 @@ test_option_save (Fixture *fixture, gconstpointer pData) OPTION_NAME_AUTO_READONLY_DAYS, 17)); qof_book_save_options (book, gnc_option_db_save, odb, TRUE); - g_assert_cmpstr (kvp_frame_get_string (slots, "options/Accounts/Use Trading Accounts"), == , "t"); - g_assert_cmpstr (kvp_frame_get_string (slots, "options/Accounts/Use Split Action Field for Number"), == , "t"); - g_assert_cmpstr (kvp_frame_get_string (slots, "options/Business/Company Name"), ==, "Bogus Company"); - g_assert_cmpfloat (kvp_frame_get_double (slots, "options/Accounts/Day Threshold for Read-Only Transactions (red line)"), ==, 17); + g_assert_cmpstr (slots->get_slot("options/Accounts/Use Trading Accounts")->get(), == , "t"); + g_assert_cmpstr (slots->get_slot("options/Accounts/Use Split Action Field for Number")->get(), == , "t"); + g_assert_cmpstr (slots->get_slot("options/Business/Company Name")->get(), ==, "Bogus Company"); + g_assert_cmpfloat (slots->get_slot("options/Accounts/Day Threshold for Read-Only Transactions (red line)")->get(), ==, 17); gnc_option_db_destroy (odb); } @@ -232,7 +234,7 @@ test_option_save_book_currency (Fixture *fixture, gconstpointer pData) gnc_option_db_destroy (odb); } -void +extern "C" void test_suite_option_util (void) { GNC_TEST_ADD (suitename, "Option DB Load", Fixture, NULL, setup_kvp, test_option_load, teardown); diff --git a/src/backend/dbi/test/Makefile.am b/src/backend/dbi/test/Makefile.am index ee3308bb66..a2b5b802f0 100644 --- a/src/backend/dbi/test/Makefile.am +++ b/src/backend/dbi/test/Makefile.am @@ -58,8 +58,8 @@ endif test_backend_dbi_SOURCES = \ test-backend-dbi.c \ - test-backend-dbi-basic.c \ - test-dbi-stuff.c \ + test-backend-dbi-basic.cpp \ + test-dbi-stuff.cpp \ test-dbi-business-stuff.c test_backend_dbi_LDFLAGS="-ldbi" diff --git a/src/backend/dbi/test/test-backend-dbi-basic.c b/src/backend/dbi/test/test-backend-dbi-basic.cpp similarity index 91% rename from src/backend/dbi/test/test-backend-dbi-basic.c rename to src/backend/dbi/test/test-backend-dbi-basic.cpp index b692f92cf5..cd00f22435 100644 --- a/src/backend/dbi/test/test-backend-dbi-basic.c +++ b/src/backend/dbi/test/test-backend-dbi-basic.cpp @@ -4,7 +4,10 @@ * Created on: 2011-04-23 * Author: phil */ +#include +extern "C" +{ #include "config.h" #include @@ -12,7 +15,6 @@ #include #include -#include #include #include #include @@ -34,6 +36,7 @@ /* For version_control */ #include #include +} #if LIBDBI_VERSION >= 900 #define HAVE_LIBDBI_R 1 @@ -43,7 +46,7 @@ static dbi_inst dbi_instance = NULL; #endif static const gchar* suitename = "/backend/dbi"; -void test_suite_gnc_backend_dbi (void); +extern "C" void test_suite_gnc_backend_dbi (void); typedef struct { @@ -80,7 +83,6 @@ setup_memory (Fixture *fixture, gconstpointer pData) gchar *url = (gchar*)pData; QofBook* book; Account *root, *acct1, *acct2; - KvpFrame* frame; Transaction* tx; Split *spl1, *spl2; gnc_commodity_table* table; @@ -98,15 +100,16 @@ setup_memory (Fixture *fixture, gconstpointer pData) xaccAccountSetName (acct1, "Bank 1"); xaccAccountSetCommodity (acct1, currency); - frame = qof_instance_get_slots (QOF_INSTANCE(acct1)); - kvp_frame_set_gint64 (frame, "int64-val", 100); - kvp_frame_set_double (frame, "double-val", 3.14159); - kvp_frame_set_numeric (frame, "numeric-val", gnc_numeric_zero()); + auto frame = qof_instance_get_slots (QOF_INSTANCE(acct1)); + frame->set("int64-val", new KvpValue(INT64_C(100))); + frame->set("double-val", new KvpValue(3.14159)); + frame->set("numeric-val", new KvpValue(gnc_numeric_zero())); - kvp_frame_set_timespec (frame, "timespec-val", timespec_now ()); + frame->set("timespec-val", new KvpValue(timespec_now ())); - kvp_frame_set_string (frame, "string-val", "abcdefghijklmnop"); - kvp_frame_set_guid (frame, "guid-val", qof_instance_get_guid (QOF_INSTANCE(acct1))); + frame->set("string-val", new KvpValue("abcdefghijklmnop")); + auto guid = qof_instance_get_guid (QOF_INSTANCE(acct1)); + frame->set("guid-val", new KvpValue(const_cast(guid))); gnc_account_append_child (root, acct1); @@ -228,9 +231,9 @@ destroy_database (gchar* url) gchar *basename = NULL; gint portnum = 0; gchar *port = NULL; - gchar *pgsql = "pgsql"; + auto pgsql = "pgsql"; dbi_conn conn = NULL; - gchar *errfmt = "Unable to delete tables in %s: %s"; + auto errfmt = "Unable to delete tables in %s: %s"; gint fail = 0; dbi_result tables; GSList *list = NULL; @@ -296,11 +299,11 @@ destroy_database (gchar* url) static void teardown (Fixture *fixture, gconstpointer pData) { - gchar *lockfile = g_strdup_printf ("%s/test-dbi.xml.LCK", + auto lockfile = g_strdup_printf ("%s/test-dbi.xml.LCK", g_path_get_dirname (DBI_TEST_XML_FILENAME)); - gchar *msg = g_strdup_printf ("[xml_session_end()] Error on g_unlink(%s): 2: No such file or directory", lockfile); - gchar *logdomain = "gnc.backend"; - guint loglevel = G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL; + auto msg = g_strdup_printf ("[xml_session_end()] Error on g_unlink(%s): 2: No such file or directory", lockfile); + auto logdomain = "gnc.backend"; + auto loglevel = static_cast(G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL); TestErrorStruct *check = test_error_struct_new (logdomain, loglevel, msg); fixture->hdlrs = test_log_set_fatal_handler (fixture->hdlrs, check, (GLogFunc)test_checked_handler); @@ -335,7 +338,8 @@ test_conn_index_functions (QofBackend *qbe) for (iter = index_list; iter != NULL; iter = g_slist_next (iter)) { const char *errmsg; - conn->provider->drop_index (be->conn, iter->data); + conn->provider->drop_index (be->conn, + static_cast(iter->data)); g_assert (DBI_ERROR_NONE == dbi_conn_error (conn->conn, &errmsg)); } @@ -354,9 +358,9 @@ test_dbi_store_and_reload (Fixture *fixture, gconstpointer pData) QofSession* session_3; QofBackend *be; - gchar *msg = "[gnc_dbi_unlock()] There was no lock entry in the Lock table"; - gchar *log_domain = "gnc.backend.dbi"; - guint loglevel = G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL; + auto msg = "[gnc_dbi_unlock()] There was no lock entry in the Lock table"; + auto log_domain = "gnc.backend.dbi"; + auto loglevel = static_cast(G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL); TestErrorStruct *check = test_error_struct_new (log_domain, loglevel, msg); fixture->hdlrs = test_log_set_fatal_handler (fixture->hdlrs, check, (GLogFunc)test_checked_handler); @@ -402,13 +406,13 @@ test_dbi_store_and_reload (Fixture *fixture, gconstpointer pData) static void test_dbi_safe_save (Fixture *fixture, gconstpointer pData) { - gchar *url = (gchar*)pData; + auto url = (gchar*)pData; QofSession *session_1 = NULL, *session_2 = NULL; QofBackend *be; - gchar *msg = "[gnc_dbi_unlock()] There was no lock entry in the Lock table"; - gchar *log_domain = "gnc.backend.dbi"; - guint loglevel = G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL; + auto msg = "[gnc_dbi_unlock()] There was no lock entry in the Lock table"; + auto log_domain = "gnc.backend.dbi"; + auto loglevel = static_cast(G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL); TestErrorStruct *check = test_error_struct_new (log_domain, loglevel, msg); if (fixture->filename) @@ -479,7 +483,7 @@ cleanup: static void test_dbi_version_control (Fixture *fixture, gconstpointer pData) { - gchar *url = (gchar*)pData; + auto url = (gchar*)pData; QofSession *sess; QofBook *book; QofBackend *qbe; @@ -548,9 +552,9 @@ test_dbi_business_store_and_reload (Fixture *fixture, gconstpointer pData) QofSession* session_3; const gchar* url = (gchar*)pData; - gchar *msg = "[gnc_dbi_unlock()] There was no lock entry in the Lock table"; - gchar *log_domain = "gnc.backend.dbi"; - guint loglevel = G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL; + auto msg = "[gnc_dbi_unlock()] There was no lock entry in the Lock table"; + auto log_domain = "gnc.backend.dbi"; + auto loglevel = static_cast(G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL); TestErrorStruct *check = test_error_struct_new (log_domain, loglevel, msg); if (fixture->filename) url = fixture->filename; @@ -577,9 +581,9 @@ test_dbi_business_store_and_reload (Fixture *fixture, gconstpointer pData) } static void -create_dbi_test_suite (gchar *dbm_name, gchar *url) +create_dbi_test_suite (const char *dbm_name, const char *url) { - gchar *subsuite = g_strdup_printf ("%s/%s", suitename, dbm_name); + auto subsuite = g_strdup_printf ("%s/%s", suitename, dbm_name); GNC_TEST_ADD (subsuite, "store_and_reload", Fixture, url, setup, test_dbi_store_and_reload, teardown); GNC_TEST_ADD (subsuite, "safe_save", Fixture, url, setup_memory, @@ -592,7 +596,7 @@ create_dbi_test_suite (gchar *dbm_name, gchar *url) } -void +extern "C" void test_suite_gnc_backend_dbi (void) { dbi_driver driver = NULL; diff --git a/src/backend/dbi/test/test-dbi-stuff.c b/src/backend/dbi/test/test-dbi-stuff.cpp similarity index 92% rename from src/backend/dbi/test/test-dbi-stuff.c rename to src/backend/dbi/test/test-dbi-stuff.cpp index e6ad4a694a..f9e4899aae 100644 --- a/src/backend/dbi/test/test-dbi-stuff.c +++ b/src/backend/dbi/test/test-dbi-stuff.cpp @@ -22,10 +22,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ - +extern "C" +{ #include #include -#include #include #include #include @@ -38,6 +38,9 @@ #include #include #include "../gnc-backend-dbi-priv.h" +} + +#include G_GNUC_UNUSED static QofLogModule log_module = "test-dbi"; @@ -98,7 +101,7 @@ get_sx_by_guid (QofBook* book, const GncGUID *guid) const GncGUID *sx_guid; sx_guid = qof_instance_get_guid (QOF_INSTANCE(sxitem->data)); if (guid_equal (sx_guid, guid)) - return sxitem->data; + return static_cast(sxitem->data); } return NULL; } @@ -127,7 +130,8 @@ compare_recurrences (GList *rl_1, GList *rl_2) for (ritem1 = rl_1, ritem2 = rl_2; ritem1 != NULL && ritem2 != NULL; ritem1 = g_list_next (ritem1), ritem2 = g_list_next (ritem2)) { - Recurrence *r1 = ritem1->data, *r2 = ritem2->data; + auto r1 = static_cast(ritem1->data); + auto r2 = static_cast(ritem2->data); TEST_GDATES_EQUAL (&r1->start, &r2->start); g_assert_cmpint (r1->ptype, ==, r2->ptype); @@ -185,8 +189,8 @@ compare_single_lot( QofInstance* inst, gpointer user_data ) gnc_lot_get_account (lot_2), FALSE )); g_assert_cmpint (gnc_lot_is_closed (lot_1), ==, gnc_lot_is_closed (lot_2)); - g_assert (kvp_frame_compare (qof_instance_get_slots (QOF_INSTANCE (lot_1)), - qof_instance_get_slots (QOF_INSTANCE (lot_2))) == 0); + g_assert (compare (qof_instance_get_slots (QOF_INSTANCE (lot_1)), + qof_instance_get_slots (QOF_INSTANCE (lot_2))) == 0); splits1 = gnc_lot_get_split_list (lot_1); splits2 = gnc_lot_get_split_list (lot_2); g_assert_cmpint (g_list_length (splits1), ==, g_list_length (splits2)); @@ -197,7 +201,8 @@ compare_single_lot( QofInstance* inst, gpointer user_data ) split2 = xaccSplitLookup (qof_instance_get_guid (split1->data), info->book_2); g_assert (GNC_IS_SPLIT (split2)); - g_assert (xaccSplitEqual (split1->data, split2, TRUE, TRUE, TRUE)); + g_assert (xaccSplitEqual (static_cast(split1->data), + split2, TRUE, TRUE, TRUE)); } } @@ -221,7 +226,8 @@ test_conn_index_functions( QofBackend *qbe ) for ( iter = index_list; iter != NULL; iter = g_slist_next( iter) ) { const char *errmsg; - conn->provider->drop_index (be->conn, iter->data); + conn->provider->drop_index (be->conn, + static_cast(iter->data)); g_assert (DBI_ERROR_NONE == dbi_conn_error( conn->conn, &errmsg)); } diff --git a/src/backend/dbi/test/test-dbi-stuff.h b/src/backend/dbi/test/test-dbi-stuff.h index 92c23badd7..c9a025a92e 100644 --- a/src/backend/dbi/test/test-dbi-stuff.h +++ b/src/backend/dbi/test/test-dbi-stuff.h @@ -25,7 +25,10 @@ #ifndef _TEST_DBI_STUFF_H_ #define _TEST_DBI_STUFF_H_ - +#ifdef __cplusplus +extern "C" +{ +#endif #include "qof.h" typedef struct @@ -37,5 +40,7 @@ typedef struct void compare_books( QofBook* book_1, QofBook* book_2 ); void do_compare( QofBook* book_1, QofBook* book_2, const gchar* id, QofInstanceForeachCB cb, const gchar* msg ); - +#ifdef __cplusplus +} +#endif #endif diff --git a/src/backend/xml/test/Makefile.am b/src/backend/xml/test/Makefile.am index 40c10489ec..b1d24c6ef7 100644 --- a/src/backend/xml/test/Makefile.am +++ b/src/backend/xml/test/Makefile.am @@ -29,7 +29,7 @@ test_kvp_frames_SOURCES = \ ${top_srcdir}/src/backend/xml/sixtp-stack.c \ ${top_srcdir}/src/backend/xml/sixtp-to-dom-parser.c \ ${top_srcdir}/src/backend/xml/gnc-xml-helper.c \ - test-kvp-frames.c + test-kvp-frames.cpp # the xml backend is now a GModule - this test does # not load it as a module and cannot link to it @@ -221,7 +221,7 @@ TESTS_ENVIRONMENT = \ check_LTLIBRARIES = libgnc-test-file-stuff.la -libgnc_test_file_stuff_la_SOURCES = test-file-stuff.c +libgnc_test_file_stuff_la_SOURCES = test-file-stuff.cpp libgnc_test_file_stuff_la_LIBADD = \ ${top_builddir}/src/engine/libgncmod-engine.la diff --git a/src/backend/xml/test/test-file-stuff.c b/src/backend/xml/test/test-file-stuff.cpp similarity index 96% rename from src/backend/xml/test/test-file-stuff.c rename to src/backend/xml/test/test-file-stuff.cpp index c763275f91..86017e0507 100644 --- a/src/backend/xml/test/test-file-stuff.c +++ b/src/backend/xml/test/test-file-stuff.cpp @@ -20,7 +20,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ +#include +extern "C" +{ #include "config.h" #include @@ -40,13 +43,13 @@ #include "test-stuff.h" #include "io-gncxml-gen.h" #include "sixtp-utils.h" - /* #define __DEBUG 1 */ /***********************************************************************/ extern KvpFrame* dom_tree_to_kvp_frame(xmlNodePtr node); +} static int files_return(int ret, const char* msg) @@ -109,7 +112,7 @@ print_dom_tree(gpointer data_for_children, GSList* data_from_children, if (parent_data == NULL) { xmlElemDump((FILE*)global_data, NULL, (xmlNodePtr)data_for_children); - xmlFreeNode(data_for_children); + xmlFreeNode(static_cast(data_for_children)); } return TRUE; } @@ -252,25 +255,22 @@ equals_node_val_vs_kvp_frame(xmlNodePtr node, const KvpFrame *frm) g_return_val_if_fail(cmpfrm, FALSE); - if (kvp_frame_compare(frm, cmpfrm) == 0) + if (compare(frm, cmpfrm) == 0) { - kvp_frame_delete(cmpfrm); + delete cmpfrm; return TRUE; } else { - gchar *frm1str; - gchar *frm2str; - - frm1str = kvp_frame_to_string(frm); - frm2str = kvp_frame_to_string(cmpfrm); + auto frm1str = g_strdup(frm->to_string().c_str()); + auto frm2str = g_strdup(cmpfrm->to_string().c_str()); printf("%s vs %s\n", frm1str, frm2str); g_free(frm1str); g_free(frm2str); - kvp_frame_delete(cmpfrm); + delete cmpfrm; return FALSE; } } diff --git a/src/backend/xml/test/test-file-stuff.h b/src/backend/xml/test/test-file-stuff.h index 812a0478d1..c2d8d39cd7 100644 --- a/src/backend/xml/test/test-file-stuff.h +++ b/src/backend/xml/test/test-file-stuff.h @@ -4,17 +4,19 @@ #ifndef TEST_FILE_STUFF_H #define TEST_FILE_STUFF_H - +#ifdef __cplusplus +extern "C" +{ +#endif #include -#include #include #include #include #include #include - +typedef struct KvpFrameImpl KvpFrame; void write_dom_node_to_file(xmlNodePtr node, int fd); @@ -40,5 +42,7 @@ void test_files_in_dir(int argc, char **argv, gxpf_callback cb, sixtp *parser, const char *parser_tag, QofBook *book); - +#ifdef __cplusplus +} +#endif #endif diff --git a/src/backend/xml/test/test-kvp-frames.c b/src/backend/xml/test/test-kvp-frames.c deleted file mode 100644 index 1727282dba..0000000000 --- a/src/backend/xml/test/test-kvp-frames.c +++ /dev/null @@ -1,227 +0,0 @@ -#include "config.h" - -#include - -#include "test-stuff.h" -#include "test-engine-stuff.h" -#include "test-file-stuff.h" - -#include "qof.h" - -#include "sixtp-dom-generators.h" -#include "sixtp-dom-parsers.h" - -#define GNC_V2_STRING "gnc-v2" -const gchar *gnc_v2_xml_version_string = GNC_V2_STRING; -extern KvpFrame* dom_tree_to_kvp_frame(xmlNodePtr node); - -static void -test_kvp_get_slot(int run, - KvpFrame *test_frame1, const KvpValue *test_val1, - const gchar *test_key) -{ - const KvpValue *test_val2; - test_val2 = kvp_frame_get_slot(test_frame1, test_key); - if (kvp_value_compare(test_val1, test_val2) == 0) - { - success_args("kvp_frame_get_slot", __FILE__, __LINE__, "run=%d", run); - } - else - { - gchar *tmp; - failure_args("kvp_frame_get_slot", __FILE__, __LINE__, "run=%d", run); - tmp = kvp_value_to_string(test_val2); - printf(" Value is %s\n", tmp); - g_free(tmp); - } -} - -static void -test_kvp_copy_compare(int run, - KvpFrame *test_frame1, const KvpValue *test_val1, - const gchar *test_key) -{ - KvpFrame *test_frame2; - - test_frame2 = kvp_frame_copy(test_frame1); - - do_test_args(test_frame2 != NULL, "kvp_frame_copy", - __FILE__, __LINE__, "run=%d", run); - - if (kvp_frame_compare(test_frame1, test_frame2) == 0) - { - success_args("kvp_frame_copy->kvp_frame_compare", - __FILE__, __LINE__, "run=%d", run); - } - else - { - gchar *tmp; - failure_args("kvp_frame_copy->kvp_frame_compare", - __FILE__, __LINE__, "run=%d", run); - tmp = kvp_frame_to_string(test_frame1); - printf("Frame1 is %s\n", tmp); - g_free(tmp); - tmp = kvp_frame_to_string(test_frame2); - printf("Frame2 is %s\n", tmp); - g_free(tmp); - } - - kvp_frame_delete(test_frame2); -} - -static void -test_kvp_copy_get_slot(int run, - KvpFrame *test_frame1, const KvpValue *test_val1, - const gchar *test_key) -{ - KvpFrame *test_frame2; - const KvpValue *test_val2; - - test_frame2 = kvp_frame_copy(test_frame1); - test_val2 = kvp_frame_get_slot(test_frame2, test_key); - if (kvp_value_compare(test_val1, test_val2) == 0) - { - success_args("kvp_frame_copy->kvp_frame_get_slot", - __FILE__, __LINE__, "run=%d", run); - } - else - { - gchar *tmp; - failure_args("kvp_frame_copy->kvp_frame_get_slot", - __FILE__, __LINE__, "run=%d", run); - tmp = kvp_frame_to_string(test_frame1); - printf("Frame1 is %s\n", tmp); - g_free(tmp); - tmp = kvp_frame_to_string(test_frame2); - printf("Frame2 is %s\n", tmp); - g_free(tmp); - } - kvp_frame_delete(test_frame2); -} - -static void -test_kvp_create_delete(void) -{ - KvpFrame *test_frame; - - test_frame = kvp_frame_new(); - - if (test_frame != NULL) - { - kvp_frame_delete(test_frame); - test_frame = NULL; - success("kvp_frame_new"); - } - else - { - failure("kvp_frame_new"); - } -} - -static void -test_kvp_frames1(void) -{ - int i; - - for (i = 0; i < 20; i++) - { - KvpFrame *test_frame1; - gchar *test_key; - KvpValue *test_val1; - - test_val1 = get_random_kvp_value(i % KVP_TYPE_FRAME); - - test_frame1 = kvp_frame_new(); - test_key = get_random_string_without("/"); - - kvp_frame_set_slot(test_frame1, test_key, test_val1); - - test_kvp_get_slot(i, test_frame1, test_val1, test_key); - test_kvp_copy_compare(i, test_frame1, test_val1, test_key); - test_kvp_copy_get_slot(i, test_frame1, test_val1, test_key); - - kvp_value_delete(test_val1); - g_free(test_key); - kvp_frame_delete(test_frame1); - } -} - -static void -test_kvp_printing(void) -{ - int i; - for (i = 0; i < 20; i++) - { - KvpFrame *ran_frame; - gchar *char_rep; - - ran_frame = get_random_kvp_frame(); - char_rep = kvp_frame_to_string(ran_frame); - - /* if we don't crash it's good :) */ - /* puts(char_rep); */ - - g_free(char_rep); - kvp_frame_delete(ran_frame); - } -} - -static void -test_kvp_xml_stuff(void) -{ - int i; - for (i = 0; i < 20; i++) - { - QofInstance *inst = g_object_new (QOF_TYPE_INSTANCE, NULL); - KvpFrame *test_frame2; - xmlNodePtr test_node; - - inst->kvp_data = get_random_kvp_frame(); - - test_node = qof_instance_slots_to_dom_tree("test-kvp", inst); - - if (!test_node) - { - failure_args("xml stuff", __FILE__, __LINE__, - "kvp_frame_to_dom_tree produced NULL"); - } - else - { - test_frame2 = dom_tree_to_kvp_frame(test_node); - - if (kvp_frame_compare(inst->kvp_data, test_frame2) == 0) - { - success("xml stuff"); - } - else - { - gchar *tmp; - failure("xml stuff"); - tmp = kvp_frame_to_string(inst->kvp_data); - printf(" with kvp_frame 1:\n%s\n", tmp); - g_free(tmp); - printf(" and xml:\n"); - xmlElemDump(stdout, NULL, test_node); - printf("\n"); - tmp = kvp_frame_to_string(test_frame2); - printf(" and kvp_frame 2:\n%s\n", tmp); - g_free(tmp); - } - kvp_frame_delete(test_frame2); - xmlFreeNode(test_node); - } - g_object_unref (inst); - } -} - -int -main(int argc, char** argv) -{ - qof_init(); - test_kvp_create_delete(); - test_kvp_printing(); - test_kvp_frames1(); - test_kvp_xml_stuff(); - print_test_results(); - exit(get_rv()); -} diff --git a/src/backend/xml/test/test-kvp-frames.cpp b/src/backend/xml/test/test-kvp-frames.cpp new file mode 100644 index 0000000000..7c13ca8d0c --- /dev/null +++ b/src/backend/xml/test/test-kvp-frames.cpp @@ -0,0 +1,196 @@ +#include + +extern "C" +{ +#include "config.h" + +#include + +#include "test-stuff.h" +#include "test-engine-stuff.h" +#include "test-file-stuff.h" + +#include "qof.h" + +#include "sixtp-dom-generators.h" +#include "sixtp-dom-parsers.h" + +#define GNC_V2_STRING "gnc-v2" +const gchar *gnc_v2_xml_version_string = GNC_V2_STRING; +extern KvpFrame* dom_tree_to_kvp_frame(xmlNodePtr node); +} + +static void +test_kvp_get_slot(int run, + KvpFrame *test_frame1, const KvpValue *test_val1, + const gchar *test_key) +{ + auto test_val2 = test_frame1->get_slot(test_key); + auto msg = "KvpFrame::get_slot"; + if (compare(test_val1, test_val2) == 0) + { + success_args(msg, __FILE__, __LINE__, "run=%d", run); + } + else + { + gchar *tmp; + failure_args(msg, __FILE__, __LINE__, "run=%d", run); + printf(" Value is %s\n", test_val2->to_string()); + } +} + +static void +test_kvp_copy_compare(int run, + KvpFrame *test_frame1, const KvpValue *test_val1, + const gchar *test_key) +{ + auto test_frame2 = new KvpFrame(*test_frame1); + auto msg = "compare after KvpFrame copy construction"; + do_test_args(test_frame2 != NULL, "KvpFrame Copy Constructor", + __FILE__, __LINE__, "run=%d", run); + + if (compare(test_frame1, test_frame2) == 0) + { + success_args(msg, __FILE__, __LINE__, "run=%d", run); + } + else + { + gchar *tmp; + failure_args(msg, __FILE__, __LINE__, "run=%d", run); + printf("Frame1 is %s\n", test_frame1->to_string().c_str()); + printf("Frame2 is %s\n",test_frame2->to_string().c_str()); + } + + delete test_frame2; +} + +static void +test_kvp_copy_get_slot(int run, + KvpFrame *test_frame1, const KvpValue *test_val1, + const gchar *test_key) +{ + auto test_frame2 = new KvpFrame(*test_frame1); + auto test_val2 = test_frame2->get_slot(test_key); + auto msg = "KvpFrame::get_slot() from a copy-constructed frame"; + if (compare(test_val1, test_val2) == 0) + { + success_args(msg, __FILE__, __LINE__, "run=%d", run); + } + else + { + gchar *tmp; + failure_args(msg, __FILE__, __LINE__, "run=%d", run); + printf("Frame1 is %s\n", test_frame1->to_string().c_str()); + printf("Frame2 is %s\n", test_frame2->to_string().c_str()); + } + delete test_frame2; +} + +static void +test_kvp_create_delete(void) +{ + auto test_frame = new KvpFrame; + auto msg = "KvpFrame default constructor"; + if (test_frame != nullptr) + { + delete test_frame; + test_frame = nullptr; + success(msg); + } + else + { + failure(msg); + } +} + +static void +test_kvp_frames1(void) +{ + int i; + + for (i = 0; i < 20; i++) + { + auto test_val1 = get_random_kvp_value(i % KVP_TYPE_FRAME); + auto test_frame1 = new KvpFrame; + auto test_key = get_random_string_without("/"); + + test_frame1->set(test_key, test_val1); + + test_kvp_get_slot(i, test_frame1, test_val1, test_key); + test_kvp_copy_compare(i, test_frame1, test_val1, test_key); + test_kvp_copy_get_slot(i, test_frame1, test_val1, test_key); + + delete test_val1; + g_free(test_key); + delete test_frame1; + } +} + +static void +test_kvp_printing(void) +{ + int i; + for (i = 0; i < 20; i++) + { + auto ran_frame = get_random_kvp_frame(); + assert(!ran_frame->to_string().empty()); + delete ran_frame; + } +} + +static void +test_kvp_xml_stuff(void) +{ + int i; + for (i = 0; i < 20; i++) + { + auto inst = static_cast(g_object_new (QOF_TYPE_INSTANCE, NULL)); + KvpFrame *test_frame2; + xmlNodePtr test_node; + + inst->kvp_data = get_random_kvp_frame(); + auto msg = "XML Stuff"; + + test_node = qof_instance_slots_to_dom_tree("test-kvp", inst); + + if (!test_node) + { + failure_args("xml stuff", __FILE__, __LINE__, + "kvp_frame_to_dom_tree produced NULL"); + } + else + { + test_frame2 = dom_tree_to_kvp_frame(test_node); + + if (compare(inst->kvp_data, test_frame2) == 0) + { + success(msg); + } + else + { + failure(msg); + printf(" With KvpFrame 1:\n%s\n", + inst->kvp_data->to_string().c_str()); + printf(" and XML:\n"); + xmlElemDump(stdout, NULL, test_node); + printf("\n and kvp_frame 2:\n%s\n", + test_frame2->to_string().c_str()); + } + delete test_frame2; + xmlFreeNode(test_node); + } + g_object_unref (inst); + } +} + +int +main(int argc, char** argv) +{ + qof_init(); + test_kvp_create_delete(); + test_kvp_printing(); + test_kvp_frames1(); + test_kvp_xml_stuff(); + print_test_results(); + exit(get_rv()); +} diff --git a/src/engine/test-core/Makefile.am b/src/engine/test-core/Makefile.am index 76618e7e9b..928f79abaf 100644 --- a/src/engine/test-core/Makefile.am +++ b/src/engine/test-core/Makefile.am @@ -6,7 +6,7 @@ LDADD = \ ${top_builddir}/src/libqof/qof/libgnc-qof.la \ ${GLIB_LIBS} -libgncmod_test_engine_la_SOURCES = gncmod-test-engine.c test-engine-stuff.c +libgncmod_test_engine_la_SOURCES = gncmod-test-engine.c test-engine-stuff.cpp libgncmod_test_engine_la_LDFLAGS = -module libgncmod_test_engine_la_LIBADD = \ ${top_builddir}/src/gnc-module/libgnc-module.la \ diff --git a/src/engine/test-core/test-engine-stuff.c b/src/engine/test-core/test-engine-stuff.cpp similarity index 92% rename from src/engine/test-core/test-engine-stuff.c rename to src/engine/test-core/test-engine-stuff.cpp index 0969bfbc3b..6955f7b808 100644 --- a/src/engine/test-core/test-engine-stuff.c +++ b/src/engine/test-core/test-engine-stuff.cpp @@ -15,6 +15,10 @@ * Created by Linux Developers Group, 2001 * Updates Linas Vepstas July 2004 */ +#include + +extern "C" +{ #include "config.h" #include @@ -44,6 +48,7 @@ #include "test-engine-stuff.h" #include "test-stuff.h" #include "test-engine-strings.h" +} static gboolean glist_strings_only = FALSE; @@ -128,12 +133,6 @@ kvp_type_excluded (KvpValueType kvp_type) return FALSE; } -void -random_glist_strings_only (gboolean strings_only) -{ - glist_strings_only = strings_only; -} - static gboolean zero_nsec = FALSE; void @@ -189,14 +188,11 @@ get_random_glist_depth (gint depth) for (i = 0; i < count; i++) { - KvpValueType kvpt; - KvpValue *value; - - kvpt = glist_strings_only ? KVP_TYPE_STRING : -2; + KvpValue *value = nullptr; do { - value = get_random_kvp_value_depth (kvpt, depth + 1); + value = get_random_kvp_value_depth (-2, depth + 1); } while (!value); @@ -206,12 +202,6 @@ get_random_glist_depth (gint depth) return ret; } -GList* -get_random_glist(void) -{ - return get_random_glist_depth (0); -} - /* ========================================================== */ /* Time/Date, GncGUID data stuff */ @@ -248,19 +238,21 @@ static KvpFrame* get_random_kvp_frame_depth (gint depth); static KvpValue* get_random_kvp_value_depth (int type, gint depth) { - int datype = type; + KvpValueType datype; KvpValue *ret; - if (datype == -1) + if (type == -1) { - datype = get_random_int_in_range(KVP_TYPE_GINT64, KVP_TYPE_FRAME); + datype = static_cast(get_random_int_in_range(KVP_TYPE_GINT64, KVP_TYPE_FRAME)); } - if (datype == -2) + else if (type == -2) { - datype = get_random_int_in_range(KVP_TYPE_GINT64, KVP_TYPE_FRAME - 1); + datype = static_cast(get_random_int_in_range(KVP_TYPE_GINT64, KVP_TYPE_FRAME - 1)); } - + else + datype = static_cast(type); + if (datype == KVP_TYPE_FRAME && depth >= kvp_max_depth) return NULL; @@ -496,13 +488,13 @@ get_random_commodity_from_table (gnc_commodity_table *table) GList *commodities; char *name_space; - name_space = get_random_list_element (namespaces); + name_space = static_cast(get_random_list_element (namespaces)); commodities = gnc_commodity_table_get_commodities (table, name_space); if (!commodities) continue; - com = get_random_list_element (commodities); + com = static_cast(get_random_list_element (commodities)); g_list_free (commodities); @@ -604,7 +596,7 @@ make_random_changes_to_commodity_table (gnc_commodity_table *table) for (node = namespaces; node; node = node->next) { - const char *ns = node->data; + auto ns = static_cast(node->data); GList *commodities; GList *com_node; @@ -615,7 +607,7 @@ make_random_changes_to_commodity_table (gnc_commodity_table *table) for (com_node = commodities; com_node; com_node = com_node->next) { - gnc_commodity *com = com_node->data; + auto com = static_cast(com_node->data); gnc_commodity_table_remove (table, com); make_random_changes_to_commodity (com); @@ -748,7 +740,7 @@ get_random_pricedb(QofBook *book) static gboolean price_accumulator (GNCPrice *p, gpointer data) { - GList **list = data; + auto list = static_cast(data); *list = g_list_prepend (*list, p); @@ -767,7 +759,7 @@ make_random_changes_to_pricedb (QofBook *book, GNCPriceDB *pdb) for (node = list; node; node = node->next) { - GNCPrice *p = node->data; + auto p = static_cast(node->data); switch (get_random_int_in_range (0, 5)) { @@ -898,7 +890,6 @@ get_random_account_tree (QofBook *book) static void add_random_splits(QofBook *book, Transaction *trn, GList *account_list) { - Account *acc, *bcc; Split *s1, *s2; gnc_numeric val; int s2_scu; @@ -906,11 +897,11 @@ add_random_splits(QofBook *book, Transaction *trn, GList *account_list) /* Gotta have at least two different accounts */ if (1 >= g_list_length (account_list)) return; - acc = get_random_list_element (account_list); + auto acc = static_cast(get_random_list_element (account_list)); xaccTransBeginEdit(trn); s1 = get_random_split(book, acc, trn); - bcc = get_random_list_element (account_list); + auto bcc = static_cast(get_random_list_element (account_list)); if ((bcc == acc) && (!do_bork())) { /* Make sure that each side of the transaction is in @@ -919,7 +910,7 @@ add_random_splits(QofBook *book, Transaction *trn, GList *account_list) * this case? */ while (bcc == acc) { - bcc = get_random_list_element (account_list); + bcc = static_cast(get_random_list_element (account_list)); } } @@ -994,10 +985,8 @@ make_random_changes_to_transaction_and_splits (QofBook *book, splits = xaccTransGetSplitList (trans); for (node = splits; node; node = node->next) { - Split *split = node->data; - Account *account; - - account = get_random_list_element (accounts); + auto split = static_cast(node->data); + auto account = static_cast(get_random_list_element (accounts)); xaccAccountInsertSplit (account, split); } @@ -1022,7 +1011,7 @@ make_random_changes_to_transaction_and_splits (QofBook *book, splits = xaccTransGetSplitList (trans); for (node = splits; node; node = node->next) { - Split *split = node->data; + auto split = static_cast(node->data); if (get_random_boolean ()) make_random_changes_to_split (split); @@ -1038,7 +1027,7 @@ static int add_trans_helper (Transaction *trans, gpointer data) { TransInfo *ti; - GList **list = data; + auto list = static_cast(data); ti = g_new (TransInfo, 1); @@ -1069,7 +1058,7 @@ make_random_changes_to_level (QofBook *book, Account *parent) gnc_account_append_child (parent, new_account); else { - account = get_random_list_element (accounts); + account = static_cast(get_random_list_element (accounts)); gnc_account_append_child (account, new_account); } @@ -1083,7 +1072,7 @@ make_random_changes_to_level (QofBook *book, Account *parent) /* Mess with the accounts */ for (node = accounts; node; node = node->next) { - Account *account = node->data; + auto account = static_cast(node->data); if (get_random_boolean ()) make_random_changes_to_account (book, account); @@ -1095,7 +1084,7 @@ make_random_changes_to_level (QofBook *book, Account *parent) for (node = transes; node; node = node->next) { - TransInfo *ti = node->data; + auto ti = static_cast(node->data); Transaction *trans = xaccTransLookup (&ti->guid, book); if (!trans) @@ -1106,7 +1095,7 @@ make_random_changes_to_level (QofBook *book, Account *parent) for (node = transes; node; node = node->next) { - TransInfo *ti = node->data; + auto ti = static_cast(node->data); g_free (ti); } @@ -1114,18 +1103,18 @@ make_random_changes_to_level (QofBook *book, Account *parent) transes = NULL; /* delete an account */ - account = get_random_list_element (accounts); + account = static_cast(get_random_list_element (accounts)); splits = xaccAccountGetSplitList (account); splits = g_list_copy (splits); for (node = splits; node; node = node->next) { - Split *split = node->data; + auto split = static_cast(node->data); do { - new_account = get_random_list_element (accounts); + new_account = static_cast(get_random_list_element (accounts)); } while (new_account == account); @@ -1147,12 +1136,12 @@ make_random_changes_to_level (QofBook *book, Account *parent) while (i--) { - Account *a1, *a2; + Account *a2; - a1 = get_random_list_element (accounts); + auto a1 = static_cast(get_random_list_element (accounts)); if (get_random_boolean ()) - a2 = get_random_list_element (accounts); + a2 = static_cast(get_random_list_element (accounts)); else a2 = NULL; @@ -1191,7 +1180,7 @@ get_random_account(QofBook *book) sane_account_names); tmp_int = get_random_int_in_range(ACCT_TYPE_BANK, NUM_ACCOUNT_TYPES - 1); - xaccAccountSetType(ret, tmp_int); + xaccAccountSetType(ret, static_cast(tmp_int)); set_account_random_string(ret, xaccAccountSetCode); set_account_random_string(ret, xaccAccountSetDescription); @@ -1224,7 +1213,7 @@ make_random_changes_to_account (QofBook *book, Account *account) set_account_random_string (account, xaccAccountSetName); tmp_int = get_random_int_in_range (ACCT_TYPE_BANK, NUM_ACCOUNT_TYPES - 1); - xaccAccountSetType (account, tmp_int); + xaccAccountSetType (account, static_cast(tmp_int)); set_account_random_string (account, xaccAccountSetCode); set_account_random_string (account, xaccAccountSetDescription); @@ -1387,7 +1376,7 @@ set_tran_random_string(Transaction* trn, void(*func)(Transaction *act, const gchar*str)) { gchar *tmp_str = get_random_string(); - if (!trn || !(&trn->inst)) + if (!trn) { return; } @@ -1660,7 +1649,7 @@ set_query_sort (QofQuery *q, sort_type_t sort_code) { GSList *p1 = NULL, *p2 = NULL, *p3 = NULL, *standard; - standard = g_slist_prepend (NULL, QUERY_DEFAULT_SORT); + standard = g_slist_prepend (NULL, const_cast(QUERY_DEFAULT_SORT)); switch (sort_code) { @@ -1668,36 +1657,36 @@ set_query_sort (QofQuery *q, sort_type_t sort_code) p1 = standard; break; case BY_DATE: - p1 = g_slist_prepend (p1, TRANS_DATE_POSTED); - p1 = g_slist_prepend (p1, SPLIT_TRANS); + p1 = g_slist_prepend (p1, const_cast(TRANS_DATE_POSTED)); + p1 = g_slist_prepend (p1, const_cast(SPLIT_TRANS)); p2 = standard; break; case BY_DATE_ENTERED: - p1 = g_slist_prepend (p1, TRANS_DATE_ENTERED); - p1 = g_slist_prepend (p1, SPLIT_TRANS); + p1 = g_slist_prepend (p1, const_cast(TRANS_DATE_ENTERED)); + p1 = g_slist_prepend (p1, const_cast(SPLIT_TRANS)); p2 = standard; break; case BY_DATE_RECONCILED: - p1 = g_slist_prepend (p1, SPLIT_RECONCILE); - p2 = g_slist_prepend (p2, SPLIT_DATE_RECONCILED); + p1 = g_slist_prepend (p1, const_cast(SPLIT_RECONCILE)); + p2 = g_slist_prepend (p2, const_cast(SPLIT_DATE_RECONCILED)); p3 = standard; break; case BY_NUM: - p1 = g_slist_prepend (p1, TRANS_NUM); - p1 = g_slist_prepend (p1, SPLIT_TRANS); + p1 = g_slist_prepend (p1, const_cast(TRANS_NUM)); + p1 = g_slist_prepend (p1, const_cast(SPLIT_TRANS)); p2 = standard; break; case BY_AMOUNT: - p1 = g_slist_prepend (p1, SPLIT_VALUE); + p1 = g_slist_prepend (p1, const_cast(SPLIT_VALUE)); p2 = standard; break; case BY_MEMO: - p1 = g_slist_prepend (p1, SPLIT_MEMO); + p1 = g_slist_prepend (p1, const_cast(SPLIT_MEMO)); p2 = standard; break; case BY_DESC: - p1 = g_slist_prepend (p1, TRANS_DESCRIPTION); - p1 = g_slist_prepend (p1, SPLIT_TRANS); + p1 = g_slist_prepend (p1, const_cast(TRANS_DESCRIPTION)); + p1 = g_slist_prepend (p1, const_cast(SPLIT_TRANS)); p2 = standard; break; case BY_NONE: @@ -1712,6 +1701,13 @@ set_query_sort (QofQuery *q, sort_type_t sort_code) qof_query_set_sort_order (q, p1, p2, p3); } +template inline T +compare_param(int max) +{ + auto ret = get_random_int_in_range (max == 1 ? 0 : 1, max); + return static_cast(ret); +} + QofQuery * get_random_query(void) { @@ -1744,7 +1740,7 @@ get_random_query(void) xaccQueryAddAccountGUIDMatch (q, guids, - get_random_int_in_range (1, QOF_GUID_MATCH_NONE), + compare_param(QOF_GUID_MATCH_NONE), get_random_queryop ()); free_random_guids (guids); break; @@ -1755,7 +1751,7 @@ get_random_query(void) string, get_random_boolean (), get_random_boolean (), - get_random_int_in_range (1, QOF_COMPARE_CONTAINS), + compare_param(QOF_COMPARE_CONTAINS), get_random_queryop ()); g_free (string); break; @@ -1763,19 +1759,19 @@ get_random_query(void) case 3: /* PR_BALANCE */ xaccQueryAddBalanceMatch (q, - get_random_boolean (), + compare_param (1), get_random_queryop ()); break; case 4: /* PR_CLEARED */ xaccQueryAddClearedMatch (q, - get_random_int_in_range (1, + static_cast(get_random_int_in_range (1, CLEARED_NO | CLEARED_CLEARED | CLEARED_RECONCILED | CLEARED_FROZEN | - CLEARED_VOIDED), + CLEARED_VOIDED)), get_random_queryop ()); break; @@ -1798,7 +1794,7 @@ get_random_query(void) string, get_random_boolean (), get_random_boolean (), - get_random_int_in_range (1, QOF_COMPARE_CONTAINS), + compare_param(QOF_COMPARE_CONTAINS), get_random_queryop ()); g_free (string); break; @@ -1821,7 +1817,7 @@ get_random_query(void) string, get_random_boolean (), get_random_boolean (), - get_random_int_in_range (1, QOF_COMPARE_CONTAINS), + compare_param(QOF_COMPARE_CONTAINS), get_random_queryop ()); g_free (string); break; @@ -1832,7 +1828,7 @@ get_random_query(void) string, get_random_boolean (), get_random_boolean (), - get_random_int_in_range (1, QOF_COMPARE_CONTAINS), + compare_param(QOF_COMPARE_CONTAINS), get_random_queryop ()); g_free (string); break; @@ -1841,7 +1837,7 @@ get_random_query(void) xaccQueryAddSharePriceMatch (q, get_random_gnc_numeric (GNC_DENOM_AUTO), - get_random_int_in_range (1, QOF_COMPARE_NEQ), + compare_param (QOF_COMPARE_NEQ), get_random_queryop ()); break; @@ -1849,7 +1845,7 @@ get_random_query(void) xaccQueryAddSharesMatch (q, get_random_gnc_numeric (GNC_DENOM_AUTO), - get_random_int_in_range (1, QOF_COMPARE_NEQ), + compare_param (QOF_COMPARE_NEQ), get_random_queryop ()); break; @@ -1857,8 +1853,8 @@ get_random_query(void) xaccQueryAddValueMatch (q, get_random_gnc_numeric (GNC_DENOM_AUTO), - get_random_int_in_range (1, QOF_NUMERIC_MATCH_ANY), - get_random_int_in_range (1, QOF_COMPARE_NEQ), + compare_param (QOF_NUMERIC_MATCH_ANY), + compare_param (QOF_COMPARE_NEQ), get_random_queryop ()); break; @@ -1870,7 +1866,7 @@ get_random_query(void) } if (gnc_engine_debug_random) printf ("\n"); - set_query_sort (q, get_random_int_in_range (1, BY_NONE)); + set_query_sort (q, compare_param(BY_NONE)); qof_query_set_sort_increasing (q, get_random_boolean (), @@ -2088,7 +2084,7 @@ make_trans_query (Transaction *trans, TestQueryTypes query_types) list = NULL; for (node = xaccTransGetSplitList (trans); node; node = node->next) { - Split * split = node->data; + auto split = static_cast(node->data); list = g_list_prepend (list, xaccSplitGetAccount (split)); } xaccQueryAddAccountMatch (q, list, QOF_GUID_MATCH_ALL, QOF_QUERY_AND); diff --git a/src/engine/test-core/test-engine-stuff.h b/src/engine/test-core/test-engine-stuff.h index 557bba8aa3..73360b460e 100644 --- a/src/engine/test-core/test-engine-stuff.h +++ b/src/engine/test-core/test-engine-stuff.h @@ -4,7 +4,10 @@ #ifndef TEST_ENGINE_STUFF_H #define TEST_ENGINE_STUFF_H - +#ifdef __cplusplus +extern "C" +{ +#endif #include #include #include @@ -32,9 +35,7 @@ bin_data* get_random_binary_data(void); KvpFrame* get_random_kvp_frame(void); gnc_numeric get_random_gnc_numeric(int64_t); GncGUID* get_random_guid(void); -GList* get_random_glist(void); -void random_glist_strings_only (gboolean strings_only); void kvp_exclude_type (KvpValueType kvp_type); void set_max_kvp_depth (gint max_kvp_depth); void set_max_kvp_frame_elements (gint max_kvp_frame_elements); @@ -95,4 +96,7 @@ SchedXaction* add_daily_sx(gchar *name, const GDate *start, const GDate *end, co SchedXaction* add_once_sx(gchar *name, const GDate *when); void remove_sx(SchedXaction *sx); +#ifdef __cplusplus +} +#endif #endif diff --git a/src/engine/test/Makefile.am b/src/engine/test/Makefile.am index 8f1cf03dc1..7366d7561a 100644 --- a/src/engine/test/Makefile.am +++ b/src/engine/test/Makefile.am @@ -94,7 +94,7 @@ EXTRA_DIST += \ test_engine_SOURCES = \ test-engine.c \ - utest-Account.c \ + utest-Account.cpp \ utest-Budget.c \ utest-Entry.c \ utest-Invoice.c \ @@ -124,7 +124,7 @@ libutest_Split_la_CXXFLAGS = -Wno-write-strings $(AM_CXXFLAGS) libutest_Split_la_LIBADD = $(LDADD) libutest_Trans_la_SOURCES = \ - utest-Transaction.c + utest-Transaction.cpp libutest_Trans_la_LIBADD = $(LDADD) diff --git a/src/engine/test/gtest-import-map.cpp b/src/engine/test/gtest-import-map.cpp index a4d4885b93..e24a64f3e3 100644 --- a/src/engine/test/gtest-import-map.cpp +++ b/src/engine/test/gtest-import-map.cpp @@ -26,7 +26,6 @@ extern "C" #include "../Account.h" #include #include -#include struct GncImportMatchMap { @@ -48,6 +47,7 @@ extern void gnc_imap_add_account_bayes (GncImportMatchMap *imap, Account *acc); } +#include #include class ImapTest : public testing::Test @@ -103,14 +103,12 @@ protected: TEST_F(ImapPlainTest, FindAccount) { auto root = qof_instance_get_slots(QOF_INSTANCE(t_bank_account)); - auto acc1_val = kvp_value_new_guid(xaccAccountGetGUID(t_expense_account1)); - auto acc2_val = kvp_value_new_guid(xaccAccountGetGUID(t_expense_account2)); - kvp_frame_set_slot_path(root, acc1_val, IMAP_FRAME, "foo", "bar", NULL); - kvp_frame_set_slot_path(root, acc2_val, IMAP_FRAME, "baz", "waldo", NULL); - kvp_frame_set_slot_path(root, acc1_val, IMAP_FRAME, "pepper", NULL); - kvp_frame_set_slot_path(root, acc2_val, IMAP_FRAME, "salt", NULL); - kvp_value_delete(acc1_val); - kvp_value_delete(acc2_val); + auto acc1_val = new KvpValue(const_cast(xaccAccountGetGUID(t_expense_account1))); + auto acc2_val = new KvpValue(const_cast(xaccAccountGetGUID(t_expense_account2))); + root->set_path({IMAP_FRAME, "foo", "bar"}, acc1_val); + root->set_path({IMAP_FRAME, "baz", "waldo"}, acc2_val); + root->set_path({IMAP_FRAME, "pepper"}, acc1_val); + root->set_path({IMAP_FRAME, "salt"}, acc2_val); EXPECT_EQ(t_expense_account1, gnc_imap_find_account(t_imap, "foo", "bar")); EXPECT_EQ(t_expense_account2, @@ -140,17 +138,17 @@ TEST_F(ImapPlainTest, AddAccount) qof_instance_reset_editlevel(QOF_INSTANCE(t_bank_account)); auto root = qof_instance_get_slots(QOF_INSTANCE(t_bank_account)); - auto value = kvp_frame_get_slot_path(root, IMAP_FRAME, "foo", "bar", NULL); + auto value = root->get_slot({IMAP_FRAME, "foo", "bar"}); auto check_account = [this](KvpValue* v) { - return xaccAccountLookup(kvp_value_get_guid(v), this->t_imap->book); }; + return xaccAccountLookup(v->get(), this->t_imap->book); }; EXPECT_EQ(t_expense_account1, check_account(value)); - value = kvp_frame_get_slot_path(root, IMAP_FRAME, "baz", "waldo", NULL); + value = root->get_slot({IMAP_FRAME, "baz", "waldo"}); EXPECT_EQ(t_expense_account2, check_account(value)); - value = kvp_frame_get_slot_path(root, IMAP_FRAME, "pepper", NULL); + value = root->get_slot({IMAP_FRAME, "pepper"}); EXPECT_EQ(t_expense_account1, check_account(value)); - value = kvp_frame_get_slot_path(root, IMAP_FRAME, "salt", NULL); + value = root->get_slot({IMAP_FRAME, "salt"}); EXPECT_EQ(t_expense_account2, check_account(value)); - value = kvp_frame_get_slot_path(root, IMAP_FRAME, "pork", "sausage", NULL); + value = root->get_slot({IMAP_FRAME, "pork", "sausage"}); EXPECT_EQ(nullptr, value); } @@ -205,21 +203,14 @@ TEST_F(ImapBayesTest, FindAccountBayes) auto root = qof_instance_get_slots(QOF_INSTANCE(t_bank_account)); auto acct1_name = gnc_account_get_full_name(t_expense_account1); auto acct2_name = gnc_account_get_full_name(t_expense_account2); - auto value = kvp_value_new_gint64(42); + auto value = new KvpValue(INT64_C(42)); - kvp_frame_set_slot_path(root, value, IMAP_FRAME_BAYES, - foo, acct1_name, NULL); - kvp_frame_set_slot_path(root, value, IMAP_FRAME_BAYES, - bar, acct1_name, NULL); - kvp_frame_set_slot_path(root, value, IMAP_FRAME_BAYES, - baz, acct2_name, NULL); - kvp_frame_set_slot_path(root, value, IMAP_FRAME_BAYES, - waldo, acct2_name, NULL); - kvp_frame_set_slot_path(root, value, IMAP_FRAME_BAYES, - pepper, acct1_name, NULL); - kvp_frame_set_slot_path(root, value, IMAP_FRAME_BAYES, - salt, acct2_name, NULL); - kvp_value_delete(value); + root->set_path({IMAP_FRAME_BAYES, foo, acct1_name}, value); + root->set_path({IMAP_FRAME_BAYES, bar, acct1_name}, value); + root->set_path({IMAP_FRAME_BAYES, baz, acct2_name}, value); + root->set_path({IMAP_FRAME_BAYES, waldo, acct2_name}, value); + root->set_path({IMAP_FRAME_BAYES, pepper, acct1_name}, value); + root->set_path({IMAP_FRAME_BAYES, salt, acct2_name}, value); auto account = gnc_imap_find_account_bayes(t_imap, t_list1); EXPECT_EQ(t_expense_account1, account); @@ -252,37 +243,28 @@ TEST_F(ImapBayesTest, AddAccountBayes) auto root = qof_instance_get_slots(QOF_INSTANCE(t_bank_account)); auto acct1_name = gnc_account_get_full_name(t_expense_account1); auto acct2_name = gnc_account_get_full_name(t_expense_account2); - auto value = kvp_frame_get_slot_path(root, IMAP_FRAME_BAYES, "foo", "bar", NULL); + auto value = root->get_slot({IMAP_FRAME_BAYES, "foo", "bar"}); auto check_account = [this](KvpValue* v) { - return (kvp_value_get_string(v), - this->t_imap->book); }; - value = kvp_frame_get_slot_path(root, IMAP_FRAME_BAYES, foo, acct1_name, - NULL); - EXPECT_EQ(1, kvp_value_get_gint64(value)); - value = kvp_frame_get_slot_path(root, IMAP_FRAME_BAYES, bar, acct1_name, - NULL); - EXPECT_EQ(1, kvp_value_get_gint64(value)); - value = kvp_frame_get_slot_path(root, IMAP_FRAME_BAYES, baz, acct2_name, - NULL); - EXPECT_EQ(1, kvp_value_get_gint64(value)); - value = kvp_frame_get_slot_path(root, IMAP_FRAME_BAYES, waldo, acct2_name, - NULL); - EXPECT_EQ(1, kvp_value_get_gint64(value)); - value = kvp_frame_get_slot_path(root, IMAP_FRAME_BAYES, pepper, acct1_name, - NULL); - EXPECT_EQ(1, kvp_value_get_gint64(value)); - value = kvp_frame_get_slot_path(root, IMAP_FRAME_BAYES, salt, acct2_name, - NULL); - EXPECT_EQ(1, kvp_value_get_gint64(value)); - value = kvp_frame_get_slot_path(root, IMAP_FRAME_BAYES, baz, acct1_name, - NULL); - EXPECT_EQ(0, kvp_value_get_gint64(value)); + return (v->get(), this->t_imap->book); }; + value = root->get_slot({IMAP_FRAME_BAYES, foo, acct1_name}); + EXPECT_EQ(1, value->get()); + value = root->get_slot({IMAP_FRAME_BAYES, bar, acct1_name}); + EXPECT_EQ(1, value->get()); + value = root->get_slot({IMAP_FRAME_BAYES, baz, acct2_name}); + EXPECT_EQ(1, value->get()); + value = root->get_slot({IMAP_FRAME_BAYES, waldo, acct2_name}); + EXPECT_EQ(1, value->get()); + value = root->get_slot({IMAP_FRAME_BAYES, pepper, acct1_name}); + EXPECT_EQ(1, value->get()); + value = root->get_slot({IMAP_FRAME_BAYES, salt, acct2_name}); + EXPECT_EQ(1, value->get()); + value = root->get_slot({IMAP_FRAME_BAYES, baz, acct1_name}); + EXPECT_EQ(nullptr, value); qof_instance_increase_editlevel(QOF_INSTANCE(t_bank_account)); gnc_imap_add_account_bayes(t_imap, t_list2, t_expense_account2); qof_instance_mark_clean(QOF_INSTANCE(t_bank_account)); qof_instance_reset_editlevel(QOF_INSTANCE(t_bank_account)); - value = kvp_frame_get_slot_path(root, IMAP_FRAME_BAYES, baz, acct2_name, - NULL); - EXPECT_EQ(2, kvp_value_get_gint64(value)); + value = root->get_slot({IMAP_FRAME_BAYES, baz, acct2_name}); + EXPECT_EQ(2, value->get()); } diff --git a/src/engine/test/utest-Account.c b/src/engine/test/utest-Account.cpp similarity index 89% rename from src/engine/test/utest-Account.c rename to src/engine/test/utest-Account.cpp index f1c69147f8..747f9d6bbb 100644 --- a/src/engine/test/utest-Account.c +++ b/src/engine/test/utest-Account.cpp @@ -18,14 +18,15 @@ * 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 * -********************************************************************/ + ********************************************************************/ +extern "C" +{ #include "config.h" #include #include #include #include #include -#include #include /* Add specific headers for this class */ #include "../Account.h" @@ -44,6 +45,9 @@ #endif static const gchar *suitename = "/engine/Account"; void test_suite_account (void); +} + +#include typedef struct { @@ -54,20 +58,20 @@ typedef struct typedef struct { GNCAccountType type; - char *name; - char *parent; - char *code; - char *desc; - char *color; - char *notes; - char *num; + const char *name; + const char *parent; + const char *code; + const char *desc; + const char *color; + const char *notes; + const char *num; GNCPolicy *policy; } AccountParms; typedef struct { - char *memo; - char *account; + const char *memo; + const char *account; char reconciled; gnc_numeric amount; gnc_numeric value; @@ -76,7 +80,7 @@ typedef struct typedef struct { - gchar *desc; + const char *desc; gint date_offset; SplitParms splits[2]; } TxnParms; @@ -265,10 +269,10 @@ static SetupData complex_data = {G_N_ELEMENTS (complex_accts), static Split* insert_split (Account *parent, Transaction *txn, SplitParms *p) { - QofBook *book = gnc_account_get_book (parent); - Split *split = xaccMallocSplit (book); - Account *acct = gnc_account_lookup_by_name (parent, p->account); - LotList* lotlist = xaccAccountGetLotList (acct); + auto book = gnc_account_get_book (parent); + auto split = xaccMallocSplit (book); + auto acct = gnc_account_lookup_by_name (parent, p->account); + auto lotlist = xaccAccountGetLotList (acct); GNCLot* lot = NULL; g_assert (acct != NULL); xaccSplitSetParent (split, txn); @@ -297,31 +301,32 @@ insert_split (Account *parent, Transaction *txn, SplitParms *p) static void setup (Fixture *fixture, gconstpointer pData) { - QofBook *book = qof_book_new (); - Account *root = gnc_account_create_root (book), *acct = NULL; - SetupData *parms = (SetupData *)pData; + auto book = qof_book_new (); + auto root = gnc_account_create_root (book); + auto parms = static_cast(pData); TxnParms *t_arr; AccountParms *p_arr; - GHashTable *accts = g_hash_table_new (g_str_hash, g_str_equal); + auto accts = g_hash_table_new (g_str_hash, g_str_equal); guint ind; - g_hash_table_insert (accts, "root", root); + auto root_str = static_cast(CACHE_INSERT("root")); + g_hash_table_insert (accts, root_str, root); fixture->func = _utest_account_fill_functions (); if (parms == NULL) { fixture->acct = root; return; } - acct = root; + auto acct = root; p_arr = (AccountParms*)parms->accounts; for (ind = 0; ind < parms->num_accounts; ind++) { - Account *child = xaccMallocAccount (book); + auto child = xaccMallocAccount (book); AccountParms p = p_arr[ind]; if (p.parent && strlen (p.parent) > 0) { - Account *parent = g_hash_table_lookup (accts, p.parent); + auto parent = static_cast(g_hash_table_lookup (accts, p.parent)); g_assert (parent != NULL); gnc_account_append_child (parent, child); } @@ -332,7 +337,7 @@ setup (Fixture *fixture, gconstpointer pData) if (p.name) { xaccAccountSetName (acct, p.name); - g_hash_table_insert (accts, p.name, acct); + g_hash_table_insert (accts, const_cast(p.name), acct); } if (p.code) xaccAccountSetCode (acct, p.code); @@ -427,27 +432,28 @@ static void test_gnc_account_name_violations_errmsg () { GList *badnames = NULL, *nonames = NULL, *node = NULL; - gchar *separator = ":", *message, *validation_message, *account_list = NULL; + auto separator = ":"; + char *account_list = NULL; /* FUT wants to free the strings, so we alloc them */ badnames = g_list_prepend (badnames, g_strdup ("Foo:bar")); badnames = g_list_prepend (badnames, g_strdup ("baz")); badnames = g_list_prepend (badnames, g_strdup ("waldo:pepper")); - message = gnc_account_name_violations_errmsg (separator, nonames); + auto message = gnc_account_name_violations_errmsg (separator, nonames); for (node = badnames; node; node = g_list_next (node)) { if (!account_list) - account_list = g_strdup (node->data); + account_list = g_strdup (static_cast(node->data)); else { - gchar *tmp_list = g_strconcat ( account_list, "\n", - node->data, NULL); + auto tmp_list = g_strconcat ( account_list, "\n", + static_cast(node->data), NULL); g_free (account_list); account_list = tmp_list; } } message = gnc_account_name_violations_errmsg (separator, nonames); g_assert (message == NULL); - validation_message = g_strdup_printf ( + auto validation_message = g_strdup_printf ( "The separator character \"%s\" is used in one or more account " "names.\n\nThis will result in unexpected behaviour. " "Either change the account names or choose another separator " @@ -464,33 +470,33 @@ GList *gnc_account_list_name_violations (QofBook *book, const gchar *separator)/ static void test_gnc_account_list_name_violations (Fixture *fixture, gconstpointer pData) { - guint log_level = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; - gchar *log_domain = "gnc.engine"; + auto log_level = static_cast(G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL); + auto log_domain = "gnc.engine"; #ifdef USE_CLANG_FUNC_SIG #define _func "GList *gnc_account_list_name_violations(QofBook *, const gchar *)" #else #define _func "gnc_account_list_name_violations" #endif - gchar *msg = _func ": assertion " _Q "separator != NULL' failed"; + auto msg = _func ": assertion " _Q "separator != NULL' failed"; #undef _func - TestErrorStruct check = { log_level, log_domain, msg, 0 }; + auto check = test_error_struct_new(log_domain, log_level, msg); GList *results, *res_iter; - gchar *sep = ":"; + auto sep = ":"; QofBook *book = gnc_account_get_book (fixture->acct); /* Because of GLib bug 653052, we have to set the logging user_data to * affect the test_log_fatal_handler */ - GLogFunc oldlogger = g_log_set_default_handler ((GLogFunc)test_null_handler, &check); - g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check); + GLogFunc oldlogger = g_log_set_default_handler ((GLogFunc)test_null_handler, check); + g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, check); g_assert (gnc_account_list_name_violations (NULL, NULL) == NULL); - g_assert_cmpint (check.hits, ==, 1); + g_assert_cmpint (check->hits, ==, 1); g_assert (gnc_account_list_name_violations (book, NULL) == NULL); - g_assert_cmpint (check.hits, ==, 2); + g_assert_cmpint (check->hits, ==, 2); g_assert (gnc_account_list_name_violations (NULL, sep) == NULL); g_log_set_default_handler (oldlogger, NULL); results = gnc_account_list_name_violations (book, sep); g_assert_cmpuint (g_list_length (results), == , 2); - g_assert_cmpint (check.hits, ==, 2); + g_assert_cmpint (check->hits, ==, 2); for (res_iter = results; res_iter; res_iter = g_list_next (res_iter)) test_free (res_iter->data); g_list_free (results); @@ -546,8 +552,8 @@ gnc_account_init (Account* acc)// 1 static void test_gnc_account_create_and_destroy (void) { - Account *acc = g_object_new (GNC_TYPE_ACCOUNT, NULL); - gchar *name, *fname, *code, *desc, *color, *notes, *tax_code, *tax_src; + auto acc = static_cast(g_object_new (GNC_TYPE_ACCOUNT, NULL)); + char *name, *fname, *code, *desc, *color, *notes, *tax_code, *tax_src; GNCAccountType type; gnc_commodity *commo; gint commo_scu, mark; @@ -660,10 +666,10 @@ Simple pass-through for qof_collection_get_data () static void test_gnc_book_set_get_root_account (Fixture *fixture, gconstpointer pData) { - guint log_level = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; - gchar *log_domain = "gnc.account"; - gchar *msg = "[gnc_book_set_root_account()] cannot mix and match books freely!"; - TestErrorStruct check = { log_level, log_domain, msg, 0 }; + auto log_level = static_cast(G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL); + auto log_domain = "gnc.account"; + auto msg = "[gnc_book_set_root_account()] cannot mix and match books freely!"; + auto check = test_error_struct_new(log_domain, log_level, msg); Account *acc1, *acc2; QofBook* book1 = qof_book_new (); GLogFunc oldlogger; @@ -679,12 +685,12 @@ test_gnc_book_set_get_root_account (Fixture *fixture, gconstpointer pData) /* Now try to set the book's root account to the fixture * accout. Should throw an error. */ - oldlogger = g_log_set_default_handler ((GLogFunc)test_null_handler, &check); + oldlogger = g_log_set_default_handler ((GLogFunc)test_null_handler, check); g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, - &check); + check); gnc_book_set_root_account (book1, fixture->acct); g_assert (gnc_book_get_root_account (book1) == acc1); - g_assert_cmpint (check.hits, ==, 1); + g_assert_cmpint (check->hits, ==, 1); g_log_set_default_handler (oldlogger, NULL); /* Check that if we set the same root, it stays set */ gnc_book_set_root_account (book2, fixture->acct); @@ -728,7 +734,7 @@ test_gnc_account_create_root (void) QofBook *book = qof_book_new (); QofCollection *coll = qof_book_get_collection (book, GNC_ID_ROOT_ACCOUNT); Account *acc; - gchar *name; + char *name; AccountTestFunctions *func = _utest_account_fill_functions (); /* Can't use gnc_book_get_root_account, it creates one if it doesn't * yet exist */ @@ -752,27 +758,28 @@ test_xaccCloneAccount (Fixture *fixture, gconstpointer pData) { Account *clone; QofBook *book = gnc_account_get_book (fixture->acct); - guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; + auto loglevel = static_cast(G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL); #ifdef USE_CLANG_FUNC_SIG #define _func "Account *xaccCloneAccount(const Account *, QofBook *)" #else #define _func "xaccCloneAccount" #endif - gchar *msg1 = _func ": assertion " _Q "GNC_IS_ACCOUNT(from)' failed"; - gchar *msg2 = _func ": assertion " _Q "QOF_IS_BOOK(book)' failed"; + auto msg1 = _func ": assertion " _Q "GNC_IS_ACCOUNT(from)' failed"; + auto msg2 = _func ": assertion " _Q "QOF_IS_BOOK(book)' failed"; #undef _func - TestErrorStruct check = { loglevel, "gnc.engine", msg1, 0 }; - GLogFunc oldlogger; + auto check = test_error_struct_new("gnc.engine", loglevel, msg1); AccountPrivate *acct_p, *clone_p; - oldlogger = g_log_set_default_handler ((GLogFunc)test_null_handler, &check); - g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check); + auto oldlogger = g_log_set_default_handler ((GLogFunc)test_null_handler, + check); + g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, check); clone = xaccCloneAccount (NULL, book); g_assert (clone == NULL); - g_assert_cmpint (check.hits, ==, 1); - check.msg = msg2; + g_assert_cmpint (check->hits, ==, 1); + g_free(check->msg); + check->msg = g_strdup(msg2); clone = xaccCloneAccount (fixture->acct, NULL); g_assert (clone == NULL); - g_assert_cmpint (check.hits, ==, 2); + g_assert_cmpint (check->hits, ==, 2); g_log_set_default_handler (oldlogger, NULL); /* Now test the real clone */ clone = xaccCloneAccount (fixture->acct, book); @@ -783,12 +790,13 @@ test_xaccCloneAccount (Fixture *fixture, gconstpointer pData) g_assert (clone_p->accountName == acct_p->accountName); g_assert (clone_p->accountCode == acct_p->accountCode); g_assert (clone_p->description == acct_p->description); - g_assert (kvp_frame_compare (clone->inst.kvp_data, - fixture->acct->inst.kvp_data) == 0); + g_assert (compare (clone->inst.kvp_data, + fixture->acct->inst.kvp_data) == 0); g_assert (gnc_commodity_equal (clone_p->commodity, acct_p->commodity)); g_assert (clone_p->commodity_scu == acct_p->commodity_scu); g_assert (clone_p->non_standard_scu == acct_p->non_standard_scu); /* Clean Up */ + test_error_struct_free(check); g_object_unref (clone); } @@ -854,18 +862,18 @@ acc_free static void test_xaccFreeAccount (Fixture *fixture, gconstpointer pData) { - gchar *msg1 = "[xaccFreeAccount()] instead of calling xaccFreeAccount(), please call \n" + auto msg1 = "[xaccFreeAccount()] instead of calling xaccFreeAccount(), please call \n" " xaccAccountBeginEdit(); xaccAccountDestroy(); \n"; #ifdef USE_CLANG_FUNC_SIG #define _func "int xaccTransGetSplitIndex(const Transaction *, const Split *)" #else #define _func "xaccTransGetSplitIndex" #endif - gchar *msg2 = _func ": assertion " _Q "trans && split' failed"; + auto msg2 = _func ": assertion " _Q "trans && split' failed"; #undef _func - guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; - TestErrorStruct check1 = { loglevel, "gnc.account", msg1, 0 }; - TestErrorStruct check2 = { loglevel, "gnc.engine", msg2, 0 }; + auto loglevel = static_cast(G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL); + auto check1 = test_error_struct_new("gnc.account", loglevel, msg1); + auto check2 = test_error_struct_new("gnc.engine", loglevel, msg2); QofBook *book = gnc_account_get_book (fixture->acct); Account *parent = gnc_account_get_parent (fixture->acct); AccountPrivate *p_priv = fixture->func->get_private (parent); @@ -873,12 +881,12 @@ test_xaccFreeAccount (Fixture *fixture, gconstpointer pData) guint i = 0; guint hdlr1, hdlr2; gnc_commodity *commodity = gnc_commodity_new (book, "US Dollar", "CURRENCY", "USD", "0", 100); - test_add_error (&check1); - test_add_error (&check2); + test_add_error (check1); + test_add_error (check2); hdlr1 = g_log_set_handler ("gnc.account", loglevel, - (GLogFunc)test_checked_handler, &check1); + (GLogFunc)test_checked_handler, check1); hdlr2 = g_log_set_handler ("gnc.engine", loglevel, - (GLogFunc)test_checked_handler, &check2); + (GLogFunc)test_checked_handler, check2); g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_list_handler, NULL); for (i = 0; i < numItems; i++) { @@ -894,8 +902,8 @@ test_xaccFreeAccount (Fixture *fixture, gconstpointer pData) g_assert (p_priv->splits != NULL); g_assert (p_priv->parent != NULL); g_assert (p_priv->commodity != NULL); - g_assert_cmpint (check1.hits, ==, 0); - g_assert_cmpint (check2.hits, ==, 0); + g_assert_cmpint (check1->hits, ==, 0); + g_assert_cmpint (check2->hits, ==, 0); /* Now set the other private parts to something so that they can be set back */ p_priv->cleared_balance = gnc_numeric_create ( 5, 12); p_priv->reconciled_balance = gnc_numeric_create ( 5, 12); @@ -903,8 +911,8 @@ test_xaccFreeAccount (Fixture *fixture, gconstpointer pData) p_priv->balance_dirty = TRUE; p_priv->sort_dirty = TRUE; fixture->func->xaccFreeAccount (parent); - g_assert_cmpint (check1.hits, ==, 6); - g_assert_cmpint (check2.hits, ==, 6); + g_assert_cmpint (check1->hits, ==, 6); + g_assert_cmpint (check2->hits, ==, 6); /* cleanup what's left */ g_log_remove_handler ("gnc.account", hdlr1); g_log_remove_handler ("gnc.engine", hdlr2); @@ -968,18 +976,18 @@ Also tests: static void test_xaccAccountCommitEdit (Fixture *fixture, gconstpointer pData) { - gchar *msg1 = "[xaccFreeAccount()] instead of calling xaccFreeAccount(), please call \n" + auto msg1 = "[xaccFreeAccount()] instead of calling xaccFreeAccount(), please call \n" " xaccAccountBeginEdit(); xaccAccountDestroy(); \n"; #ifdef USE_CLANG_FUNC_SIG #define _func "int xaccTransGetSplitIndex(const Transaction *, const Split *)" #else #define _func "xaccTransGetSplitIndex" #endif - gchar *msg2 = _func ": assertion " _Q "trans && split' failed"; + auto msg2 = _func ": assertion " _Q "trans && split' failed"; #undef _func - guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; - TestErrorStruct check1 = { loglevel, "gnc.account", msg1, 0 }; - TestErrorStruct check2 = { loglevel, "gnc.engine", msg2, 0 }; + auto loglevel = static_cast(G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL); + auto check1 = test_error_struct_new("gnc.account", loglevel, msg1); + auto check2 = test_error_struct_new("gnc.engine", loglevel, msg2); guint hdlr1, hdlr2; TestSignal sig1, sig2; QofBook *book = gnc_account_get_book (fixture->acct); @@ -988,12 +996,12 @@ test_xaccAccountCommitEdit (Fixture *fixture, gconstpointer pData) const guint numItems = 3; guint i = 0; gnc_commodity *commodity = gnc_commodity_new (book, "US Dollar", "CURRENCY", "USD", "0", 100); - test_add_error (&check1); - test_add_error (&check2); + test_add_error (check1); + test_add_error (check2); hdlr1 = g_log_set_handler ("gnc.account", loglevel, - (GLogFunc)test_checked_handler, &check1); + (GLogFunc)test_checked_handler, check1); hdlr2 = g_log_set_handler ("gnc.engine", loglevel, - (GLogFunc)test_checked_handler, &check2); + (GLogFunc)test_checked_handler, check2); g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_list_handler, NULL); for (i = 0; i < numItems; i++) { @@ -1009,8 +1017,8 @@ test_xaccAccountCommitEdit (Fixture *fixture, gconstpointer pData) g_assert (p_priv->splits != NULL); g_assert (p_priv->parent != NULL); g_assert (p_priv->commodity != NULL); - g_assert_cmpint (check1.hits, ==, 0); - g_assert_cmpint (check2.hits, ==, 0); + g_assert_cmpint (check1->hits, ==, 0); + g_assert_cmpint (check2->hits, ==, 0); sig1 = test_signal_new (&parent->inst, QOF_EVENT_MODIFY, NULL); sig2 = test_signal_new (&parent->inst, QOF_EVENT_DESTROY, NULL); @@ -1025,8 +1033,8 @@ test_xaccAccountCommitEdit (Fixture *fixture, gconstpointer pData) g_assert (p_priv->splits != NULL); g_assert (p_priv->parent != NULL); g_assert (p_priv->commodity != NULL); - g_assert_cmpint (check1.hits, ==, 0); - g_assert_cmpint (check2.hits, ==, 0); + g_assert_cmpint (check1->hits, ==, 0); + g_assert_cmpint (check2->hits, ==, 0); /* xaccAccountDestroy destroys the account by calling * qof_instance_set_destroying (), then xaccAccountCommitEdit (); */ @@ -1035,8 +1043,8 @@ test_xaccAccountCommitEdit (Fixture *fixture, gconstpointer pData) /* So this time we make sure that the account is destroyed */ test_signal_assert_hits (sig1, 2); test_signal_assert_hits (sig2, 1); - g_assert_cmpint (check1.hits, ==, 2); - g_assert_cmpint (check2.hits, ==, 12); + g_assert_cmpint (check1->hits, ==, 2); + g_assert_cmpint (check2->hits, ==, 12); /* And clean up */ test_signal_free (sig1); test_signal_free (sig2); @@ -1092,22 +1100,22 @@ test_gnc_account_insert_remove_split (Fixture *fixture, gconstpointer pData) #else #define _func "gnc_account_insert_split" #endif - gchar *msg1 = _func ": assertion " _Q "GNC_IS_ACCOUNT(acc)' failed"; - gchar *msg2 = _func ": assertion " _Q "GNC_IS_SPLIT(s)' failed"; + auto msg1 = _func ": assertion " _Q "GNC_IS_ACCOUNT(acc)' failed"; + auto msg2 = _func ": assertion " _Q "GNC_IS_SPLIT(s)' failed"; #undef _func - guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; -// gchar *log_domain = "gnc.engine"; - TestErrorStruct check1 = { loglevel, "gnc.engine", msg1, 0 }; - TestErrorStruct check2 = { loglevel, "gnc.engine", msg2, 0 }; - TestErrorStruct check3 = { loglevel, "gnc.engine", NULL, 0 }; + auto loglevel = static_cast(G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL); +// auto log_domain = "gnc.engine"; + auto check1 = test_error_struct_new("gnc.engine", loglevel, msg1); + auto check2 = test_error_struct_new("gnc.engine", loglevel, msg2); + auto check3 = test_error_struct_new("gnc.engine", loglevel, NULL); guint logger; sig1 = test_signal_new (&fixture->acct->inst, QOF_EVENT_MODIFY, NULL); sig2 = test_signal_new (&fixture->acct->inst, GNC_EVENT_ITEM_ADDED, split1); - test_add_error (&check1); - test_add_error (&check2); + test_add_error (check1); + test_add_error (check2); logger = g_log_set_handler ("gnc.engine", loglevel, - (GLogFunc)test_null_handler, &check3); + (GLogFunc)test_null_handler, check3); g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_list_handler, NULL); /* Check that the call fails with invalid account and split (throws) */ @@ -1129,9 +1137,9 @@ test_gnc_account_insert_remove_split (Fixture *fixture, gconstpointer pData) /* g_assert (!priv->balance_dirty); */ /* test_signal_assert_hits (sig1, 0); */ /* test_signal_assert_hits (sig2, 0); */ - g_assert_cmpint (check1.hits, ==, 1); - g_assert_cmpint (check2.hits, ==, 1); - g_assert_cmpint (check3.hits, ==, 0); + g_assert_cmpint (check1->hits, ==, 1); + g_assert_cmpint (check2->hits, ==, 1); + g_assert_cmpint (check3->hits, ==, 0); g_log_remove_handler ("gnc.engine", logger); test_clear_error_list (); @@ -1321,10 +1329,9 @@ test_xaccAccountRecomputeBalance (Fixture *fixture, gconstpointer pData) clr_bal = gnc_numeric_zero (); SetupData *sdata = (SetupData*)pData; TxnParms* t_arr; - int ind; g_assert (sdata != NULL); t_arr = (TxnParms*)sdata->txns; - for (ind = 0; ind < sdata->num_txns; ind++) + for (unsigned int ind = 0; ind < sdata->num_txns; ind++) { SplitParms p = t_arr[ind].splits[1]; bal = gnc_numeric_add_fixed (bal, p.amount); @@ -1474,12 +1481,14 @@ test_gnc_account_append_remove_child (Fixture *fixture, gconstpointer pData) QofBook *fbook = qof_book_new (); Account *froot = gnc_account_create_root (fbook); Account *account = xaccMallocAccount (fbook); - gchar *logdomain = "gnc.account"; - gchar *msg1 = "[gnc_account_append_child()] reparenting accounts across books is not correctly supported\n"; - gchar *msg2 = "[gnc_account_remove_child()] account not a child of parent"; + auto logdomain = "gnc.account"; + auto msg1 = "[gnc_account_append_child()] reparenting accounts across books is not correctly supported\n"; + auto msg2 = "[gnc_account_remove_child()] account not a child of parent"; guint log_handler = 0; - TestErrorStruct check_warn = {G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL, "gnc.account", msg1, 0 }; - TestErrorStruct check_err = {G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL, "gnc.account", msg2, 0 }; + auto loglevelc = static_cast(G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL); + auto loglevelw = static_cast(G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL); + auto check_warn = test_error_struct_new("gnc.account", loglevelw, msg1); + auto check_err = test_error_struct_new("gnc.account", loglevelc, msg2); TestSignal sig1, sig2, sig3; AccountTestFunctions *func = _utest_account_fill_functions (); AccountPrivate *frpriv = func->get_private (froot), @@ -1494,25 +1503,29 @@ test_gnc_account_append_remove_child (Fixture *fixture, gconstpointer pData) test_signal_assert_hits (sig1, 1); test_signal_assert_hits (sig2, 0); test_signal_assert_hits (sig3, 0); - g_assert_cmpint (check_warn.hits, ==, 0); - g_assert_cmpint (check_err.hits, ==, 0); + g_assert_cmpint (check_warn->hits, ==, 0); + g_assert_cmpint (check_err->hits, ==, 0); g_assert (qof_instance_get_dirty (QOF_INSTANCE (froot))); g_assert (qof_instance_get_dirty (QOF_INSTANCE (account))); g_assert (g_list_find (frpriv->children, account)); g_assert (qof_collection_lookup_entity ( qof_book_get_collection (fbook, GNC_ID_ACCOUNT), acct_guid)); - log_handler = g_log_set_handler (logdomain, G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, (GLogFunc)test_null_handler, &check_warn); - g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check_warn); + auto loglevelr = static_cast(G_LOG_LEVEL_WARNING | + G_LOG_FLAG_FATAL | + G_LOG_FLAG_RECURSION); + log_handler = g_log_set_handler (logdomain, loglevelr, + (GLogFunc)test_null_handler, check_warn); + g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, check_warn); gnc_account_append_child (fixture->acct, account); g_log_remove_handler (logdomain, log_handler); - g_assert_cmpstr (msg1, == , check_warn.msg); + g_assert_cmpstr (msg1, == , check_warn->msg); g_assert (gnc_account_get_parent (account) == fixture->acct); test_signal_assert_hits (sig1, 2); test_signal_assert_hits (sig2, 1); test_signal_assert_hits (sig3, 1); - g_assert_cmpint (check_warn.hits, ==, 1); - g_assert_cmpint (check_err.hits, ==, 0); + g_assert_cmpint (check_warn->hits, ==, 1); + g_assert_cmpint (check_err->hits, ==, 0); g_assert (!qof_collection_lookup_entity ( qof_book_get_collection (fbook, GNC_ID_ACCOUNT), acct_guid)); @@ -1528,24 +1541,24 @@ test_gnc_account_append_remove_child (Fixture *fixture, gconstpointer pData) test_signal_free (sig3); sig1 = test_signal_new (&account->inst, QOF_EVENT_REMOVE, NULL); sig2 = test_signal_new (&(fixture->acct)->inst, QOF_EVENT_MODIFY, NULL); - log_handler = g_log_set_handler (logdomain, G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL, - (GLogFunc)test_null_handler, &check_err); - g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check_err); + log_handler = g_log_set_handler (logdomain, loglevelc, + (GLogFunc)test_null_handler, check_err); + g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, check_err); gnc_account_remove_child (froot, account); g_log_remove_handler (logdomain, log_handler); test_signal_assert_hits (sig1, 0); test_signal_assert_hits (sig2, 0); - g_assert_cmpint (check_err.hits, ==, 1); - g_assert_cmpint (check_warn.hits, ==, 1); + g_assert_cmpint (check_err->hits, ==, 1); + g_assert_cmpint (check_warn->hits, ==, 1); gnc_account_remove_child (fixture->acct, account); g_assert (gnc_account_get_parent (account) == NULL); g_assert (g_list_find (apriv->children, account) == NULL); test_signal_assert_hits (sig1, 1); test_signal_assert_hits (sig2, 1); - g_assert_cmpint (check_warn.hits, ==, 1); - g_assert_cmpint (check_err.hits, ==, 1); + g_assert_cmpint (check_warn->hits, ==, 1); + g_assert_cmpint (check_err->hits, ==, 1); test_signal_free (sig1); test_signal_free (sig2); xaccAccountBeginEdit (account); @@ -1706,23 +1719,23 @@ test_gnc_account_lookup_by_full_name_helper ( Fixture *fixture, gconstpointer pData ) { Account *root, *target; - gchar *names1[] = {"income", "taxable", "int", NULL}; - gchar *names2[] = {"income", "exempt", "int", NULL}; - gchar *names3[] = {"expense", "taxable", "int", NULL}; - gchar *code; + const char *names1[] = {"income", "taxable", "int", NULL}; + const char *names2[] = {"income", "exempt", "int", NULL}; + const char *names3[] = {"expense", "taxable", "int", NULL}; + char *code; AccountTestFunctions *func = _utest_account_fill_functions (); root = gnc_account_get_root (fixture->acct); - target = func->gnc_account_lookup_by_full_name_helper (root, names1); + target = func->gnc_account_lookup_by_full_name_helper (root, const_cast(names1)); g_assert (target != NULL); g_object_get (target, "code", &code, NULL); g_assert_cmpstr (code, == , "4160"); g_free (code); - target = func->gnc_account_lookup_by_full_name_helper (root, names2); + target = func->gnc_account_lookup_by_full_name_helper (root, const_cast(names2)); g_assert (target != NULL); g_object_get (target, "code", &code, NULL); g_assert_cmpstr (code, == , "4210"); - target = func->gnc_account_lookup_by_full_name_helper (root, names3); + target = func->gnc_account_lookup_by_full_name_helper (root, const_cast(names3)); g_assert (target == NULL); g_free (code); } @@ -1733,9 +1746,9 @@ static void test_gnc_account_lookup_by_full_name (Fixture *fixture, gconstpointer pData) { Account *root, *target; - gchar *names1 = "income:taxable:int"; - gchar *names2 = "income:exempt:int"; - gchar *names3 = "expense:taxable:int"; + auto names1 = "income:taxable:int"; + auto names2 = "income:exempt:int"; + auto names3 = "expense:taxable:int"; gchar *code; root = gnc_account_get_root (fixture->acct); @@ -1831,13 +1844,12 @@ test_gnc_account_foreach_descendant_until (Fixture *fixture, gconstpointer pData Account *first = gnc_account_lookup_by_code (root, "2000"); Account *second = gnc_account_lookup_by_code (root, "4000"); Account *expected = gnc_account_lookup_by_code (root, "4160"); - Account *result; - guint counter = 0; - result = gnc_account_foreach_descendant_until (first, thunk2, &counter); + unsigned int counter = 0; + auto result = static_cast(gnc_account_foreach_descendant_until (first, thunk2, &counter)); g_assert_cmpint (counter, == , 11); g_assert (result == NULL); counter = 0; - result = gnc_account_foreach_descendant_until (second, thunk2, &counter); + result = static_cast(gnc_account_foreach_descendant_until (second, thunk2, &counter)); g_assert (result == expected); g_assert_cmpint (counter, == , 6); } @@ -2051,7 +2063,7 @@ test_xaccAccountFindOpenLots (Fixture *fixture, gconstpointer pData) static gpointer bogus_for_each_lot_func (GNCLot *lot, gpointer data) { - guint *count = data; + auto count = static_cast(data); ++*count; return (*count > 4 ? lot : NULL); } @@ -2108,6 +2120,14 @@ test_xaccAccountHasAncestor (Fixture *fixture, gconstpointer pData) g_assert (!xaccAccountHasAncestor (ltcg, expense)); } +inline GNCAccountType& operator++(GNCAccountType& x) +{ + using AcctTypeType = std::underlying_type; + if (x < ACCT_TYPE_LAST) + x = static_cast(x + 1); + return x; +} + /* xaccAccountTypeEnumAsString * xaccAccountStringToType * xaccAccountStringToEnum @@ -2118,19 +2138,19 @@ xaccAccountTypeEnumAsString (GNCAccountType type)// C: 5 in 3 */ static void test_xaccAccountType_Stuff (void) { - GNCAccountType type; - gint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; - gchar *logdomain = "gnc.account"; - gchar *msg1 = g_strdup_printf ("[xaccAccountTypeEnumAsString()] asked to translate unknown account type %d.\n", ACCT_TYPE_LAST); - gchar *msg2 = "[xaccAccountStringToType()] asked to translate unknown account type string (null).\n"; - gchar *msg3 = "[xaccAccountStringToType()] asked to translate unknown account type string LAST.\n"; + auto loglevel = static_cast(G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL); + auto logdomain = "gnc.account"; + auto msg1 = g_strdup_printf ("[xaccAccountTypeEnumAsString()] asked to translate unknown account type %d.\n", ACCT_TYPE_LAST); + auto msg2 = "[xaccAccountStringToType()] asked to translate unknown account type string (null).\n"; + auto msg3 = "[xaccAccountStringToType()] asked to translate unknown account type string LAST.\n"; guint loghandler = 0; - TestErrorStruct check1 = { loglevel, logdomain, msg1, 0 }; - TestErrorStruct check2 = { loglevel, logdomain, msg2, 0 }; - TestErrorStruct check3 = { loglevel, logdomain, msg3, 0 }; - Account *acc = g_object_new (GNC_TYPE_ACCOUNT, NULL); + auto check1 = test_error_struct_new(logdomain, loglevel, msg1); + auto check2 = test_error_struct_new(logdomain, loglevel, msg2); + auto check3 = test_error_struct_new(logdomain, loglevel, msg3); + auto acc = static_cast(g_object_new (GNC_TYPE_ACCOUNT, NULL)); + GNCAccountType type; - for (type = ACCT_TYPE_NONE; type < ACCT_TYPE_LAST; type = type + 1) + for (type = ACCT_TYPE_NONE; type < ACCT_TYPE_LAST; ++type) { const gchar *type_name = xaccAccountTypeEnumAsString (type); const gchar *typestr; @@ -2145,19 +2165,19 @@ test_xaccAccountType_Stuff (void) typestr_uc = g_ascii_strup (typestr, strlen (typestr)); if (type == ACCT_TYPE_PAYABLE || type == ACCT_TYPE_RECEIVABLE) { - gchar *cmpstr = g_strconcat ("A/", type_name, NULL); + auto cmpstr = g_strconcat ("A/", type_name, NULL); g_assert_cmpstr (typestr_uc, == , cmpstr); g_free (cmpstr); } else if (type == ACCT_TYPE_CREDIT) { - gchar *cmpstr = g_strconcat (type_name, " CARD", NULL); + auto cmpstr = g_strconcat (type_name, " CARD", NULL); g_assert_cmpstr (typestr_uc, == , cmpstr); g_free (cmpstr); } else if (type == ACCT_TYPE_MUTUAL) { - gchar *cmpstr = g_strconcat (type_name, " FUND", NULL); + auto cmpstr = g_strconcat (type_name, " FUND", NULL); g_assert_cmpstr (typestr_uc, == , cmpstr); g_free (cmpstr); } @@ -2178,25 +2198,25 @@ test_xaccAccountType_Stuff (void) g_object_unref (acc); loghandler = g_log_set_handler (logdomain, loglevel, - (GLogFunc)test_null_handler, &check1); - g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check1); + (GLogFunc)test_null_handler, check1); + g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, check1); g_assert (!xaccAccountTypeEnumAsString (ACCT_TYPE_LAST)); - g_assert_cmpint (check1.hits, ==, 1); + g_assert_cmpint (check1->hits, ==, 1); g_log_remove_handler (logdomain, loghandler); g_free (msg1); loghandler = g_log_set_handler (logdomain, loglevel, - (GLogFunc)test_null_handler, &check2); - g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check2); + (GLogFunc)test_null_handler, check2); + g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, check2); g_assert (!xaccAccountStringToType (NULL, &type)); - g_assert_cmpint (check2.hits, ==, 1); + g_assert_cmpint (check2->hits, ==, 1); g_log_remove_handler (logdomain, loghandler); loghandler = g_log_set_handler (logdomain, loglevel, - (GLogFunc)test_null_handler, &check3); - g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check3); + (GLogFunc)test_null_handler, check3); + g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, check3); g_assert (!xaccAccountStringToType ("LAST", &type)); - g_assert_cmpint (check3.hits, ==, 1); + g_assert_cmpint (check3->hits, ==, 1); g_log_remove_handler (logdomain, loghandler); @@ -2227,27 +2247,27 @@ test_xaccAccountType_Compatibility (void) guint32 trading_compat = ((1 << ACCT_TYPE_TRADING) | (1 << ACCT_TYPE_ROOT)); guint32 compat; GNCAccountType type; - gchar *msg1 = g_strdup_printf ("[xaccParentAccountTypesCompatibleWith()] bad account type: %d", ACCT_TYPE_ROOT); - gchar *msg2 = g_strdup_printf ("[xaccParentAccountTypesCompatibleWith()] bad account type: %d", ACCT_TYPE_SAVINGS); - gchar *logdomain = "gnc.account"; - guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; - TestErrorStruct check1 = { loglevel, logdomain, msg1, 0 }; - TestErrorStruct check2 = { loglevel, logdomain, msg2, 0 }; + auto msg1 = g_strdup_printf ("[xaccParentAccountTypesCompatibleWith()] bad account type: %d", ACCT_TYPE_ROOT); + auto msg2 = g_strdup_printf ("[xaccParentAccountTypesCompatibleWith()] bad account type: %d", ACCT_TYPE_SAVINGS); + auto logdomain = "gnc.account"; + auto loglevel = static_cast(G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL); + auto check1 = test_error_struct_new(logdomain, loglevel, msg1); + auto check2 = test_error_struct_new(logdomain, loglevel, msg2); gint loghandler; - for (type = ACCT_TYPE_BANK; type < NUM_ACCOUNT_TYPES; type = type + 1) + for (type = ACCT_TYPE_BANK; type < NUM_ACCOUNT_TYPES; type = ++type) { GNCAccountType child; if (type == ACCT_TYPE_ROOT) { loghandler = g_log_set_handler (logdomain, loglevel, - (GLogFunc)test_null_handler, &check1); + (GLogFunc)test_null_handler, check1); g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, - &check1); + check1); compat = xaccParentAccountTypesCompatibleWith (type); g_log_remove_handler (logdomain, loghandler); g_assert_cmpint (compat, == , 0); - g_assert_cmpint (check1.hits, ==, 1); + g_assert_cmpint (check1->hits, ==, 1); g_free (msg1); continue; } @@ -2262,7 +2282,7 @@ test_xaccAccountType_Compatibility (void) g_assert_cmpint (compat, == , equity_compat); else if (type == ACCT_TYPE_TRADING) g_assert_cmpint (compat, == , trading_compat); - for (child = ACCT_TYPE_NONE; child < ACCT_TYPE_LAST; child = child + 1) + for (child = ACCT_TYPE_NONE; child < ACCT_TYPE_LAST; child = ++child) if (1 << child & compat) g_assert (xaccAccountTypesCompatible (type, child)); else @@ -2270,12 +2290,12 @@ test_xaccAccountType_Compatibility (void) } loghandler = g_log_set_handler (logdomain, loglevel, - (GLogFunc)test_null_handler, &check2); - g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check2); - compat = xaccParentAccountTypesCompatibleWith (type = type + 1); + (GLogFunc)test_null_handler, check2); + g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, check2); + compat = xaccParentAccountTypesCompatibleWith (++type); g_log_remove_handler (logdomain, loghandler); g_assert_cmpint (compat, == , 0); - g_assert_cmpint (check2.hits, ==, 1); + g_assert_cmpint (check2->hits, ==, 1); g_free (msg2); } /* More KVP getters & setters @@ -2379,13 +2399,13 @@ test_gnc_account_merge_children (Fixture *fixture, gconstpointer pData) gfloat baz_balance = gnc_numeric_to_double (xaccAccountGetBalance (baz)); gfloat baz2_balance = gnc_numeric_to_double (xaccAccountGetBalance (baz2)); TestSignal sig1, sig2, sig3; - gchar *logdomain = "gnc.engine"; - gint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; - gchar *msg = "[xaccSplitCommitEdit ()] Account grabbed split prematurely."; - TestErrorStruct check = { loglevel, logdomain, msg, 0 }; + auto logdomain = "gnc.engine"; + auto loglevel = static_cast(G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL); + auto msg = "[xaccSplitCommitEdit ()] Account grabbed split prematurely."; + auto check = test_error_struct_new(logdomain, loglevel, msg); guint hdlr = g_log_set_handler (logdomain, loglevel, - (GLogFunc)test_null_handler, &check); - g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check); + (GLogFunc)test_null_handler, check); + g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, check); sig1 = test_signal_new (QOF_INSTANCE (baz), QOF_EVENT_MODIFY, NULL); sig2 = test_signal_new (QOF_INSTANCE (baz2), QOF_EVENT_MODIFY, NULL); @@ -2480,10 +2500,11 @@ test_xaccAccountTreeForEachTransaction (Fixture *fixture, gconstpointer pData ) g_assert_cmpint (td.count, == , 9); g_assert_cmpint (result, == , 0); td.count = 0; - td.name = "pepper"; + td.name = g_strdup("pepper"); result = xaccAccountTreeForEachTransaction (root, thunk3, &td); g_assert_cmpint (td.count, == , result); g_assert_cmpint (result, < , 9); + g_free(td.name); } /* xaccAccountForEachTransaction gint @@ -2502,10 +2523,11 @@ test_xaccAccountForEachTransaction (Fixture *fixture, gconstpointer pData ) g_assert_cmpint (td.count, == , 9); g_assert_cmpint (result, == , 0); td.count = 0; - td.name = "pepper"; + td.name = g_strdup("pepper"); result = xaccAccountForEachTransaction (money, thunk3, &td); g_assert_cmpint (td.count, == , result); g_assert_cmpint (result, < , 9); + g_free(td.name); } diff --git a/src/engine/test/utest-Split.cpp b/src/engine/test/utest-Split.cpp index 5612990f00..d692b6a264 100644 --- a/src/engine/test/utest-Split.cpp +++ b/src/engine/test/utest-Split.cpp @@ -21,11 +21,8 @@ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 * * Boston, MA 02110-1301, USA gnu@gnu.org * ********************************************************************/ -#ifdef __cplusplus extern "C" { -#endif - #include "config.h" #include #include @@ -38,7 +35,6 @@ extern "C" #include #include #include -#include #include #ifdef HAVE_GLIB_2_38 @@ -52,10 +48,9 @@ extern "C" static const gchar *suitename = "/engine/Split"; void test_suite_split ( void ); - -#ifdef __cplusplus } -#endif + +#include typedef struct { @@ -308,7 +303,7 @@ test_xaccDupeSplit (Fixture *fixture, gconstpointer pData) g_assert (split->lot == f_split->lot); g_assert_cmpstr (split->memo, ==, f_split->memo); g_assert_cmpstr (split->action, ==, f_split->action); - g_assert (kvp_frame_compare (split->inst.kvp_data, f_split->inst.kvp_data) == 0); + g_assert (compare (split->inst.kvp_data, f_split->inst.kvp_data) == 0); g_assert_cmpint (split->reconciled, ==, f_split->reconciled); g_assert (timespec_equal (&(split->date_reconciled), &(f_split->date_reconciled))); g_assert (gnc_numeric_equal (split->value, f_split->value)); @@ -343,7 +338,7 @@ test_xaccSplitCloneNoKvp (Fixture *fixture, gconstpointer pData) g_assert (split->lot == f_split->lot); g_assert_cmpstr (split->memo, ==, f_split->memo); g_assert_cmpstr (split->action, ==, f_split->action); - g_assert (kvp_frame_is_empty (split->inst.kvp_data)); + g_assert (split->inst.kvp_data->empty()); g_assert_cmpint (split->reconciled, ==, f_split->reconciled); g_assert (timespec_equal (&(split->date_reconciled), &(f_split->date_reconciled))); g_assert (gnc_numeric_equal (split->value, f_split->value)); @@ -743,12 +738,12 @@ test_xaccSplitDetermineGainStatus (Fixture *fixture, gconstpointer pData) fixture->split->gains = GAINS_STATUS_UNKNOWN; fixture->split->gains_split = NULL; - g_assert (kvp_frame_get_slot (fixture->split->inst.kvp_data, "gains_source") == NULL); + g_assert (fixture->split->inst.kvp_data->get_slot("gains_source") == NULL); xaccSplitDetermineGainStatus (fixture->split); g_assert (fixture->split->gains_split == NULL); g_assert_cmpint (fixture->split->gains, ==, GAINS_STATUS_A_VDIRTY | GAINS_STATUS_DATE_DIRTY); - kvp_frame_set_guid (fixture->split->inst.kvp_data, "gains-source", g_guid); + fixture->split->inst.kvp_data->set("gains-source", new KvpValue(const_cast(g_guid))); g_assert (fixture->split->gains_split == NULL); fixture->split->gains = GAINS_STATUS_UNKNOWN; xaccSplitDetermineGainStatus (fixture->split); @@ -1778,13 +1773,13 @@ test_xaccSplitGetOtherSplit (Fixture *fixture, gconstpointer pData) Split *split1 = xaccMallocSplit (book); Split *split2 = xaccMallocSplit (book); Account *acc2 = xaccMallocAccount (book); - KvpValue *kvpnow = kvp_value_new_gint64 (gnc_time (NULL)); + KvpValue *kvpnow = new KvpValue (gnc_time (NULL)); g_assert (xaccSplitGetOtherSplit (NULL) == NULL); g_assert (xaccSplitGetOtherSplit (split1) == NULL); g_assert (xaccTransUseTradingAccounts (txn) == FALSE); - g_assert (kvp_frame_get_slot (split->inst.kvp_data, "lot-split") == NULL); + g_assert (split->inst.kvp_data->get_slot("lot-split") == NULL); g_assert_cmpint (xaccTransCountSplits (txn), !=, 2); g_assert (xaccSplitGetOtherSplit (split) == NULL); @@ -1795,18 +1790,18 @@ test_xaccSplitGetOtherSplit (Fixture *fixture, gconstpointer pData) xaccSplitSetParent (split2, txn); g_assert (xaccSplitGetOtherSplit (split) == NULL); - kvp_frame_set_slot (split->inst.kvp_data, "lot-split", kvpnow); - g_assert (kvp_frame_get_slot (split->inst.kvp_data, "lot-split")); + split->inst.kvp_data->set("lot-split", kvpnow); + g_assert (split->inst.kvp_data->get_slot("lot-split")); g_assert (xaccSplitGetOtherSplit (split) == NULL); - kvp_frame_set_slot (split1->inst.kvp_data, "lot-split", kvpnow); - g_assert (kvp_frame_get_slot (split1->inst.kvp_data, "lot-split")); + split1->inst.kvp_data->set("lot-split", kvpnow); + g_assert (split1->inst.kvp_data->get_slot("lot-split")); g_assert (xaccSplitGetOtherSplit (split) == split2); - kvp_frame_set_slot (split->inst.kvp_data, "lot-split", NULL); - g_assert (kvp_frame_get_slot (split->inst.kvp_data, "lot-split") == NULL); - kvp_frame_set_slot (split1->inst.kvp_data, "lot-split", NULL); - g_assert (kvp_frame_get_slot (split1->inst.kvp_data, "lot-split") == NULL); + split->inst.kvp_data->set("lot-split", NULL); + g_assert (split->inst.kvp_data->get_slot("lot-split") == NULL); + split1->inst.kvp_data->set("lot-split", NULL); + g_assert (split1->inst.kvp_data->get_slot("lot-split") == NULL); qof_book_begin_edit (book); qof_instance_set (QOF_INSTANCE (book), "trading-accts", "t", diff --git a/src/engine/test/utest-Transaction.c b/src/engine/test/utest-Transaction.cpp similarity index 85% rename from src/engine/test/utest-Transaction.c rename to src/engine/test/utest-Transaction.cpp index ec5d6d30fd..a07270b341 100644 --- a/src/engine/test/utest-Transaction.c +++ b/src/engine/test/utest-Transaction.cpp @@ -21,6 +21,8 @@ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 * * Boston, MA 02110-1301, USA gnu@gnu.org * ********************************************************************/ +extern "C" +{ #include #include #include @@ -33,7 +35,6 @@ #include "../gnc-lot.h" #include "../gnc-event.h" #include -#include #include #ifdef HAVE_GLIB_2_38 @@ -47,6 +48,9 @@ static const gchar *suitename = "/engine/Transaction"; void test_suite_transaction ( void ); +} + +#include /* Copied from Transaction.c. Changing these values will break * existing databases, which is a good reason to fail a test. @@ -117,15 +121,14 @@ setup (Fixture *fixture, gconstpointer pData) { QofBook *book = qof_book_new (); MockBackend *mbe = mock_backend_new (); - Split *split1 = NULL, *split2 = NULL; Transaction *txn; Timespec entered = gnc_dmy2timespec (20, 4, 2012); Timespec posted = gnc_dmy2timespec (21, 4, 2012); - KvpFrame *frame = kvp_frame_new (); + auto frame = new KvpFrame (); qof_book_set_backend (book, (QofBackend*)mbe); - split1 = xaccMallocSplit (book); - split2 = xaccMallocSplit (book); + auto split1 = xaccMallocSplit (book); + auto split2 = xaccMallocSplit (book); txn = xaccMallocTransaction (book); fixture->txn = txn; fixture->curr = gnc_commodity_new (book, "Gnu Rand", "CURRENCY", "GNR", "", 240); @@ -138,23 +141,23 @@ setup (Fixture *fixture, gconstpointer pData) txn->date_posted.tv_nsec = posted.tv_nsec; txn->date_entered.tv_sec = entered.tv_sec; txn->date_entered.tv_nsec = entered.tv_nsec; - split1->memo = CACHE_INSERT ("foo"); - split1->action = CACHE_INSERT ("bar"); + split1->memo = static_cast(CACHE_INSERT ("foo")); + split1->action = static_cast(CACHE_INSERT ("bar")); split1->amount = gnc_numeric_create (100000, 1000); split1->value = gnc_numeric_create (3200, 240); split2->amount = gnc_numeric_create (-3200, 240); split2->value = gnc_numeric_create (-3200, 240); split1->acc = fixture->acc1; split2->acc = fixture->acc2; - txn->num = CACHE_INSERT ("123"); - txn->description = CACHE_INSERT ("Waldo Pepper"); + txn->num = static_cast(CACHE_INSERT ("123")); + txn->description = static_cast(CACHE_INSERT ("Waldo Pepper")); xaccTransBeginEdit (txn); { xaccTransSetCurrency (txn, fixture->curr); xaccSplitSetParent (split1, txn); xaccSplitSetParent (split2, txn); - kvp_frame_set_string (frame, trans_notes_str, "Salt pork sausage"); - kvp_frame_set_double (frame, "/qux/quux/corge", 123.456); + frame->set(trans_notes_str, new KvpValue("Salt pork sausage")); + frame->set_path("/qux/quux/corge", new KvpValue(123.456)); qof_instance_set_slots (QOF_INSTANCE (txn), frame); } xaccTransCommitEdit (txn); @@ -174,8 +177,6 @@ setup_with_gains (GainsFixture *fixture, gconstpointer pData) { QofBook *book; Fixture *base = &(fixture->base); - Split *gains_split1 = NULL, *gains_split2 = NULL; - Split *base_split = NULL; setup (base, NULL); @@ -183,8 +184,8 @@ setup_with_gains (GainsFixture *fixture, gconstpointer pData) fixture->gains_txn = xaccMallocTransaction (book); fixture->gains_acc = xaccMallocAccount (book); xaccAccountSetCommodity (fixture->gains_acc, base->curr); - gains_split1 = xaccMallocSplit (book); - gains_split2 = xaccMallocSplit (book); + auto gains_split1 = xaccMallocSplit (book); + auto gains_split2 = xaccMallocSplit (book); gains_split1->acc = base->acc1; gains_split2->acc = fixture->gains_acc; gains_split1->amount = gnc_numeric_create (30, 240); @@ -198,7 +199,7 @@ setup_with_gains (GainsFixture *fixture, gconstpointer pData) xaccSplitSetParent (gains_split2, fixture->gains_txn); } xaccTransCommitEdit (fixture->gains_txn); - base_split = g_list_nth_data (base->txn->splits, 1); + auto base_split = static_cast(g_list_nth_data (base->txn->splits, 1)); base_split->gains_split = gains_split1; } @@ -237,10 +238,10 @@ void check_open (const Transaction *trans)// Local: 1:0:0 static void test_check_open (Fixture *fixture, gconstpointer pData) { - gchar *msg = g_strdup_printf ("[check_open()] transaction %p not open for editing", fixture->txn); - GLogLevelFlags loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; - TestErrorStruct *check = test_error_struct_new ("gnc.engine", loglevel, - msg); + auto msg = g_strdup_printf ("[check_open()] transaction %p not open for editing", fixture->txn); + auto loglevel = static_cast(G_LOG_LEVEL_CRITICAL | + G_LOG_FLAG_FATAL); + auto check = test_error_struct_new ("gnc.engine", loglevel, msg); g_free (msg); fixture->hdlrs = test_log_set_fatal_handler (fixture->hdlrs, check, (GLogFunc)test_checked_handler); @@ -260,7 +261,7 @@ static void test_xaccTransStillHasSplit (Fixture *fixture, gconstpointer pData) { QofBook *book = qof_instance_get_book (QOF_INSTANCE (fixture->txn)); - Split *split = xaccMallocSplit (book); + auto split = xaccMallocSplit (book); g_assert (!xaccTransStillHasSplit (fixture->txn, split)); xaccSplitSetParent (split, fixture->txn); g_assert (xaccTransStillHasSplit (fixture->txn, split)); @@ -280,7 +281,7 @@ void mark_trans (Transaction *trans)// Local: 3:0:0 #define check_split_dirty(xsplit, test) \ { \ gboolean sort_dirty, balance_dirty; \ - Split *split = xsplit; \ + auto split = xsplit; \ g_object_get (split->acc, \ "sort-dirty", &sort_dirty, \ "balance-dirty", &balance_dirty, \ @@ -299,7 +300,7 @@ test_mark_trans (Fixture *fixture, gconstpointer pData) { if (!splits->data) continue; g_assert (!qof_instance_get_dirty_flag (splits->data)); - check_split_dirty (splits->data, FALSE); + check_split_dirty (static_cast(splits->data), FALSE); } fixture->func->mark_trans (fixture->txn); g_assert (!qof_instance_get_dirty_flag (fixture->txn)); @@ -307,7 +308,7 @@ test_mark_trans (Fixture *fixture, gconstpointer pData) { if (!splits->data) continue; g_assert (!qof_instance_get_dirty_flag (splits->data)); - check_split_dirty (splits->data, TRUE); + check_split_dirty (static_cast(splits->data), TRUE); } } /* gen_event_trans @@ -316,7 +317,7 @@ void gen_event_trans (Transaction *trans)// Local: 2:0:0 static void test_gen_event_trans (Fixture *fixture, gconstpointer pData) { - Split *split = fixture->txn->splits->data; + auto split = static_cast(fixture->txn->splits->data); GNCLot *lot = gnc_lot_new (qof_instance_get_book (QOF_INSTANCE (fixture->txn))); TestSignal sig1 = test_signal_new (QOF_INSTANCE (fixture->acc1), GNC_EVENT_ITEM_CHANGED, split); @@ -340,7 +341,7 @@ gnc_transaction_init(Transaction* trans)*/ static void test_gnc_transaction_init () { - Transaction *txn = g_object_new (GNC_TYPE_TRANSACTION, NULL); + auto txn = static_cast(g_object_new (GNC_TYPE_TRANSACTION, NULL)); g_assert_cmpstr (txn->num, ==, ""); g_assert_cmpstr (txn->description, ==, ""); g_assert (txn->common_currency == NULL); @@ -361,9 +362,9 @@ static void test_gnc_transaction_dispose () { QofBook *book = qof_book_new (); - Transaction *txn = g_object_new (GNC_TYPE_TRANSACTION, "book", book, NULL); - Split *split = g_object_new (GNC_TYPE_SPLIT, "book", book, NULL); - Split *s_ref = split; + auto txn = static_cast(g_object_new (GNC_TYPE_TRANSACTION, "book", book, NULL)); + auto split = static_cast(g_object_new (GNC_TYPE_SPLIT, "book", book, NULL)); + auto s_ref = split; gnc_commodity *curr = gnc_commodity_new (book, "Gnu Rand", "CURRENCY", "GNR", "", 240), *t_curr = NULL; gnc_commodity *c_ref = curr; @@ -398,7 +399,7 @@ gnc_transaction_finalize(GObject* txnp)*/ static void test_gnc_transaction_finalize () { - Transaction *txn = g_object_new (GNC_TYPE_TRANSACTION, NULL); + auto txn = static_cast(g_object_new (GNC_TYPE_TRANSACTION, NULL)); test_destroy (txn); } /* gnc_transaction_get_property @@ -409,21 +410,20 @@ static void test_gnc_transaction_set_get_property (Fixture *fixture, gconstpointer pData) { QofBook *book = qof_book_new (); - Transaction *txn = g_object_new (GNC_TYPE_TRANSACTION, "book", book, NULL); - gchar *num = "42", *desc = "The Answer", *t_num = NULL, *t_desc = NULL, *phony = NULL; + auto txn = static_cast(g_object_new (GNC_TYPE_TRANSACTION, "book", book, NULL)); + auto num = "42", desc = "The Answer"; + gchar *t_num = NULL, *t_desc = NULL, *phony = NULL; gnc_commodity *curr = gnc_commodity_new (book, "Gnu Rand", "CURRENCY", "GNR", "", 240), *t_curr = NULL; Timespec now = timespec_now (), *t_entered = NULL, *t_posted = NULL; time_t secs = (time_t)now.tv_sec; - gchar *msg1 = "g_object_set_valist: object class " _Q "Transaction' has no property named " _Q "bogus'"; - gchar *msg2 = g_strdup_printf ("[xaccTransSetDateInternal] addr=%p set date to %" G_GUINT64_FORMAT ".%09ld %s", + auto msg1 = "g_object_set_valist: object class " _Q "Transaction' has no property named " _Q "bogus'"; + auto msg2 = g_strdup_printf ("[xaccTransSetDateInternal] addr=%p set date to %" G_GUINT64_FORMAT ".%09ld %s", txn, now.tv_sec, now.tv_nsec, ctime (&secs)); - GLogLevelFlags loglevel1 = G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL; - GLogLevelFlags loglevel2 = G_LOG_LEVEL_INFO; - TestErrorStruct *check1 = test_error_struct_new ("GLib-GObject", - loglevel1, msg1); - TestErrorStruct *check2 = test_error_struct_new ("gnc.engine", - loglevel2, msg2); + auto loglevel1 = static_cast(G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL); + auto loglevel2 =static_cast(G_LOG_LEVEL_INFO); + auto check1 = test_error_struct_new ("GLib-GObject", loglevel1, msg1); + auto check2 = test_error_struct_new ("gnc.engine", loglevel2, msg2); g_free (msg2); fixture->hdlrs = test_log_set_fatal_handler (fixture->hdlrs, check1, (GLogFunc)test_checked_handler); @@ -494,12 +494,11 @@ test_xaccMallocTransaction (Fixture *fixture, gconstpointer pData) #else #define _func "xaccMallocTransaction" #endif - gchar *msg = _func ": assertion " _Q "book' failed"; + auto msg = _func ": assertion " _Q "book' failed"; #undef _func - gchar *logdomain = "gnc.engine"; - guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; - TestErrorStruct *check = test_error_struct_new ("gnc.engine", loglevel, - msg); + auto logdomain = "gnc.engine"; + auto loglevel = static_cast(G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL); + auto check = test_error_struct_new ("gnc.engine", loglevel, msg); fixture->hdlrs = test_log_set_fatal_handler (fixture->hdlrs, check, (GLogFunc)test_checked_handler); test_signal_assert_hits (sig1, 0); @@ -526,8 +525,8 @@ test_xaccTransSortSplits (Fixture *fixture, gconstpointer pData) { Transaction *txn = fixture->txn; QofBook *book = qof_instance_get_book (QOF_INSTANCE (txn)); - Split *split1 = txn->splits->data; - Split *split2 = txn->splits->next->data; + auto split1 = static_cast(txn->splits->data); + auto split2 = static_cast(txn->splits->next->data); Split *split[3]; guint i; GList *node; @@ -587,8 +586,8 @@ test_dupe_trans (Fixture *fixture, gconstpointer pData) oldtxn->date_posted = posted; oldtxn->date_entered = entered; - kvp_frame_set_string (oldtxn->inst.kvp_data, "/foo/bar/baz", - "The Great Waldo Pepper"); + oldtxn->inst.kvp_data->set("/foo/bar/baz", + new KvpValue("The Great Waldo Pepper")); newtxn = fixture->func->dupe_trans (oldtxn); @@ -597,7 +596,8 @@ test_dupe_trans (Fixture *fixture, gconstpointer pData) for (newnode = newtxn->splits; newnode && oldnode; newnode = g_list_next (newnode)) { - g_assert (xaccSplitEqual (newnode->data, oldnode->data, + g_assert (xaccSplitEqual (static_cast(newnode->data), + static_cast(oldnode->data), TRUE, FALSE, TRUE)); oldnode = g_list_next (oldnode); } @@ -613,7 +613,7 @@ test_dupe_trans (Fixture *fixture, gconstpointer pData) g_assert (guid_equal (qof_instance_get_guid (QOF_INSTANCE (newtxn)), guid_null ())); g_assert (qof_instance_get_book (QOF_INSTANCE (newtxn)) == old_book); - g_assert (kvp_frame_compare (oldtxn->inst.kvp_data, newtxn->inst.kvp_data) == 0); + g_assert (compare (oldtxn->inst.kvp_data, newtxn->inst.kvp_data) == 0); test_destroy (newtxn); } @@ -648,7 +648,8 @@ test_xaccTransClone (Fixture *fixture, gconstpointer pData) for (newnode = newtxn->splits; newnode && oldnode; newnode = g_list_next (newnode)) { - g_assert (xaccSplitEqual (newnode->data, oldnode->data, + g_assert (xaccSplitEqual (static_cast(newnode->data), + static_cast(oldnode->data), FALSE, FALSE, FALSE)); oldnode = g_list_next (oldnode); } @@ -664,7 +665,7 @@ test_xaccTransClone (Fixture *fixture, gconstpointer pData) g_assert (newtxn->common_currency == fixture->curr); g_assert (qof_instance_get_book (QOF_INSTANCE (newtxn)) == old_book); - g_assert (kvp_frame_compare (oldtxn->inst.kvp_data, newtxn->inst.kvp_data) == 0); + g_assert (compare (oldtxn->inst.kvp_data, newtxn->inst.kvp_data) == 0); test_destroy (newtxn); } @@ -690,7 +691,7 @@ test_xaccTransCopyFromClipBoard (Fixture *fixture, gconstpointer pData) Transaction *to_txn = xaccMallocTransaction (book); Timespec now = timespec_now(); Timespec never = {0, 0}; - KvpFrame *to_frame = to_txn->inst.kvp_data; + auto to_frame = to_txn->inst.kvp_data; xaccAccountSetCommodity (acc1, fixture->comm); xaccTransCopyFromClipBoard (txn, to_txn, fixture->acc1, acc1, FALSE); @@ -743,13 +744,14 @@ test_xaccFreeTransaction (Fixture *fixture, gconstpointer pData) { Transaction *txn = fixture->txn; Transaction *orig = xaccMallocTransaction (qof_instance_get_book (QOF_INSTANCE (txn))); - Split *split = txn->splits->data; - gchar *txn_num = "321"; - g_object_add_weak_pointer (G_OBJECT (txn->splits->data), (gpointer)&split); + auto split = static_cast(txn->splits->data); + auto txn_num = "321"; + g_object_add_weak_pointer (G_OBJECT (txn->splits->data), + reinterpret_cast(&split)); /* so the "free" doesn't, leaving the structure for us to test */ g_object_ref (txn); g_object_ref (orig); - orig->num = CACHE_INSERT (txn_num); + orig->num = static_cast(CACHE_INSERT (txn_num)); txn->orig = orig; fixture->func->xaccFreeTransaction (txn); @@ -791,21 +793,20 @@ test_xaccTransEqual (Fixture *fixture, gconstpointer pData) Transaction *txn1 = xaccTransClone (txn0); const GncGUID *guid_f_txn = qof_instance_get_guid (txn0); gchar entered[DATE_BUF_SIZE], posted[DATE_BUF_SIZE]; - gchar *msg1 = "[xaccTransEqual] one is NULL"; + auto msg1 = "[xaccTransEqual] one is NULL"; gchar *msg2 = NULL; - gchar *cleanup_fmt = "[trans_cleanup_commit] get rid of rollback trans=%p"; + auto cleanup_fmt = "[trans_cleanup_commit] get rid of rollback trans=%p"; gchar split_guid0[GUID_ENCODING_LENGTH + 1]; gchar split_guid1[GUID_ENCODING_LENGTH + 1]; - gchar *logdomain = "gnc.engine"; - guint loglevel = G_LOG_LEVEL_INFO; - TestErrorStruct *check = test_error_struct_new (logdomain, loglevel, msg1); - TestErrorStruct check2 = {loglevel, logdomain, msg2, 0}; - TestErrorStruct check3 = {loglevel, logdomain, "", 0}; - TestErrorStruct *cleanup = test_error_struct_new (logdomain, loglevel, ""); - Split *split0 = xaccTransGetSplit (txn0, 0); - Split *split1; + auto logdomain = "gnc.engine"; + auto loglevel = static_cast(G_LOG_LEVEL_INFO); + auto check = test_error_struct_new (logdomain, loglevel, msg1); + auto check2 = test_error_struct_new(logdomain, loglevel, msg2); + auto check3 = test_error_struct_new(logdomain, loglevel, ""); + auto cleanup = test_error_struct_new (logdomain, loglevel, ""); + auto split0 = xaccTransGetSplit (txn0, 0); test_add_error (check); - test_add_error (&check2); + test_add_error (check2); test_add_error (cleanup); fixture->hdlrs = test_log_set_handler (fixture->hdlrs, check, @@ -869,7 +870,7 @@ test_xaccTransEqual (Fixture *fixture, gconstpointer pData) xaccTransBeginEdit (clone); cleanup->msg = g_strdup_printf (cleanup_fmt, clone->orig); clone->date_entered.tv_sec = txn0->date_entered.tv_sec; - clone->num = "123"; + clone->num = g_strdup("123"); xaccTransCommitEdit (clone); g_free (cleanup->msg); g_free (check->msg); @@ -879,15 +880,17 @@ test_xaccTransEqual (Fixture *fixture, gconstpointer pData) g_assert (xaccTransEqual (txn1, clone, TRUE, FALSE, TRUE, TRUE)); g_assert_cmpint (check->hits, ==, 5); - txn1->num = "321"; + txn1->num = g_strdup("321"); g_free (check->msg); check->msg = g_strdup ("[xaccTransEqual] num differs: 321 vs 123"); g_assert (!xaccTransEqual (txn1, txn0, TRUE, FALSE, TRUE, TRUE)); g_assert_cmpint (check->hits, ==, 6); - clone->num = CACHE_INSERT("123"); - txn1->num = "123"; - clone->description = "salt pork"; + g_free(clone->num); + clone->num = static_cast(CACHE_INSERT("123")); + g_free(txn1->num); + txn1->num = g_strdup("123"); + clone->description = g_strdup("salt pork"); g_free (check->msg); check->msg = g_strdup ("[xaccTransEqual] descriptions differ: salt pork vs Waldo Pepper"); g_assert (!xaccTransEqual (clone, txn0, TRUE, FALSE, TRUE, TRUE)); @@ -899,47 +902,47 @@ test_xaccTransEqual (Fixture *fixture, gconstpointer pData) xaccTransBeginEdit (clone); cleanup->msg = g_strdup_printf (cleanup_fmt, clone->orig); - clone->description = CACHE_INSERT ("Waldo Pepper"); - kvp_frame_set_double (qof_instance_get_slots (QOF_INSTANCE (clone)), - "/qux/quux/corge", 654.321); + g_free(clone->description); + clone->description = static_cast(CACHE_INSERT ("Waldo Pepper")); + auto frame = qof_instance_get_slots (QOF_INSTANCE (clone)); + frame->set("/qux/quux/corge", new KvpValue(654.321)); xaccTransCommitEdit (clone); g_free (cleanup->msg); g_free (check->msg); - check->msg = g_strdup ("[xaccTransEqual] kvp frames differ:\n{\n notes => KVP_VALUE_STRING(Salt pork sausage),\n qux => KVP_VALUE_FRAME({\n quux => KVP_VALUE_FRAME({\n corge => KVP_VALUE_DOUBLE(654.321),\n}\n),\n}\n),\n}\n\n\nvs\n\n{\n notes => KVP_VALUE_STRING(Salt pork sausage),\n qux => KVP_VALUE_FRAME({\n quux => KVP_VALUE_FRAME({\n corge => KVP_VALUE_DOUBLE(123.456),\n}\n),\n}\n),\n}\n"); + check->msg = g_strdup ("[xaccTransEqual] kvp frames differ:\n{\n => KVP_VALUE_FRAME({\n qux => KVP_VALUE_FRAME({\n quux => KVP_VALUE_FRAME({\n corge => KVP_VALUE_DOUBLE(654.321),\n}\n),\n}\n),\n}\n),\n notes => KVP_VALUE_STRING(Salt pork sausage),\n}\n\n\nvs\n\n{\n => KVP_VALUE_FRAME({\n qux => KVP_VALUE_FRAME({\n quux => KVP_VALUE_FRAME({\n corge => KVP_VALUE_DOUBLE(123.456),\n}\n),\n}\n),\n}\n),\n notes => KVP_VALUE_STRING(Salt pork sausage),\n}\n"); g_assert (!xaccTransEqual (clone, txn0, TRUE, FALSE, TRUE, TRUE)); g_assert_cmpint (check->hits, ==, 9); xaccTransBeginEdit (clone); cleanup->msg = g_strdup_printf (cleanup_fmt, clone->orig); - clone->description = CACHE_INSERT ("Waldo Pepper"); - kvp_frame_set_double (qof_instance_get_slots (QOF_INSTANCE (clone)), - "/qux/quux/corge", 123.456); + clone->description = static_cast(CACHE_INSERT ("Waldo Pepper")); + frame->set("/qux/quux/corge", new KvpValue(123.456)); xaccTransCommitEdit (clone); g_free (cleanup->msg); g_free (check->msg); check->msg = g_strdup ("[xaccSplitEqual] GUIDs differ"); - split1 = xaccTransGetSplit (clone, 0); + auto split1 = xaccTransGetSplit (clone, 0); guid_to_string_buff (qof_instance_get_guid (split0), split_guid0); guid_to_string_buff (qof_instance_get_guid (split1), split_guid1); - check2.msg = g_strdup_printf ( + check2->msg = g_strdup_printf ( "[xaccTransEqual] splits %s and %s differ", split_guid1, split_guid0); g_assert (!xaccTransEqual (clone, txn0, TRUE, TRUE, TRUE, TRUE)); g_assert (xaccTransEqual (clone, txn0, FALSE, FALSE, FALSE, TRUE)); g_assert_cmpint (check->hits, ==, 10); - g_assert_cmpint (check2.hits, ==, 1); + g_assert_cmpint (check2->hits, ==, 1); g_free (check->msg); - g_free (check2.msg); + g_free (check2->msg); check->msg = g_strdup("[xaccSplitEqual] amounts differ: 13333/1000 vs 100000/1000"); - check2.msg = g_strdup_printf ( + check2->msg = g_strdup_printf ( "[xaccTransEqual] splits %s and %s differ", split_guid0, split_guid0); qof_instance_set_guid (split1, qof_instance_get_guid (split0)); g_assert (!xaccTransEqual (clone, txn0, TRUE, TRUE, TRUE, TRUE)); g_assert (xaccTransEqual (clone, txn0, TRUE, FALSE, FALSE, TRUE)); g_assert_cmpint (check->hits, ==, 11); - g_assert_cmpint (check2.hits, ==, 2); + g_assert_cmpint (check2->hits, ==, 2); qof_instance_set_guid (xaccTransGetSplit (txn1, 0), qof_instance_get_guid (split0)); @@ -951,26 +954,26 @@ test_xaccTransEqual (Fixture *fixture, gconstpointer pData) Split* split01 = xaccTransGetSplit (txn0, 1); Split* split10 = xaccTransGetSplit (txn1, 0); Split* split11 = xaccTransGetSplit (txn1, 1); - gchar *bal00 = gnc_numeric_to_string (split00->balance); - gchar *bal01 = gnc_numeric_to_string (split01->balance); - gchar *bal10 = gnc_numeric_to_string (split10->balance); - gchar *bal11 = gnc_numeric_to_string (split11->balance); + auto bal00 = gnc_numeric_to_string (split00->balance); + auto bal01 = gnc_numeric_to_string (split01->balance); + auto bal10 = gnc_numeric_to_string (split10->balance); + auto bal11 = gnc_numeric_to_string (split11->balance); check->msg = g_strdup_printf("[xaccSplitEqualCheckBal] balances differ: %s vs %s", bal10, bal00); - check3.msg = g_strdup_printf("[xaccSplitEqualCheckBal] balances differ: %s vs %s", bal11, bal01); + check3->msg = g_strdup_printf("[xaccSplitEqualCheckBal] balances differ: %s vs %s", bal11, bal01); - test_add_error (&check3); + test_add_error (check3); g_assert (!xaccTransEqual (txn1, txn0, TRUE, TRUE, TRUE, TRUE)); g_assert (xaccTransEqual (txn1, txn0, TRUE, TRUE, FALSE, TRUE)); g_assert_cmpint (check->hits, ==, 12); - g_assert_cmpint (check2.hits, ==, 3); - g_assert_cmpint (check3.hits, ==, 0); + g_assert_cmpint (check2->hits, ==, 3); + g_assert_cmpint (check3->hits, ==, 0); split10->balance = split00->balance; split11->balance = split01->balance; g_assert (xaccTransEqual (txn1, txn0, TRUE, TRUE, TRUE, TRUE)); } - g_free (check3.msg); - g_free (check2.msg); + g_free (check3->msg); + g_free (check2->msg); } /* xaccTransUseTradingAccounts xaccTransUseTradingAccounts @@ -999,12 +1002,12 @@ static void test_xaccTransGetImbalanceValue (Fixture *fixture, gconstpointer pData) { QofBook *book = qof_instance_get_book (QOF_INSTANCE (fixture->txn)); - Split *split1 = xaccMallocSplit (book); + auto split1 = xaccMallocSplit (book); g_assert (gnc_numeric_equal (xaccTransGetImbalanceValue (fixture->txn), gnc_numeric_zero ())); split1->acc = fixture->acc1; - split1->memo = CACHE_INSERT ("foo"); - split1->action = CACHE_INSERT ("bar"); + split1->memo = static_cast(CACHE_INSERT ("foo")); + split1->action = static_cast(CACHE_INSERT ("bar")); split1->amount = gnc_numeric_create (100000, 1000); split1->value = gnc_numeric_create (3200, 240); xaccTransBeginEdit (fixture->txn); @@ -1022,15 +1025,15 @@ static void test_xaccTransGetImbalance (Fixture *fixture, gconstpointer pData) { QofBook *book = qof_instance_get_book (QOF_INSTANCE (fixture->txn)); - Split *split1 = xaccMallocSplit (book); + auto split1 = xaccMallocSplit (book); MonetaryList *mlist; g_assert (xaccTransGetImbalance (NULL) == NULL); mlist = xaccTransGetImbalance (fixture->txn); g_assert_cmpint (g_list_length (mlist), ==, 0); split1->acc = fixture->acc1; - split1->memo = CACHE_INSERT ("foo"); - split1->action = CACHE_INSERT ("bar"); + split1->memo = static_cast(CACHE_INSERT ("foo")); + split1->action = static_cast(CACHE_INSERT ("bar")); split1->amount = gnc_numeric_create (100000, 1000); split1->value = gnc_numeric_create (3200, 240); xaccTransBeginEdit (fixture->txn); @@ -1046,8 +1049,8 @@ test_xaccTransGetImbalance_trading (Fixture *fixture, gconstpointer pData) { QofBook *book = qof_instance_get_book (QOF_INSTANCE (fixture->txn)); - Split *split1 = xaccMallocSplit (book); - Split *split2 = xaccMallocSplit (book); + auto split1 = xaccMallocSplit (book); + auto split2 = xaccMallocSplit (book); Account *acc1 = xaccMallocAccount (book); Account *acc2 = xaccMallocAccount (book); gnc_numeric value; @@ -1071,13 +1074,13 @@ test_xaccTransGetImbalance_trading (Fixture *fixture, g_assert (!xaccTransIsBalanced (fixture->txn)); /* Make it look like a proper trading accounts transactionm */ split1->acc = acc1; - split1->memo = CACHE_INSERT ("foo"); - split1->action = CACHE_INSERT ("bar"); + split1->memo = static_cast(CACHE_INSERT ("foo")); + split1->action = static_cast(CACHE_INSERT ("bar")); split1->amount = gnc_numeric_create (-10000, 100); split1->value = gnc_numeric_create (-3200, 240); split2->acc = acc2; - split2->memo = CACHE_INSERT ("foo"); - split2->action = CACHE_INSERT ("bar"); + split2->memo = static_cast(CACHE_INSERT ("foo")); + split2->action = static_cast(CACHE_INSERT ("bar")); split2->amount = gnc_numeric_create (3000, 240); split2->value = gnc_numeric_create (3200, 240); xaccTransBeginEdit (fixture->txn); @@ -1114,13 +1117,13 @@ static void test_xaccTransIsBalanced (Fixture *fixture, gconstpointer pData) { QofBook *book = qof_instance_get_book (QOF_INSTANCE (fixture->txn)); - Split *split1 = xaccMallocSplit (book); + auto split1 = xaccMallocSplit (book); g_assert (!xaccTransIsBalanced (NULL)); g_assert (xaccTransIsBalanced (fixture->txn)); split1->acc = fixture->acc1; - split1->memo = CACHE_INSERT ("foo"); - split1->action = CACHE_INSERT ("bar"); + split1->memo = static_cast(CACHE_INSERT ("foo")); + split1->action = static_cast(CACHE_INSERT ("bar")); split1->amount = gnc_numeric_create (100000, 1000); split1->value = gnc_numeric_create (3200, 240); xaccTransBeginEdit (fixture->txn); @@ -1134,8 +1137,8 @@ static void test_xaccTransIsBalanced_trading (Fixture *fixture, gconstpointer pData) { QofBook *book = qof_instance_get_book (QOF_INSTANCE (fixture->txn)); - Split *split1 = xaccMallocSplit (book); - Split *split2 = xaccMallocSplit (book); + auto split1 = xaccMallocSplit (book); + auto split2 = xaccMallocSplit (book); Account *acc1 = xaccMallocAccount (book); Account *acc2 = xaccMallocAccount (book); @@ -1152,13 +1155,13 @@ test_xaccTransIsBalanced_trading (Fixture *fixture, gconstpointer pData) /* The setup transaction is unbalanced in a trading-accounts environment. */ g_assert (!xaccTransIsBalanced (fixture->txn)); split1->acc = acc1; - split1->memo = CACHE_INSERT ("foo"); - split1->action = CACHE_INSERT ("bar"); + split1->memo = static_cast(CACHE_INSERT ("foo")); + split1->action = static_cast(CACHE_INSERT ("bar")); split1->amount = gnc_numeric_create (3200, 240); split1->value = gnc_numeric_create (3200, 240); split2->acc = acc2; - split2->memo = CACHE_INSERT ("foo"); - split2->action = CACHE_INSERT ("bar"); + split2->memo = static_cast(CACHE_INSERT ("foo")); + split2->action = static_cast(CACHE_INSERT ("bar")); split2->amount = gnc_numeric_create (-10000, 100); split2->value = gnc_numeric_create (-3000, 240); xaccTransBeginEdit (fixture->txn); @@ -1218,8 +1221,8 @@ test_xaccTransGetRateForCommodity (Fixture *fixture, gconstpointer pData) { gnc_numeric rate = gnc_numeric_zero (); QofBook *book = qof_instance_get_book (QOF_INSTANCE (fixture->txn)); - Split *split0 = xaccMallocSplit (book); - Split *split1 = xaccTransFindSplitByAccount(fixture->txn, fixture->acc1); + auto split0 = xaccMallocSplit (book); + auto split1 = xaccTransFindSplitByAccount(fixture->txn, fixture->acc1); g_assert (!xaccTransGetRateForCommodity (NULL, fixture->comm, split0, &rate)); g_assert (!xaccTransGetRateForCommodity (fixture->txn, NULL, @@ -1246,11 +1249,10 @@ xaccTransGetAccountConvRate(const Transaction *txn, const Account *acc)// C: 5 i static void test_xaccTransGetAccountConvRate (Fixture *fixture, gconstpointer pData) { - gchar *msg1 = "[xaccTransGetAccountConvRate()] How can amount be nonzero and value be zero?"; - guint loglevel = G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL; - TestErrorStruct *check = test_error_struct_new ("gnc.engine", loglevel, - msg1); - Split *split1 = xaccTransFindSplitByAccount(fixture->txn, fixture->acc1); + auto msg1 = "[xaccTransGetAccountConvRate()] How can amount be nonzero and value be zero?"; + auto loglevel = static_cast(G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL); + auto check = test_error_struct_new ("gnc.engine", loglevel, msg1); + auto split1 = xaccTransFindSplitByAccount(fixture->txn, fixture->acc1); gnc_numeric rate; fixture->hdlrs = test_log_set_fatal_handler (fixture->hdlrs, check, @@ -1281,12 +1283,11 @@ test_xaccTransGetAccountBalance (Fixture *fixture, gconstpointer pData) #else #define _func "xaccTransGetAccountBalance" #endif - gchar *msg1 = _func ": assertion " _Q "account && trans' failed"; + auto msg1 = _func ": assertion " _Q "account && trans' failed"; #undef _func - guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; - TestErrorStruct *check = test_error_struct_new ("gnc.engine", loglevel, - msg1); - Split *split1 = xaccTransFindSplitByAccount(fixture->txn, fixture->acc1); + auto loglevel = static_cast(G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL); + auto check = test_error_struct_new ("gnc.engine", loglevel, msg1); + auto split1 = xaccTransFindSplitByAccount(fixture->txn, fixture->acc1); gnc_numeric rate; fixture->hdlrs = test_log_set_fatal_handler (fixture->hdlrs, check, @@ -1323,7 +1324,7 @@ test_xaccTransSetCurrency (Fixture *fixture, gconstpointer pData) { QofBook *book = qof_instance_get_book (QOF_INSTANCE (fixture->txn)); gnc_commodity *curr = gnc_commodity_new (book, "Japanese Yen", "CURRENCY", "JPY", "Â¥", 1); - Split *split1 = xaccTransFindSplitByAccount (fixture->txn, fixture->acc1); + auto split1 = xaccTransFindSplitByAccount (fixture->txn, fixture->acc1); gnc_numeric old_val = xaccSplitGetValue (split1); /* Prevent commit in xaccTransSetCurrency() */ xaccTransBeginEdit(fixture->txn); @@ -1344,12 +1345,12 @@ test_xaccTransBeginEdit () QofBook *book = qof_book_new (); Transaction *txn = xaccMallocTransaction (book); Transaction *dupe = NULL; - gchar *msg1 = "[xaccOpenLog] Attempt to open disabled transaction log"; - gchar *msg2 = "[xaccTransWriteLog] Attempt to write disabled transaction log"; - guint loglevel = G_LOG_LEVEL_INFO; - gchar *logdomain = "gnc.translog"; - TestErrorStruct *check1 = test_error_struct_new (logdomain, loglevel, msg1); - TestErrorStruct *check2 = test_error_struct_new (logdomain, loglevel, msg2); + auto msg1 = "[xaccOpenLog] Attempt to open disabled transaction log"; + auto msg2 = "[xaccTransWriteLog] Attempt to write disabled transaction log"; + auto loglevel = static_cast(G_LOG_LEVEL_INFO); + auto logdomain = "gnc.translog"; + auto check1 = test_error_struct_new (logdomain, loglevel, msg1); + auto check2 = test_error_struct_new (logdomain, loglevel, msg2); guint hdlr = g_log_set_handler (logdomain, loglevel, (GLogFunc)test_list_handler, NULL); test_add_error (check1); @@ -1435,7 +1436,7 @@ test_destroy_gains (GainsFixture *fixture, gconstpointer pData) * function that isn't protected. */ Fixture *base = &(fixture->base); - Split *base_split = g_list_nth_data (base->txn->splits, 1); + auto base_split = static_cast(g_list_nth_data (base->txn->splits, 1)); xaccTransBeginEdit (fixture->gains_txn); /* Protect it from being actually destroyed */ base->func->destroy_gains (base->txn); g_assert (qof_instance_get_destroying (QOF_INSTANCE (fixture->gains_txn))); @@ -1452,12 +1453,12 @@ static void test_do_destroy (GainsFixture *fixture, gconstpointer pData) { Fixture *base = &(fixture->base); - Split *base_split = g_list_nth_data (base->txn->splits, 1); + auto base_split = static_cast(g_list_nth_data (base->txn->splits, 1)); QofBook *book = qof_instance_get_book (base->txn); TestSignal sig = test_signal_new (QOF_INSTANCE (base->txn), QOF_EVENT_DESTROY, NULL); g_object_add_weak_pointer (G_OBJECT (base->txn->splits->data), - (gpointer)&base_split); + reinterpret_cast(&base_split)); g_object_ref (base->txn); g_object_ref (fixture->gains_txn); @@ -1491,7 +1492,7 @@ test_was_trans_emptied (Fixture *fixture, gconstpointer pData) static void trans_on_error(Transaction *trans, QofBackendError errcode)// Local: 0:1:0 callback for qof_commit_edit_part2, xaccTransCommitEdit */ -static QofBackendError errorvalue = 0; +static QofBackendError errorvalue = ERR_BACKEND_NO_ERR; static void commit_error_cb (gpointer data, QofBackendError errcode) { @@ -1502,13 +1503,13 @@ static void test_trans_on_error (Fixture *fixture, gconstpointer pData) { QofBackendError errcode = ERR_BACKEND_MODIFIED; - gchar *msg = + auto msg = "[trans_on_error()] Another user has modified this transaction\n" "\tjust a moment ago. Please look at their changes,\n" "\tand try again, if needed.\n"; - gchar *logdomain = "gnc.engine"; - guint loglevel = G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL; - TestErrorStruct *check = test_error_struct_new (logdomain, loglevel, msg); + auto logdomain = "gnc.engine"; + auto loglevel = static_cast(G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL); + auto check = test_error_struct_new (logdomain, loglevel, msg); fixture->hdlrs = test_log_set_fatal_handler (fixture->hdlrs, check, (GLogFunc)test_checked_handler); gnc_engine_add_commit_error_callback ((EngineCommitErrorCallback)commit_error_cb, NULL); @@ -1518,7 +1519,7 @@ test_trans_on_error (Fixture *fixture, gconstpointer pData) g_assert_cmpint (check->hits, ==, 1); g_assert_cmpint ((guint)errorvalue, ==, (guint)errcode); g_assert_cmpint (qof_instance_get_editlevel (fixture->txn), ==, 0); - errorvalue = 0; + errorvalue = ERR_BACKEND_NO_ERR; } /* trans_cleanup_commit static void trans_cleanup_commit(Transaction *trans)// Local: 0:1:0 callback for qof_commit_edit_part2, xaccTransCommitEdit @@ -1527,22 +1528,22 @@ static void test_trans_cleanup_commit (Fixture *fixture, gconstpointer pData) { QofBook *book = qof_instance_get_book (QOF_INSTANCE (fixture->txn)); - Split *destr_split = xaccMallocSplit (book); - Split *bogus_split = xaccMallocSplit (book); - Split *split0 = fixture->txn->splits->data; + auto destr_split = xaccMallocSplit (book); + auto bogus_split = xaccMallocSplit (book); + auto split0 = static_cast(fixture->txn->splits->data); Account *acct0 = split0->acc; Transaction *orig = NULL; - TestSignal *sig_d_remove = test_signal_new (QOF_INSTANCE (destr_split), + auto sig_d_remove = test_signal_new (QOF_INSTANCE (destr_split), QOF_EVENT_REMOVE, NULL); - TestSignal *sig_b_remove = test_signal_new (QOF_INSTANCE (bogus_split), + auto sig_b_remove = test_signal_new (QOF_INSTANCE (bogus_split), QOF_EVENT_REMOVE, NULL); - TestSignal *sig_d_destroy = test_signal_new (QOF_INSTANCE (destr_split), + auto sig_d_destroy = test_signal_new (QOF_INSTANCE (destr_split), QOF_EVENT_DESTROY, NULL); - TestSignal *sig_b_modify = test_signal_new (QOF_INSTANCE (bogus_split), + auto sig_b_modify = test_signal_new (QOF_INSTANCE (bogus_split), QOF_EVENT_MODIFY, NULL); - TestSignal *sig_t_modify = test_signal_new (QOF_INSTANCE (fixture->txn), + auto sig_t_modify = test_signal_new (QOF_INSTANCE (fixture->txn), QOF_EVENT_MODIFY, NULL); - TestSignal *sig_a_changed = test_signal_new (QOF_INSTANCE (acct0), + auto sig_a_changed = test_signal_new (QOF_INSTANCE (acct0), GNC_EVENT_ITEM_CHANGED, NULL); xaccTransBeginEdit (fixture->txn); @@ -1605,8 +1606,8 @@ static void test_xaccTransCommitEdit (void) { QofBook *book = qof_book_new (); - Split *split1 = xaccMallocSplit (book); - Split *split2 = xaccMallocSplit (book); + auto split1 = xaccMallocSplit (book); + auto split2 = xaccMallocSplit (book); Transaction *txn = xaccMallocTransaction (book); Account *acc1 = xaccMallocAccount (book); Account *acc2 = xaccMallocAccount (book); @@ -1617,11 +1618,11 @@ test_xaccTransCommitEdit (void) Timespec posted = gnc_dmy2timespec (21, 4, 2012); - TestSignal *sig_1_modify = test_signal_new (QOF_INSTANCE (split1), + auto sig_1_modify = test_signal_new (QOF_INSTANCE (split1), QOF_EVENT_MODIFY, NULL); - TestSignal *sig_2_modify = test_signal_new (QOF_INSTANCE (split2), + auto sig_2_modify = test_signal_new (QOF_INSTANCE (split2), QOF_EVENT_MODIFY, NULL); - TestSignal *sig_txn_destroy = test_signal_new (QOF_INSTANCE (txn), + auto sig_txn_destroy = test_signal_new (QOF_INSTANCE (txn), QOF_EVENT_DESTROY, NULL); @@ -1629,8 +1630,8 @@ test_xaccTransCommitEdit (void) xaccAccountSetCommodity (acc2, curr); txn->date_posted.tv_sec = posted.tv_sec; txn->date_posted.tv_nsec = posted.tv_nsec; - split1->memo = CACHE_INSERT ("foo"); - split1->action = CACHE_INSERT ("bar"); + split1->memo = static_cast(CACHE_INSERT ("foo")); + split1->action = static_cast(CACHE_INSERT ("bar")); split1->amount = gnc_numeric_create (100000, 1000); split1->value = gnc_numeric_create (3200, 240); /* Note, deliberately imblanced to force xaccTransScrubImbalance @@ -1640,8 +1641,8 @@ test_xaccTransCommitEdit (void) split2->value = gnc_numeric_create (-3000, 240); split1->acc = acc1; split2->acc = acc2; - txn->num = CACHE_INSERT ("123"); - txn->description = CACHE_INSERT ("Waldo Pepper"); + txn->num = static_cast(CACHE_INSERT ("123")); + txn->description = static_cast(CACHE_INSERT ("Waldo Pepper")); xaccTransBeginEdit (txn); { xaccTransSetCurrency (txn, curr); @@ -1689,20 +1690,20 @@ test_xaccTransRollbackEdit (Fixture *fixture, gconstpointer pData) Timespec orig_post = txn->date_posted; Timespec orig_entered = txn->date_entered; KvpFrame *base_frame = NULL; - TestSignal *sig_account = test_signal_new (QOF_INSTANCE (fixture->acc1), + auto sig_account = test_signal_new (QOF_INSTANCE (fixture->acc1), GNC_EVENT_ITEM_CHANGED, NULL); MockBackend *mbe = (MockBackend*)qof_book_get_backend (book); - Split *split_00 = txn->splits->data, *split_01 = txn->splits->next->data; - Split *split_02 = xaccMallocSplit (book); - Split *split_10 = NULL, *split_11 = NULL; + auto split_00 = static_cast(txn->splits->data); + auto split_01 = static_cast(txn->splits->next->data); + auto split_02 = xaccMallocSplit (book); xaccTransBeginEdit (txn); qof_instance_set_destroying (txn, TRUE); orig = txn->orig; base_frame = orig->inst.kvp_data; /* DupeTransaction copies the kvp_frame */ g_object_ref (orig); /* Keep rollback from actually freeing it */ - txn->num = "321"; - txn->description = "salt peanuts"; + txn->num = static_cast(CACHE_INSERT("321")); + txn->description = static_cast(CACHE_INSERT("salt peanuts")); txn->common_currency = NULL; txn->inst.kvp_data = NULL; txn->date_entered = new_entered; @@ -1712,9 +1713,9 @@ test_xaccTransRollbackEdit (Fixture *fixture, gconstpointer pData) qof_instance_set_dirty (QOF_INSTANCE (split_01)); xaccSplitSetParent (split_02, txn); g_object_ref (split_02); - split_10 = xaccDupeSplit(orig->splits->data); + auto split_10 = xaccDupeSplit(static_cast(orig->splits->data)); g_object_ref (split_10); - split_11 = xaccDupeSplit(orig->splits->next->data); + auto split_11 = xaccDupeSplit(static_cast(orig->splits->next->data)); g_object_ref (split_11); qof_instance_increase_editlevel (QOF_INSTANCE (txn)); /* So it's 2 */ xaccTransRollbackEdit (txn); @@ -1735,10 +1736,10 @@ test_xaccTransRollbackEdit (Fixture *fixture, gconstpointer pData) g_assert_cmpuint (test_signal_return_hits (sig_account), ==, 1); g_assert_cmpuint (g_list_length (txn->splits), ==, 2); g_assert_cmpint (GPOINTER_TO_INT(split_02->memo), ==, 1); - g_assert (xaccSplitEqual (txn->splits->data, split_10, - FALSE, FALSE, FALSE)); - g_assert (xaccSplitEqual (txn->splits->next->data, split_10, + g_assert (xaccSplitEqual (static_cast(txn->splits->data), split_10, FALSE, FALSE, FALSE)); + g_assert (xaccSplitEqual (static_cast(txn->splits->next->data), + split_10, FALSE, FALSE, FALSE)); g_assert_cmpstr (mbe->last_call, ==, "rollback"); g_assert_cmpuint (qof_instance_get_editlevel (QOF_INSTANCE (txn)), ==, 0); g_assert (qof_instance_get_destroying (txn) == FALSE); @@ -1754,10 +1755,9 @@ static void test_xaccTransRollbackEdit_BackendErrors (Fixture *fixture, gconstpointer pData) { MockBackend *mbe = (MockBackend*)qof_book_get_backend (qof_instance_get_book (fixture->txn)); - guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; - gchar *msg = "[xaccTransRollbackEdit()] Rollback Failed. Ouch!"; - TestErrorStruct *check = test_error_struct_new ("gnc.engine", - loglevel, msg); + auto loglevel = static_cast(G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL); + auto msg = "[xaccTransRollbackEdit()] Rollback Failed. Ouch!"; + auto check = test_error_struct_new ("gnc.engine", loglevel, msg); fixture->hdlrs = test_log_set_fatal_handler (fixture->hdlrs, check, (GLogFunc)test_checked_handler); g_object_ref (fixture->txn); @@ -1795,13 +1795,13 @@ test_xaccTransOrder_num_action (Fixture *fixture, gconstpointer pData) g_assert_cmpint (xaccTransOrder_num_action (NULL, NULL, NULL, NULL), ==, 0); g_assert_cmpint (xaccTransOrder_num_action (txnA, NULL, txnB, NULL), ==, qof_instance_guid_compare (txnA, txnB)); - txnB->description = CACHE_INSERT ("Salt Peanuts"); + txnB->description = static_cast(CACHE_INSERT ("Salt Peanuts")); g_assert_cmpint (xaccTransOrder_num_action (txnA, NULL, txnB, NULL), >=, 1); txnB->date_entered.tv_sec += 1; g_assert_cmpint (xaccTransOrder_num_action (txnA, NULL, txnB, NULL), ==, -1); - txnB->num = CACHE_INSERT ("101"); + txnB->num = static_cast(CACHE_INSERT ("101")); g_assert_cmpint (xaccTransOrder_num_action (txnA, NULL, txnB, NULL), ==, 1); - txnB->num = CACHE_INSERT ("one-oh-one"); + txnB->num = static_cast(CACHE_INSERT ("one-oh-one")); g_assert_cmpint (xaccTransOrder_num_action (txnA, NULL, txnB, NULL), ==, 1); g_assert_cmpint (xaccTransOrder_num_action (txnA, "24", txnB, "42"), ==, -1); txnB->date_posted.tv_sec -= 1; @@ -1870,26 +1870,25 @@ static void test_xaccTransVoid (Fixture *fixture, gconstpointer pData) { /* Actual function variables start here. */ - KvpFrame *frame = fixture->txn->inst.kvp_data; - gchar *void_reason = "Voided for Unit Test"; - gchar *txn_notes = g_strdup (kvp_frame_get_string (frame, trans_notes_str)); - KvpValue *val; + auto frame = fixture->txn->inst.kvp_data; + auto void_reason = "Voided for Unit Test"; + auto txn_notes = g_strdup (frame->get_slot(trans_notes_str)->get()); Timespec now = timespec_now (); char iso8601_str[ISO_DATELENGTH + 1] = ""; GList *split = NULL; xaccTransVoid (fixture->txn, void_reason); - g_assert_cmpstr (kvp_frame_get_string (frame, trans_notes_str), ==, + g_assert_cmpstr (frame->get_slot(trans_notes_str)->get(), ==, "Voided transaction"); - g_assert_cmpstr (kvp_frame_get_string (frame, void_former_notes_str), ==, - txn_notes); - g_assert_cmpstr (kvp_frame_get_string (frame, void_reason_str), ==, + g_assert_cmpstr (frame->get_slot(void_former_notes_str)->get(), + ==, txn_notes); + g_assert_cmpstr (frame->get_slot(void_reason_str)->get(), ==, void_reason); gnc_timespec_to_iso8601_buff (now, iso8601_str); - g_assert_cmpstr (kvp_frame_get_string (frame, void_time_str), ==, + g_assert_cmpstr (frame->get_slot(void_time_str)->get(), ==, iso8601_str); - g_assert_cmpstr (kvp_frame_get_string (frame, TRANS_READ_ONLY_REASON), ==, - "Transaction Voided"); + g_assert_cmpstr (frame->get_slot(TRANS_READ_ONLY_REASON)->get(), + ==, "Transaction Voided"); for (split = fixture->txn->splits; split; split=g_list_next (split)) { g_assert (gnc_numeric_zero_p (((Split*)(split->data))->value)); @@ -1898,12 +1897,12 @@ test_xaccTransVoid (Fixture *fixture, gconstpointer pData) xaccTransUnvoid (fixture->txn); - g_assert_cmpstr (kvp_frame_get_string (frame, trans_notes_str), ==, + g_assert_cmpstr (frame->get_slot(trans_notes_str)->get(), ==, txn_notes); - g_assert (kvp_frame_get_slot (frame, void_former_notes_str) == NULL); - g_assert (kvp_frame_get_slot (frame, void_reason_str) == NULL); - g_assert (kvp_frame_get_slot (frame, void_time_str) == NULL); - g_assert (kvp_frame_get_slot (frame, TRANS_READ_ONLY_REASON) == NULL); + g_assert (frame->get_slot(void_former_notes_str) == NULL); + g_assert (frame->get_slot(void_reason_str) == NULL); + g_assert (frame->get_slot(void_time_str) == NULL); + g_assert (frame->get_slot(TRANS_READ_ONLY_REASON) == NULL); for (split = fixture->txn->splits; split; split=g_list_next (split)) { g_assert (!gnc_numeric_zero_p (((Split*)(split->data))->value)); @@ -1921,10 +1920,10 @@ static void test_xaccTransReverse (Fixture *fixture, gconstpointer pData) { Transaction *rev = xaccTransReverse (fixture->txn); - KvpFrame *frame = fixture->txn->inst.kvp_data; + auto frame = fixture->txn->inst.kvp_data; GList *orig_splits = NULL, *rev_splits = NULL; - g_assert (guid_equal (kvp_frame_get_guid (frame, TRANS_REVERSED_BY), + g_assert (guid_equal (frame->get_slot(TRANS_REVERSED_BY)->get(), xaccTransGetGUID (rev))); g_assert (qof_instance_is_dirty (QOF_INSTANCE (rev))); @@ -1936,8 +1935,8 @@ test_xaccTransReverse (Fixture *fixture, gconstpointer pData) orig_splits = g_list_next (orig_splits), rev_splits = g_list_next (rev_splits)) { - Split *orig_split = orig_splits->data; - Split *rev_split = rev_splits->data; + auto orig_split = static_cast(orig_splits->data); + auto rev_split = static_cast(rev_splits->data); g_assert (gnc_numeric_equal (orig_split->amount, gnc_numeric_neg (rev_split->amount))); g_assert (gnc_numeric_equal (orig_split->value, @@ -1961,8 +1960,8 @@ static void test_xaccTransScrubGainsDate_no_dirty (GainsFixture *fixture, gconstpointer pData) { - Split *base_split = g_list_nth_data (fixture->base.txn->splits, 1); - Split *gains_split = base_split->gains_split; + auto base_split = static_cast(g_list_nth_data (fixture->base.txn->splits, 1)); + auto gains_split = base_split->gains_split; base_split->gains = GAINS_STATUS_GAINS; gains_split->gains = GAINS_STATUS_GAINS; @@ -1980,8 +1979,8 @@ static void test_xaccTransScrubGainsDate_base_dirty (GainsFixture *fixture, gconstpointer pData) { - Split *base_split = g_list_nth_data (fixture->base.txn->splits, 1); - Split *gains_split = base_split->gains_split; + auto base_split = static_cast(g_list_nth_data (fixture->base.txn->splits, 1)); + auto gains_split = base_split->gains_split; base_split->gains = GAINS_STATUS_GAINS | GAINS_STATUS_DATE_DIRTY; gains_split->gains = GAINS_STATUS_GAINS; @@ -1999,8 +1998,8 @@ static void test_xaccTransScrubGainsDate_gains_dirty (GainsFixture *fixture, gconstpointer pData) { - Split *base_split = g_list_nth_data (fixture->base.txn->splits, 1); - Split *gains_split = base_split->gains_split; + auto base_split = static_cast(g_list_nth_data (fixture->base.txn->splits, 1)); + auto gains_split = base_split->gains_split; base_split->gains = GAINS_STATUS_GAINS; gains_split->gains = GAINS_STATUS_GAINS | GAINS_STATUS_DATE_DIRTY; diff --git a/src/libqof/qof/kvp_frame.cpp b/src/libqof/qof/kvp_frame.cpp index 8e8ff35767..475ae5a891 100644 --- a/src/libqof/qof/kvp_frame.cpp +++ b/src/libqof/qof/kvp_frame.cpp @@ -142,6 +142,12 @@ walk_path_and_create(KvpFrameImpl* frame, Path path) return frame; } +KvpValue* +KvpFrameImpl::set_path(const char* path, KvpValue* value) noexcept +{ + return set_path(make_vector(path), value); +} + KvpValue* KvpFrameImpl::set_path(Path path, KvpValue* value) noexcept { diff --git a/src/libqof/qof/kvp_frame.hpp b/src/libqof/qof/kvp_frame.hpp index 322e9faa0d..46ec14b3e4 100644 --- a/src/libqof/qof/kvp_frame.hpp +++ b/src/libqof/qof/kvp_frame.hpp @@ -78,7 +78,21 @@ struct KvpFrameImpl * Set the value with the key in a subframe following the keys in path, * replacing and returning the old value if it exists or nullptr if it * doesn't. Creates any missing intermediate frames. - * @param path: The path of subframes leading to the frame in which to + * @param path: The path of subframes as a '/'-delimited string leading to the frame in which to + * insert/replace. + * @param newvalue: The value to set at key. + * @return The old value if there was one or nullptr. + */ + KvpValue* set_path(const char* path, KvpValue* newvalue) noexcept; + /** + * Make a string representation of the frame. Mostly useful for debugging. + * @return A std::string representing the frame and all its children. + */ + /** + * Set the value with the key in a subframe following the keys in path, + * replacing and returning the old value if it exists or nullptr if it + * doesn't. Creates any missing intermediate frames. + * @param path: The path of subframes as a std::vector leading to the frame in which to * insert/replace. * @param newvalue: The value to set at key. * @return The old value if there was one or nullptr. diff --git a/src/libqof/qof/test/Makefile.am b/src/libqof/qof/test/Makefile.am index 48eaf3ff48..e233cc184d 100644 --- a/src/libqof/qof/test/Makefile.am +++ b/src/libqof/qof/test/Makefile.am @@ -12,8 +12,7 @@ test_qof_SOURCES = \ test-gnc-date.c \ test-qof.c \ test-qofbook.c \ - test-qofinstance.c \ - test-kvp_frame.c \ + test-qofinstance.cpp \ test-qofobject.c \ test-qofsession.c \ test-qof-string-cache.c \ diff --git a/src/libqof/qof/test/test-kvp_frame.c b/src/libqof/qof/test/test-kvp_frame.c deleted file mode 100644 index 8717374fdc..0000000000 --- a/src/libqof/qof/test/test-kvp_frame.c +++ /dev/null @@ -1,1703 +0,0 @@ -/******************************************************************** - * test-kvp_frame.c: GLib g_test test suite for kvp_frame.c. * - * 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 * -********************************************************************/ -#ifdef __cplusplus -extern "C" -{ -#endif - -#include "config.h" -#include -#include -#include -#include -#include -#ifdef __cplusplus -} -#endif - - - -static const gchar *suitename = "/qof/kvp_frame"; -void test_suite_kvp_frame ( void ); - -typedef struct -{ - KvpFrame *frame; - GSList *hdlrs; -} Fixture; - -static void -setup( Fixture *fixture, gconstpointer pData ) -{ - fixture->frame = kvp_frame_new(); - fixture->hdlrs = NULL; -} - -static void -teardown( Fixture *fixture, gconstpointer pData ) -{ - kvp_frame_delete( fixture->frame ); - g_slist_free_full (fixture->hdlrs, test_free_log_handler); - test_clear_error_list (); -} - -static gchar* glist_to_string( const GList *list ) -{ - KvpValue * val = kvp_value_new_glist( list ); - gchar * ret = kvp_value_to_string( val ); - kvp_value_delete( val ); - return ret; -} - -extern KvpFrame* ( *p_get_trailer_make )( KvpFrame *frame, const char *key_path, char **end_key ); -extern KvpFrame* ( *p_get_or_make )( KvpFrame *fr, const char * key ); -extern const KvpFrame* ( *p_kvp_frame_get_frame_or_null_slash_trash )( const KvpFrame *frame, char *key_path ); -extern const KvpFrame* ( *p_get_trailer_or_null )( const KvpFrame * frame, const char * key_path, char **end_key ); - -extern void init_static_test_pointers( void ); - -static void -setup_static( Fixture *fixture, gconstpointer pData ) -{ - fixture->frame = kvp_frame_new(); - fixture->hdlrs = NULL; - init_static_test_pointers(); - g_assert( p_get_trailer_make && p_get_or_make && p_get_trailer_or_null && - p_kvp_frame_get_frame_or_null_slash_trash ); -} - -static void -teardown_static( Fixture *fixture, gconstpointer pData ) -{ - kvp_frame_delete( fixture->frame ); - g_slist_free_full (fixture->hdlrs, test_free_log_handler); - test_clear_error_list (); - p_get_trailer_make = NULL; - p_get_or_make = NULL; - p_kvp_frame_get_frame_or_null_slash_trash = NULL; - p_get_trailer_or_null = NULL; -} - -static GncGUID* -populate_frame (KvpFrame *frame) -{ - GList *list = NULL; - Timespec ts; - GncGUID *guid; - GDate gdate; - - ts.tv_sec = 1; - ts.tv_nsec = 1; - guid = guid_new (); - g_date_set_dmy (&gdate, 26, 1, 1957); - - kvp_frame_set_gint64( frame, "gint64-type", 100 ); - kvp_frame_set_double( frame, "double-type", 3.14159 ); - kvp_frame_set_numeric( frame, "numeric-type", gnc_numeric_zero() ); - kvp_frame_set_timespec( frame, "timespec-type", ts ); - kvp_frame_set_string( frame, "string-type", "abcdefghijklmnop" ); - kvp_frame_set_guid( frame, "guid-type", guid ); - kvp_frame_set_value_nc (frame, "gdate-type", kvp_value_new_gdate (gdate)); - kvp_frame_set_frame( frame, "frame-type", kvp_frame_new() ); - - list = g_list_prepend (list, kvp_value_new_guid (guid)); - list = g_list_prepend (list, kvp_value_new_string ("qrstuvwxyz")); - list = g_list_prepend (list, kvp_value_new_timespec (ts)); - list = g_list_prepend (list, kvp_value_new_numeric (gnc_numeric_create (256, 120))); - list = g_list_prepend (list, kvp_value_new_double (0.4342944819)); - list = g_list_prepend (list, kvp_value_new_gint64 (0x1f2e3d4c5b6a79LL)); - kvp_frame_set_value (frame, "list-type", kvp_value_new_glist_nc (list)); - - return guid; -} - -static void -test_kvp_frame_new_delete( void ) -{ - KvpFrame *frame; - GncGUID *guid; - - frame = kvp_frame_new(); - g_assert( frame ); - g_assert( kvp_frame_is_empty( frame ) ); - - guid = populate_frame (frame); - - g_assert( !kvp_frame_is_empty( frame ) ); - - kvp_frame_delete( frame ); - g_assert( frame ); - guid_free (guid); -} - -static void -test_kvp_frame_copy( Fixture *fixture, gconstpointer pData ) -{ - KvpFrame *to_copy = NULL; - gint64 test_gint64, copy_gint64; - double test_double, copy_double; - gnc_numeric test_gnc_numeric, copy_gnc_numeric; - Timespec test_ts, copy_ts; - const char* test_str, *copy_str; - GncGUID *test_guid, *copy_guid; - KvpFrame *test_frame, *copy_frame; - - /* init data in source frame */ - test_gint64 = 111; - test_double = 1.1; - test_gnc_numeric = gnc_numeric_zero(); - test_ts.tv_sec = 1; - test_ts.tv_nsec = 1; - test_str = "abcdefghijklmnop"; - test_guid = guid_new(); - test_frame = kvp_frame_new(); - - g_assert( fixture->frame ); - kvp_frame_set_gint64( fixture->frame, "gint64-type", test_gint64 ); - kvp_frame_set_double( fixture->frame, "double-type", test_double ); - kvp_frame_set_numeric( fixture->frame, "numeric-type", test_gnc_numeric ); - kvp_frame_set_timespec( fixture->frame, "timespec-type", test_ts ); - kvp_frame_set_string( fixture->frame, "string-type", test_str ); - kvp_frame_set_guid( fixture->frame, "guid-type", test_guid ); - kvp_frame_set_frame( fixture->frame, "frame-type", test_frame ); - g_assert( !kvp_frame_is_empty( fixture->frame ) ); - - g_test_message( "Test frame copy" ); - to_copy = kvp_frame_copy( fixture->frame ); - g_assert( to_copy ); - g_assert( !kvp_frame_is_empty( to_copy ) ); - g_assert( to_copy != fixture->frame ); - - g_assert_cmpint( kvp_frame_compare( fixture->frame, to_copy ), == , 0 ); - copy_gint64 = kvp_frame_get_gint64( to_copy, "gint64-type" ); - g_assert( ©_gint64 != &test_gint64 ); - g_assert_cmpint( copy_gint64, == , test_gint64 ); - copy_double = kvp_frame_get_double( to_copy, "double-type" ); - g_assert( ©_double != &test_double ); - g_assert_cmpfloat( copy_double, == , test_double ); - copy_gnc_numeric = kvp_frame_get_numeric( to_copy, "numeric-type" ); - g_assert( ©_gnc_numeric != &test_gnc_numeric ); - g_assert_cmpfloat( copy_gnc_numeric.num, == , test_gnc_numeric.num ); - g_assert_cmpfloat( copy_gnc_numeric.denom, == , test_gnc_numeric.denom ); - copy_ts = kvp_frame_get_timespec( to_copy, "timespec-type" ); - g_assert( ©_ts != &test_ts ); - g_assert_cmpfloat( copy_ts.tv_sec, == , test_ts.tv_sec ); - g_assert_cmpfloat( copy_ts.tv_nsec, == , test_ts.tv_nsec ); - copy_str = kvp_frame_get_string( to_copy, "string-type" ); - g_assert( copy_str != test_str ); - g_assert_cmpstr( copy_str, == , test_str ); - copy_guid = kvp_frame_get_guid( to_copy, "guid-type" ); - g_assert( copy_guid != test_guid ); - g_assert( guid_equal( copy_guid, test_guid ) ); - copy_frame = kvp_frame_get_frame( to_copy, "frame-type"); - g_assert( copy_frame ); - g_assert( kvp_frame_is_empty( copy_frame ) ); - g_assert( copy_frame != test_frame ); - g_assert_cmpint( kvp_frame_compare( copy_frame, test_frame ), == , 0 ); - - kvp_frame_delete( to_copy ); - guid_free( test_guid ); -} - -static void -test_kvp_frame_set_foo( Fixture *fixture, gconstpointer pData ) -{ - gnc_numeric test_gnc_numeric, copy_gnc_numeric; - Timespec test_ts, copy_ts; - GncGUID *test_guid, *copy_guid; - - test_gnc_numeric = gnc_numeric_zero(); - test_ts.tv_sec = 1; - test_ts.tv_nsec = 1; - test_guid = guid_new(); - - g_assert( fixture->frame ); - g_assert( kvp_frame_is_empty( fixture->frame ) ); - - g_test_message( "Test gint64 setup and replace, test frame is created" ); - g_assert( kvp_frame_get_frame( fixture->frame, "/test" ) == NULL ); - kvp_frame_set_gint64( fixture->frame, "/test/gint64", 1 ); - g_assert( kvp_frame_get_frame( fixture->frame, "/test" ) != NULL ); - g_assert_cmpint( kvp_frame_get_gint64( fixture->frame, "/test/gint64" ), == , 1 ); - kvp_frame_set_gint64( fixture->frame, "/test/gint64", 5 ); - g_assert_cmpint( kvp_frame_get_gint64( fixture->frame, "/test/gint64" ), == , 5 ); - - g_test_message( "Test double setup and replace, test2 frame is created" ); - g_assert( kvp_frame_get_frame( fixture->frame, "/test2" ) == NULL ); - kvp_frame_set_double( fixture->frame, "/test2/double", 1.1 ); - g_assert( kvp_frame_get_frame( fixture->frame, "/test2" ) != NULL ); - g_assert_cmpfloat( kvp_frame_get_double( fixture->frame, "/test2/double" ), == , 1.1 ); - kvp_frame_set_double( fixture->frame, "/test2/double", 5.5 ); - g_assert_cmpfloat( kvp_frame_get_double( fixture->frame, "/test2/double" ), == , 5.5 ); - - g_test_message( "Test double setup and replace, test3 frame is created" ); - g_assert( kvp_frame_get_frame( fixture->frame, "/test3" ) == NULL ); - kvp_frame_set_numeric( fixture->frame, "/test3/numeric", test_gnc_numeric ); - g_assert( kvp_frame_get_frame( fixture->frame, "/test3" ) != NULL ); - copy_gnc_numeric = kvp_frame_get_numeric( fixture->frame, "/test3/numeric" ); - g_assert_cmpint( copy_gnc_numeric.num, == , 0 ); - g_assert_cmpint( copy_gnc_numeric.denom, == , 1 ); - test_gnc_numeric.num = 2; - test_gnc_numeric.denom = 3; - kvp_frame_set_numeric( fixture->frame, "/test3/numeric", test_gnc_numeric ); - copy_gnc_numeric = kvp_frame_get_numeric( fixture->frame, "/test3/numeric" ); - g_assert_cmpint( copy_gnc_numeric.num, == , 2 ); - g_assert_cmpint( copy_gnc_numeric.denom, == , 3 ); - - g_test_message( "Test timespec setup and replace, test4 frame is created" ); - g_assert( kvp_frame_get_frame( fixture->frame, "/test4" ) == NULL ); - kvp_frame_set_timespec( fixture->frame, "/test4/timespec", test_ts ); - g_assert( kvp_frame_get_frame( fixture->frame, "/test4" ) != NULL ); - copy_ts = kvp_frame_get_timespec( fixture->frame, "/test4/timespec" ); - g_assert_cmpint( copy_ts.tv_sec, == , 1 ); - g_assert_cmpint( copy_ts.tv_nsec, == , 1 ); - test_ts.tv_sec = 7; - test_ts.tv_nsec = 13; - kvp_frame_set_timespec( fixture->frame, "/test4/timespec", test_ts ); - copy_ts = kvp_frame_get_timespec( fixture->frame, "/test4/timespec" ); - g_assert_cmpint( copy_ts.tv_sec, == , 7 ); - g_assert_cmpint( copy_ts.tv_nsec, == , 13 ); - - g_test_message( "Test string setup and replace, test5 frame is created" ); - g_assert( kvp_frame_get_frame( fixture->frame, "/test5" ) == NULL ); - kvp_frame_set_string( fixture->frame, "/test5/string", "one string" ); - g_assert( kvp_frame_get_frame( fixture->frame, "/test5" ) != NULL ); - g_assert_cmpstr( kvp_frame_get_string( fixture->frame, "/test5/string" ), == , "one string" ); - kvp_frame_set_string( fixture->frame, "/test5/string", "another string" ); - g_assert_cmpstr( kvp_frame_get_string( fixture->frame, "/test5/string" ), == , "another string" ); - - g_test_message( "Test guid setup and replace, test6 frame is created" ); - g_assert( kvp_frame_get_frame( fixture->frame, "/test6" ) == NULL ); - kvp_frame_set_guid( fixture->frame, "/test6/guid", test_guid ); - g_assert( kvp_frame_get_frame( fixture->frame, "/test6" ) != NULL ); - copy_guid = kvp_frame_get_guid( fixture->frame, "/test6/guid" ); - g_assert( guid_equal( copy_guid, test_guid ) ); - kvp_frame_set_guid( fixture->frame, "/test6/guid", guid_null() ); - copy_guid = kvp_frame_get_guid( fixture->frame, "/test6/guid" ); - g_assert( guid_equal( copy_guid, guid_null() ) ); - - g_test_message( "Test frame setup and replace, test7 frame is created" ); - g_assert( kvp_frame_get_frame( fixture->frame, "/test7" ) == NULL ); - kvp_frame_set_frame( fixture->frame, "/test7", kvp_frame_new() ); - g_assert( kvp_frame_get_frame( fixture->frame, "/test7" ) != NULL ); - kvp_frame_set_frame( fixture->frame, "/test7", NULL ); - g_assert( kvp_frame_get_frame( fixture->frame, "/test7" ) == NULL ); -} - -static void -test_kvp_frame_get_frame_slash( Fixture *fixture, gconstpointer pData ) -{ - KvpFrame *result_frame = NULL; - /* Mostly testing static routine kvp_frmae_get_frame_slash_trash */ - g_assert( fixture->frame ); - - g_test_message( "Test path with one slash same frame should be returned" ); - result_frame = kvp_frame_get_frame_slash( fixture->frame, "/" ); - g_assert( result_frame ); - g_assert( result_frame == fixture->frame ); - - g_test_message( "Test path with trailing slash same frame should be returned" ); - result_frame = kvp_frame_get_frame_slash( fixture->frame, "/////" ); - g_assert( result_frame ); - g_assert( result_frame == fixture->frame ); - - g_test_message( "Test new frame is created" ); - result_frame = kvp_frame_get_frame_slash( fixture->frame, "/test" ); - g_assert( result_frame ); - g_assert( result_frame != fixture->frame ); - g_assert( result_frame == kvp_frame_get_frame( fixture->frame, "/test" ) ); - - g_test_message( "Test trailing slashes are ignored and frame created" ); - result_frame = kvp_frame_get_frame_slash( fixture->frame, "////test2/////" ); - g_assert( result_frame ); - g_assert( result_frame != fixture->frame ); - g_assert( result_frame == kvp_frame_get_frame( fixture->frame, "/test2" ) ); - g_assert( result_frame != kvp_frame_get_frame( fixture->frame, "/test" ) ); - - g_test_message( "Test frames are created along the path if not exist and last frame is returned" ); - result_frame = kvp_frame_get_frame_slash( fixture->frame, "////test3/////test4//////" ); - g_assert( result_frame ); - g_assert( result_frame != fixture->frame ); - g_assert( result_frame != kvp_frame_get_frame( fixture->frame, "/test2" ) ); - g_assert( result_frame != kvp_frame_get_frame( fixture->frame, "/test" ) ); - g_assert( kvp_frame_get_frame( fixture->frame, "/test3" ) != NULL ); - g_assert( result_frame != kvp_frame_get_frame( fixture->frame, "/test3" ) ); - g_assert( result_frame == kvp_frame_get_frame( fixture->frame, "/test3/test4" ) ); - - g_test_message( "Test existing frame is returned" ); - g_assert( result_frame == kvp_frame_get_frame_slash( fixture->frame, "////test3/////test4//////" ) ); -} - -static void -test_kvp_frame_get_slot_path( Fixture *fixture, gconstpointer pData ) -{ - KvpValue *result_value = NULL ; - - g_assert( fixture->frame ); - g_assert( kvp_frame_is_empty( fixture->frame ) ); - - g_test_message( "Test with non existing path should return NULL" ); - result_value = kvp_frame_get_slot_path( fixture->frame, "test", "test2", NULL ); - g_assert( !result_value ); - - g_test_message( "Test with existing value set to current frame" ); - kvp_frame_set_gint64( fixture->frame, "/test", 1 ); - result_value = kvp_frame_get_slot_path( fixture->frame, "test", NULL ); - g_assert( result_value ); - g_assert( kvp_value_get_type( result_value ) == KVP_TYPE_GINT64 ); - g_assert_cmpint( kvp_value_get_gint64( result_value ), == , 1 ); - - g_test_message( "Test should return null as test is not a frame" ); - kvp_frame_set_gint64( fixture->frame, "/test/test2", 2 ); - result_value = kvp_frame_get_slot_path( fixture->frame, "test", "test2", NULL ); - g_assert( !result_value ); - - g_test_message( "Test should return last value in the path" ); - kvp_frame_set_gint64( fixture->frame, "/test2/test3", 2 ); - result_value = kvp_frame_get_slot_path( fixture->frame, "test2", "test3", NULL ); - g_assert( result_value ); - g_assert( kvp_value_get_type( result_value ) == KVP_TYPE_GINT64 ); - g_assert_cmpint( kvp_value_get_gint64( result_value ), == , 2 ); - - g_test_message( "Test should return null as last value in the path does not exist" ); - result_value = kvp_frame_get_slot_path( fixture->frame, "test2", "test3", "test4", NULL ); - g_assert( !result_value ); -} - -static void -test_kvp_frame_get_slot_path_gslist( Fixture *fixture, gconstpointer pData ) -{ - /* similar to previous test except path is passed as GSList*/ - GSList *path_list = NULL; - KvpValue *result_value = NULL ; - - g_assert( fixture->frame ); - g_assert( kvp_frame_is_empty( fixture->frame ) ); - - g_test_message( "Test with non existing path should return NULL" ); - path_list = g_slist_append (path_list, "test"); - path_list = g_slist_append (path_list, "test2"); - result_value = kvp_frame_get_slot_path_gslist( fixture->frame, path_list ); - g_assert( !result_value ); - - g_test_message( "Test with existing value set to current frame" ); - path_list = g_slist_remove( path_list, "test2" ); - kvp_frame_set_gint64( fixture->frame, "/test", 1 ); - result_value = kvp_frame_get_slot_path_gslist( fixture->frame, path_list ); - g_assert( result_value ); - g_assert( kvp_value_get_type( result_value ) == KVP_TYPE_GINT64 ); - g_assert_cmpint( kvp_value_get_gint64( result_value ), == , 1 ); - - g_test_message( "Test should return null as test is not a frame" ); - path_list = g_slist_append (path_list, "test2"); - kvp_frame_set_gint64( fixture->frame, "/test/test2", 2 ); - result_value = kvp_frame_get_slot_path_gslist( fixture->frame, path_list ); - g_assert( !result_value ); - - g_test_message( "Test should return last value in the path" ); - path_list = g_slist_remove( path_list, "test" ); - path_list = g_slist_append (path_list, "test3"); - kvp_frame_set_gint64( fixture->frame, "/test2/test3", 2 ); - result_value = kvp_frame_get_slot_path_gslist( fixture->frame, path_list ); - g_assert( result_value ); - g_assert( kvp_value_get_type( result_value ) == KVP_TYPE_GINT64 ); - g_assert_cmpint( kvp_value_get_gint64( result_value ), == , 2 ); - - g_test_message( "Test should return null as last value in the path does not exist" ); - path_list = g_slist_append (path_list, "test4"); - result_value = kvp_frame_get_slot_path_gslist( fixture->frame, path_list ); - g_assert( !result_value ); - g_slist_free( path_list ); -} - -static void -test_kvp_frame_add_frame_nc( Fixture *fixture, gconstpointer pData ) -{ - /* basically we test static function kvp_frame_add_value_nc - * if path not exist it's created - * if gslist exist on the path new value added to the list - * if any other value exist it's converted to gslist and newvalue added - */ - KvpFrame *test_frame = NULL, - *test_frame2 = NULL, - *test_frame3 = NULL, - *result_frame = NULL; - KvpValue *result_value = NULL; - GList *result_list = NULL; - - g_assert( fixture->frame ); - g_assert( kvp_frame_is_empty( fixture->frame ) ); - - g_test_message( "Test when path does not exist it is created" ); - result_frame = kvp_frame_get_frame( fixture->frame, "/test/test2/test3" ); - g_assert( !result_frame ); - test_frame = kvp_frame_new(); - kvp_frame_add_frame_nc( fixture->frame, "/test/test2/test3", test_frame ); - result_frame = kvp_frame_get_frame( fixture->frame, "/test/test2/test3" ); - g_assert( result_frame ); - g_assert( result_frame == test_frame ); /* no copying done */ - result_frame = kvp_frame_get_frame( fixture->frame, "/test/test2" ); - g_assert( result_frame != test_frame ); - result_frame = kvp_frame_get_frame( fixture->frame, "/test" ); - g_assert( result_frame != test_frame ); - - g_test_message( "Test when value exist on the path it's converted to bag and new value added" ); - test_frame2 = kvp_frame_new(); - kvp_frame_add_frame_nc( fixture->frame, "/test/test2/test3", test_frame2 ); - result_value = kvp_frame_get_value( fixture->frame, "/test/test2/test3" ); - result_list = kvp_value_get_glist( result_value ); - g_assert( result_list ); - g_assert_cmpint( g_list_length( result_list ), == , 2 ); - result_value = g_list_first( result_list )->data; - g_assert( result_value ); - g_assert( kvp_value_get_type( result_value ) == KVP_TYPE_FRAME ); - g_assert( kvp_value_get_frame( result_value ) == test_frame ); - result_value = g_list_next( result_list )->data; - g_assert( result_value ); - g_assert( kvp_value_get_type( result_value ) == KVP_TYPE_FRAME ); - g_assert( kvp_value_get_frame( result_value ) == test_frame2 ); - - g_test_message( "Test when bag exists on the path new values are added to it" ); - test_frame3 = kvp_frame_new(); - kvp_frame_add_frame_nc( fixture->frame, "/test/test2/test3", test_frame3 ); - result_value = kvp_frame_get_value( fixture->frame, "/test/test2/test3" ); - g_assert( result_list == kvp_value_get_glist( result_value ) ); /* same list used */ - g_assert_cmpint( g_list_length( result_list ), == , 3 ); - result_value = g_list_first( result_list )->data; - g_assert( result_value ); - g_assert( kvp_value_get_type( result_value ) == KVP_TYPE_FRAME ); - g_assert( kvp_value_get_frame( result_value ) == test_frame ); - result_value = g_list_next( result_list )->data; - g_assert( result_value ); - g_assert( kvp_value_get_type( result_value ) == KVP_TYPE_FRAME ); - g_assert( kvp_value_get_frame( result_value ) == test_frame2 ); - result_value = g_list_last( result_list )->data; - g_assert( result_value ); - g_assert( kvp_value_get_type( result_value ) == KVP_TYPE_FRAME ); - g_assert( kvp_value_get_frame( result_value ) == test_frame3 ); -} - -static void -test_kvp_value_copy( void ) -{ - KvpValue *gint64_orig_value, *gint64_copy_value; - KvpValue *double_orig_value, *double_copy_value; - KvpValue *numeric_orig_value, *numeric_copy_value; - KvpValue *string_orig_value, *string_copy_value; - KvpValue *guid_orig_value, *guid_copy_value; - KvpValue *timespec_orig_value, *timespec_copy_value; - KvpValue *glist_orig_value, *glist_copy_value; - KvpValue *frame_orig_value, *frame_copy_value; - - /* data init */ - gnc_numeric gnc_numeric_orig, gnc_numeric_copy; - GncGUID *guid_orig, *guid_copy; - Timespec ts_orig, ts_copy; - GList *list_orig, *list_copy; - KvpFrame *frame_orig, *frame_copy; - - gnc_numeric_orig = gnc_numeric_zero(); - guid_orig = guid_new(); - ts_orig.tv_sec = 1; - ts_orig.tv_nsec = 1; - list_orig = NULL; - list_orig = g_list_append( list_orig, kvp_value_new_string( "abcdefghijklmnop" ) ); - frame_orig = kvp_frame_new(); - - g_test_message( "Test creates original values and checks copies of them" ); - gint64_orig_value = kvp_value_new_gint64( 2 ); - double_orig_value = kvp_value_new_double( 3.3 ); - numeric_orig_value = kvp_value_new_gnc_numeric( gnc_numeric_orig ); - string_orig_value = kvp_value_new_string( "abcdefghijklmnop" ); - guid_orig_value = kvp_value_new_guid( guid_orig ); - timespec_orig_value = kvp_value_new_timespec( ts_orig ); - glist_orig_value = kvp_value_new_glist( list_orig ); - frame_orig_value = kvp_value_new_frame( frame_orig ); - g_assert( gint64_orig_value && double_orig_value && numeric_orig_value && string_orig_value - && guid_orig_value && timespec_orig_value && glist_orig_value && frame_orig_value ); - - /* copy values */ - gint64_copy_value = kvp_value_copy( gint64_orig_value ); - g_assert( gint64_copy_value ); - g_assert( gint64_copy_value != gint64_orig_value ); - g_assert( kvp_value_get_type( gint64_copy_value ) == KVP_TYPE_GINT64 ); - g_assert_cmpint( kvp_value_get_gint64( gint64_copy_value ), == , 2 ); - - double_copy_value = kvp_value_copy( double_orig_value ); - g_assert( double_copy_value ); - g_assert( double_copy_value != double_orig_value ); - g_assert( kvp_value_get_type( double_copy_value ) == KVP_TYPE_DOUBLE ); - g_assert_cmpfloat( kvp_value_get_double( double_copy_value ), == , 3.3 ); - - numeric_copy_value = kvp_value_copy( numeric_orig_value ); - g_assert( numeric_copy_value ); - g_assert( numeric_copy_value != numeric_orig_value ); - g_assert( kvp_value_get_type( numeric_copy_value ) == KVP_TYPE_NUMERIC ); - gnc_numeric_copy = kvp_value_get_numeric( numeric_copy_value ); - g_assert_cmpfloat( gnc_numeric_copy.num, == , gnc_numeric_orig.num ); - g_assert_cmpfloat( gnc_numeric_copy.denom, == , gnc_numeric_orig.denom ); - - string_copy_value = kvp_value_copy( string_orig_value ); - g_assert( string_copy_value ); - g_assert( string_copy_value != string_orig_value ); - g_assert( kvp_value_get_type( string_copy_value ) == KVP_TYPE_STRING ); - g_assert_cmpstr( kvp_value_get_string( string_copy_value ), == , "abcdefghijklmnop" ); - - guid_copy_value = kvp_value_copy( guid_orig_value ); - g_assert( guid_copy_value ); - g_assert( guid_copy_value != guid_orig_value ); - g_assert( kvp_value_get_type( guid_copy_value ) == KVP_TYPE_GUID ); - guid_copy = kvp_value_get_guid( guid_copy_value ); - g_assert( guid_orig != guid_copy ); - g_assert( guid_equal( guid_orig, guid_copy ) ); - - timespec_copy_value = kvp_value_copy( timespec_orig_value ); - g_assert( timespec_copy_value ); - g_assert( timespec_copy_value != timespec_orig_value ); - g_assert( kvp_value_get_type( timespec_copy_value ) == KVP_TYPE_TIMESPEC ); - ts_copy = kvp_value_get_timespec( timespec_copy_value ); - g_assert_cmpfloat( ts_copy.tv_sec, == , ts_orig.tv_sec ); - g_assert_cmpfloat( ts_copy.tv_nsec, == , ts_orig.tv_nsec ); - - glist_copy_value = kvp_value_copy( glist_orig_value ); - g_assert( glist_copy_value ); - g_assert( glist_copy_value != glist_orig_value ); - g_assert( kvp_value_get_type( glist_copy_value ) == KVP_TYPE_GLIST ); - list_copy = kvp_value_get_glist( glist_copy_value ); - g_assert( list_copy != list_orig ); - g_assert_cmpint( g_list_length( list_copy ), == , g_list_length( list_orig ) ); - g_assert_cmpint( kvp_glist_compare( list_orig, list_copy ), == , 0 ); - - frame_copy_value = kvp_value_copy( frame_orig_value ); - g_assert( frame_copy_value ); - g_assert( frame_copy_value != frame_orig_value ); - g_assert( kvp_value_get_type( frame_copy_value ) == KVP_TYPE_FRAME ); - frame_copy = kvp_value_get_frame( frame_copy_value ); - g_assert_cmpint( kvp_frame_compare( frame_orig, frame_copy ), == , 0 ); - - /* destroy objects */ - kvp_value_delete( gint64_orig_value ); - kvp_value_delete( double_orig_value ); - kvp_value_delete( numeric_orig_value ); - kvp_value_delete( string_orig_value ); - kvp_value_delete( guid_orig_value ); - kvp_value_delete( timespec_orig_value ); - kvp_value_delete( glist_orig_value ); - kvp_value_delete( frame_orig_value ); - - kvp_value_delete( gint64_copy_value ); - kvp_value_delete( double_copy_value ); - kvp_value_delete( numeric_copy_value ); - kvp_value_delete( string_copy_value ); - kvp_value_delete( guid_copy_value ); - kvp_value_delete( timespec_copy_value ); - kvp_value_delete( glist_copy_value ); - kvp_value_delete( frame_copy_value ); -} - -static void -test_kvp_glist_copy( void ) -{ - GList *value_list = NULL, *copy_list = NULL, *lp1 = NULL, *lp2 = NULL; - KvpValue *gint64_value; - KvpValue *double_value; - KvpValue *numeric_value; - KvpValue *string_value; - KvpValue *guid_value; - KvpValue *timespec_value; - KvpValue *glist_value; - KvpValue *frame_value; - - gnc_numeric gnc_numeric_orig; - GncGUID *guid_orig; - Timespec ts_orig; - GList *list_orig; - KvpFrame *frame_orig; - - gnc_numeric_orig = gnc_numeric_zero(); - guid_orig = guid_new(); - ts_orig.tv_sec = 1; - ts_orig.tv_nsec = 1; - list_orig = NULL; - list_orig = g_list_append( list_orig, kvp_value_new_string( "abcdefghijklmnop" ) ); - frame_orig = kvp_frame_new(); - - gint64_value = kvp_value_new_gint64( 2 ); - double_value = kvp_value_new_double( 3.3 ); - numeric_value = kvp_value_new_gnc_numeric( gnc_numeric_orig ); - string_value = kvp_value_new_string( "abcdefghijklmnop" ); - guid_value = kvp_value_new_guid( guid_orig ); - timespec_value = kvp_value_new_timespec( ts_orig ); - glist_value = kvp_value_new_glist( list_orig ); - frame_value = kvp_value_new_frame( frame_orig ); - - value_list = g_list_append( value_list, gint64_value ); - value_list = g_list_append( value_list, double_value ); - value_list = g_list_append( value_list, numeric_value ); - value_list = g_list_append( value_list, string_value ); - value_list = g_list_append( value_list, guid_value ); - value_list = g_list_append( value_list, timespec_value ); - value_list = g_list_append( value_list, glist_value ); - value_list = g_list_append( value_list, frame_value ); - g_assert( value_list ); - g_assert_cmpint( g_list_length( value_list ), == , 8 ); - - g_test_message( "Test list and all values are copied to new list" ); - copy_list = kvp_glist_copy( value_list ); - g_assert( copy_list ); - g_assert( copy_list != value_list ); - g_assert_cmpint( g_list_length( copy_list ), == , 8 ); - lp1 = value_list; - lp2 = copy_list; - while (lp1 && lp2) - { - KvpValue *v1 = (KvpValue *) lp1->data; - KvpValue *v2 = (KvpValue *) lp2->data; - g_assert( v1 != v2 ); - g_assert_cmpint( kvp_value_compare(v1, v2), == , 0 ); - lp1 = lp1->next; - lp2 = lp2->next; - } - g_assert_cmpint( kvp_glist_compare( value_list, copy_list ), == , 0 ); - - /* destroy */ - kvp_glist_delete( value_list ); - kvp_glist_delete( copy_list ); -} - -static void -test_kvp_glist_compare( void ) -{ - GList *list1 = NULL, *list2 = NULL; - - KvpValue *gint64_value; - KvpValue *double_value; - KvpValue *numeric_value; - KvpValue *string_value; - KvpValue *guid_value; - KvpValue *timespec_value; - KvpValue *glist_value; - KvpValue *frame_value; - - gnc_numeric gnc_numeric_orig; - GncGUID *guid_orig; - Timespec ts_orig; - GList *list_orig; - KvpFrame *frame_orig; - - gnc_numeric_orig = gnc_numeric_zero(); - guid_orig = guid_new(); - ts_orig.tv_sec = 1; - ts_orig.tv_nsec = 1; - list_orig = NULL; - list_orig = g_list_append( list_orig, kvp_value_new_string( "abcdefghijklmnop" ) ); - frame_orig = kvp_frame_new(); - - gint64_value = kvp_value_new_gint64( 2 ); - double_value = kvp_value_new_double( 3.3 ); - numeric_value = kvp_value_new_gnc_numeric( gnc_numeric_orig ); - string_value = kvp_value_new_string( "abcdefghijklmnop" ); - guid_value = kvp_value_new_guid( guid_orig ); - timespec_value = kvp_value_new_timespec( ts_orig ); - glist_value = kvp_value_new_glist( list_orig ); - frame_value = kvp_value_new_frame( frame_orig ); - - /* init list 1 */ - list1 = g_list_append( list1, gint64_value ); - list1 = g_list_append( list1, double_value ); - list1 = g_list_append( list1, numeric_value ); - list1 = g_list_append( list1, string_value ); - list1 = g_list_append( list1, guid_value ); - list1 = g_list_append( list1, timespec_value ); - list1 = g_list_append( list1, glist_value ); - list1 = g_list_append( list1, frame_value ); - g_assert( list1 ); - g_assert_cmpint( g_list_length( list1 ), == , 8 ); - - g_test_message( "Test when list is the same" ); - list2 = list1; - g_assert_cmpint( kvp_glist_compare( list1, list2 ), == , 0 ); - - g_test_message( "Test when list1 is null" ); - g_assert_cmpint( kvp_glist_compare( NULL, list2 ), == , -1 ); - - g_test_message( "Test when list2 is null" ); - g_assert_cmpint( kvp_glist_compare( list1, NULL ), == , 1 ); - - g_test_message( "Copy list and test they are equal" ); - list2 = kvp_glist_copy( list1 ); - g_assert( list1 != list2 ); - g_assert_cmpint( g_list_length( list1 ), == , g_list_length( list2 ) ); - g_assert_cmpint( kvp_glist_compare( list1, list2 ), == , 0 ); - - g_test_message( "Test when list 1 is shorter lists are not equal" ); - list1 = g_list_remove( list1, frame_value ); - g_assert_cmpint( g_list_length( list1 ), == , 7 ); - g_assert_cmpint( g_list_length( list2 ), == , 8 ); - g_assert_cmpint( kvp_glist_compare( list1, list2 ), == , -1 ); - - g_test_message( "Test when list 2 is shorter lists are not equal" ); - list1 = g_list_append( list1, frame_value ); - list1 = g_list_append( list1, frame_value ); - g_assert_cmpint( g_list_length( list1 ), == , 9 ); - g_assert_cmpint( g_list_length( list2 ), == , 8 ); - g_assert_cmpint( kvp_glist_compare( list1, list2 ), == , 1 ); - - g_test_message( "Test when data is not equal lists are not equal" ); - list1 = g_list_remove( list1, frame_value ); - g_assert_cmpint( g_list_length( list1 ), == , g_list_length( list2 ) ); - g_assert_cmpint( kvp_glist_compare( list1, list2 ), == , 0 ); - list1 = g_list_remove( list1, gint64_value ); - kvp_value_delete( gint64_value ); - list1 = g_list_prepend( list1, kvp_value_new_gint64( 5 ) ); - g_assert_cmpint( g_list_length( list1 ), == , g_list_length( list2 ) ); - g_assert_cmpint( kvp_glist_compare( list1, list2 ), != , 0 ); - - /* delete lists */ - kvp_glist_delete( list1 ); - kvp_glist_delete( list2 ); -} - -static void -test_kvp_value_compare( void ) -{ - KvpValue *gint64_orig_value, *gint64_copy_value; - KvpValue *double_orig_value, *double_copy_value; - KvpValue *numeric_orig_value, *numeric_copy_value; - KvpValue *string_orig_value, *string_copy_value; - KvpValue *guid_orig_value, *guid_copy_value; - KvpValue *timespec_orig_value, *timespec_copy_value; - KvpValue *glist_orig_value, *glist_copy_value; - KvpValue *frame_orig_value, *frame_copy_value; - - /* data init */ - gnc_numeric gnc_numeric_orig, gnc_numeric_copy; - GncGUID *guid_orig, *guid_copy; - Timespec ts_orig, ts_copy; - GList *list_orig, *list_copy; - KvpFrame *frame_orig, *frame_copy; - - gnc_numeric_orig = gnc_numeric_zero(); - gnc_numeric_copy = gnc_numeric_zero(); - guid_orig = guid_new(); - guid_copy = guid_new(); - ts_orig.tv_sec = 1; - ts_orig.tv_nsec = 1; - ts_copy.tv_sec = 2; - ts_copy.tv_nsec = 2; - list_orig = NULL; - list_orig = g_list_append( list_orig, kvp_value_new_string( "abcdefghijklmnop" ) ); - list_copy = NULL; - list_copy = g_list_append( list_copy, kvp_value_new_string( "abcdefg" ) ); - frame_orig = kvp_frame_new(); - frame_copy = kvp_frame_new(); - - gint64_orig_value = kvp_value_new_gint64( 2 ); - gint64_copy_value = kvp_value_new_gint64( 5 ); - double_orig_value = kvp_value_new_double( 3.3 ); - double_copy_value = kvp_value_new_double( 3.5 ); - numeric_orig_value = kvp_value_new_gnc_numeric( gnc_numeric_orig ); - numeric_copy_value = kvp_value_new_gnc_numeric( gnc_numeric_copy ); - string_orig_value = kvp_value_new_string( "abcdefghijklmnop" ); - string_copy_value = kvp_value_new_string( "abcdefghijklmnop" ); - guid_orig_value = kvp_value_new_guid( guid_orig ); - guid_copy_value = kvp_value_new_guid( guid_copy ); - timespec_orig_value = kvp_value_new_timespec( ts_orig ); - timespec_copy_value = kvp_value_new_timespec( ts_copy ); - glist_orig_value = kvp_value_new_glist( list_orig ); - glist_copy_value = kvp_value_new_glist( list_copy ); - frame_orig_value = kvp_value_new_frame( frame_orig ); - frame_copy_value = kvp_value_new_frame( frame_copy ); - - g_test_message( "Test the same kvpvalue is equal" ); - g_assert_cmpint( kvp_value_compare( gint64_orig_value, gint64_orig_value ), == , 0 ); - - g_test_message( "Test first value is null" ); - g_assert_cmpint( kvp_value_compare( NULL, gint64_orig_value ), == , -1 ); - - g_test_message( "Test second value is null" ); - g_assert_cmpint( kvp_value_compare( gint64_orig_value, NULL ), == , 1 ); - - g_test_message( "Test diffrent data types first is lesser" ); - g_assert_cmpint( kvp_value_compare( gint64_orig_value, double_orig_value ), == , -1 ); - - g_test_message( "Test diffrent data types second is lesser" ); - g_assert_cmpint( kvp_value_compare( double_orig_value, gint64_orig_value ), == , 1 ); - - /* testing all different cases of data equality is not the aim - * of this test. Rather we check that all data types are being compared. - */ - g_test_message( "Test different kvpvalues of all the types" ); - g_assert_cmpint( kvp_value_compare( gint64_orig_value, gint64_copy_value ), == , -1 ); - g_assert_cmpint( kvp_value_compare( gint64_copy_value, gint64_orig_value ), == , 1 ); - g_assert_cmpint( kvp_value_compare( double_orig_value, double_copy_value ), == , -1 ); - g_assert_cmpint( kvp_value_compare( numeric_orig_value, numeric_copy_value ), == , gnc_numeric_compare( gnc_numeric_orig, gnc_numeric_copy ) ); - g_assert_cmpint( kvp_value_compare( string_orig_value, string_copy_value ), == , strcmp( "abcdefghijklmnop", "abcdefghijklmnop" ) ); - g_assert_cmpint( kvp_value_compare( guid_orig_value, guid_copy_value ), == , guid_compare( guid_orig, guid_copy ) ); - g_assert_cmpint( kvp_value_compare( timespec_orig_value, timespec_copy_value ), == , timespec_cmp( &ts_orig, &ts_copy ) ); - g_assert_cmpint( kvp_value_compare( glist_orig_value, glist_copy_value ), == , kvp_glist_compare( list_orig, list_copy ) ); - g_assert_cmpint( kvp_value_compare( frame_orig_value, frame_copy_value ), == , kvp_frame_compare( frame_orig, frame_copy ) ); - - /* destroy objects */ - kvp_value_delete( gint64_orig_value ); - kvp_value_delete( double_orig_value ); - kvp_value_delete( numeric_orig_value ); - kvp_value_delete( string_orig_value ); - kvp_value_delete( guid_orig_value ); - kvp_value_delete( timespec_orig_value ); - kvp_value_delete( glist_orig_value ); - kvp_value_delete( frame_orig_value ); - - kvp_value_delete( gint64_copy_value ); - kvp_value_delete( double_copy_value ); - kvp_value_delete( numeric_copy_value ); - kvp_value_delete( string_copy_value ); - kvp_value_delete( guid_copy_value ); - kvp_value_delete( timespec_copy_value ); - kvp_value_delete( glist_copy_value ); - kvp_value_delete( frame_copy_value ); -} - -static void -test_kvp_value_new_foo_nc( void ) -{ - KvpValue *glist_value_nc, *frame_value_nc; - void *val; - guint64 size; - GList *list = NULL; - KvpFrame *frame = NULL; - - g_test_message( "Test new glist is not copied" ); - list = g_list_append( list, kvp_value_new_gint64( 2 ) ); - g_assert_cmpint( g_list_length( list ), == , 1 ); - glist_value_nc = kvp_value_new_glist_nc( list ); - g_assert( glist_value_nc ); - g_assert( kvp_value_get_type( glist_value_nc ) == KVP_TYPE_GLIST ); - g_assert( kvp_value_get_glist( glist_value_nc ) == list ); - - g_test_message( "Test new frame is not copied" ); - frame = kvp_frame_new(); - frame_value_nc = kvp_value_new_frame_nc( frame ); - g_assert( frame_value_nc ); - g_assert( kvp_value_get_type( frame_value_nc ) == KVP_TYPE_FRAME ); - g_assert( kvp_value_get_frame( frame_value_nc ) == frame ); - - kvp_value_delete( glist_value_nc ); - kvp_value_delete( frame_value_nc ); -} - -static void -test_kvp_frame_compare( Fixture *fixture, gconstpointer pData ) -{ - KvpFrame *cmp_frame = NULL; - - cmp_frame = kvp_frame_new(); - g_assert( cmp_frame ); - - g_test_message( "Test the same frame is equal with itself" ); - g_assert_cmpint( kvp_frame_compare( fixture->frame, fixture->frame ), == , 0 ); - - g_test_message( "Test first frame null second not null" ); - g_assert_cmpint( kvp_frame_compare( NULL, fixture->frame ), == , -1 ); - - g_test_message( "Test first frame not null second null" ); - g_assert_cmpint( kvp_frame_compare( fixture->frame, NULL ), == , 1 ); - - g_test_message( "Test first frame is empty second not empty" ); - kvp_frame_set_gint64( fixture->frame, "/test/test2", 64 ); - g_assert( !kvp_frame_is_empty( fixture->frame ) ); - g_assert( kvp_frame_is_empty( cmp_frame ) ); - g_assert_cmpint( kvp_frame_compare( cmp_frame, fixture->frame ), == , -1 ); - - g_test_message( "Test first frame is not empty second is empty" ); - g_assert_cmpint( kvp_frame_compare( fixture->frame, cmp_frame ), == , 1 ); - - g_test_message( "Test when frames are equal" ); - kvp_frame_set_gint64( cmp_frame, "/test/test2", 64 ); - g_assert( !kvp_frame_is_empty( cmp_frame ) ); - g_assert_cmpint( kvp_frame_compare( fixture->frame, cmp_frame ), == , 0 ); - - g_test_message( "Test when frames have equal data but second frame has additional slot set" ); - kvp_frame_set_string( fixture->frame, "/test/test3", "abcdefghijklmnop" ); - g_assert_cmpint( kvp_frame_compare( cmp_frame, fixture->frame ), == , -1 ); - - g_test_message( "Test when frames have equal data but first frame has additional slot set" ); - g_assert_cmpint( kvp_frame_compare( fixture->frame, cmp_frame ), == , 1 ); - - g_test_message( "Test when frames have equal number of slots second frame has different data in one slot" ); - kvp_frame_set_string( cmp_frame, "/test/test3", "abcdefg" ); - g_assert_cmpint( kvp_frame_compare( cmp_frame, fixture->frame ), < , 0 ); - - g_test_message( "Test when frames have equal number of slots second frame has different data in one slot" ); - g_assert_cmpint( kvp_frame_compare( fixture->frame, cmp_frame ), > , 0 ); - - kvp_frame_delete( cmp_frame ); -} - -static void -test_kvp_value_to_string( void ) -{ - gchar guidstr[GUID_ENCODING_LENGTH+1]; - gchar *str_tmp2, *str_tmp3; - gchar *result; - KvpValue *gint64_value; - KvpValue *double_value; - KvpValue *numeric_value; - KvpValue *string_value; - KvpValue *guid_value; - KvpValue *timespec_value; - KvpValue *glist_value; - KvpValue *frame_value; - - gnc_numeric gnc_numeric_orig; - GncGUID *guid_orig; - Timespec ts_orig; - GList *list_orig; - KvpFrame *frame_orig; - - gnc_numeric_orig = gnc_numeric_zero(); - guid_orig = guid_new(); - ts_orig.tv_sec = 1; - ts_orig.tv_nsec = 1; - list_orig = NULL; - list_orig = g_list_append( list_orig, kvp_value_new_string( "abcdefghijklmnop" ) ); - frame_orig = kvp_frame_new(); - - gint64_value = kvp_value_new_gint64( 2 ); - double_value = kvp_value_new_double( 3.3 ); - numeric_value = kvp_value_new_gnc_numeric( gnc_numeric_orig ); - string_value = kvp_value_new_string( "abcdefghijklmnop" ); - guid_value = kvp_value_new_guid( guid_orig ); - timespec_value = kvp_value_new_timespec( ts_orig ); - glist_value = kvp_value_new_glist( list_orig ); - frame_value = kvp_value_new_frame( frame_orig ); - - g_test_message( "Test value string representation with different data types" ); - result = kvp_value_to_string( gint64_value ); - g_assert( result ); - g_assert_cmpstr( result, == , "KVP_VALUE_GINT64(2)" ); - g_free( result ); - - result = kvp_value_to_string( double_value ); - g_assert( result ); - g_assert_cmpstr( result, == , "KVP_VALUE_DOUBLE(3.3)" ); - g_free( result ); - - result = kvp_value_to_string( numeric_value ); - g_assert( result ); - g_assert_cmpstr( result, == , "KVP_VALUE_NUMERIC(0/1)" ); - g_free( result ); - - result = kvp_value_to_string( string_value ); - g_assert( result ); - g_assert_cmpstr( result, == , "KVP_VALUE_STRING(abcdefghijklmnop)" ); - g_free( result ); - - result = kvp_value_to_string( guid_value ); - g_assert( result ); - guid_to_string_buff( kvp_value_get_guid( guid_value ), guidstr); - str_tmp2 = g_strdup_printf("KVP_VALUE_GUID(%s)", guidstr); - g_assert_cmpstr( result, == , str_tmp2 ); - g_free( result ); - g_free( str_tmp2 ); - - result = kvp_value_to_string( timespec_value ); - g_assert( result ); - str_tmp2 = g_new0 (char, 40); - gnc_timespec_to_iso8601_buff( kvp_value_get_timespec( timespec_value ), str_tmp2 ); - str_tmp3 = g_strdup_printf("KVP_VALUE_TIMESPEC(%s)", str_tmp2); - g_assert_cmpstr( result, == , str_tmp3 ); - g_free( result ); - g_free( str_tmp2 ); - g_free( str_tmp3 ); - - result = kvp_value_to_string( glist_value ); - g_assert( result ); - g_assert_cmpstr( result, == , "KVP_VALUE_GLIST([ KVP_VALUE_STRING(abcdefghijklmnop), ])" ); - g_free( result ); - - result = kvp_value_to_string( frame_value ); - g_assert( result ); - g_assert_cmpstr( result, == , "KVP_VALUE_FRAME({\n}\n)" ); - g_free( result ); - - kvp_value_delete( gint64_value ); - kvp_value_delete( double_value ); - kvp_value_delete( numeric_value ); - kvp_value_delete( string_value ); - kvp_value_delete( guid_value ); - kvp_value_delete( timespec_value ); - kvp_value_delete( glist_value ); - kvp_value_delete( frame_value ); -} - -static void -test_kvp_frame_to_string( Fixture *fixture, gconstpointer pData ) -{ - gchar *result; - gnc_numeric test_gnc_numeric; - GncGUID *test_guid; - Timespec test_ts; - KvpFrame *test_frame; - - test_gnc_numeric = gnc_numeric_zero(); - test_guid = guid_new(); - test_ts.tv_sec = 1; - test_ts.tv_nsec = 1; - test_frame = kvp_frame_new(); - - g_assert( fixture->frame ); - g_assert( kvp_frame_is_empty( fixture->frame ) ); - - g_test_message( "Test empty frame" ); - result = kvp_frame_to_string( fixture->frame ); - g_assert_cmpstr( result, == , "{\n}\n" ); - g_free( result ); - - /* slots can be randomly distributed in hash table - * instead of checking the whole return string we rather check if certain entries exist in it - */ - g_test_message( "Test with all data types and nested frames" ); - kvp_frame_set_gint64( fixture->frame, "/gint64-type", 2 ); - result = kvp_frame_to_string( fixture->frame ); - g_assert( g_strrstr( result, " gint64-type => KVP_VALUE_GINT64(2),\n" ) != NULL ); - g_free( result ); - - kvp_frame_set_double( fixture->frame, "/double-type", 3.3 ); - result = kvp_frame_to_string( fixture->frame ); - g_assert( g_strrstr( result, " double-type => KVP_VALUE_DOUBLE(3.3),\n" ) != NULL ); - g_free( result ); - - kvp_frame_set_numeric( fixture->frame, "/numeric-type", test_gnc_numeric ); - result = kvp_frame_to_string( fixture->frame ); - g_assert( g_strrstr( result, " numeric-type => KVP_VALUE_NUMERIC(0/1),\n" ) != NULL ); - g_free( result ); - - kvp_frame_set_timespec( fixture->frame, "/timespec-type", test_ts ); - result = kvp_frame_to_string( fixture->frame ); - g_assert( g_strrstr( result, " timespec-type => KVP_VALUE_TIMESPEC" ) != NULL ); - g_free( result ); - - kvp_frame_set_string( fixture->frame, "/string-type", "abcdefghijklmnop" ); - result = kvp_frame_to_string( fixture->frame ); - g_assert( g_strrstr( result, " string-type => KVP_VALUE_STRING(abcdefghijklmnop),\n" ) != NULL ); - g_free( result ); - - kvp_frame_set_guid( fixture->frame, "/guid-type", test_guid ); - result = kvp_frame_to_string( fixture->frame ); - g_assert( g_strrstr( result, " guid-type => KVP_VALUE_GUID" ) != NULL ); - g_free( result ); - - kvp_frame_set_frame( fixture->frame, "/nested/frame-type", test_frame ); - result = kvp_frame_to_string( fixture->frame ); - g_assert( g_strrstr( result, " nested => KVP_VALUE_FRAME({\n frame-type => KVP_VALUE_FRAME({\n}\n),\n}\n),\n" ) != NULL ); - g_free( result ); -} - -static void -test_kvp_frame_set_slot_path( Fixture *fixture, gconstpointer pData ) -{ - KvpValue *input_value, *output_value; - - g_assert( fixture->frame ); - g_assert( kvp_frame_is_empty( fixture->frame ) ); - - g_test_message( "Test with a simple value added to the empty frame" ); - input_value = kvp_value_new_gint64( 2 ); - kvp_frame_set_slot_path( fixture->frame, input_value, "test", NULL ); - output_value = kvp_frame_get_slot_path( fixture->frame, "test", NULL ); - g_assert( output_value ); - g_assert( input_value != output_value ); /* copied */ - g_assert_cmpint( kvp_value_compare( output_value, input_value ), == , 0 ); - kvp_value_delete( input_value ); - - g_test_message( "Test when value is being replaced" ); - input_value = kvp_value_new_double( 3.3 ); - kvp_frame_set_slot_path( fixture->frame, input_value, "test", NULL ); - output_value = kvp_frame_get_slot_path( fixture->frame, "test", NULL ); - g_assert( output_value ); - g_assert( input_value != output_value ); /* copied */ - g_assert_cmpint( kvp_value_compare( output_value, input_value ), == , 0 ); /* old value removed */ - kvp_value_delete( input_value ); - - g_test_message( "Test when existing path elements are not frames" ); - input_value = kvp_value_new_string( "abcdefghijklmnop" ); - kvp_frame_set_slot_path( fixture->frame, input_value, "test", "test2", NULL ); - g_assert( kvp_frame_get_slot_path( fixture->frame, "test2", NULL ) == NULL );/* was not added */ - g_assert_cmpint( kvp_value_compare( output_value, kvp_frame_get_slot_path( fixture->frame, "test", NULL ) ), == , 0 ); /* nothing changed */ - kvp_value_delete( input_value ); - - g_test_message( "Test frames are created along the path when needed" ); - input_value = kvp_value_new_string( "abcdefghijklmnop" ); - kvp_frame_set_slot_path( fixture->frame, input_value, "test2", "test3", NULL ); - output_value = kvp_frame_get_slot_path( fixture->frame, "test2", NULL ); - g_assert( output_value ); - g_assert( kvp_value_get_type( output_value ) == KVP_TYPE_FRAME ); - output_value = kvp_frame_get_slot_path( fixture->frame, "test2", "test3", NULL ); - g_assert( output_value ); - g_assert( input_value != output_value ); /* copied */ - g_assert_cmpint( kvp_value_compare( output_value, input_value ), == , 0 ); - kvp_value_delete( input_value ); -} - -static void -test_kvp_frame_set_slot_path_gslist( Fixture *fixture, gconstpointer pData ) -{ - /* similar to previous test except path is passed as GSList*/ - GSList *path_list = NULL; - KvpValue *input_value, *output_value; - - g_assert( fixture->frame ); - g_assert( kvp_frame_is_empty( fixture->frame ) ); - - g_test_message( "Test with a simple value added to the empty frame" ); - path_list = g_slist_append( path_list, "test" ); - input_value = kvp_value_new_gint64( 2 ); - kvp_frame_set_slot_path_gslist( fixture->frame, input_value, path_list ); - output_value = kvp_frame_get_slot_path( fixture->frame, "test", NULL ); - g_assert( output_value ); - g_assert( input_value != output_value ); /* copied */ - g_assert_cmpint( kvp_value_compare( output_value, input_value ), == , 0 ); - kvp_value_delete( input_value ); - - g_test_message( "Test when value is being replaced" ); - input_value = kvp_value_new_double( 3.3 ); - kvp_frame_set_slot_path_gslist( fixture->frame, input_value, path_list ); - output_value = kvp_frame_get_slot_path( fixture->frame, "test", NULL ); - g_assert( output_value ); - g_assert( input_value != output_value ); /* copied */ - g_assert_cmpint( kvp_value_compare( output_value, input_value ), == , 0 ); /* old value removed */ - kvp_value_delete( input_value ); - - g_test_message( "Test when existing path elements are not frames" ); - path_list = g_slist_append( path_list, "test2"); - input_value = kvp_value_new_string( "abcdefghijklmnop" ); - kvp_frame_set_slot_path_gslist( fixture->frame, input_value, path_list ); - g_assert( kvp_frame_get_slot_path( fixture->frame, "test2", NULL ) == NULL );/* was not added */ - g_assert_cmpint( kvp_value_compare( output_value, kvp_frame_get_slot_path( fixture->frame, "test", NULL ) ), == , 0 ); /* nothing changed */ - kvp_value_delete( input_value ); - - g_test_message( "Test frames are created along the path when needed" ); - path_list = g_slist_remove( path_list, "test" ); - path_list = g_slist_append( path_list, "test3"); - input_value = kvp_value_new_string( "abcdefghijklmnop" ); - kvp_frame_set_slot_path_gslist( fixture->frame, input_value, path_list ); - output_value = kvp_frame_get_slot_path( fixture->frame, "test2", NULL ); - g_assert( output_value ); - g_assert( kvp_value_get_type( output_value ) == KVP_TYPE_FRAME ); - output_value = kvp_frame_get_slot_path( fixture->frame, "test2", "test3", NULL ); - g_assert( output_value ); - g_assert( input_value != output_value ); /* copied */ - g_assert_cmpint( kvp_value_compare( output_value, input_value ), == , 0 ); - kvp_value_delete( input_value ); - - g_slist_free( path_list ); -} - -static void -test_kvp_frame_replace_slot_nc( Fixture *fixture, gconstpointer pData ) -{ - KvpValue *orig_value, *orig_value2; - const char ** keys; - /* test indirectly static function kvp_frame_replace_slot_nc */ - g_assert( fixture->frame ); - g_assert( kvp_frame_is_empty( fixture->frame ) ); - - g_test_message( "Test when new value is created frame hash init and value stored in hash" ); - orig_value = kvp_value_new_gint64( 2 ); - kvp_frame_set_slot( fixture->frame, "test", orig_value ); - g_assert( !kvp_frame_is_empty( fixture->frame ) ); - keys = kvp_frame_get_keys( fixture->frame ); - g_assert( keys ); - g_assert( !keys[1] ); - g_assert( orig_value != kvp_frame_get_value( fixture->frame, keys[0] ) ); - g_assert_cmpint( kvp_value_compare( kvp_frame_get_value( fixture->frame, keys[0] ), orig_value ), ==, 0 ); - g_free( keys ); - - g_test_message( "Test when value is replaced" ); - orig_value2 = kvp_value_new_gint64( 5 ); - kvp_frame_set_slot( fixture->frame, "test", orig_value2 ); - keys = kvp_frame_get_keys( fixture->frame ); - g_assert( keys ); - g_assert( !keys[1] ); - g_assert( orig_value != kvp_frame_get_value( fixture->frame, keys[0] ) ); - g_assert_cmpint( kvp_value_compare( kvp_frame_get_value( fixture->frame, keys[0] ), orig_value2 ), ==, 0 ); - g_assert_cmpint( kvp_value_compare( kvp_frame_get_value( fixture->frame, keys[0] ), orig_value ), !=, 0 ); - g_free( keys ); - - kvp_value_delete( orig_value ); - kvp_value_delete( orig_value2 ); -} - -static void -test_get_trailer_make( Fixture *fixture, gconstpointer pData ) -{ - char *last_key = NULL; - KvpValue *frame_value = NULL; - KvpFrame *frame = NULL, *frame2 = NULL; - - g_test_message( "Test null frame and empty string checks" ); - g_assert( p_get_trailer_make( NULL, "test", &last_key ) == NULL ); - g_assert( !last_key ); - g_assert( p_get_trailer_make( fixture->frame, NULL, &last_key ) == NULL ); - g_assert( !last_key ); - g_assert( p_get_trailer_make( fixture->frame, "", &last_key ) == NULL ); - g_assert( !last_key ); - - g_test_message( "Test single frame on the path with no slash" ); - g_assert( p_get_trailer_make( fixture->frame, "test", &last_key ) == fixture->frame ); - g_assert_cmpstr( last_key, == , "test" ); - - g_test_message( "Test single frame on the path with slash" ); - last_key = NULL; - g_assert( p_get_trailer_make( fixture->frame, "/test", &last_key ) == fixture->frame ); - g_assert_cmpstr( last_key, == , "test" ); - - g_test_message( "Test path of trailing slash" ); - last_key = NULL; - g_assert( p_get_trailer_make( fixture->frame, "test/", &last_key ) == NULL ); - g_assert( !last_key ); - - g_test_message( "Test path of two entries: frame for test should be created" ); - /* test is considered to be last frame on the path - * and it is returned. Currently it doesn't exist and will be created - * test2 is stripped away and returned as last entry of the path - */ - last_key = NULL; - frame = p_get_trailer_make( fixture->frame, "/test/test2", &last_key ); - g_assert( frame ); - g_assert( frame != fixture->frame ); - frame_value = kvp_frame_get_slot( fixture->frame, "test" ); - g_assert( frame_value ); - g_assert( kvp_value_get_frame( frame_value ) == frame ); - frame_value = kvp_frame_get_slot( frame, "test2" ); - g_assert( !frame_value ); - g_assert_cmpstr( last_key, == , "test2" ); - - g_test_message( "Test path of two entries: test frame already exist" ); - /* here test frame already exist and should be returned - */ - last_key = NULL; - g_assert( frame == p_get_trailer_make( fixture->frame, "/test/test2", &last_key ) ); - g_assert_cmpstr( last_key, == , "test2" ); - - g_test_message( "Test path of three entries: neither frame exist" ); - /* test3 and test4 frames will be created. test4 will be created inside test3 frame - * while test3 inside fixture->frame. test4 will be returned - * test5 stripped away and returned in last_key - */ - last_key = NULL; - frame = p_get_trailer_make( fixture->frame, "/test3/test4/test5", &last_key ); - g_assert( frame ); - g_assert( frame != fixture->frame ); - frame_value = kvp_frame_get_slot( fixture->frame, "test3" ); - g_assert( frame_value ); - frame2 = kvp_value_get_frame( frame_value ); - g_assert( frame2 != frame ); - g_assert( frame2 != fixture->frame ); - frame_value = kvp_frame_get_slot( frame2, "test4" ); - g_assert( frame_value ); - g_assert( kvp_value_get_frame( frame_value ) == frame ); - frame_value = kvp_frame_get_slot( frame, "test5" ); - g_assert( !frame_value ); - g_assert_cmpstr( last_key, == , "test5" ); -} - -static void -test_kvp_value_glist_to_string( Fixture *fixture, gconstpointer pData ) -{ - /* - * kvp_value_glist_to_string and kvp_value_to_string call each other - */ - GList *value_list = NULL; - gchar *result; - - gnc_numeric gnc_numeric_orig; - GList *list_orig; - KvpFrame *frame_orig; - - gnc_numeric_orig = gnc_numeric_zero(); - list_orig = NULL; - list_orig = g_list_append( list_orig, kvp_value_new_string( "abcdefghijklmnop" ) ); - frame_orig = kvp_frame_new(); - - g_test_message( "Test empty list" ); - result = glist_to_string( value_list ); - g_assert_cmpstr( result, == , "" ); - g_free( result ); - - g_test_message( "Test list with simple and complex values" ); - value_list = g_list_append( value_list, kvp_value_new_gint64( 2 ) ); - value_list = g_list_append( value_list, kvp_value_new_double( 3.3 ) ); - value_list = g_list_append( value_list, kvp_value_new_gnc_numeric( gnc_numeric_orig ) ); - value_list = g_list_append( value_list, kvp_value_new_string( "abcdefghijklmnop" ) ); - value_list = g_list_append( value_list, kvp_value_new_glist( list_orig ) ); - value_list = g_list_append( value_list, kvp_value_new_frame( frame_orig ) ); - g_assert( value_list ); - g_assert_cmpint( g_list_length( value_list ), == , 6 ); - result = glist_to_string( value_list ); - - g_assert_cmpstr( result, == , "KVP_VALUE_GLIST([ KVP_VALUE_GINT64(2), KVP_VALUE_DOUBLE(3.3), KVP_VALUE_NUMERIC(0/1), KVP_VALUE_STRING(abcdefghijklmnop), KVP_VALUE_GLIST([ KVP_VALUE_STRING(abcdefghijklmnop), ]), KVP_VALUE_FRAME({\n}\n), ])" ); - g_free( result ); - - kvp_glist_delete( value_list ); -} - -static void -test_get_or_make( Fixture *fixture, gconstpointer pData ) -{ - KvpFrame *test_frame = NULL; - - g_assert( fixture->frame ); - g_assert( kvp_frame_is_empty( fixture->frame ) ); - - g_test_message( "Test new frame is created" ); - test_frame = p_get_or_make( fixture->frame, "test" ); - g_assert( test_frame ); - g_assert( test_frame != fixture->frame ); - g_assert( kvp_frame_get_frame( fixture->frame, "test" ) == test_frame ); - - g_test_message( "Test existing frame is returned" ); - g_assert( test_frame == p_get_or_make( fixture->frame, "test" ) ); - g_assert( kvp_frame_get_frame( fixture->frame, "test" ) == test_frame ); -} - -static void -test_kvp_frame_get_frame_or_null_slash_trash( Fixture *fixture, gconstpointer pData ) -{ - g_test_message( "Test null checks" ); - g_assert( p_kvp_frame_get_frame_or_null_slash_trash( NULL, "test" ) == NULL ); - g_assert( p_kvp_frame_get_frame_or_null_slash_trash( fixture->frame, NULL ) == NULL ); - - g_test_message( "Test single slash and trailing slash path" ); - g_assert( p_kvp_frame_get_frame_or_null_slash_trash( fixture->frame, "/" ) == fixture->frame ); - g_assert( p_kvp_frame_get_frame_or_null_slash_trash( fixture->frame, "////" ) == fixture->frame ); - - g_test_message( "Test non existing path" ); - g_assert( p_kvp_frame_get_frame_or_null_slash_trash( fixture->frame, "/test" ) == NULL ); - - g_test_message( "Test existing path when value is not frame" ); - kvp_frame_set_gint64( fixture->frame, "/test", 2 ); - g_assert( p_kvp_frame_get_frame_or_null_slash_trash( fixture->frame, "/test" ) == NULL ); - - g_test_message( "Test existing path when value is frame" ); - kvp_frame_set_frame( fixture->frame, "/test2", kvp_frame_new() ); - g_assert( p_kvp_frame_get_frame_or_null_slash_trash( fixture->frame, "/test2" ) != NULL ); -} - -static void -test_get_trailer_or_null( Fixture *fixture, gconstpointer pData ) -{ - char *last_key = NULL; - KvpFrame *frame = NULL; - const KvpFrame* frame2 = NULL; - - g_test_message( "Test null frame and empty string checks" ); - g_assert( p_get_trailer_or_null( NULL, "test", &last_key ) == NULL ); - g_assert( !last_key ); - g_assert( p_get_trailer_or_null( fixture->frame, NULL, &last_key ) == NULL ); - g_assert( !last_key ); - g_assert( p_get_trailer_or_null( fixture->frame, "", &last_key ) == NULL ); - g_assert( !last_key ); - - g_test_message( "Test single frame on the path with no slash" ); - g_assert( p_get_trailer_or_null( fixture->frame, "test", &last_key ) == fixture->frame ); - g_assert_cmpstr( last_key, == , "test" ); - - g_test_message( "Test single frame on the path with slash" ); - last_key = NULL; - g_assert( p_get_trailer_or_null( fixture->frame, "/test", &last_key ) == fixture->frame ); - g_assert_cmpstr( last_key, == , "test" ); - - g_test_message( "Test path of trailing slash" ); - last_key = NULL; - g_assert( p_get_trailer_or_null( fixture->frame, "test/", &last_key ) == NULL ); - g_assert( !last_key ); - - g_test_message( "Test with non existing path" ); - last_key = NULL; - g_assert( p_get_trailer_or_null( fixture->frame, "/test/test2", &last_key ) == NULL ); - g_assert_cmpstr( last_key, == , "test2" ); - - g_test_message( "Test with existing path" ); - last_key = NULL; - frame = kvp_frame_new(); - kvp_frame_set_frame( fixture->frame, "/test/test2", frame ); - frame2 = p_get_trailer_or_null( fixture->frame, "/test/test2", &last_key ); - g_assert( kvp_frame_get_frame( fixture->frame, "/test") == frame2 ); - g_assert_cmpstr( last_key, == , "test2" ); -} - -static void -test_kvp_frame_get_gvalue (Fixture *fixture, gconstpointer pData) -{ - KvpFrame *frame = fixture->frame; - GValue *value; - Timespec ts = {1, 1}; - GncGUID *guid = populate_frame (frame); - GDate date; - gchar *log_domain = "qof.kvp"; - gint log_level = G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL; - gchar *msg1 = "[gvalue_from_kvp_value()] Error! Attempt to transfer KvpFrame!"; - gchar *msg2 = "[gvalue_from_kvp_value()] Error! Invalid KVP Transfer Request!"; -#undef _func - TestErrorStruct *check1 = test_error_struct_new (log_domain, log_level, - msg1); - TestErrorStruct *check2 = test_error_struct_new (log_domain, log_level, - msg2); - fixture->hdlrs = test_log_set_fatal_handler (fixture->hdlrs, check1, - (GLogFunc)test_list_handler); - test_add_error (check1); - test_add_error (check2); - - g_date_clear (&date, 1); - g_date_set_dmy (&date, 26, 1, 1957); - - value = kvp_frame_get_gvalue (frame, "gint64-type"); - g_assert (value != NULL); - g_assert (G_VALUE_HOLDS_INT64 (value)); - g_assert_cmpint (g_value_get_int64 (value), ==, 100); - gnc_gvalue_free (value); - - value = kvp_frame_get_gvalue (frame, "double-type"); - g_assert (value != NULL); - g_assert (G_VALUE_HOLDS_DOUBLE (value)); - g_assert_cmpfloat (g_value_get_double (value), ==, 3.14159); - gnc_gvalue_free (value); - - value = kvp_frame_get_gvalue (frame, "numeric-type"); - g_assert (value != NULL); - g_assert_cmpint (G_VALUE_TYPE (value), ==, GNC_TYPE_NUMERIC); - g_assert (gnc_numeric_zero_p (*(gnc_numeric*)g_value_get_boxed (value))); - gnc_gvalue_free (value); - - value = kvp_frame_get_gvalue (frame, "timespec-type"); - g_assert (value != NULL); - g_assert_cmpint (G_VALUE_TYPE (value), ==, GNC_TYPE_TIMESPEC); - g_assert (timespec_equal (&ts, (Timespec*)g_value_get_boxed (value))); - gnc_gvalue_free (value); - - value = kvp_frame_get_gvalue (frame, "string-type"); - g_assert (value != NULL); - g_assert (G_VALUE_HOLDS_STRING (value)); - g_assert_cmpstr (g_value_get_string (value), ==, "abcdefghijklmnop"); - gnc_gvalue_free (value); - - value = kvp_frame_get_gvalue (frame, "guid-type"); - g_assert (value != NULL); - g_assert_cmpint (G_VALUE_TYPE (value), ==, GNC_TYPE_GUID); - g_assert (guid_equal (guid, (GncGUID*)g_value_get_boxed (value))); - gnc_gvalue_free (value); - - value = kvp_frame_get_gvalue (frame, "gdate-type"); - g_assert (value != NULL); - g_assert_cmpint (G_VALUE_TYPE (value), ==, G_TYPE_DATE); - g_assert_cmpint (g_date_compare (&date, (GDate*)g_value_get_boxed (value)), ==, 0); - gnc_gvalue_free (value); - - value = kvp_frame_get_gvalue (frame, "frame-type"); - g_assert (value == NULL); - g_assert_cmpint (check1->hits, ==, 1); - g_assert_cmpint (check2->hits, ==, 1); - - value = kvp_frame_get_gvalue (frame, "list-type"); - g_assert (value != NULL); - g_assert_cmpint (G_VALUE_TYPE (value), ==, GNC_TYPE_VALUE_LIST); - { - GList *list = (GList*)g_value_get_boxed (value); - GValue *value = NULL; - - value = (GValue*)(list->data); - g_assert (G_VALUE_HOLDS_INT64 (value)); - g_assert (g_value_get_int64 (value) == 0x1f2e3d4c5b6a79LL); - list = g_list_next (list); - - value = (GValue*)(list->data); - g_assert (G_VALUE_HOLDS_DOUBLE (value)); - g_assert_cmpfloat (g_value_get_double (value), ==, 0.4342944819); - list = g_list_next (list); - - value = (GValue*)(list->data); - g_assert_cmpint (G_VALUE_TYPE (value), ==, GNC_TYPE_NUMERIC); - g_assert (gnc_numeric_eq (*(gnc_numeric*)g_value_get_boxed (value), - gnc_numeric_create (256, 120))); - list = g_list_next (list); - - value = (GValue*)(list->data); - g_assert_cmpint (G_VALUE_TYPE (value), ==, GNC_TYPE_TIMESPEC); - g_assert (timespec_equal (&ts, (Timespec*)g_value_get_boxed (value))); - list = g_list_next (list); - - value = (GValue*)(list->data); - g_assert (G_VALUE_HOLDS_STRING (value)); - g_assert_cmpstr (g_value_get_string (value), ==, "qrstuvwxyz"); - list = g_list_next (list); - - value = (GValue*)(list->data); - g_assert_cmpint (G_VALUE_TYPE (value), ==, GNC_TYPE_GUID); - g_assert (guid_equal (guid, (GncGUID*)g_value_get_boxed (value))); - list = g_list_next (list); - - g_assert (list == NULL); - - } - gnc_gvalue_free (value); -} - -static void -test_kvp_frame_set_gvalue (Fixture *fixture, gconstpointer pData) -{ -/* Bit of a shortcut: We'll use kvp_frame_get_item to make our KvpItem - * and feed it into a new frame; something of a round-trip test. - */ - KvpFrame *o_frame = fixture->frame; - KvpFrame *n_frame = kvp_frame_new (); - GValue *value; - GList *o_list, *n_list; - - populate_frame (o_frame); - - value = kvp_frame_get_gvalue (o_frame, "gint64-type"); - g_assert (value != NULL); - kvp_frame_set_gvalue (n_frame, "gint64-type", value); - g_assert_cmpint (kvp_frame_get_gint64 (o_frame, "gint64-type"), ==, - kvp_frame_get_gint64 (n_frame, "gint64-type")); - - value = kvp_frame_get_gvalue (o_frame, "double-type"); - g_assert (value != NULL); - kvp_frame_set_gvalue (n_frame, "double-type", value); - g_assert_cmpint (kvp_frame_get_double (o_frame, "double-type"), ==, - kvp_frame_get_double (n_frame, "double-type")); - - value = kvp_frame_get_gvalue (o_frame, "numeric-type"); - g_assert (value != NULL); - kvp_frame_set_gvalue (n_frame, "numeric-type", value); - g_assert (gnc_numeric_equal (kvp_frame_get_numeric (o_frame, "numeric-type"), - kvp_frame_get_numeric (n_frame, "numeric-type"))); - - value = kvp_frame_get_gvalue (o_frame, "timespec-type"); - g_assert (value != NULL); - kvp_frame_set_gvalue (n_frame, "timespec-type", value); - { - Timespec o_ts = kvp_frame_get_timespec (o_frame, "timespec-type"); - Timespec n_ts = kvp_frame_get_timespec (n_frame, "timespec-type"); - g_assert (timespec_equal (&o_ts, &n_ts)); - } - - value = kvp_frame_get_gvalue (o_frame, "string-type"); - g_assert (value != NULL); - kvp_frame_set_gvalue (n_frame, "string-type", value); - g_assert_cmpstr (kvp_frame_get_string (o_frame, "string-type"), ==, - kvp_frame_get_string (n_frame, "string-type")); - - value = kvp_frame_get_gvalue (o_frame, "gdate-type"); - g_assert (value != NULL); - kvp_frame_set_gvalue (n_frame, "gdate-type", value); - { - GDate o_date = kvp_value_get_gdate (kvp_frame_get_slot (o_frame, - "gdate-type")); - GDate n_date = kvp_value_get_gdate (kvp_frame_get_slot (n_frame, - "gdate-type")); - g_assert_cmpint (g_date_compare (&o_date, &n_date), ==, 0); - } - - value = kvp_frame_get_gvalue (o_frame, "guid-type"); - g_assert (value != NULL); - kvp_frame_set_gvalue (n_frame, "guid-type", value); - g_assert (guid_equal (kvp_frame_get_guid (o_frame, "guid-type"), - kvp_frame_get_guid (n_frame, "guid-type"))); - - value = kvp_frame_get_gvalue (o_frame, "list-type"); - g_assert (value != NULL); - kvp_frame_set_gvalue (n_frame, "list-type", value); - o_list = kvp_value_get_glist (kvp_frame_get_slot (o_frame, "list_type")); - n_list = kvp_value_get_glist (kvp_frame_get_slot (n_frame, "list_type")); - - g_assert_cmpint (g_list_length (o_list), ==, g_list_length (n_list)); - while (o_list && n_list) - { - g_assert_cmpint (kvp_value_compare ((KvpValue*)o_list->data, - (KvpValue*)n_list->data), ==, 0); - o_list = g_list_next (o_list); - n_list = g_list_next (n_list); - } - kvp_frame_delete (n_frame); -} - -static void -test_kvp_frame_get_keys( void ) -{ - KvpFrame * frame = kvp_frame_new(); - const char * key1 = "number one"; - const char * key2 = "number one/number two"; - const char * key3 = "number three"; - const char * val1 = "Value1"; - const char * val2 = "Value2"; - const char * val3 = "Value3"; - unsigned int spot = 0; - const char ** keys; - kvp_frame_set_string(frame, key1, val1); - kvp_frame_set_string(frame, key2, val2); - kvp_frame_set_string(frame, key3, val3); - keys = kvp_frame_get_keys(frame); - - g_assert(keys); - g_assert(keys[spot]); - g_assert(strcmp(keys[spot++], val1)); - g_assert(keys[spot]); - g_assert(strcmp(keys[spot++], val3)); - g_assert(!keys[spot]); - - g_free(keys); - kvp_frame_delete(frame); -} - -void -test_suite_kvp_frame( void ) -{ - GNC_TEST_ADD_FUNC( suitename, "kvp frame new and delete", test_kvp_frame_new_delete ); - GNC_TEST_ADD( suitename, "kvp frame copy", Fixture, NULL, setup, test_kvp_frame_copy, teardown ); - GNC_TEST_ADD( suitename, "kvp frame set foo", Fixture, NULL, setup, test_kvp_frame_set_foo, teardown ); - GNC_TEST_ADD( suitename, "kvp frame get frame slash", Fixture, NULL, setup, test_kvp_frame_get_frame_slash, teardown ); - GNC_TEST_ADD( suitename, "kvp frame get slot path", Fixture, NULL, setup, test_kvp_frame_get_slot_path, teardown ); - GNC_TEST_ADD( suitename, "kvp frame get slot path gslist", Fixture, NULL, setup, test_kvp_frame_get_slot_path_gslist, teardown ); - GNC_TEST_ADD( suitename, "kvp frame add frame nc", Fixture, NULL, setup, test_kvp_frame_add_frame_nc, teardown ); - GNC_TEST_ADD_FUNC( suitename, "kvp value copy", test_kvp_value_copy ); - GNC_TEST_ADD_FUNC( suitename, "kvp glist copy", test_kvp_glist_copy ); - GNC_TEST_ADD_FUNC( suitename, "kvp glist compare", test_kvp_glist_compare ); - GNC_TEST_ADD_FUNC( suitename, "kvp value compare", test_kvp_value_compare ); - GNC_TEST_ADD_FUNC( suitename, "kvp value new foo no copy", test_kvp_value_new_foo_nc ); - GNC_TEST_ADD( suitename, "kvp frame compare", Fixture, NULL, setup, test_kvp_frame_compare, teardown ); - GNC_TEST_ADD_FUNC( suitename, "kvp value to string", test_kvp_value_to_string ); - GNC_TEST_ADD( suitename, "kvp frame to string", Fixture, NULL, setup, test_kvp_frame_to_string, teardown ); - GNC_TEST_ADD( suitename, "kvp frame set slot path", Fixture, NULL, setup, test_kvp_frame_set_slot_path, teardown ); - GNC_TEST_ADD( suitename, "kvp frame set slot path gslist", Fixture, NULL, setup, test_kvp_frame_set_slot_path_gslist, teardown ); - GNC_TEST_ADD( suitename, "kvp frame replace slot nc", Fixture, NULL, setup, test_kvp_frame_replace_slot_nc, teardown ); - GNC_TEST_ADD_FUNC( suitename, "kvp frame get keys", test_kvp_frame_get_keys ); - GNC_TEST_ADD( suitename, "get trailer make", Fixture, NULL, setup_static, test_get_trailer_make, teardown_static ); - GNC_TEST_ADD( suitename, "kvp value glist to string", Fixture, NULL, setup_static, test_kvp_value_glist_to_string, teardown_static ); - GNC_TEST_ADD( suitename, "get or make", Fixture, NULL, setup_static, test_get_or_make, teardown_static ); - GNC_TEST_ADD( suitename, "kvp frame get frame or null slash trash", Fixture, NULL, setup_static, test_kvp_frame_get_frame_or_null_slash_trash, teardown_static ); - GNC_TEST_ADD( suitename, "get trailer or null", Fixture, NULL, setup_static, test_get_trailer_or_null, teardown_static ); - GNC_TEST_ADD ( suitename, "kvp frame get gvalue", Fixture, NULL, setup, test_kvp_frame_get_gvalue, teardown); - GNC_TEST_ADD ( suitename, "kvp frame set gvalue", Fixture, NULL, setup, test_kvp_frame_set_gvalue, teardown); -} diff --git a/src/libqof/qof/test/test-qof.c b/src/libqof/qof/test/test-qof.c index b019e6c975..cd7ce43b4f 100644 --- a/src/libqof/qof/test/test-qof.c +++ b/src/libqof/qof/test/test-qof.c @@ -27,7 +27,6 @@ extern void test_suite_qofbook(); extern void test_suite_qofinstance(); -extern void test_suite_kvp_frame(); extern void test_suite_qofobject(); extern void test_suite_qofsession(); extern void test_suite_gnc_date(); @@ -47,7 +46,6 @@ main (int argc, test_suite_gnc_guid(); test_suite_qofbook(); test_suite_qofinstance(); - test_suite_kvp_frame(); test_suite_qofobject(); test_suite_qofsession(); test_suite_gnc_date(); diff --git a/src/libqof/qof/test/test-qofinstance.c b/src/libqof/qof/test/test-qofinstance.cpp similarity index 93% rename from src/libqof/qof/test/test-qofinstance.c rename to src/libqof/qof/test/test-qofinstance.cpp index ab1e630cfe..a25a9047e6 100644 --- a/src/libqof/qof/test/test-qofinstance.c +++ b/src/libqof/qof/test/test-qofinstance.cpp @@ -19,15 +19,17 @@ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 * * Boston, MA 02110-1301, USA gnu@gnu.org * \********************************************************************/ +extern "C" +{ #include #include #include #include "../qof.h" #include "../qofbackend-p.h" -#include "../kvp_frame.h" - +} +#include "../kvp_frame.hpp" static const gchar *suitename = "/qof/qofinstance"; -void test_suite_qofinstance ( void ); +extern "C" void test_suite_qofinstance ( void ); static gchar* error_message; static gboolean is_called; @@ -56,7 +58,7 @@ fatal_handler ( const char * log_domain, static void setup( Fixture *fixture, gconstpointer pData ) { - fixture->inst = g_object_new(QOF_TYPE_INSTANCE, NULL); + fixture->inst = static_cast(g_object_new(QOF_TYPE_INSTANCE, NULL)); } static void @@ -122,16 +124,16 @@ test_instance_new_destroy( void ) QofInstanceClass *klass; /* test var */ Timespec *timespec_priv; - gchar *msg1 = "qof_instance_get_collection: assertion " _Q "QOF_IS_INSTANCE(ptr)' failed"; - gchar *msg2 = "qof_instance_get_editlevel: assertion " _Q "QOF_IS_INSTANCE(ptr)' failed"; - gchar *msg3 = "qof_instance_get_destroying: assertion " _Q "QOF_IS_INSTANCE(ptr)' failed"; - gchar *msg4 = "qof_instance_get_dirty_flag: assertion " _Q "QOF_IS_INSTANCE(ptr)' failed"; - gchar *log_domain = "qof"; - guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL, hdlr; - TestErrorStruct check = { loglevel, log_domain, msg1 }; + const char *msg1 = "qof_instance_get_collection: assertion " _Q "QOF_IS_INSTANCE(ptr)' failed"; + const char *msg2 = "qof_instance_get_editlevel: assertion " _Q "QOF_IS_INSTANCE(ptr)' failed"; + const char *msg3 = "qof_instance_get_destroying: assertion " _Q "QOF_IS_INSTANCE(ptr)' failed"; + const char *msg4 = "qof_instance_get_dirty_flag: assertion " _Q "QOF_IS_INSTANCE(ptr)' failed"; + const char *log_domain = "qof"; + auto loglevel = static_cast(G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL); + auto check = test_error_struct_new(log_domain, loglevel, msg1); g_test_message( "Testing qofinstance object initialization" ); - inst = g_object_new(QOF_TYPE_INSTANCE, NULL); + inst = static_cast(g_object_new(QOF_TYPE_INSTANCE, NULL)); g_assert( QOF_IS_INSTANCE( inst ) ); /* test class fields */ klass = QOF_INSTANCE_GET_CLASS( inst ); @@ -162,27 +164,31 @@ test_instance_new_destroy( void ) g_assert( !QOF_IS_INSTANCE( inst ) ); /* set fatal handler */ g_test_log_set_fatal_handler ( ( GTestLogFatalFunc )fatal_handler, NULL ); - hdlr = g_log_set_handler (log_domain, loglevel, - (GLogFunc)test_checked_handler, &check); + auto hdlr = g_log_set_handler (log_domain, loglevel, + (GLogFunc)test_checked_handler, check); g_assert( qof_instance_get_collection( inst ) == NULL ); g_assert( g_strrstr( error_message, "assertion " _Q "QOF_IS_INSTANCE(ptr)' failed" ) != NULL ); g_free( error_message ); - check.msg = msg2; + g_free(check->msg); + check->msg = g_strdup(msg2); g_assert_cmpint( qof_instance_get_editlevel( inst ), == , 0 ); g_assert( g_strrstr( error_message, "assertion " _Q "QOF_IS_INSTANCE(ptr)' failed" ) != NULL ); g_free( error_message ); - check.msg = msg3; + g_free(check->msg); + check->msg = g_strdup(msg3); g_assert( !qof_instance_get_destroying( inst ) ); g_assert( g_strrstr( error_message, "assertion " _Q "QOF_IS_INSTANCE(ptr)' failed" ) != NULL ); g_free( error_message ); - check.msg = msg4; + g_free(check->msg); + check->msg = g_strdup(msg4); g_assert( !qof_instance_get_dirty_flag( inst ) ); g_assert( g_strrstr( error_message, "assertion " _Q "QOF_IS_INSTANCE(ptr)' failed" ) != NULL ); g_free( error_message ); g_log_remove_handler (log_domain, hdlr); + test_error_struct_free(check); } static void @@ -197,7 +203,7 @@ test_instance_init_data( void ) char guid_id_after[GUID_ENCODING_LENGTH + 1]; /* set up */ - inst = g_object_new( QOF_TYPE_INSTANCE, NULL ); + inst = static_cast(g_object_new( QOF_TYPE_INSTANCE, NULL )); g_assert( QOF_IS_INSTANCE( inst ) ); book = qof_book_new(); g_assert( QOF_IS_BOOK( book ) ); @@ -244,7 +250,7 @@ test_instance_get_set_slots( Fixture *fixture, gconstpointer pData ) g_assert( qof_instance_get_dirty_flag( fixture->inst ) ); g_test_message( "Test when kvp frame is not the same" ); - kvp_frame2 = kvp_frame_new(); + kvp_frame2 = new KvpFrame; g_assert( kvp_frame != kvp_frame2 ); qof_instance_set_slots( fixture->inst, kvp_frame2 ); g_assert( kvp_frame2 == qof_instance_get_slots( fixture->inst ) ); @@ -265,8 +271,8 @@ test_instance_version_cmp( void ) Timespec timespec_left, timespec_right; /* set up*/ - left = g_object_new( QOF_TYPE_INSTANCE, NULL ); - right = g_object_new( QOF_TYPE_INSTANCE, NULL ); + left = static_cast(g_object_new( QOF_TYPE_INSTANCE, NULL )); + right = static_cast(g_object_new( QOF_TYPE_INSTANCE, NULL )); g_test_message( "Test both null" ); result = qof_instance_version_cmp( NULL, NULL ); @@ -498,10 +504,10 @@ static void test_instance_commit_edit( Fixture *fixture, gconstpointer pData ) { gboolean result; - gchar *msg = "[qof_commit_edit()] unbalanced call - resetting (was -2)"; - gchar *log_domain = "qof.engine"; - guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL, hdlr; - TestErrorStruct check = { loglevel, log_domain, msg }; + const gchar *msg = "[qof_commit_edit()] unbalanced call - resetting (was -2)"; + const gchar *log_domain = "qof.engine"; + auto loglevel = static_cast(G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL); + auto check = test_error_struct_new(log_domain, loglevel, msg); g_test_message( "Test when instance set to null" ); result = qof_commit_edit( NULL ); @@ -522,8 +528,8 @@ test_instance_commit_edit( Fixture *fixture, gconstpointer pData ) g_test_message( "Test when instance's editlevel < 0" ); g_test_log_set_fatal_handler ( ( GTestLogFatalFunc )fatal_handler, NULL ); - hdlr = g_log_set_handler (log_domain, loglevel, - (GLogFunc)test_checked_handler, &check); + auto hdlr = g_log_set_handler (log_domain, loglevel, + (GLogFunc)test_checked_handler, check); qof_instance_decrease_editlevel( fixture->inst ); g_assert_cmpint( qof_instance_get_editlevel( fixture->inst ), == , -1 ); result = qof_commit_edit( fixture->inst ); @@ -531,6 +537,7 @@ test_instance_commit_edit( Fixture *fixture, gconstpointer pData ) g_assert_cmpstr( error_message, == , "[qof_commit_edit()] unbalanced call - resetting (was -2)" ); g_free( error_message ); g_log_remove_handler (log_domain, hdlr); + test_error_struct_free(check); } /* backend commit test start */ @@ -728,7 +735,7 @@ test_instance_refers_to_object( Fixture *fixture, gconstpointer pData ) { QofInstance * ref; - ref = g_object_new( QOF_TYPE_INSTANCE, NULL ); + ref = static_cast(g_object_new( QOF_TYPE_INSTANCE, NULL )); g_assert( fixture->inst ); g_assert( ref ); g_assert( QOF_INSTANCE_GET_CLASS( fixture->inst )->refers_to_object == NULL ); @@ -784,7 +791,7 @@ test_instance_get_referring_object_list_from_collection( void ) book = qof_book_new(); g_assert( book ); g_assert( QOF_IS_BOOK( book ) ); - ref = g_object_new( QOF_TYPE_INSTANCE, NULL ); + ref = static_cast(g_object_new( QOF_TYPE_INSTANCE, NULL )); g_assert( ref ); g_assert( QOF_IS_INSTANCE( ref ) ); QOF_INSTANCE_GET_CLASS( ref )->refers_to_object = NULL; @@ -795,7 +802,7 @@ test_instance_get_referring_object_list_from_collection( void ) */ for (i = 0; i < list_length; i++ ) { - QofInstance *inst = g_object_new( QOF_TYPE_INSTANCE, NULL ); + auto inst = static_cast(g_object_new( QOF_TYPE_INSTANCE, NULL )); g_assert( inst ); qof_instance_init_data( inst, type, book ); inst_list = g_list_append ( inst_list, inst ); @@ -860,8 +867,8 @@ test_instance_get_typed_referring_object_list( void ) GList* result = NULL; /* setup */ - inst = g_object_new( QOF_TYPE_INSTANCE, NULL ); - ref = g_object_new( QOF_TYPE_INSTANCE, NULL ); + inst = static_cast(g_object_new( QOF_TYPE_INSTANCE, NULL )); + ref = static_cast(g_object_new( QOF_TYPE_INSTANCE, NULL )); book = qof_book_new(); g_assert( inst ); g_assert( ref ); @@ -945,9 +952,9 @@ test_instance_get_referring_object_list( void ) book = qof_book_new(); g_assert( book ); g_assert( QOF_IS_BOOK( book ) ); - ref1 = g_object_new( QOF_TYPE_INSTANCE, NULL ); + ref1 = static_cast(g_object_new( QOF_TYPE_INSTANCE, NULL )); g_assert( ref1 ); - ref2 = g_object_new( QOF_TYPE_INSTANCE, NULL ); + ref2 = static_cast(g_object_new( QOF_TYPE_INSTANCE, NULL )); g_assert( ref2 ); qof_instance_init_data( ref1, type1, book ); qof_instance_init_data( ref2, type2, book ); @@ -963,7 +970,7 @@ test_instance_get_referring_object_list( void ) */ for (i = 0; i < col1_length; i++ ) { - QofInstance *inst = g_object_new( QOF_TYPE_INSTANCE, NULL ); + auto inst = static_cast(g_object_new( QOF_TYPE_INSTANCE, NULL )); g_assert( inst ); qof_instance_init_data( inst, type1, book ); inst_list1 = g_list_append ( inst_list1, inst ); @@ -974,7 +981,7 @@ test_instance_get_referring_object_list( void ) for (j = 0; j < col2_length; j++ ) { - QofInstance *inst = g_object_new( QOF_TYPE_INSTANCE, NULL ); + auto inst = static_cast(g_object_new( QOF_TYPE_INSTANCE, NULL )); g_assert( inst ); qof_instance_init_data( inst, type2, book ); inst_list2 = g_list_append ( inst_list2, inst ); @@ -1046,7 +1053,7 @@ test_instance_get_referring_object_list( void ) qof_book_destroy( book ); } -void +extern "C" void test_suite_qofinstance ( void ) { GNC_TEST_ADD( suitename, "set get book", Fixture, NULL, setup, test_instance_set_get_book, teardown ); diff --git a/src/test-core/test-stuff.h b/src/test-core/test-stuff.h index 8ef9d4b90a..c7fa548fd6 100644 --- a/src/test-core/test-stuff.h +++ b/src/test-core/test-stuff.h @@ -37,21 +37,6 @@ Otherwise, only failures are printed out. #include #include -/** - * Use this to indicate the result of a test. - * The result is TRUE for success, FALSE for failure. - * title describes the test - * Tests are automatically identified by their source file and line. - */ -#define do_test( result, title ) do_test_call( result, title, __FILE__, __LINE__ ) -#define success( title ) success_call( title, __FILE__, __LINE__ ); -#define failure( title ) failure_call( title, __FILE__, __LINE__ ); - -/** This one doesn't work because macros can't take a variable number of arguments. - * well, apparently gcc can, but it's non-standard. - * Apparently C99 can, too, but it's not exactly standard either. -#define do_test_args( result, title, format ) do_test_call( result, title, __FILE__, __LINE__, format, ... ); -*/ /* Privately used to indicate a test result. You may use these if you @@ -117,6 +102,22 @@ void failure_args( const char *format, ... ); +/** + * Use this to indicate the result of a test. + * The result is TRUE for success, FALSE for failure. + * title describes the test + * Tests are automatically identified by their source file and line. + */ +#define do_test( result, title ) do_test_call( result, title, __FILE__, __LINE__ ) +#define success( title ) success_call( title, __FILE__, __LINE__ ); +#define failure( title ) failure_call( title, __FILE__, __LINE__ ); + +/** This one doesn't work because macros can't take a variable number of arguments. + * well, apparently gcc can, but it's non-standard. + * Apparently C99 can, too, but it's not exactly standard either. +#define do_test_args( result, title, format ) do_test_call( result, title, __FILE__, __LINE__, format, ... ); +*/ + gboolean get_random_boolean(void); gint get_random_int_in_range(int start, int end); void random_character_include_funky_chars (gboolean use_funky_chars); diff --git a/src/test-core/unittest-support.c b/src/test-core/unittest-support.c index 8e257ba947..86cbe44ca1 100644 --- a/src/test-core/unittest-support.c +++ b/src/test-core/unittest-support.c @@ -29,7 +29,7 @@ typedef struct { gpointer data; gboolean called; - gchar *msg; + char *msg; } TestStruct; static TestStruct tdata; @@ -41,7 +41,8 @@ test_list_nohit_handler (const char *log_domain, GLogLevelFlags log_level, const gchar *msg, gpointer user_data); TestErrorStruct* -test_error_struct_new (gchar *log_domain, GLogLevelFlags log_level, gchar *msg) +test_error_struct_new (const char *log_domain, GLogLevelFlags log_level, + const char *msg) { TestErrorStruct *err = g_slice_new0 (TestErrorStruct); err->log_domain = g_strdup (log_domain); diff --git a/src/test-core/unittest-support.h b/src/test-core/unittest-support.h index fa4d07bbf6..9d6ded8a2c 100644 --- a/src/test-core/unittest-support.h +++ b/src/test-core/unittest-support.h @@ -87,8 +87,8 @@ typedef struct { GLogLevelFlags log_level; - gchar *log_domain; - gchar *msg; + char *log_domain; + char *msg; guint hits; } TestErrorStruct; @@ -105,9 +105,9 @@ typedef struct * @param msg: The exact error message that the logger will emit * @return: A TestErrorStruct * */ -TestErrorStruct* test_error_struct_new (gchar *log_domain, - GLogLevelFlags log_level, - gchar *msg); +TestErrorStruct* test_error_struct_new (const char *log_domain, + const GLogLevelFlags log_level, + const char *msg); /** * Free a TestErrorStruct created with test_error_struct_new