Account.c to Account.cpp

Since Account.c is now Account.cpp, the function signatures look a bit
different internally. The tests rely on function signatures in error
messages. Instead of trying to figure out what the exact
function signature might be, I use a substring matching strategy to
ensure that the correct error was issued.
This commit is contained in:
lmat 2017-08-14 14:32:45 -04:00
parent 318f7ebc4f
commit eb6c741bf9
20 changed files with 278 additions and 136 deletions

View File

@ -143,6 +143,29 @@ test_clear_error_list (void)
message_queue = NULL; message_queue = NULL;
} }
gboolean
test_list_substring_handler (const char *log_domain, GLogLevelFlags log_level,
const gchar *msg, gpointer user_data)
{
GList *list = g_list_first (message_queue);
const guint fatal = G_LOG_FLAG_FATAL;
while (list)
{
TestErrorStruct *error = (TestErrorStruct*)list->data;
if (!g_strcmp0 (log_domain, error->log_domain)
&& ((log_level | fatal) == (error->log_level | fatal))
&& g_strrstr (msg, error->msg))
{
++(error->hits);
return FALSE;
}
list = g_list_next (list);
}
/* No list or no matches, fall through */
return test_checked_substring_handler (log_domain, log_level, msg, user_data);
}
static gboolean static gboolean
do_test_list_handler (const char *log_domain, GLogLevelFlags log_level, do_test_list_handler (const char *log_domain, GLogLevelFlags log_level,
const gchar *msg, gpointer user_data, gboolean hits) const gchar *msg, gpointer user_data, gboolean hits)
@ -205,6 +228,27 @@ do_test_checked_handler (const char *log_domain, GLogLevelFlags log_level,
} }
gboolean
test_checked_substring_handler (const char *log_domain, GLogLevelFlags log_level,
const gchar *msg, gpointer user_data)
{
TestErrorStruct *tdata = (TestErrorStruct*)user_data;
if ((tdata == NULL)
|| (tdata->log_domain != NULL
&& g_strcmp0 (log_domain, tdata->log_domain))
|| (tdata->log_level && tdata->log_level != log_level)
|| (tdata->msg && !g_strrstr (msg, tdata->msg)))
{
gchar *level = test_log_level (log_level);
g_printf ( "<%s> (%s) %s\n", level, log_domain, msg);
g_free (level);
g_assert (log_level ^ G_LOG_FLAG_FATAL);
return FALSE;
}
++(tdata->hits);
return FALSE;
}
gboolean gboolean
test_checked_handler (const char *log_domain, GLogLevelFlags log_level, test_checked_handler (const char *log_domain, GLogLevelFlags log_level,
const gchar *msg, gpointer user_data ) const gchar *msg, gpointer user_data )

View File

