Merge branch 'fix_bayes' of https://github.com/limitedAtonement/gnucash into unstable

This commit is contained in:
Geert Janssens
2017-12-23 15:10:48 +01:00
70 changed files with 1644 additions and 1700 deletions

View File

@@ -57,7 +57,9 @@ Otherwise, only failures are printed out.
#include <glib.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Privately used to indicate a test result. You may use these if you
* wish, but it's easier to use the do_test macro above.
@@ -150,5 +152,8 @@ gint64 get_random_gint64(void);
double get_random_double(void);
const char* get_random_string_in_array(const char* str_list[]);
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /* TEST_STUFF_H */

View File

@@ -143,6 +143,29 @@ test_clear_error_list (void)
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
do_test_list_handler (const char *log_domain, GLogLevelFlags log_level,
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
test_checked_handler (const char *log_domain, GLogLevelFlags log_level,
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);
/**
* 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
* 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_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
* test_add_error. If the list is empty or nothing matches, passes