1/* GLib testing utilities
2 * Copyright (C) 2007 Imendio AB
3 * Authors: Tim Janik
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef __G_TEST_UTILS_H__
20#define __G_TEST_UTILS_H__
21
22#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
23#error "Only <glib.h> can be included directly."
24#endif
25
26#include <glib/gmessages.h>
27#include <glib/gstring.h>
28#include <glib/gerror.h>
29#include <glib/gslist.h>
30#include <string.h>
31
32G_BEGIN_DECLS
33
34typedef struct GTestCase GTestCase;
35typedef struct GTestSuite GTestSuite;
36typedef void (*GTestFunc) (void);
37typedef void (*GTestDataFunc) (gconstpointer user_data);
38typedef void (*GTestFixtureFunc) (gpointer fixture,
39 gconstpointer user_data);
40
41/* assertion API */
42#define g_assert_cmpstr(s1, cmp, s2) G_STMT_START { \
43 const char *__s1 = (s1), *__s2 = (s2); \
44 if (g_strcmp0 (__s1, __s2) cmp 0) ; else \
45 g_assertion_message_cmpstr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
46 #s1 " " #cmp " " #s2, __s1, #cmp, __s2); \
47 } G_STMT_END
48#define g_assert_cmpint(n1, cmp, n2) G_STMT_START { \
49 gint64 __n1 = (n1), __n2 = (n2); \
50 if (__n1 cmp __n2) ; else \
51 g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
52 #n1 " " #cmp " " #n2, (long double) __n1, #cmp, (long double) __n2, 'i'); \
53 } G_STMT_END
54#define g_assert_cmpuint(n1, cmp, n2) G_STMT_START { \
55 guint64 __n1 = (n1), __n2 = (n2); \
56 if (__n1 cmp __n2) ; else \
57 g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
58 #n1 " " #cmp " " #n2, (long double) __n1, #cmp, (long double) __n2, 'i'); \
59 } G_STMT_END
60#define g_assert_cmphex(n1, cmp, n2) G_STMT_START {\
61 guint64 __n1 = (n1), __n2 = (n2); \
62 if (__n1 cmp __n2) ; else \
63 g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
64 #n1 " " #cmp " " #n2, (long double) __n1, #cmp, (long double) __n2, 'x'); \
65 } G_STMT_END
66#define g_assert_cmpfloat(n1,cmp,n2) G_STMT_START { \
67 long double __n1 = (long double) (n1), __n2 = (long double) (n2); \
68 if (__n1 cmp __n2) ; else \
69 g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
70 #n1 " " #cmp " " #n2, (long double) __n1, #cmp, (long double) __n2, 'f'); \
71 } G_STMT_END
72#define g_assert_cmpfloat_with_epsilon(n1,n2,epsilon) \
73 G_STMT_START { \
74 double __n1 = (n1), __n2 = (n2), __epsilon = (epsilon); \
75 if (G_APPROX_VALUE (__n1, __n2, __epsilon)) ; else \
76 g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
77 #n1 " == " #n2 " (+/- " #epsilon ")", __n1, "==", __n2, 'f'); \
78 } G_STMT_END
79#define g_assert_cmpmem(m1, l1, m2, l2) G_STMT_START {\
80 gconstpointer __m1 = m1, __m2 = m2; \
81 int __l1 = l1, __l2 = l2; \
82 if (__l1 != __l2) \
83 g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
84 #l1 " (len(" #m1 ")) == " #l2 " (len(" #m2 "))", \
85 (long double) __l1, "==", (long double) __l2, 'i'); \
86 else if (__l1 != 0 && __m2 != NULL && memcmp (__m1, __m2, __l1) != 0) \
87 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
88 "assertion failed (" #m1 " == " #m2 ")"); \
89 } G_STMT_END
90#define g_assert_cmpvariant(v1, v2) \
91 G_STMT_START \
92 { \
93 GVariant *__v1 = (v1), *__v2 = (v2); \
94 if (!g_variant_equal (__v1, __v2)) \
95 { \
96 gchar *__s1, *__s2, *__msg; \
97 __s1 = g_variant_print (__v1, TRUE); \
98 __s2 = g_variant_print (__v2, TRUE); \
99 __msg = g_strdup_printf ("assertion failed (" #v1 " == " #v2 "): %s does not equal %s", __s1, __s2); \
100 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, __msg); \
101 g_free (__s1); \
102 g_free (__s2); \
103 g_free (__msg); \
104 } \
105 } \
106 G_STMT_END
107#define g_assert_no_error(err) G_STMT_START { \
108 if (err) \
109 g_assertion_message_error (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
110 #err, err, 0, 0); \
111 } G_STMT_END
112#define g_assert_error(err, dom, c) G_STMT_START { \
113 if (!err || (err)->domain != dom || (err)->code != c) \
114 g_assertion_message_error (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
115 #err, err, dom, c); \
116 } G_STMT_END
117#define g_assert_true(expr) G_STMT_START { \
118 if G_LIKELY (expr) ; else \
119 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
120 "'" #expr "' should be TRUE"); \
121 } G_STMT_END
122#define g_assert_false(expr) G_STMT_START { \
123 if G_LIKELY (!(expr)) ; else \
124 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
125 "'" #expr "' should be FALSE"); \
126 } G_STMT_END
127
128/* Use nullptr in C++ to catch misuse of these macros. */
129#if defined(__cplusplus) && __cplusplus >= 201100L
130#define g_assert_null(expr) G_STMT_START { if G_LIKELY ((expr) == nullptr) ; else \
131 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
132 "'" #expr "' should be nullptr"); \
133 } G_STMT_END
134#define g_assert_nonnull(expr) G_STMT_START { \
135 if G_LIKELY ((expr) != nullptr) ; else \
136 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
137 "'" #expr "' should not be nullptr"); \
138 } G_STMT_END
139#else /* not C++ */
140#define g_assert_null(expr) G_STMT_START { if G_LIKELY ((expr) == NULL) ; else \
141 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
142 "'" #expr "' should be NULL"); \
143 } G_STMT_END
144#define g_assert_nonnull(expr) G_STMT_START { \
145 if G_LIKELY ((expr) != NULL) ; else \
146 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
147 "'" #expr "' should not be NULL"); \
148 } G_STMT_END
149#endif
150
151#ifdef G_DISABLE_ASSERT
152/* https://gcc.gnu.org/onlinedocs/gcc-8.3.0/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005funreachable
153 * GCC 5 is not a strict lower bound for versions of GCC which provide __builtin_unreachable(). */
154#if __GNUC__ >= 5 || g_macro__has_builtin(__builtin_unreachable)
155#define g_assert_not_reached() G_STMT_START { (void) 0; __builtin_unreachable (); } G_STMT_END
156#else /* if __builtin_unreachable() is not supported: */
157#define g_assert_not_reached() G_STMT_START { (void) 0; } G_STMT_END
158#endif
159
160#define g_assert(expr) G_STMT_START { (void) 0; } G_STMT_END
161#else /* !G_DISABLE_ASSERT */
162#define g_assert_not_reached() G_STMT_START { g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, NULL); } G_STMT_END
163#define g_assert(expr) G_STMT_START { \
164 if G_LIKELY (expr) ; else \
165 g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
166 #expr); \
167 } G_STMT_END
168#endif /* !G_DISABLE_ASSERT */
169
170GLIB_AVAILABLE_IN_ALL
171int g_strcmp0 (const char *str1,
172 const char *str2);
173
174/* report performance results */
175GLIB_AVAILABLE_IN_ALL
176void g_test_minimized_result (double minimized_quantity,
177 const char *format,
178 ...) G_GNUC_PRINTF (2, 3);
179GLIB_AVAILABLE_IN_ALL
180void g_test_maximized_result (double maximized_quantity,
181 const char *format,
182 ...) G_GNUC_PRINTF (2, 3);
183
184/* initialize testing framework */
185GLIB_AVAILABLE_IN_ALL
186void g_test_init (int *argc,
187 char ***argv,
188 ...) G_GNUC_NULL_TERMINATED;
189
190/**
191 * G_TEST_OPTION_ISOLATE_DIRS:
192 *
193 * Creates a unique temporary directory for each unit test and uses
194 * g_set_user_dirs() to set XDG directories to point into subdirectories of it
195 * for the duration of the unit test. The directory tree is cleaned up after the
196 * test finishes successfully. Note that this doesn’t take effect until
197 * g_test_run() is called, so calls to (for example) g_get_user_home_dir() will
198 * return the system-wide value when made in a test program’s main() function.
199 *
200 * The following functions will return subdirectories of the temporary directory
201 * when this option is used. The specific subdirectory paths in use are not
202 * guaranteed to be stable API — always use a getter function to retrieve them.
203 *
204 * - g_get_home_dir()
205 * - g_get_user_cache_dir()
206 * - g_get_system_config_dirs()
207 * - g_get_user_config_dir()
208 * - g_get_system_data_dirs()
209 * - g_get_user_data_dir()
210 * - g_get_user_runtime_dir()
211 *
212 * The subdirectories may not be created by the test harness; as with normal
213 * calls to functions like g_get_user_cache_dir(), the caller must be prepared
214 * to create the directory if it doesn’t exist.
215 *
216 * Since: 2.60
217 */
218#define G_TEST_OPTION_ISOLATE_DIRS "isolate_dirs"
219
220/* While we discourage its use, g_assert() is often used in unit tests
221 * (especially in legacy code). g_assert_*() should really be used instead.
222 * g_assert() can be disabled at client program compile time, which can render
223 * tests useless. Highlight that to the user. */
224#ifdef G_DISABLE_ASSERT
225#if defined(G_HAVE_ISO_VARARGS)
226#define g_test_init(argc, argv, ...) \
227 G_STMT_START { \
228 g_printerr ("Tests were compiled with G_DISABLE_ASSERT and are likely no-ops. Aborting.\n"); \
229 exit (1); \
230 } G_STMT_END
231#elif defined(G_HAVE_GNUC_VARARGS)
232#define g_test_init(argc, argv...) \
233 G_STMT_START { \
234 g_printerr ("Tests were compiled with G_DISABLE_ASSERT and are likely no-ops. Aborting.\n"); \
235 exit (1); \
236 } G_STMT_END
237#else /* no varargs */
238 /* do nothing */
239#endif /* varargs support */
240#endif /* G_DISABLE_ASSERT */
241
242/* query testing framework config */
243#define g_test_initialized() (g_test_config_vars->test_initialized)
244#define g_test_quick() (g_test_config_vars->test_quick)
245#define g_test_slow() (!g_test_config_vars->test_quick)
246#define g_test_thorough() (!g_test_config_vars->test_quick)
247#define g_test_perf() (g_test_config_vars->test_perf)
248#define g_test_verbose() (g_test_config_vars->test_verbose)
249#define g_test_quiet() (g_test_config_vars->test_quiet)
250#define g_test_undefined() (g_test_config_vars->test_undefined)
251GLIB_AVAILABLE_IN_2_38
252gboolean g_test_subprocess (void);
253
254/* run all tests under toplevel suite (path: /) */
255GLIB_AVAILABLE_IN_ALL
256int g_test_run (void);
257/* hook up a test functions under test path */
258GLIB_AVAILABLE_IN_ALL
259void g_test_add_func (const char *testpath,
260 GTestFunc test_func);
261
262GLIB_AVAILABLE_IN_ALL
263void g_test_add_data_func (const char *testpath,
264 gconstpointer test_data,
265 GTestDataFunc test_func);
266
267GLIB_AVAILABLE_IN_2_34
268void g_test_add_data_func_full (const char *testpath,
269 gpointer test_data,
270 GTestDataFunc test_func,
271 GDestroyNotify data_free_func);
272
273/* tell about failure */
274GLIB_AVAILABLE_IN_2_30
275void g_test_fail (void);
276GLIB_AVAILABLE_IN_2_38
277void g_test_incomplete (const gchar *msg);
278GLIB_AVAILABLE_IN_2_38
279void g_test_skip (const gchar *msg);
280GLIB_AVAILABLE_IN_2_38
281gboolean g_test_failed (void);
282GLIB_AVAILABLE_IN_2_38
283void g_test_set_nonfatal_assertions (void);
284
285/**
286 * g_test_add:
287 * @testpath: The test path for a new test case.
288 * @Fixture: The type of a fixture data structure.
289 * @tdata: Data argument for the test functions.
290 * @fsetup: The function to set up the fixture data.
291 * @ftest: The actual test function.
292 * @fteardown: The function to tear down the fixture data.
293 *
294 * Hook up a new test case at @testpath, similar to g_test_add_func().
295 * A fixture data structure with setup and teardown functions may be provided,
296 * similar to g_test_create_case().
297 *
298 * g_test_add() is implemented as a macro, so that the fsetup(), ftest() and
299 * fteardown() callbacks can expect a @Fixture pointer as their first argument
300 * in a type safe manner. They otherwise have type #GTestFixtureFunc.
301 *
302 * Since: 2.16
303 */
304#define g_test_add(testpath, Fixture, tdata, fsetup, ftest, fteardown) \
305 G_STMT_START { \
306 void (*add_vtable) (const char*, \
307 gsize, \
308 gconstpointer, \
309 void (*) (Fixture*, gconstpointer), \
310 void (*) (Fixture*, gconstpointer), \
311 void (*) (Fixture*, gconstpointer)) = (void (*) (const gchar *, gsize, gconstpointer, void (*) (Fixture*, gconstpointer), void (*) (Fixture*, gconstpointer), void (*) (Fixture*, gconstpointer))) g_test_add_vtable; \
312 add_vtable \
313 (testpath, sizeof (Fixture), tdata, fsetup, ftest, fteardown); \
314 } G_STMT_END
315
316/* add test messages to the test report */
317GLIB_AVAILABLE_IN_ALL
318void g_test_message (const char *format,
319 ...) G_GNUC_PRINTF (1, 2);
320GLIB_AVAILABLE_IN_ALL
321void g_test_bug_base (const char *uri_pattern);
322GLIB_AVAILABLE_IN_ALL
323void g_test_bug (const char *bug_uri_snippet);
324GLIB_AVAILABLE_IN_2_62
325void g_test_summary (const char *summary);
326/* measure test timings */
327GLIB_AVAILABLE_IN_ALL
328void g_test_timer_start (void);
329GLIB_AVAILABLE_IN_ALL
330double g_test_timer_elapsed (void); /* elapsed seconds */
331GLIB_AVAILABLE_IN_ALL
332double g_test_timer_last (void); /* repeat last elapsed() result */
333
334/* automatically g_free or g_object_unref upon teardown */
335GLIB_AVAILABLE_IN_ALL
336void g_test_queue_free (gpointer gfree_pointer);
337GLIB_AVAILABLE_IN_ALL
338void g_test_queue_destroy (GDestroyNotify destroy_func,
339 gpointer destroy_data);
340#define g_test_queue_unref(gobject) g_test_queue_destroy (g_object_unref, gobject)
341
342/**
343 * GTestTrapFlags:
344 * @G_TEST_TRAP_SILENCE_STDOUT: Redirect stdout of the test child to
345 * `/dev/null` so it cannot be observed on the console during test
346 * runs. The actual output is still captured though to allow later
347 * tests with g_test_trap_assert_stdout().
348 * @G_TEST_TRAP_SILENCE_STDERR: Redirect stderr of the test child to
349 * `/dev/null` so it cannot be observed on the console during test
350 * runs. The actual output is still captured though to allow later
351 * tests with g_test_trap_assert_stderr().
352 * @G_TEST_TRAP_INHERIT_STDIN: If this flag is given, stdin of the
353 * child process is shared with stdin of its parent process.
354 * It is redirected to `/dev/null` otherwise.
355 *
356 * Test traps are guards around forked tests.
357 * These flags determine what traps to set.
358 *
359 * Deprecated: 2.38: #GTestTrapFlags is used only with g_test_trap_fork(),
360 * which is deprecated. g_test_trap_subprocess() uses
361 * #GTestSubprocessFlags.
362 */
363typedef enum {
364 G_TEST_TRAP_SILENCE_STDOUT = 1 << 7,
365 G_TEST_TRAP_SILENCE_STDERR = 1 << 8,
366 G_TEST_TRAP_INHERIT_STDIN = 1 << 9
367} GTestTrapFlags GLIB_DEPRECATED_TYPE_IN_2_38_FOR(GTestSubprocessFlags);
368
369G_GNUC_BEGIN_IGNORE_DEPRECATIONS
370
371GLIB_DEPRECATED_IN_2_38_FOR (g_test_trap_subprocess)
372gboolean g_test_trap_fork (guint64 usec_timeout,
373 GTestTrapFlags test_trap_flags);
374
375G_GNUC_END_IGNORE_DEPRECATIONS
376
377typedef enum {
378 G_TEST_SUBPROCESS_INHERIT_STDIN = 1 << 0,
379 G_TEST_SUBPROCESS_INHERIT_STDOUT = 1 << 1,
380 G_TEST_SUBPROCESS_INHERIT_STDERR = 1 << 2
381} GTestSubprocessFlags;
382
383GLIB_AVAILABLE_IN_2_38
384void g_test_trap_subprocess (const char *test_path,
385 guint64 usec_timeout,
386 GTestSubprocessFlags test_flags);
387
388GLIB_AVAILABLE_IN_ALL
389gboolean g_test_trap_has_passed (void);
390GLIB_AVAILABLE_IN_ALL
391gboolean g_test_trap_reached_timeout (void);
392#define g_test_trap_assert_passed() g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 0, 0)
393#define g_test_trap_assert_failed() g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 1, 0)
394#define g_test_trap_assert_stdout(soutpattern) g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 2, soutpattern)
395#define g_test_trap_assert_stdout_unmatched(soutpattern) g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 3, soutpattern)
396#define g_test_trap_assert_stderr(serrpattern) g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 4, serrpattern)
397#define g_test_trap_assert_stderr_unmatched(serrpattern) g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 5, serrpattern)
398
399/* provide seed-able random numbers for tests */
400#define g_test_rand_bit() (0 != (g_test_rand_int() & (1 << 15)))
401GLIB_AVAILABLE_IN_ALL
402gint32 g_test_rand_int (void);
403GLIB_AVAILABLE_IN_ALL
404gint32 g_test_rand_int_range (gint32 begin,
405 gint32 end);
406GLIB_AVAILABLE_IN_ALL
407double g_test_rand_double (void);
408GLIB_AVAILABLE_IN_ALL
409double g_test_rand_double_range (double range_start,
410 double range_end);
411
412/*
413 * semi-internal API: non-documented symbols with stable ABI. You
414 * should use the non-internal helper macros instead. However, for
415 * compatibility reason, you may use this semi-internal API.
416 */
417GLIB_AVAILABLE_IN_ALL
418GTestCase* g_test_create_case (const char *test_name,
419 gsize data_size,
420 gconstpointer test_data,
421 GTestFixtureFunc data_setup,
422 GTestFixtureFunc data_test,
423 GTestFixtureFunc data_teardown);
424GLIB_AVAILABLE_IN_ALL
425GTestSuite* g_test_create_suite (const char *suite_name);
426GLIB_AVAILABLE_IN_ALL
427GTestSuite* g_test_get_root (void);
428GLIB_AVAILABLE_IN_ALL
429void g_test_suite_add (GTestSuite *suite,
430 GTestCase *test_case);
431GLIB_AVAILABLE_IN_ALL
432void g_test_suite_add_suite (GTestSuite *suite,
433 GTestSuite *nestedsuite);
434GLIB_AVAILABLE_IN_ALL
435int g_test_run_suite (GTestSuite *suite);
436
437GLIB_AVAILABLE_IN_ALL
438void g_test_trap_assertions (const char *domain,
439 const char *file,
440 int line,
441 const char *func,
442 guint64 assertion_flags, /* 0-pass, 1-fail, 2-outpattern, 4-errpattern */
443 const char *pattern);
444GLIB_AVAILABLE_IN_ALL
445void g_assertion_message (const char *domain,
446 const char *file,
447 int line,
448 const char *func,
449 const char *message);
450GLIB_AVAILABLE_IN_ALL
451void g_assertion_message_expr (const char *domain,
452 const char *file,
453 int line,
454 const char *func,
455 const char *expr) G_GNUC_NORETURN;
456GLIB_AVAILABLE_IN_ALL
457void g_assertion_message_cmpstr (const char *domain,
458 const char *file,
459 int line,
460 const char *func,
461 const char *expr,
462 const char *arg1,
463 const char *cmp,
464 const char *arg2);
465GLIB_AVAILABLE_IN_ALL
466void g_assertion_message_cmpnum (const char *domain,
467 const char *file,
468 int line,
469 const char *func,
470 const char *expr,
471 long double arg1,
472 const char *cmp,
473 long double arg2,
474 char numtype);
475GLIB_AVAILABLE_IN_ALL
476void g_assertion_message_error (const char *domain,
477 const char *file,
478 int line,
479 const char *func,
480 const char *expr,
481 const GError *error,
482 GQuark error_domain,
483 int error_code);
484GLIB_AVAILABLE_IN_ALL
485void g_test_add_vtable (const char *testpath,
486 gsize data_size,
487 gconstpointer test_data,
488 GTestFixtureFunc data_setup,
489 GTestFixtureFunc data_test,
490 GTestFixtureFunc data_teardown);
491typedef struct {
492 gboolean test_initialized;
493 gboolean test_quick; /* disable thorough tests */
494 gboolean test_perf; /* run performance tests */
495 gboolean test_verbose; /* extra info */
496 gboolean test_quiet; /* reduce output */
497 gboolean test_undefined; /* run tests that are meant to assert */
498} GTestConfig;
499GLIB_VAR const GTestConfig * const g_test_config_vars;
500
501/* internal logging API */
502typedef enum {
503 G_TEST_RUN_SUCCESS,
504 G_TEST_RUN_SKIPPED,
505 G_TEST_RUN_FAILURE,
506 G_TEST_RUN_INCOMPLETE
507} GTestResult;
508
509typedef enum {
510 G_TEST_LOG_NONE,
511 G_TEST_LOG_ERROR, /* s:msg */
512 G_TEST_LOG_START_BINARY, /* s:binaryname s:seed */
513 G_TEST_LOG_LIST_CASE, /* s:testpath */
514 G_TEST_LOG_SKIP_CASE, /* s:testpath */
515 G_TEST_LOG_START_CASE, /* s:testpath */
516 G_TEST_LOG_STOP_CASE, /* d:status d:nforks d:elapsed */
517 G_TEST_LOG_MIN_RESULT, /* s:blurb d:result */
518 G_TEST_LOG_MAX_RESULT, /* s:blurb d:result */
519 G_TEST_LOG_MESSAGE, /* s:blurb */
520 G_TEST_LOG_START_SUITE,
521 G_TEST_LOG_STOP_SUITE
522} GTestLogType;
523
524typedef struct {
525 GTestLogType log_type;
526 guint n_strings;
527 gchar **strings; /* NULL terminated */
528 guint n_nums;
529 long double *nums;
530} GTestLogMsg;
531typedef struct {
532 /*< private >*/
533 GString *data;
534 GSList *msgs;
535} GTestLogBuffer;
536
537GLIB_AVAILABLE_IN_ALL
538const char* g_test_log_type_name (GTestLogType log_type);
539GLIB_AVAILABLE_IN_ALL
540GTestLogBuffer* g_test_log_buffer_new (void);
541GLIB_AVAILABLE_IN_ALL
542void g_test_log_buffer_free (GTestLogBuffer *tbuffer);
543GLIB_AVAILABLE_IN_ALL
544void g_test_log_buffer_push (GTestLogBuffer *tbuffer,
545 guint n_bytes,
546 const guint8 *bytes);
547GLIB_AVAILABLE_IN_ALL
548GTestLogMsg* g_test_log_buffer_pop (GTestLogBuffer *tbuffer);
549GLIB_AVAILABLE_IN_ALL
550void g_test_log_msg_free (GTestLogMsg *tmsg);
551
552/**
553 * GTestLogFatalFunc:
554 * @log_domain: the log domain of the message
555 * @log_level: the log level of the message (including the fatal and recursion flags)
556 * @message: the message to process
557 * @user_data: user data, set in g_test_log_set_fatal_handler()
558 *
559 * Specifies the prototype of fatal log handler functions.
560 *
561 * Returns: %TRUE if the program should abort, %FALSE otherwise
562 *
563 * Since: 2.22
564 */
565typedef gboolean (*GTestLogFatalFunc) (const gchar *log_domain,
566 GLogLevelFlags log_level,
567 const gchar *message,
568 gpointer user_data);
569GLIB_AVAILABLE_IN_ALL
570void
571g_test_log_set_fatal_handler (GTestLogFatalFunc log_func,
572 gpointer user_data);
573
574GLIB_AVAILABLE_IN_2_34
575void g_test_expect_message (const gchar *log_domain,
576 GLogLevelFlags log_level,
577 const gchar *pattern);
578GLIB_AVAILABLE_IN_2_34
579void g_test_assert_expected_messages_internal (const char *domain,
580 const char *file,
581 int line,
582 const char *func);
583
584typedef enum
585{
586 G_TEST_DIST,
587 G_TEST_BUILT
588} GTestFileType;
589
590GLIB_AVAILABLE_IN_2_38
591gchar * g_test_build_filename (GTestFileType file_type,
592 const gchar *first_path,
593 ...) G_GNUC_NULL_TERMINATED;
594GLIB_AVAILABLE_IN_2_38
595const gchar *g_test_get_dir (GTestFileType file_type);
596GLIB_AVAILABLE_IN_2_38
597const gchar *g_test_get_filename (GTestFileType file_type,
598 const gchar *first_path,
599 ...) G_GNUC_NULL_TERMINATED;
600
601#define g_test_assert_expected_messages() g_test_assert_expected_messages_internal (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC)
602
603G_END_DECLS
604
605#endif /* __G_TEST_UTILS_H__ */
606