@ -178,6 +178,14 @@ GSList *test_log_set_fatal_handler (GSList *list, TestErrorStruct *error,
*/ */
void test_free_log_handler (gpointer item); void test_free_log_handler (gpointer item);
/**
* Check that the user_data error message is a substring of the
* actual error otherwise assert. Displays the error (and asserts
* if G_LOG_FLAG_FATAL is TRUE) if NULL is passed as user_data,
* but a NULL or 0 value member matches anything.
*/
gboolean test_checked_substring_handler (const char *log_domain, GLogLevelFlags log_level,
const gchar *msg, gpointer user_data);
/** /**
* Check the user_data against the actual error and assert on any * Check the user_data against the actual error and assert on any
* differences. Displays the error (and asserts if G_LOG_FLAG_FATAL * differences. Displays the error (and asserts if G_LOG_FLAG_FATAL
@ -213,6 +221,18 @@ gboolean test_null_handler (const char *log_domain, GLogLevelFlags log_level,
void test_add_error (TestErrorStruct *error); void test_add_error (TestErrorStruct *error);
void test_clear_error_list (void); void test_clear_error_list (void);
/**
* Checks received errors against the list created by
* test_add_error. Rather than checking for an exact match, this function
* checks using a substring match. If the list is empty or nothing
* matches, passes control on to test_checked_substring_handler, giving
* the opportunity for an additional check that's not in the list
* (set user_data to NULL if you want test_checked_handler to
* immediately print the error).
*/
gboolean test_list_substring_handler (const char *log_domain, GLogLevelFlags log_level,
const gchar *msg, gpointer user_data);
/** /**
* Checks received errors against the list created by * Checks received errors against the list created by
* test_add_error. If the list is empty or nothing matches, passes * test_add_error. If the list is empty or nothing matches, passes

View File

@ -39,6 +39,10 @@
#include <glib.h> #include <glib.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @name Character Sets /** @name Character Sets
@{ @{
*/ */
@ -186,6 +190,10 @@ void gnc_gpid_kill(GPid pid);
/** @} */ /** @} */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* GNC_GLIB_UTILS_H */ #endif /* GNC_GLIB_UTILS_H */
/** @} */ /** @} */
/** @} */ /** @} */

View File

@ -171,7 +171,7 @@ gchar *gnc_account_name_violations_errmsg (const gchar *separator, GList* invali
for ( node = invalid_account_names; node; node = g_list_next(node)) for ( node = invalid_account_names; node; node = g_list_next(node))
{ {
if ( !account_list ) if ( !account_list )
account_list = node->data; account_list = static_cast<gchar *>(node->data);
else else
{ {
gchar *tmp_list = NULL; gchar *tmp_list = NULL;
@ -251,9 +251,9 @@ gnc_account_init(Account* acc)
priv->parent = NULL; priv->parent = NULL;
priv->children = NULL; priv->children = NULL;
priv->accountName = CACHE_INSERT(""); priv->accountName = static_cast<char*>(qof_string_cache_insert(""));
priv->accountCode = CACHE_INSERT(""); priv->accountCode = static_cast<char*>(qof_string_cache_insert(""));
priv->description = CACHE_INSERT(""); priv->description = static_cast<char*>(qof_string_cache_insert(""));
priv->type = ACCT_TYPE_NONE; priv->type = ACCT_TYPE_NONE;
@ -473,10 +473,10 @@ gnc_account_set_property (GObject *object,
break; break;
case PROP_TYPE: case PROP_TYPE:
// NEED TO BE CONVERTED TO A G_TYPE_ENUM // NEED TO BE CONVERTED TO A G_TYPE_ENUM
xaccAccountSetType(account, g_value_get_int(value)); xaccAccountSetType(account, static_cast<GNCAccountType>(g_value_get_int(value)));
break; break;
case PROP_COMMODITY: case PROP_COMMODITY:
xaccAccountSetCommodity(account, g_value_get_object(value)); xaccAccountSetCommodity(account, static_cast<gnc_commodity*>(g_value_get_object(value)));
break; break;
case PROP_COMMODITY_SCU: case PROP_COMMODITY_SCU:
xaccAccountSetCommoditySCU(account, g_value_get_int(value)); xaccAccountSetCommoditySCU(account, g_value_get_int(value));
@ -491,19 +491,19 @@ gnc_account_set_property (GObject *object,
gnc_account_set_balance_dirty(account); gnc_account_set_balance_dirty(account);
break; break;
case PROP_START_BALANCE: case PROP_START_BALANCE:
number = g_value_get_boxed(value); number = static_cast<gnc_numeric*>(g_value_get_boxed(value));
gnc_account_set_start_balance(account, *number); gnc_account_set_start_balance(account, *number);
break; break;
case PROP_START_CLEARED_BALANCE: case PROP_START_CLEARED_BALANCE:
number = g_value_get_boxed(value); number = static_cast<gnc_numeric*>(g_value_get_boxed(value));
gnc_account_set_start_cleared_balance(account, *number); gnc_account_set_start_cleared_balance(account, *number);
break; break;
case PROP_START_RECONCILED_BALANCE: case PROP_START_RECONCILED_BALANCE:
number = g_value_get_boxed(value); number = static_cast<gnc_numeric*>(g_value_get_boxed(value));
gnc_account_set_start_reconciled_balance(account, *number); gnc_account_set_start_reconciled_balance(account, *number);
break; break;
case PROP_POLICY: case PROP_POLICY:
gnc_account_set_policy(account, g_value_get_pointer(value)); gnc_account_set_policy(account, static_cast<GNCPolicy*>(g_value_get_pointer(value)));
break; break;
case PROP_MARK: case PROP_MARK:
xaccAccountSetMark(account, g_value_get_int(value)); xaccAccountSetMark(account, g_value_get_int(value));
@ -595,7 +595,7 @@ gnc_account_class_init (AccountClass *klass)
"repeated. but no two accounts that share " "repeated. but no two accounts that share "
"a parent may have the same name.", "a parent may have the same name.",
NULL, NULL,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -606,7 +606,7 @@ gnc_account_class_init (AccountClass *klass)
"all its parent account names to indicate " "all its parent account names to indicate "
"a unique account.", "a unique account.",
NULL, NULL,
G_PARAM_READABLE)); static_cast<GParamFlags>(G_PARAM_READABLE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -618,7 +618,7 @@ gnc_account_class_init (AccountClass *klass)
"be reporting code that is a synonym for " "be reporting code that is a synonym for "
"the accountName.", "the accountName.",
NULL, NULL,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -630,7 +630,7 @@ gnc_account_class_init (AccountClass *klass)
"to be a longer, 1-5 sentence description of " "to be a longer, 1-5 sentence description of "
"what this account is all about.", "what this account is all about.",
NULL, NULL,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -641,7 +641,7 @@ gnc_account_class_init (AccountClass *klass)
"by the user. It is intended to highlight the " "by the user. It is intended to highlight the "
"account based on the users wishes.", "account based on the users wishes.",
NULL, NULL,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -652,7 +652,7 @@ gnc_account_class_init (AccountClass *klass)
"for the user to attach any other text that " "for the user to attach any other text that "
"they would like to associate with the account.", "they would like to associate with the account.",
NULL, NULL,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -665,7 +665,7 @@ gnc_account_class_init (AccountClass *klass)
ACCT_TYPE_NONE, ACCT_TYPE_NONE,
NUM_ACCOUNT_TYPES - 1, NUM_ACCOUNT_TYPES - 1,
ACCT_TYPE_BANK, ACCT_TYPE_BANK,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -676,7 +676,7 @@ gnc_account_class_init (AccountClass *klass)
"'stuff' stored in this account, whether " "'stuff' stored in this account, whether "
"it is USD, gold, stock, etc.", "it is USD, gold, stock, etc.",
GNC_TYPE_COMMODITY, GNC_TYPE_COMMODITY,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -691,7 +691,7 @@ gnc_account_class_init (AccountClass *klass)
0, 0,
G_MAXINT32, G_MAXINT32,
1000000, 1000000,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -704,7 +704,7 @@ gnc_account_class_init (AccountClass *klass)
"mismatched values in older versions of " "mismatched values in older versions of "
"GnuCash.", "GnuCash.",
FALSE, FALSE,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -719,7 +719,7 @@ gnc_account_class_init (AccountClass *klass)
"affect the sort order of the account. Note: " "affect the sort order of the account. Note: "
"This value can only be set to TRUE.", "This value can only be set to TRUE.",
FALSE, FALSE,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -733,7 +733,7 @@ gnc_account_class_init (AccountClass *klass)
"the engine to say a split has been modified. " "the engine to say a split has been modified. "
"Note: This value can only be set to TRUE.", "Note: This value can only be set to TRUE.",
FALSE, FALSE,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -749,7 +749,7 @@ gnc_account_class_init (AccountClass *klass)
"the 'starting balance' will represent the " "the 'starting balance' will represent the "
"summation of the splits up to that date.", "summation of the splits up to that date.",
GNC_TYPE_NUMERIC, GNC_TYPE_NUMERIC,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -766,7 +766,7 @@ gnc_account_class_init (AccountClass *klass)
"balance' will represent the summation of the " "balance' will represent the summation of the "
"splits up to that date.", "splits up to that date.",
GNC_TYPE_NUMERIC, GNC_TYPE_NUMERIC,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -783,7 +783,7 @@ gnc_account_class_init (AccountClass *klass)
"balance' will represent the summation of the " "balance' will represent the summation of the "
"splits up to that date.", "splits up to that date.",
GNC_TYPE_NUMERIC, GNC_TYPE_NUMERIC,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -818,7 +818,7 @@ gnc_account_class_init (AccountClass *klass)
"the starting balance and all reconciled splits " "the starting balance and all reconciled splits "
"in the account.", "in the account.",
GNC_TYPE_NUMERIC, GNC_TYPE_NUMERIC,
G_PARAM_READABLE)); static_cast<GParamFlags>(G_PARAM_READABLE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -826,7 +826,7 @@ gnc_account_class_init (AccountClass *klass)
g_param_spec_pointer ("policy", g_param_spec_pointer ("policy",
"Policy", "Policy",
"The account lots policy.", "The account lots policy.",
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -837,7 +837,7 @@ gnc_account_class_init (AccountClass *klass)
0, 0,
G_MAXINT16, G_MAXINT16,
0, 0,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -847,7 +847,7 @@ gnc_account_class_init (AccountClass *klass)
"Whether the account maps to an entry on an " "Whether the account maps to an entry on an "
"income tax document.", "income tax document.",
FALSE, FALSE,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -859,7 +859,7 @@ gnc_account_class_init (AccountClass *klass)
"United States it is used to transfer totals " "United States it is used to transfer totals "
"into tax preparation software.", "into tax preparation software.",
NULL, NULL,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -868,7 +868,7 @@ gnc_account_class_init (AccountClass *klass)
"Tax Source", "Tax Source",
"This specifies where exported name comes from.", "This specifies where exported name comes from.",
NULL, NULL,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -880,7 +880,7 @@ gnc_account_class_init (AccountClass *klass)
(gint64)1, (gint64)1,
G_MAXINT64, G_MAXINT64,
(gint64)1, (gint64)1,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -890,7 +890,7 @@ gnc_account_class_init (AccountClass *klass)
"Whether the account should be hidden in the " "Whether the account should be hidden in the "
"account tree.", "account tree.",
FALSE, FALSE,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -900,7 +900,7 @@ gnc_account_class_init (AccountClass *klass)
"Whether the account is a placeholder account which does not " "Whether the account is a placeholder account which does not "
"allow transactions to be created, edited or deleted.", "allow transactions to be created, edited or deleted.",
FALSE, FALSE,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -910,7 +910,7 @@ gnc_account_class_init (AccountClass *klass)
"The account filter is a value saved to allow " "The account filter is a value saved to allow "
"filters to be recalled.", "filters to be recalled.",
NULL, NULL,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -920,7 +920,7 @@ gnc_account_class_init (AccountClass *klass)
"The account sort order is a value saved to allow " "The account sort order is a value saved to allow "
"the sort order to be recalled.", "the sort order to be recalled.",
NULL, NULL,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -929,7 +929,7 @@ gnc_account_class_init (AccountClass *klass)
"Account Sort Reversed", "Account Sort Reversed",
"Parameter to store whether the sort order is reversed or not.", "Parameter to store whether the sort order is reversed or not.",
FALSE, FALSE,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -940,7 +940,7 @@ gnc_account_class_init (AccountClass *klass)
(gint64)1, (gint64)1,
G_MAXINT64, G_MAXINT64,
(gint64)1, (gint64)1,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -950,7 +950,7 @@ gnc_account_class_init (AccountClass *klass)
"The online account which corresponds to this " "The online account which corresponds to this "
"account for OFX import", "account for OFX import",
NULL, NULL,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property( g_object_class_install_property(
gobject_class, gobject_class,
@ -959,7 +959,7 @@ gnc_account_class_init (AccountClass *klass)
"Associated income account", "Associated income account",
"Used by the OFX importer.", "Used by the OFX importer.",
GNC_TYPE_GUID, GNC_TYPE_GUID,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -969,7 +969,7 @@ gnc_account_class_init (AccountClass *klass)
"The AqBanking account which corresponds to this " "The AqBanking account which corresponds to this "
"account for AQBanking import", "account for AQBanking import",
NULL, NULL,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
PROP_AB_BANK_CODE, PROP_AB_BANK_CODE,
@ -978,7 +978,7 @@ gnc_account_class_init (AccountClass *klass)
"The online account which corresponds to this " "The online account which corresponds to this "
"account for AQBanking import", "account for AQBanking import",
NULL, NULL,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -989,7 +989,7 @@ gnc_account_class_init (AccountClass *klass)
(gint64)1, (gint64)1,
G_MAXINT64, G_MAXINT64,
(gint64)1, (gint64)1,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, (gobject_class,
@ -999,7 +999,7 @@ gnc_account_class_init (AccountClass *klass)
"The time of the last transaction retrieval for this " "The time of the last transaction retrieval for this "
"account.", "account.",
GNC_TYPE_TIMESPEC, GNC_TYPE_TIMESPEC,
G_PARAM_READWRITE)); static_cast<GParamFlags>(G_PARAM_READWRITE)));
} }
@ -1028,7 +1028,7 @@ static Account *
gnc_coll_get_root_account (QofCollection *col) gnc_coll_get_root_account (QofCollection *col)
{ {
if (!col) return NULL; if (!col) return NULL;
return qof_collection_get_data (col); return static_cast<Account*>(qof_collection_get_data (col));
} }
static void static void
@ -1101,7 +1101,7 @@ xaccMallocAccount (QofBook *book)
g_return_val_if_fail (book, NULL); g_return_val_if_fail (book, NULL);
acc = g_object_new (GNC_TYPE_ACCOUNT, NULL); acc = static_cast<Account*>(g_object_new (GNC_TYPE_ACCOUNT, NULL));
xaccInitAccount (acc, book); xaccInitAccount (acc, book);
qof_event_gen (&acc->inst, QOF_EVENT_CREATE, NULL); qof_event_gen (&acc->inst, QOF_EVENT_CREATE, NULL);
@ -1118,7 +1118,7 @@ gnc_account_create_root (QofBook *book)
rpriv = GET_PRIVATE(root); rpriv = GET_PRIVATE(root);
xaccAccountBeginEdit(root); xaccAccountBeginEdit(root);
rpriv->type = ACCT_TYPE_ROOT; rpriv->type = ACCT_TYPE_ROOT;
CACHE_REPLACE(rpriv->accountName, "Root Account"); qof_string_cache_replace((void const **)(&rpriv->accountName), "Root Account");
mark_account (root); mark_account (root);
xaccAccountCommitEdit(root); xaccAccountCommitEdit(root);
gnc_book_set_root_account(book, root); gnc_book_set_root_account(book, root);
@ -1135,7 +1135,7 @@ xaccCloneAccount(const Account *from, QofBook *book)
g_return_val_if_fail(QOF_IS_BOOK(book), NULL); g_return_val_if_fail(QOF_IS_BOOK(book), NULL);
ENTER (" "); ENTER (" ");
ret = g_object_new (GNC_TYPE_ACCOUNT, NULL); ret = static_cast<Account*>(g_object_new (GNC_TYPE_ACCOUNT, NULL));
g_return_val_if_fail (ret, NULL); g_return_val_if_fail (ret, NULL);
from_priv = GET_PRIVATE(from); from_priv = GET_PRIVATE(from);
@ -1147,9 +1147,9 @@ xaccCloneAccount(const Account *from, QofBook *book)
* Also let caller issue the generate_event (EVENT_CREATE) */ * Also let caller issue the generate_event (EVENT_CREATE) */
priv->type = from_priv->type; priv->type = from_priv->type;
priv->accountName = CACHE_INSERT(from_priv->accountName); priv->accountName = static_cast<char*>(qof_string_cache_insert(from_priv->accountName));
priv->accountCode = CACHE_INSERT(from_priv->accountCode); priv->accountCode = static_cast<char*>(qof_string_cache_insert(from_priv->accountCode));
priv->description = CACHE_INSERT(from_priv->description); priv->description = static_cast<char*>(qof_string_cache_insert(from_priv->description));
qof_instance_copy_kvp (QOF_INSTANCE (ret), QOF_INSTANCE (from)); qof_instance_copy_kvp (QOF_INSTANCE (ret), QOF_INSTANCE (from));
@ -1229,7 +1229,7 @@ xaccFreeAccount (Account *acc)
for (lp = priv->lots; lp; lp = lp->next) for (lp = priv->lots; lp; lp = lp->next)
{ {
GNCLot *lot = lp->data; GNCLot *lot = static_cast<GNCLot*>(lp->data);
gnc_lot_destroy (lot); gnc_lot_destroy (lot);
} }
g_list_free (priv->lots); g_list_free (priv->lots);
@ -1261,15 +1261,16 @@ xaccFreeAccount (Account *acc)
*/ */
} }
CACHE_REPLACE(priv->accountName, NULL); qof_string_cache_remove(priv->accountName);
CACHE_REPLACE(priv->accountCode, NULL); qof_string_cache_remove(priv->accountCode);
CACHE_REPLACE(priv->description, NULL); qof_string_cache_remove(priv->description);
priv->accountName = priv->accountCode = priv->description = nullptr;
/* zero out values, just in case stray /* zero out values, just in case stray
* pointers are pointing here. */ * pointers are pointing here. */
priv->parent = NULL; priv->parent = nullptr;
priv->children = NULL; priv->children = nullptr;
priv->balance = gnc_numeric_zero(); priv->balance = gnc_numeric_zero();
priv->cleared_balance = gnc_numeric_zero(); priv->cleared_balance = gnc_numeric_zero();
@ -1327,7 +1328,7 @@ destroy_pending_splits_for_account(QofInstance *ent, gpointer acc)
Split *split; Split *split;
if (xaccTransIsOpen(trans)) if (xaccTransIsOpen(trans))
while ((split = xaccTransFindSplitByAccount(trans, acc))) while ((split = xaccTransFindSplitByAccount(trans, static_cast<Account*>(acc))))
xaccSplitDestroy(split); xaccSplitDestroy(split);
} }
@ -1365,7 +1366,7 @@ xaccAccountCommitEdit (Account *acc)
slist = g_list_copy(priv->splits); slist = g_list_copy(priv->splits);
for (lp = slist; lp; lp = lp->next) for (lp = slist; lp; lp = lp->next)
{ {
Split *s = lp->data; Split *s = static_cast<Split *>(lp->data);
xaccSplitDestroy (s); xaccSplitDestroy (s);
} }
g_list_free(slist); g_list_free(slist);
@ -1392,7 +1393,7 @@ xaccAccountCommitEdit (Account *acc)
/* the lots should be empty by now */ /* the lots should be empty by now */
for (lp = priv->lots; lp; lp = lp->next) for (lp = priv->lots; lp; lp = lp->next)
{ {
GNCLot *lot = lp->data; GNCLot *lot = static_cast<GNCLot*>(lp->data);
gnc_lot_destroy (lot); gnc_lot_destroy (lot);
} }
} }
@ -1455,7 +1456,7 @@ xaccAcctChildrenEqual(const GList *na,
while (na) while (na)
{ {
Account *aa = na->data; Account *aa = static_cast<Account*>(na->data);
Account *ab; Account *ab;
GList *node = g_list_find_custom ((GList*)nb, aa, GList *node = g_list_find_custom ((GList*)nb, aa,
(GCompareFunc)compare_account_by_name); (GCompareFunc)compare_account_by_name);
@ -1465,7 +1466,7 @@ xaccAcctChildrenEqual(const GList *na,
PINFO ("Unable to find matching child account."); PINFO ("Unable to find matching child account.");
return FALSE; return FALSE;
} }
ab = node->data; ab = static_cast<Account*>(node->data);
if (!xaccAccountEqual(aa, ab, check_guids)) if (!xaccAccountEqual(aa, ab, check_guids))
{ {
char sa[GUID_ENCODING_LENGTH + 1]; char sa[GUID_ENCODING_LENGTH + 1];
@ -1883,7 +1884,7 @@ xaccClearMarkDown (Account *acc, short val)
priv->mark = val; priv->mark = val;
for (node = priv->children; node; node = node->next) for (node = priv->children; node; node = node->next)
{ {
xaccClearMarkDown(node->data, val); xaccClearMarkDown(static_cast<Account*>(node->data), val);
} }
} }
@ -2254,7 +2255,7 @@ xaccAccountSetName (Account *acc, const char *str)
return; return;
xaccAccountBeginEdit(acc); xaccAccountBeginEdit(acc);
CACHE_REPLACE(priv->accountName, str); qof_string_cache_replace((void const **)(&priv->accountName), str);
mark_account (acc); mark_account (acc);
xaccAccountCommitEdit(acc); xaccAccountCommitEdit(acc);
} }
@ -2273,7 +2274,7 @@ xaccAccountSetCode (Account *acc, const char *str)
return; return;
xaccAccountBeginEdit(acc); xaccAccountBeginEdit(acc);
CACHE_REPLACE(priv->accountCode, str ? str : ""); qof_string_cache_replace((void const **)(&priv->accountCode), str ? str : "");
mark_account (acc); mark_account (acc);
xaccAccountCommitEdit(acc); xaccAccountCommitEdit(acc);
} }
@ -2292,7 +2293,7 @@ xaccAccountSetDescription (Account *acc, const char *str)
return; return;
xaccAccountBeginEdit(acc); xaccAccountBeginEdit(acc);
CACHE_REPLACE(priv->description, str ? str : ""); qof_string_cache_replace((void const **)(&priv->description), str ? str : "");
mark_account (acc); mark_account (acc);
xaccAccountCommitEdit(acc); xaccAccountCommitEdit(acc);
} }
@ -2691,7 +2692,7 @@ Account *
gnc_account_nth_child (const Account *parent, gint num) gnc_account_nth_child (const Account *parent, gint num)
{ {
g_return_val_if_fail(GNC_IS_ACCOUNT(parent), NULL); g_return_val_if_fail(GNC_IS_ACCOUNT(parent), NULL);
return g_list_nth_data(GET_PRIVATE(parent)->children, num); return static_cast<Account*>(g_list_nth_data(GET_PRIVATE(parent)->children, num));
} }
gint gint
@ -2706,7 +2707,7 @@ gnc_account_n_descendants (const Account *account)
priv = GET_PRIVATE(account); priv = GET_PRIVATE(account);
for (node = priv->children; node; node = g_list_next(node)) for (node = priv->children; node; node = g_list_next(node))
{ {
count += gnc_account_n_descendants(node->data) + 1; count += gnc_account_n_descendants(static_cast<Account*>(node->data)) + 1;
} }
return count; return count;
} }
@ -2745,7 +2746,7 @@ gnc_account_get_tree_depth (const Account *account)
for (node = priv->children; node; node = g_list_next(node)) for (node = priv->children; node; node = g_list_next(node))
{ {
child_depth = gnc_account_get_tree_depth(node->data); child_depth = gnc_account_get_tree_depth(static_cast<Account const *>(node->data));
depth = MAX(depth, child_depth); depth = MAX(depth, child_depth);
} }
return depth + 1; return depth + 1;
@ -2768,7 +2769,7 @@ gnc_account_get_descendants (const Account *account)
{ {
descendants = g_list_append(descendants, child->data); descendants = g_list_append(descendants, child->data);
descendants = g_list_concat(descendants, descendants = g_list_concat(descendants,
gnc_account_get_descendants(child->data)); gnc_account_get_descendants(static_cast<Account const *>(child->data)));
} }
return descendants; return descendants;
} }
@ -2793,7 +2794,7 @@ gnc_account_get_descendants_sorted (const Account *account)
{ {
descendants = g_list_append(descendants, child->data); descendants = g_list_append(descendants, child->data);
descendants = g_list_concat(descendants, descendants = g_list_concat(descendants,
gnc_account_get_descendants_sorted(child->data)); gnc_account_get_descendants_sorted(static_cast<Account const *>(child->data)));
} }
g_list_free(children); g_list_free(children);
return descendants; return descendants;
@ -2813,7 +2814,7 @@ gnc_account_lookup_by_name (const Account *parent, const char * name)
ppriv = GET_PRIVATE(parent); ppriv = GET_PRIVATE(parent);
for (node = ppriv->children; node; node = node->next) for (node = ppriv->children; node; node = node->next)
{ {
child = node->data; child = static_cast<Account*>(node->data);
cpriv = GET_PRIVATE(child); cpriv = GET_PRIVATE(child);
if (g_strcmp0(cpriv->accountName, name) == 0) if (g_strcmp0(cpriv->accountName, name) == 0)
return child; return child;
@ -2823,7 +2824,7 @@ gnc_account_lookup_by_name (const Account *parent, const char * name)
* Recursively search each of the child accounts next */ * Recursively search each of the child accounts next */
for (node = ppriv->children; node; node = node->next) for (node = ppriv->children; node; node = node->next)
{ {
child = node->data; child = static_cast<Account*>(node->data);
result = gnc_account_lookup_by_name (child, name); result = gnc_account_lookup_by_name (child, name);
if (result) if (result)
return result; return result;
@ -2846,7 +2847,7 @@ gnc_account_lookup_by_code (const Account *parent, const char * code)
ppriv = GET_PRIVATE(parent); ppriv = GET_PRIVATE(parent);
for (node = ppriv->children; node; node = node->next) for (node = ppriv->children; node; node = node->next)
{ {
child = node->data; child = static_cast<Account*>(node->data);
cpriv = GET_PRIVATE(child); cpriv = GET_PRIVATE(child);
if (g_strcmp0(cpriv->accountCode, code) == 0) if (g_strcmp0(cpriv->accountCode, code) == 0)
return child; return child;
@ -2856,7 +2857,7 @@ gnc_account_lookup_by_code (const Account *parent, const char * code)
* Recursively search each of the child accounts next */ * Recursively search each of the child accounts next */
for (node = ppriv->children; node; node = node->next) for (node = ppriv->children; node; node = node->next)
{ {
child = node->data; child = static_cast<Account*>(node->data);
result = gnc_account_lookup_by_code (child, code); result = gnc_account_lookup_by_code (child, code);
if (result) if (result)
return result; return result;
@ -2884,7 +2885,7 @@ gnc_account_lookup_by_full_name_helper (const Account *parent,
ppriv = GET_PRIVATE(parent); ppriv = GET_PRIVATE(parent);
for (node = ppriv->children; node; node = node->next) for (node = ppriv->children; node; node = node->next)
{ {
Account *account = node->data; Account *account = static_cast<Account*>(node->data);
priv = GET_PRIVATE(account); priv = GET_PRIVATE(account);
if (g_strcmp0(priv->accountName, names[0]) == 0) if (g_strcmp0(priv->accountName, names[0]) == 0)
@ -2950,7 +2951,7 @@ gnc_account_foreach_child (const Account *acc,
priv = GET_PRIVATE(acc); priv = GET_PRIVATE(acc);
for (node = priv->children; node; node = node->next) for (node = priv->children; node; node = node->next)
{ {
thunk (node->data, user_data); thunk (static_cast<Account*>(node->data), user_data);
} }
} }
@ -2969,7 +2970,7 @@ gnc_account_foreach_descendant (const Account *acc,
priv = GET_PRIVATE(acc); priv = GET_PRIVATE(acc);
for (node = priv->children; node; node = node->next) for (node = priv->children; node; node = node->next)
{ {
child = node->data; child = static_cast<Account*>(node->data);
thunk(child, user_data); thunk(child, user_data);
gnc_account_foreach_descendant(child, thunk, user_data); gnc_account_foreach_descendant(child, thunk, user_data);
} }
@ -2991,7 +2992,7 @@ gnc_account_foreach_descendant_until (const Account *acc,
priv = GET_PRIVATE(acc); priv = GET_PRIVATE(acc);
for (node = priv->children; node; node = node->next) for (node = priv->children; node; node = node->next)
{ {
child = node->data; child = static_cast<Account*>(node->data);
result = thunk(child, user_data); result = thunk(child, user_data);
if (result) if (result)
return(result); return(result);
@ -3040,7 +3041,6 @@ gnc_account_get_full_name(const Account *account)
AccountPrivate *priv; AccountPrivate *priv;
const Account *a; const Account *a;
char *fullname; char *fullname;
gchar **names;
int level; int level;
/* So much for hardening the API. Too many callers to this function don't /* So much for hardening the API. Too many callers to this function don't
@ -3067,7 +3067,7 @@ gnc_account_get_full_name(const Account *account)
/* Get all the pointers in the right order. The root node "entry" /* Get all the pointers in the right order. The root node "entry"
* becomes the terminating NULL pointer for the array of strings. */ * becomes the terminating NULL pointer for the array of strings. */
names = g_malloc(level * sizeof(gchar *)); gchar* names[level*sizeof(gchar*)];
names[--level] = NULL; names[--level] = NULL;
for (a = account; level > 0; a = priv->parent) for (a = account; level > 0; a = priv->parent)
{ {
@ -3077,7 +3077,6 @@ gnc_account_get_full_name(const Account *account)
/* Build the full name */ /* Build the full name */
fullname = g_strjoinv(account_separator, names); fullname = g_strjoinv(account_separator, names);
g_free(names);
return fullname; return fullname;
} }
@ -3267,7 +3266,7 @@ xaccAccountGetProjectedMinimumBalance (const Account *acc)
today = gnc_time64_get_today_end(); today = gnc_time64_get_today_end();
for (node = g_list_last(priv->splits); node; node = node->prev) for (node = g_list_last(priv->splits); node; node = node->prev)
{ {
Split *split = node->data; Split *split = static_cast<Split*>(node->data);
if (!seen_a_transaction) if (!seen_a_transaction)
{ {
@ -3383,7 +3382,7 @@ xaccAccountGetPresentBalance (const Account *acc)
today = gnc_time64_get_today_end(); today = gnc_time64_get_today_end();
for (node = g_list_last(priv->splits); node; node = node->prev) for (node = g_list_last(priv->splits); node; node = node->prev)
{ {
Split *split = node->data; Split *split = static_cast<Split*>(node->data);
if (xaccTransGetDate (xaccSplitGetParent (split)) <= today) if (xaccTransGetDate (xaccSplitGetParent (split)) <= today)
return xaccSplitGetBalance (split); return xaccSplitGetBalance (split);
@ -3517,7 +3516,7 @@ typedef struct
static void static void
xaccAccountBalanceHelper (Account *acc, gpointer data) xaccAccountBalanceHelper (Account *acc, gpointer data)
{ {
CurrencyBalance *cb = data; CurrencyBalance *cb = static_cast<CurrencyBalance*>(data);
gnc_numeric balance; gnc_numeric balance;
if (!cb->fn || !cb->currency) if (!cb->fn || !cb->currency)
@ -3531,7 +3530,7 @@ xaccAccountBalanceHelper (Account *acc, gpointer data)
static void static void
xaccAccountBalanceAsOfDateHelper (Account *acc, gpointer data) xaccAccountBalanceAsOfDateHelper (Account *acc, gpointer data)
{ {
CurrencyBalance *cb = data; CurrencyBalance *cb = static_cast<CurrencyBalance*>(data);
gnc_numeric balance; gnc_numeric balance;
g_return_if_fail (cb->asOfDateFn && cb->currency); g_return_if_fail (cb->asOfDateFn && cb->currency);
@ -3768,7 +3767,7 @@ xaccAccountFindOpenLots (const Account *acc,
priv = GET_PRIVATE(acc); priv = GET_PRIVATE(acc);
for (lot_list = priv->lots; lot_list; lot_list = lot_list->next) for (lot_list = priv->lots; lot_list; lot_list = lot_list->next)
{ {
GNCLot *lot = lot_list->data; GNCLot *lot = static_cast<GNCLot*>(lot_list->data);
/* If this lot is closed, then ignore it */ /* If this lot is closed, then ignore it */
if (gnc_lot_is_closed (lot)) if (gnc_lot_is_closed (lot))
@ -4111,7 +4110,7 @@ xaccAccountStringToEnum(const char* str)
/********************************************************************\ /********************************************************************\
\********************************************************************/ \********************************************************************/
static char * static char const *
account_type_name[NUM_ACCOUNT_TYPES] = account_type_name[NUM_ACCOUNT_TYPES] =
{ {
N_("Bank"), N_("Bank"),
@ -4763,7 +4762,7 @@ finder_help_function(const Account *acc, const char *description,
priv = GET_PRIVATE(acc); priv = GET_PRIVATE(acc);
for (slp = g_list_last(priv->splits); slp; slp = slp->prev) for (slp = g_list_last(priv->splits); slp; slp = slp->prev)
{ {
Split *lsplit = slp->data; Split *lsplit = static_cast<Split*>(slp->data);
Transaction *ltrans = xaccSplitGetParent(lsplit); Transaction *ltrans = xaccSplitGetParent(lsplit);
if (g_strcmp0 (description, xaccTransGetDescription (ltrans)) == 0) if (g_strcmp0 (description, xaccTransGetDescription (ltrans)) == 0)
@ -4821,7 +4820,7 @@ gnc_account_join_children (Account *to_parent, Account *from_parent)
ENTER (" "); ENTER (" ");
children = g_list_copy(from_priv->children); children = g_list_copy(from_priv->children);
for (node = children; node; node = g_list_next(node)) for (node = children; node; node = g_list_next(node))
gnc_account_append_child(to_parent, node->data); gnc_account_append_child(to_parent, static_cast <Account*> (node->data));
g_list_free(children); g_list_free(children);
LEAVE (" "); LEAVE (" ");
} }
@ -4839,12 +4838,12 @@ gnc_account_merge_children (Account *parent)
ppriv = GET_PRIVATE(parent); ppriv = GET_PRIVATE(parent);
for (node_a = ppriv->children; node_a; node_a = node_a->next) for (node_a = ppriv->children; node_a; node_a = node_a->next)
{ {
Account *acc_a = node_a->data; Account *acc_a = static_cast <Account*> (node_a->data);
priv_a = GET_PRIVATE(acc_a); priv_a = GET_PRIVATE(acc_a);
for (node_b = node_a->next; node_b; node_b = g_list_next(node_b)) for (node_b = node_a->next; node_b; node_b = g_list_next(node_b))
{ {
Account *acc_b = node_b->data; Account *acc_b = static_cast <Account*> (node_b->data);
priv_b = GET_PRIVATE(acc_b); priv_b = GET_PRIVATE(acc_b);
if (0 != null_strcmp(priv_a->accountName, priv_b->accountName)) if (0 != null_strcmp(priv_a->accountName, priv_b->accountName))
@ -4881,7 +4880,7 @@ gnc_account_merge_children (Account *parent)
/* consolidate transactions */ /* consolidate transactions */
while (priv_b->splits) while (priv_b->splits)
xaccSplitSetAccount (priv_b->splits->data, acc_a); xaccSplitSetAccount (static_cast <Split*> (priv_b->splits->data), acc_a);
/* move back one before removal. next iteration around the loop /* move back one before removal. next iteration around the loop
* will get the node after node_b */ * will get the node after node_b */
@ -4906,7 +4905,7 @@ xaccSplitsBeginStagedTransactionTraversals (GList *splits)
for (lp = splits; lp; lp = lp->next) for (lp = splits; lp; lp = lp->next)
{ {
Split *s = lp->data; Split *s = static_cast <Split*> (lp->data);
Transaction *trans = s->parent; Transaction *trans = s->parent;
if (trans) if (trans)
@ -4987,7 +4986,7 @@ xaccAccountStagedTransactionTraversal (const Account *acc,
* a thunk removes splits from this account. */ * a thunk removes splits from this account. */
next = g_list_next(split_p); next = g_list_next(split_p);
s = split_p->data; s = static_cast <Split*> (split_p->data);
trans = s->parent; trans = s->parent;
if (trans && (trans->marker < stage)) if (trans && (trans->marker < stage))
{ {
@ -5021,15 +5020,15 @@ gnc_account_tree_staged_transaction_traversal (const Account *acc,
priv = GET_PRIVATE(acc); priv = GET_PRIVATE(acc);
for (acc_p = priv->children; acc_p; acc_p = g_list_next(acc_p)) for (acc_p = priv->children; acc_p; acc_p = g_list_next(acc_p))
{ {
retval = gnc_account_tree_staged_transaction_traversal(acc_p->data, stage, retval = gnc_account_tree_staged_transaction_traversal(static_cast <Account*> (acc_p->data),
thunk, cb_data); stage, thunk, cb_data);
if (retval) return retval; if (retval) return retval;
} }
/* Now this account */ /* Now this account */
for (split_p = priv->splits; split_p; split_p = g_list_next(split_p)) for (split_p = priv->splits; split_p; split_p = g_list_next(split_p))
{ {
s = split_p->data; s = static_cast <Split*> (split_p->data);
trans = s->parent; trans = s->parent;
if (trans && (trans->marker < stage)) if (trans && (trans->marker < stage))
{ {
@ -5294,7 +5293,7 @@ highestProbability(gpointer key, gpointer value, gpointer data)
{ {
/* Save the new highest probability and the assoaciated account guid */ /* Save the new highest probability and the assoaciated account guid */
account_i->probability = GPOINTER_TO_INT(value); account_i->probability = GPOINTER_TO_INT(value);
account_i->account_guid = key; account_i->account_guid = static_cast <char*> (key);
} }
} }
@ -5370,8 +5369,8 @@ gnc_account_imap_find_account_bayes (GncImportMatchMap *imap, GList *tokens)
account_c->account_guid, account_c->token_count, account_c->account_guid, account_c->token_count,
tokenInfo.total_count); tokenInfo.total_count);
account_p = g_hash_table_lookup(running_probabilities, account_p = static_cast <account_probability*> (
account_c->account_guid); g_hash_table_lookup(running_probabilities, account_c->account_guid));
/* if the account exists in the list then continue /* if the account exists in the list then continue
* the running probablities * the running probablities
@ -5612,7 +5611,7 @@ build_bayes_layer_two (const char *key, const GValue *value, gpointer user_data)
g_free (guid); g_free (guid);
imapInfo_node = g_malloc(sizeof(*imapInfo_node)); imapInfo_node = static_cast <imap_info*> (g_malloc(sizeof(*imapInfo_node)));
imapInfo_node->source_account = imapInfo->source_account; imapInfo_node->source_account = imapInfo->source_account;
imapInfo_node->map_account = map_account; imapInfo_node->map_account = map_account;
@ -5688,7 +5687,7 @@ build_non_bayes (const char *key, const GValue *value, gpointer user_data)
PINFO("build_non_bayes: kvp_path is '%s'", kvp_path); PINFO("build_non_bayes: kvp_path is '%s'", kvp_path);
imapInfo_node = g_malloc(sizeof(*imapInfo_node)); imapInfo_node = static_cast <imap_info*> (g_malloc(sizeof(*imapInfo_node)));
imapInfo_node->source_account = imapInfo->source_account; imapInfo_node->source_account = imapInfo->source_account;
imapInfo_node->map_account = xaccAccountLookup (guid, book); imapInfo_node->map_account = xaccAccountLookup (guid, book);
@ -5810,7 +5809,7 @@ look_for_old_separator_descendants (Account *root, gchar *full_name, const gchar
/* Go through list of top level accounts */ /* Go through list of top level accounts */
for (ptr = top_accounts; ptr; ptr = g_list_next (ptr)) for (ptr = top_accounts; ptr; ptr = g_list_next (ptr))
{ {
const gchar *name = xaccAccountGetName (ptr->data); const gchar *name = xaccAccountGetName (static_cast <Account const *> (ptr->data));
// we are looking for the longest top level account that matches // we are looking for the longest top level account that matches
if (g_str_has_prefix (full_name, name)) if (g_str_has_prefix (full_name, name))
@ -5935,7 +5934,7 @@ convert_imap_account (Account *acc)
for (node = imap_list; node; node = g_list_next (node)) for (node = imap_list; node; node = g_list_next (node))
{ {
Account *map_account = NULL; Account *map_account = NULL;
GncImapInfo *imapInfo = node->data; GncImapInfo *imapInfo = static_cast <GncImapInfo *> (node->data);
// Lets start doing stuff // Lets start doing stuff
map_account = look_for_old_mapping (imapInfo); map_account = look_for_old_mapping (imapInfo);
@ -5980,7 +5979,7 @@ gnc_account_imap_convert_bayes (QofBook *book)
/* Go through list of accounts */ /* Go through list of accounts */
for (ptr = accts; ptr; ptr = g_list_next (ptr)) for (ptr = accts; ptr; ptr = g_list_next (ptr))
{ {
Account *acc = ptr->data; Account *acc = static_cast <Account*> (ptr->data);
convert_imap_account (acc); convert_imap_account (acc);
} }
@ -6020,7 +6019,7 @@ static QofObject account_object_def =
DI(.interface_version = ) QOF_OBJECT_VERSION, DI(.interface_version = ) QOF_OBJECT_VERSION,
DI(.e_type = ) GNC_ID_ACCOUNT, DI(.e_type = ) GNC_ID_ACCOUNT,
DI(.type_label = ) "Account", DI(.type_label = ) "Account",
DI(.create = ) (gpointer)xaccMallocAccount, DI(.create = ) (void*(*)(QofBook*)) xaccMallocAccount,
DI(.book_begin = ) NULL, DI(.book_begin = ) NULL,
DI(.book_end = ) gnc_account_book_end, DI(.book_end = ) gnc_account_book_end,
DI(.is_dirty = ) qof_collection_is_dirty, DI(.is_dirty = ) qof_collection_is_dirty,

View File

@ -48,6 +48,9 @@
#include "gnc-engine.h" #include "gnc-engine.h"
#include "policy.h" #include "policy.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef gnc_numeric (*xaccGetBalanceFn)( const Account *account ); typedef gnc_numeric (*xaccGetBalanceFn)( const Account *account );
typedef gnc_numeric (*xaccGetBalanceInCurrencyFn) ( typedef gnc_numeric (*xaccGetBalanceInCurrencyFn) (
@ -1517,6 +1520,10 @@ const char * dxaccAccountGetQuoteTZ (const Account *account);
* in the gnome-search parameter list. Be careful when you use this. */ * in the gnome-search parameter list. Be careful when you use this. */
#define ACCOUNT_MATCH_ALL_TYPE "account-match-all" #define ACCOUNT_MATCH_ALL_TYPE "account-match-all"
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* XACC_ACCOUNT_H */ #endif /* XACC_ACCOUNT_H */
/** @} */ /** @} */
/** @} */ /** @} */

View File

@ -41,6 +41,10 @@
#include "Account.h" #include "Account.h"
#ifdef __cplusplus
extern "C" {
#endif
#define GNC_ID_ROOT_ACCOUNT "RootAccount" #define GNC_ID_ROOT_ACCOUNT "RootAccount"
/** STRUCTS *********************************************************/ /** STRUCTS *********************************************************/
@ -149,5 +153,8 @@ typedef struct
AccountTestFunctions* _utest_account_fill_functions(void); AccountTestFunctions* _utest_account_fill_functions(void);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* XACC_ACCOUNT_P_H */ #endif /* XACC_ACCOUNT_P_H */

View File

@ -136,7 +136,7 @@ ADD_CUSTOM_COMMAND (
ADD_CUSTOM_TARGET(iso-4217-c DEPENDS ${ISO_4217_C}) ADD_CUSTOM_TARGET(iso-4217-c DEPENDS ${ISO_4217_C})
SET (engine_SOURCES SET (engine_SOURCES
Account.c Account.cpp
Recurrence.c Recurrence.c
Query.c Query.c
SchedXaction.c SchedXaction.c

View File

@ -18,7 +18,7 @@ AM_CPPFLAGS = \
libgncmod_engine_la_SOURCES = \ libgncmod_engine_la_SOURCES = \
Account.c \ Account.cpp \
Recurrence.c \ Recurrence.c \
Query.c \ Query.c \
SchedXaction.c \ SchedXaction.c \

View File

@ -41,6 +41,10 @@ typedef struct _SplitClass SplitClass;
#include "gnc-commodity.h" #include "gnc-commodity.h"
#include "gnc-engine.h" #include "gnc-engine.h"
#ifdef __cplusplus
extern "C" {
#endif
/* --- type macros --- */ /* --- type macros --- */
#define GNC_TYPE_SPLIT (gnc_split_get_type ()) #define GNC_TYPE_SPLIT (gnc_split_get_type ())
#define GNC_SPLIT(o) \ #define GNC_SPLIT(o) \
@ -550,6 +554,10 @@ gnc_numeric xaccSplitVoidFormerValue(const Split *split);
/** \deprecated */ /** \deprecated */
#define xaccSplitReturnGUID(X) (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null())) #define xaccSplitReturnGUID(X) (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null()))
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* XACC_SPLIT_H */ #endif /* XACC_SPLIT_H */
/** @} */ /** @} */
/** @} */ /** @} */

View File

@ -94,6 +94,10 @@ typedef struct _TransactionClass TransactionClass;
#include "gnc-engine.h" #include "gnc-engine.h"
#include "Split.h" #include "Split.h"
#ifdef __cplusplus
extern "C" {
#endif
/* --- type macros --- */ /* --- type macros --- */
#define GNC_TYPE_TRANSACTION (gnc_transaction_get_type ()) #define GNC_TYPE_TRANSACTION (gnc_transaction_get_type ())
#define GNC_TRANSACTION(o) \ #define GNC_TRANSACTION(o) \
@ -789,6 +793,10 @@ void xaccTransDump (const Transaction *trans, const char *tag);
/** \deprecated */ /** \deprecated */
#define xaccTransReturnGUID(X) (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null())) #define xaccTransReturnGUID(X) (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null()))
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* XACC_TRANSACTION_H */ #endif /* XACC_TRANSACTION_H */
/** @} */ /** @} */
/** @} */ /** @} */

View File

@ -53,6 +53,10 @@ typedef struct _GncCommodityNamespaceClass gnc_commodity_namespaceClass;
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include "gnc-engine.h" #include "gnc-engine.h"
#ifdef __cplusplus
extern "C" {
#endif
/* --- type macros --- */ /* --- type macros --- */
#define GNC_TYPE_COMMODITY (gnc_commodity_get_type ()) #define GNC_TYPE_COMMODITY (gnc_commodity_get_type ())
#define GNC_COMMODITY(o) \ #define GNC_COMMODITY(o) \
@ -1056,6 +1060,10 @@ void gnc_monetary_list_free(MonetaryList *list);
/** @} */ /** @} */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* GNC_COMMODITY_H */ #endif /* GNC_COMMODITY_H */
/** @} */ /** @} */
/** @} */ /** @} */

View File

@ -39,6 +39,10 @@
#include <glib.h> #include <glib.h>
#include "qof.h" #include "qof.h"
#ifdef __cplusplus
extern "C" {
#endif
/** \name QofLogModule identifiers */ /** \name QofLogModule identifiers */
// @{ // @{
#define GNC_MOD_ROOT "gnc" #define GNC_MOD_ROOT "gnc"
@ -257,6 +261,9 @@ void gnc_engine_signal_commit_error( QofBackendError errcode );
#define GNC_OWNER_GUID "owner-guid" #define GNC_OWNER_GUID "owner-guid"
#define GNC_SX_ID "sched-xaction" #define GNC_SX_ID "sched-xaction"
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif #endif
/** @} */ /** @} */

View File

@ -38,6 +38,10 @@
#include "qof.h" #include "qof.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @name Defined features /** @name Defined features
@{ @{
*/ */
@ -64,6 +68,10 @@ gchar *gnc_features_test_unknown (QofBook *book);
*/ */
void gnc_features_set_used (QofBook *book, const gchar *feature); void gnc_features_set_used (QofBook *book, const gchar *feature);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* GNC_FEATURES_H */ #endif /* GNC_FEATURES_H */
/** @} */ /** @} */
/** @} */ /** @} */

View File

@ -65,6 +65,10 @@
#include "gnc-engine.h" #include "gnc-engine.h"
/*#include "gnc-lot-p.h"*/ /*#include "gnc-lot-p.h"*/
#ifdef __cplusplus
extern "C" {
#endif
typedef struct typedef struct
{ {
QofInstanceClass parent_class; QofInstanceClass parent_class;
@ -174,6 +178,11 @@ GNCLot * gnc_lot_make_default (Account * acc);
#define LOT_BALANCE "balance" #define LOT_BALANCE "balance"
#define LOT_TITLE "lot-title" #define LOT_TITLE "lot-title"
#define LOT_NOTES "notes" #define LOT_NOTES "notes"
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* GNC_LOT_H */ #endif /* GNC_LOT_H */
/** @} */ /** @} */
/** @} */ /** @} */

View File

@ -31,6 +31,10 @@ typedef struct _GncPriceDBClass GNCPriceDBClass;
#include "gnc-commodity.h" #include "gnc-commodity.h"
#include "gnc-engine.h" #include "gnc-engine.h"
#ifdef __cplusplus
extern "C" {
#endif
/* --- type macros --- */ /* --- type macros --- */
#define GNC_TYPE_PRICE (gnc_price_get_type ()) #define GNC_TYPE_PRICE (gnc_price_get_type ())
#define GNC_PRICE(o) \ #define GNC_PRICE(o) \
@ -662,6 +666,10 @@ void gnc_pricedb_print_contents(GNCPriceDB *db, FILE *f);
/** @} */ /** @} */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* GNC_PRICEDB_H */ #endif /* GNC_PRICEDB_H */
/** @} */ /** @} */
/** @} */ /** @} */

View File

@ -37,6 +37,10 @@
#ifndef XACC_POLICY_H #ifndef XACC_POLICY_H
#define XACC_POLICY_H #define XACC_POLICY_H
#ifdef __cplusplus
extern "C" {
#endif
typedef struct gncpolicy_s GNCPolicy; typedef struct gncpolicy_s GNCPolicy;
/** Valid Policy List /** Valid Policy List
@ -83,6 +87,10 @@ GNCPolicy *xaccGetFIFOPolicy (void);
*/ */
GNCPolicy *xaccGetLIFOPolicy (void); GNCPolicy *xaccGetLIFOPolicy (void);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* XACC_POLICY_H */ #endif /* XACC_POLICY_H */
/** @} */ /** @} */
/** @} */ /** @} */

View File

@ -132,4 +132,11 @@ qof_string_cache_insert(gconstpointer key)
return NULL; return NULL;
} }
void
qof_string_cache_replace(gconstpointer * dst, gconstpointer src)
{
gpointer tmp {qof_string_cache_insert(src)};
qof_string_cache_remove(&dst);
*dst = tmp;
}
/* ************************ END OF FILE ***************************** */ /* ************************ END OF FILE ***************************** */

View File

@ -86,6 +86,10 @@ void qof_string_cache_remove(gconstpointer key);
*/ */
gpointer qof_string_cache_insert(gconstpointer key); gpointer qof_string_cache_insert(gconstpointer key);
/** Same as CACHE_REPLACE below, but safe to call from C++.
*/
void qof_string_cache_replace(gconstpointer * dst, gconstpointer src);
#define CACHE_INSERT(str) qof_string_cache_insert((gconstpointer)(str)) #define CACHE_INSERT(str) qof_string_cache_insert((gconstpointer)(str))
#define CACHE_REMOVE(str) qof_string_cache_remove((str)) #define CACHE_REMOVE(str) qof_string_cache_remove((str))

View File

@ -467,13 +467,7 @@ test_gnc_account_list_name_violations (Fixture *fixture, gconstpointer pData)
{ {
auto log_level = static_cast<GLogLevelFlags>(G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL); auto log_level = static_cast<GLogLevelFlags>(G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL);
auto log_domain = "gnc.engine"; auto log_domain = "gnc.engine";
#ifdef USE_CLANG_FUNC_SIG auto msg = ": assertion 'separator != NULL' failed";
#define _func "GList *gnc_account_list_name_violations(QofBook *, const gchar *)"
#else
#define _func "gnc_account_list_name_violations"
#endif
auto msg = _func ": assertion 'separator != NULL' failed";
#undef _func
auto check = test_error_struct_new(log_domain, log_level, msg); auto check = test_error_struct_new(log_domain, log_level, msg);
GList *results, *res_iter; GList *results, *res_iter;
auto sep = ":"; auto sep = ":";
@ -482,7 +476,7 @@ test_gnc_account_list_name_violations (Fixture *fixture, gconstpointer pData)
* affect the test_log_fatal_handler * affect the test_log_fatal_handler
*/ */
GLogFunc oldlogger = g_log_set_default_handler ((GLogFunc)test_null_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_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_substring_handler, check);
g_assert (gnc_account_list_name_violations (NULL, NULL) == NULL); 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 (gnc_account_list_name_violations (book, NULL) == NULL);
@ -759,19 +753,13 @@ test_xaccCloneAccount (Fixture *fixture, gconstpointer pData)
Account *clone; Account *clone;
QofBook *book = gnc_account_get_book (fixture->acct); QofBook *book = gnc_account_get_book (fixture->acct);
auto loglevel = static_cast<GLogLevelFlags>(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 auto msg1 = ": assertion 'GNC_IS_ACCOUNT(from)' failed";
#define _func "Account *xaccCloneAccount(const Account *, QofBook *)" auto msg2 = ": assertion 'QOF_IS_BOOK(book)' failed";
#else
#define _func "xaccCloneAccount"
#endif
auto msg1 = _func ": assertion 'GNC_IS_ACCOUNT(from)' failed";
auto msg2 = _func ": assertion 'QOF_IS_BOOK(book)' failed";
#undef _func
auto check = test_error_struct_new("gnc.engine", loglevel, msg1); auto check = test_error_struct_new("gnc.engine", loglevel, msg1);
AccountPrivate *acct_p, *clone_p; AccountPrivate *acct_p, *clone_p;
auto oldlogger = g_log_set_default_handler ((GLogFunc)test_null_handler, auto oldlogger = g_log_set_default_handler ((GLogFunc)test_null_handler,
check); check);
g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, check); g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_substring_handler, check);
clone = xaccCloneAccount (NULL, book); clone = xaccCloneAccount (NULL, book);
g_assert (clone == NULL); g_assert (clone == NULL);
g_assert_cmpint (check->hits, ==, 1); g_assert_cmpint (check->hits, ==, 1);
@ -1095,14 +1083,8 @@ test_gnc_account_insert_remove_split (Fixture *fixture, gconstpointer pData)
Split *split3 = xaccMallocSplit (book); Split *split3 = xaccMallocSplit (book);
TestSignal sig1, sig2, sig3; TestSignal sig1, sig2, sig3;
AccountPrivate *priv = fixture->func->get_private (fixture->acct); AccountPrivate *priv = fixture->func->get_private (fixture->acct);
#ifdef USE_CLANG_FUNC_SIG auto msg1 = ": assertion 'GNC_IS_ACCOUNT(acc)' failed";
#define _func "gboolean gnc_account_insert_split(Account *, Split *)" auto msg2 = ": assertion 'GNC_IS_SPLIT(s)' failed";
#else
#define _func "gnc_account_insert_split"
#endif
auto msg1 = _func ": assertion 'GNC_IS_ACCOUNT(acc)' failed";
auto msg2 = _func ": assertion 'GNC_IS_SPLIT(s)' failed";
#undef _func
auto loglevel = static_cast<GLogLevelFlags>(G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL); auto loglevel = static_cast<GLogLevelFlags>(G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL);
// auto log_domain = "gnc.engine"; // auto log_domain = "gnc.engine";
auto check1 = test_error_struct_new("gnc.engine", loglevel, msg1); auto check1 = test_error_struct_new("gnc.engine", loglevel, msg1);
@ -1116,7 +1098,7 @@ test_gnc_account_insert_remove_split (Fixture *fixture, gconstpointer pData)
test_add_error (check2); test_add_error (check2);
logger = g_log_set_handler ("gnc.engine", loglevel, 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); g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_list_substring_handler, NULL);
/* Check that the call fails with invalid account and split (throws) */ /* Check that the call fails with invalid account and split (throws) */
g_assert (!gnc_account_insert_split (NULL, split1)); g_assert (!gnc_account_insert_split (NULL, split1));

View File

@ -608,7 +608,7 @@ libgnucash/core-utils/gnc-locale-utils.c
libgnucash/core-utils/gnc-path.c libgnucash/core-utils/gnc-path.c
libgnucash/core-utils/gnc-prefs.c libgnucash/core-utils/gnc-prefs.c
libgnucash/doc/doxygen_main_page.c libgnucash/doc/doxygen_main_page.c
libgnucash/engine/Account.c libgnucash/engine/Account.cpp
libgnucash/engine/business-core.scm libgnucash/engine/business-core.scm
libgnucash/engine/cap-gains.c libgnucash/engine/cap-gains.c
libgnucash/engine/cashobjects.c libgnucash/engine/cashobjects.c