doc: updated copyright
[adg.git] / src / adg / tests / test-internal.c
blob053afcb17ea762b74c6d54076f555243bc939e88
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010,2011,2012,2013 Nicola Fontana <ntd at entidi.it>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #include <config.h>
22 #include "test-internal.h"
25 void
26 adg_test_init(int *p_argc, char **p_argv[])
28 g_type_init();
29 g_test_init(p_argc, p_argv, NULL);
30 g_log_set_always_fatal(0);
31 g_test_bug_base("http://dev.entidi.com/p/adg/issues/%s/");
34 const gpointer
35 adg_test_invalid_pointer(void)
37 static int junk[10] = { 0 };
38 return junk;
41 static void
42 _adg_log_handler(const gchar *log_domain, GLogLevelFlags log_level,
43 const gchar *message, gpointer user_data)
47 static void
48 _adg_test_func(gconstpointer user_data)
50 GCallback test_func;
51 GLogFunc previous_handler;
53 test_func = (GCallback) user_data;
55 /* Run a test in a forked environment, without showing log messages */
56 previous_handler = g_log_set_default_handler(_adg_log_handler, NULL);
57 if (g_test_trap_fork(0, G_TEST_TRAP_SILENCE_STDERR)) {
58 test_func();
59 exit(0);
61 g_log_set_default_handler(previous_handler, NULL);
63 /* On failed test, rerun it without hiding the log messages */
64 if (!g_test_trap_has_passed())
65 test_func();
68 void
69 adg_test_add_func(const char *testpath, GCallback test_func)
71 g_test_add_data_func(testpath, (gconstpointer) test_func, _adg_test_func);