*/
#include "config.h"
#include "gtestutils.h"
+#include <glib.h>
#include "galias.h"
#include <sys/types.h>
#ifdef G_OS_UNIX
#endif
#include <string.h>
#include <stdlib.h>
+#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif /* HAVE_SYS_SELECT_H */
+
+/* Global variable for storing assertion messages; this is the counterpart to
+ * glibc's (private) __abort_msg variable, and allows developers and crash
+ * analysis systems like Apport and ABRT to fish out assertion messages from
+ * core dumps, instead of having to catch them on screen output. */
+char *__glib_assert_msg = NULL;
/* --- structures --- */
struct GTestCase
}
if (test_debug_log)
{
- GTestLogBuffer *lbuffer = g_test_log_buffer_new();
+ GTestLogBuffer *lbuffer = g_test_log_buffer_new ();
GTestLogMsg *msg;
guint ui;
g_test_log_buffer_push (lbuffer, n_bytes, buffer);
msg = g_test_log_buffer_pop (lbuffer);
- g_assert (msg != NULL); /* FIXME: should be g_awrn_if_fail */
- g_assert (lbuffer->data->len == 0); /* FIXME: should be g_awrn_if_fail */
+ g_warn_if_fail (msg != NULL);
+ g_warn_if_fail (lbuffer->data->len == 0);
g_test_log_buffer_free (lbuffer);
/* print message */
g_printerr ("{*LOG(%s)", g_test_log_type_name (msg->log_type));
void *fixture;
g_test_log (G_TEST_LOG_START_CASE, test_run_name, NULL, 0, NULL);
test_run_forks = 0;
+ g_test_log_set_fatal_handler (NULL, NULL);
g_timer_start (test_run_timer);
fixture = tc->fixture_size ? g_malloc0 (tc->fixture_size) : tc->test_data;
test_run_seed (test_run_seedstr);
func, func[0] ? ":" : "",
" ", message, NULL);
g_printerr ("**\n%s\n", s);
+
+ /* store assertion message in global variable, so that it can be found in a
+ * core dump */
+ if (__glib_assert_msg != NULL)
+ /* free the old one */
+ free (__glib_assert_msg);
+ __glib_assert_msg = (char*) malloc (strlen (s) + 1);
+ strcpy (__glib_assert_msg, s);
+
g_test_log (G_TEST_LOG_ERROR, s, NULL, 0, NULL);
g_free (s);
abort();
g_free (s);
}
+void
+g_assertion_message_error (const char *domain,
+ const char *file,
+ int line,
+ const char *func,
+ const char *expr,
+ GError *error,
+ GQuark error_domain,
+ int error_code)
+{
+ GString *gstring;
+
+ /* This is used by both g_assert_error() and g_assert_no_error(), so there
+ * are three cases: expected an error but got the wrong error, expected
+ * an error but got no error, and expected no error but got an error.
+ */
+
+ gstring = g_string_new ("assertion failed ");
+ if (error_domain)
+ g_string_append_printf (gstring, "(%s == (%s, %d)): ", expr,
+ g_quark_to_string (error_domain), error_code);
+ else
+ g_string_append_printf (gstring, "(%s == NULL): ", expr);
+
+ if (error)
+ g_string_append_printf (gstring, "%s (%s, %d)", error->message,
+ g_quark_to_string (error->domain), error->code);
+ else
+ g_string_append_printf (gstring, "%s is NULL", expr);
+
+ g_assertion_message (domain, file, line, func, gstring->str);
+ g_string_free (gstring, TRUE);
+}
+
/**
* g_strcmp0:
* @str1: a C string or %NULL
* @str2: another C string or %NULL
*
- * Compares @str1 and @str2 like strcmp(). Handles %NULL strings gracefully.
+ * Compares @str1 and @str2 like strcmp(). Handles %NULL
+ * gracefully by sorting it before non-%NULL strings.
*
* Returns: -1, 0 or 1, if @str1 is <, == or > than @str2.
*