mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Convert tests to C++ and the KVP C++ API.
This commit is contained in:
parent
fd935d3b82
commit
3590de1085
@ -0,0 +1,41 @@
|
||||
From b9de55c8711b07c0fdf83d9838c8a5d65222e887 Mon Sep 17 00:00:00 2001
|
||||
From: John Ralls <jralls@ceridwen.us>
|
||||
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 <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#ifdef MAC_INTEGRATION
|
||||
-#include <gtkmacintegration-gtk2/gtkosxapplication.h>
|
||||
+#include <gtkmacintegration/gtkosxapplication.h>
|
||||
#endif
|
||||
#endif /* ENABLE_BINRELOC */
|
||||
#include <stdio.h>
|
||||
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 <gtkmacintegration-gtk2/gtkosxapplication.h>
|
||||
+#include <gtkmacintegration/gtkosxapplication.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
# include <sys/types.h>
|
||||
--
|
||||
2.2.2
|
||||
|
@ -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 \
|
||||
|
@ -21,17 +21,19 @@
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
********************************************************************/
|
||||
|
||||
#include <kvp_frame.hpp>
|
||||
#include <gmp.h>
|
||||
extern "C"
|
||||
{
|
||||
#include <config.h>
|
||||
#include <glib.h>
|
||||
#include <unittest-support.h>
|
||||
#include <qofbookslots.h>
|
||||
#include <kvp_frame.h>
|
||||
|
||||
#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<const char*>(), == , "t");
|
||||
g_assert_cmpstr (slots->get_slot("options/Accounts/Use Split Action Field for Number")->get<const char*>(), == , "t");
|
||||
g_assert_cmpstr (slots->get_slot("options/Business/Company Name")->get<const char*>(), ==, "Bogus Company");
|
||||
g_assert_cmpfloat (slots->get_slot("options/Accounts/Day Threshold for Read-Only Transactions (red line)")->get<double>(), ==, 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);
|
@ -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"
|
||||
|
@ -4,7 +4,10 @@
|
||||
* Created on: 2011-04-23
|
||||
* Author: phil
|
||||
*/
|
||||
#include <kvp_frame.hpp>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "config.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -12,7 +15,6 @@
|
||||
#include <glib/gstdio.h>
|
||||
|
||||
#include <qof.h>
|
||||
#include <kvp_frame.h>
|
||||
#include <unittest-support.h>
|
||||
#include <test-stuff.h>
|
||||
#include <test-dbi-stuff.h>
|
||||
@ -34,6 +36,7 @@
|
||||
/* For version_control */
|
||||
#include <gnc-prefs.h>
|
||||
#include <qofsession-p.h>
|
||||
}
|
||||
|
||||
#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<GncGUID*>(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<GLogLevelFlags>(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<const char*>(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<GLogLevelFlags>(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<GLogLevelFlags>(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<GLogLevelFlags>(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;
|
@ -22,10 +22,10 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include <config.h>
|
||||
#include <qof.h>
|
||||
#include <kvp_frame.h>
|
||||
#include <qofsession-p.h>
|
||||
#include <cashobjects.h>
|
||||
#include <test-dbi-stuff.h>
|
||||
@ -38,6 +38,9 @@
|
||||
#include <SX-book.h>
|
||||
#include <gnc-lot.h>
|
||||
#include "../gnc-backend-dbi-priv.h"
|
||||
}
|
||||
|
||||
#include <kvp_frame.hpp>
|
||||
|
||||
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<SchedXaction*>(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<Recurrence*>(ritem1->data);
|
||||
auto r2 = static_cast<Recurrence*>(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<Split*>(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<const char*>(iter->data));
|
||||
g_assert (DBI_ERROR_NONE == dbi_conn_error( conn->conn, &errmsg));
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -20,7 +20,10 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
#include <kvp_frame.hpp>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "config.h"
|
||||
|
||||
#include <unistd.h>
|
||||
@ -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<xmlNodePtr>(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;
|
||||
}
|
||||
}
|
@ -4,17 +4,19 @@
|
||||
|
||||
#ifndef TEST_FILE_STUFF_H
|
||||
#define TEST_FILE_STUFF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
#include <glib.h>
|
||||
|
||||
#include <kvp_frame.h>
|
||||
#include <gnc-commodity.h>
|
||||
#include <gnc-engine.h>
|
||||
#include <gnc-xml-helper.h>
|
||||
#include <io-gncxml-gen.h>
|
||||
#include <sixtp.h>
|
||||
|
||||
|
||||
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
|
||||
|
@ -1,227 +0,0 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#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());
|
||||
}
|
196
src/backend/xml/test/test-kvp-frames.cpp
Normal file
196
src/backend/xml/test/test-kvp-frames.cpp
Normal file
@ -0,0 +1,196 @@
|
||||
#include <kvp_frame.hpp>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#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<QofInstance *>(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());
|
||||
}
|
@ -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 \
|
||||
|
@ -15,6 +15,10 @@
|
||||
* Created by Linux Developers Group, 2001
|
||||
* Updates Linas Vepstas July 2004
|
||||
*/
|
||||
#include <kvp_frame.hpp>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "config.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -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<KvpValueType>(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<KvpValueType>(get_random_int_in_range(KVP_TYPE_GINT64, KVP_TYPE_FRAME - 1));
|
||||
}
|
||||
|
||||
else
|
||||
datype = static_cast<KvpValueType>(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<char*>(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<gnc_commodity*>(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<const char *>(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<gnc_commodity *>(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<GList**>(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<GNCPrice *>(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<Account*>(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<Account*>(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<Account*>(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<Split *>(node->data);
|
||||
auto account = static_cast<Account*>(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<Split *>(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<GList **>(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<Account*>(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<Account *>(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<TransInfo *>(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<TransInfo *>(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<Account*>(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<Split *>(node->data);
|
||||
|
||||
do
|
||||
{
|
||||
new_account = get_random_list_element (accounts);
|
||||
new_account = static_cast<Account*>(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<Account*>(get_random_list_element (accounts));
|
||||
|
||||
if (get_random_boolean ())
|
||||
a2 = get_random_list_element (accounts);
|
||||
a2 = static_cast<Account*>(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<GNCAccountType>(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<GNCAccountType>(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<char*>(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<char*>(TRANS_DATE_POSTED));
|
||||
p1 = g_slist_prepend (p1, const_cast<char*>(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<char*>(TRANS_DATE_ENTERED));
|
||||
p1 = g_slist_prepend (p1, const_cast<char*>(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<char*>(SPLIT_RECONCILE));
|
||||
p2 = g_slist_prepend (p2, const_cast<char*>(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<char*>(TRANS_NUM));
|
||||
p1 = g_slist_prepend (p1, const_cast<char*>(SPLIT_TRANS));
|
||||
p2 = standard;
|
||||
break;
|
||||
case BY_AMOUNT:
|
||||
p1 = g_slist_prepend (p1, SPLIT_VALUE);
|
||||
p1 = g_slist_prepend (p1, const_cast<char*>(SPLIT_VALUE));
|
||||
p2 = standard;
|
||||
break;
|
||||
case BY_MEMO:
|
||||
p1 = g_slist_prepend (p1, SPLIT_MEMO);
|
||||
p1 = g_slist_prepend (p1, const_cast<char*>(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<char*>(TRANS_DESCRIPTION));
|
||||
p1 = g_slist_prepend (p1, const_cast<char*>(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 <typename T> inline T
|
||||
compare_param(int max)
|
||||
{
|
||||
auto ret = get_random_int_in_range (max == 1 ? 0 : 1, max);
|
||||
return static_cast<T>(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<QofGuidMatch>(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<QofQueryCompare>(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<QofQueryCompare> (1),
|
||||
get_random_queryop ());
|
||||
break;
|
||||
|
||||
case 4: /* PR_CLEARED */
|
||||
xaccQueryAddClearedMatch
|
||||
(q,
|
||||
get_random_int_in_range (1,
|
||||
static_cast<cleared_match_t>(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<QofQueryCompare>(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<QofQueryCompare>(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<QofQueryCompare>(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<QofQueryCompare> (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<QofQueryCompare> (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<QofNumericMatch> (QOF_NUMERIC_MATCH_ANY),
|
||||
compare_param<QofQueryCompare> (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<sort_type_t>(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<Split * >(node->data);
|
||||
list = g_list_prepend (list, xaccSplitGetAccount (split));
|
||||
}
|
||||
xaccQueryAddAccountMatch (q, list, QOF_GUID_MATCH_ALL, QOF_QUERY_AND);
|
@ -4,7 +4,10 @@
|
||||
|
||||
#ifndef TEST_ENGINE_STUFF_H
|
||||
#define TEST_ENGINE_STUFF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
#include <glib.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
@ -26,7 +26,6 @@ extern "C"
|
||||
#include "../Account.h"
|
||||
#include <qof.h>
|
||||
#include <qofinstance-p.h>
|
||||
#include <kvp_frame.h>
|
||||
|
||||
struct GncImportMatchMap
|
||||
{
|
||||
@ -48,6 +47,7 @@ extern void gnc_imap_add_account_bayes (GncImportMatchMap *imap,
|
||||
Account *acc);
|
||||
}
|
||||
|
||||
#include <kvp_frame.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
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<GncGUID*>(xaccAccountGetGUID(t_expense_account1)));
|
||||
auto acc2_val = new KvpValue(const_cast<GncGUID*>(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<GncGUID*>(), 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<const char*>(), this->t_imap->book); };
|
||||
value = root->get_slot({IMAP_FRAME_BAYES, foo, acct1_name});
|
||||
EXPECT_EQ(1, value->get<int64_t>());
|
||||
value = root->get_slot({IMAP_FRAME_BAYES, bar, acct1_name});
|
||||
EXPECT_EQ(1, value->get<int64_t>());
|
||||
value = root->get_slot({IMAP_FRAME_BAYES, baz, acct2_name});
|
||||
EXPECT_EQ(1, value->get<int64_t>());
|
||||
value = root->get_slot({IMAP_FRAME_BAYES, waldo, acct2_name});
|
||||
EXPECT_EQ(1, value->get<int64_t>());
|
||||
value = root->get_slot({IMAP_FRAME_BAYES, pepper, acct1_name});
|
||||
EXPECT_EQ(1, value->get<int64_t>());
|
||||
value = root->get_slot({IMAP_FRAME_BAYES, salt, acct2_name});
|
||||
EXPECT_EQ(1, value->get<int64_t>());
|
||||
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<int64_t>());
|
||||
}
|
||||
|
@ -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 <string.h>
|
||||
#include <glib.h>
|
||||
#include <unittest-support.h>
|
||||
#include <gnc-event.h>
|
||||
#include <gnc-gdate-utils.h>
|
||||
#include <kvp_frame.h>
|
||||
#include <qofinstance-p.h>
|
||||
/* 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 <kvp_frame.hpp>
|
||||
|
||||
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<const SetupData*>(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<char*>(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<Account*>(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<char*>(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<char*>(node->data));
|
||||
else
|
||||
{
|
||||
gchar *tmp_list = g_strconcat ( account_list, "\n",
|
||||
node->data, NULL);
|
||||
auto tmp_list = g_strconcat ( account_list, "\n",
|
||||
static_cast<char*>(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<GLogLevelFlags>(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<Account*>(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<GLogLevelFlags>(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<GLogLevelFlags>(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<GLogLevelFlags>(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<GLogLevelFlags>(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<GLogLevelFlags>(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<GLogLevelFlags>(G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL);
|
||||
auto loglevelw = static_cast<GLogLevelFlags>(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<GLogLevelFlags>(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<char**>(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<char**>(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<char**>(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<Account*>(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<Account*>(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<unsigned int *>(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<GNCAccountType>;
|
||||
if (x < ACCT_TYPE_LAST)
|
||||
x = static_cast<GNCAccountType>(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<GLogLevelFlags>(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<Account*>(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<GLogLevelFlags>(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<GLogLevelFlags>(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);
|
||||
}
|
||||
|
||||
|
@ -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 <string.h>
|
||||
#include <glib.h>
|
||||
@ -38,7 +35,6 @@ extern "C"
|
||||
#include <TransactionP.h>
|
||||
#include <gnc-lot.h>
|
||||
#include <gnc-event.h>
|
||||
#include <kvp_frame.h>
|
||||
#include <qofinstance-p.h>
|
||||
|
||||
#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 <kvp_frame.hpp>
|
||||
|
||||
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<GncGUID*>(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",
|
||||
|
@ -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 <config.h>
|
||||
#include <string.h>
|
||||
#include <glib.h>
|
||||
@ -33,7 +35,6 @@
|
||||
#include "../gnc-lot.h"
|
||||
#include "../gnc-event.h"
|
||||
#include <qof.h>
|
||||
#include <kvp_frame.h>
|
||||
#include <qofbackend-p.h>
|
||||
|
||||
#ifdef HAVE_GLIB_2_38
|
||||
@ -47,6 +48,9 @@
|
||||
|
||||
static const gchar *suitename = "/engine/Transaction";
|
||||
void test_suite_transaction ( void );
|
||||
}
|
||||
|
||||
#include <kvp_frame.hpp>
|
||||
|
||||
/* 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<char*>(CACHE_INSERT ("foo"));
|
||||
split1->action = static_cast<char*>(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<char*>(CACHE_INSERT ("123"));
|
||||
txn->description = static_cast<char*>(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<Split*>(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<GLogLevelFlags>(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<Split*>(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<Split*>(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<Split*>(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<Transaction*>(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<Transaction*>(g_object_new (GNC_TYPE_TRANSACTION, "book", book, NULL));
|
||||
auto split = static_cast<Split*>(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<Transaction*>(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<Transaction*>(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<GLogLevelFlags>(G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL);
|
||||
auto loglevel2 =static_cast<GLogLevelFlags>(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<GLogLevelFlags>(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<Split*>(txn->splits->data);
|
||||
auto split2 = static_cast<Split*>(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<Split*>(newnode->data),
|
||||
static_cast<Split*>(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<Split*>(newnode->data),
|
||||
static_cast<Split*>(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<Split*>(txn->splits->data);
|
||||
auto txn_num = "321";
|
||||
g_object_add_weak_pointer (G_OBJECT (txn->splits->data),
|
||||
reinterpret_cast<void**>(&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<char*>(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<GLogLevelFlags>(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<char*>(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<char*>(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<char*>(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<char*>(CACHE_INSERT ("foo"));
|
||||
split1->action = static_cast<char*>(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<char*>(CACHE_INSERT ("foo"));
|
||||
split1->action = static_cast<char*>(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<char*>(CACHE_INSERT ("foo"));
|
||||
split1->action = static_cast<char*>(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<char*>(CACHE_INSERT ("foo"));
|
||||
split2->action = static_cast<char*>(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<char*>(CACHE_INSERT ("foo"));
|
||||
split1->action = static_cast<char*>(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<char*>(CACHE_INSERT ("foo"));
|
||||
split1->action = static_cast<char*>(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<char*>(CACHE_INSERT ("foo"));
|
||||
split2->action = static_cast<char*>(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<GLogLevelFlags>(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<GLogLevelFlags>(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<GLogLevelFlags>(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<Split*>(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<Split*>(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<void**>(&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<GLogLevelFlags>(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<Split*>(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<char*>(CACHE_INSERT ("foo"));
|
||||
split1->action = static_cast<char*>(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<char*>(CACHE_INSERT ("123"));
|
||||
txn->description = static_cast<char*>(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<Split*>(txn->splits->data);
|
||||
auto split_01 = static_cast<Split*>(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<char*>(CACHE_INSERT("321"));
|
||||
txn->description = static_cast<char*>(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<Split*>(orig->splits->data));
|
||||
g_object_ref (split_10);
|
||||
split_11 = xaccDupeSplit(orig->splits->next->data);
|
||||
auto split_11 = xaccDupeSplit(static_cast<Split*>(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<Split*>(txn->splits->data), split_10,
|
||||
FALSE, FALSE, FALSE));
|
||||
g_assert (xaccSplitEqual (static_cast<Split*>(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<GLogLevelFlags>(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<char*>(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<char*>(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<char*>(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<const char*>());
|
||||
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<const char*>(), ==,
|
||||
"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<const char*>(),
|
||||
==, txn_notes);
|
||||
g_assert_cmpstr (frame->get_slot(void_reason_str)->get<const char*>(), ==,
|
||||
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<const char*>(), ==,
|
||||
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<const char*>(),
|
||||
==, "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<const char*>(), ==,
|
||||
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<GncGUID*>(),
|
||||
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<Split*>(orig_splits->data);
|
||||
auto rev_split = static_cast<Split*>(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<Split *>(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<Split *>(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<Split*>(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;
|
@ -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
|
||||
{
|
||||
|
@ -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.
|
||||
|
@ -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 \
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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();
|
||||
|
@ -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 <config.h>
|
||||
#include <glib.h>
|
||||
#include <unittest-support.h>
|
||||
#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<QofInstance*>(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<GLogLevelFlags>(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<QofInstance*>(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<QofInstance*>(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<QofInstance*>(g_object_new( QOF_TYPE_INSTANCE, NULL ));
|
||||
right = static_cast<QofInstance*>(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<GLogLevelFlags>(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<QofInstance*>(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<QofInstance*>(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<QofInstance*>(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<QofInstance*>(g_object_new( QOF_TYPE_INSTANCE, NULL ));
|
||||
ref = static_cast<QofInstance*>(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<QofInstance*>(g_object_new( QOF_TYPE_INSTANCE, NULL ));
|
||||
g_assert( ref1 );
|
||||
ref2 = g_object_new( QOF_TYPE_INSTANCE, NULL );
|
||||
ref2 = static_cast<QofInstance*>(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<QofInstance*>(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<QofInstance*>(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 );
|
@ -37,21 +37,6 @@ Otherwise, only failures are printed out.
|
||||
#include <glib.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user