1 /* GLib testing utilities
2 * Copyright (C) 2007 Tim Janik
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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #include "gtestutils.h"
22 #include <sys/types.h>
30 #ifdef HAVE_SYS_SELECT_H
31 #include <sys/select.h>
32 #endif /* HAVE_SYS_SELECT_H */
34 /* --- structures --- */
39 void (*fixture_setup) (void*);
40 void (*fixture_test) (void*);
41 void (*fixture_teardown) (void*);
49 typedef struct DestroyEntry DestroyEntry;
53 GDestroyNotify destroy_func;
54 gpointer destroy_data;
57 /* --- prototypes --- */
58 static void test_run_seed (const gchar *rseed);
59 static void test_trap_clear (void);
60 static guint8* g_test_log_dump (GTestLogMsg *msg,
63 /* --- variables --- */
64 static int test_log_fd = -1;
65 static gboolean test_mode_fatal = TRUE;
66 static gboolean g_test_run_once = TRUE;
67 static gboolean test_run_list = FALSE;
68 static gchar *test_run_seedstr = NULL;
69 static GRand *test_run_rand = NULL;
70 static gchar *test_run_name = "";
71 static guint test_run_forks = 0;
72 static guint test_run_count = 0;
73 static guint test_skip_count = 0;
74 static GTimer *test_user_timer = NULL;
75 static double test_user_stamp = 0;
76 static GSList *test_paths = NULL;
77 static GTestSuite *test_suite_root = NULL;
78 static int test_trap_last_status = 0;
79 static int test_trap_last_pid = 0;
80 static char *test_trap_last_stdout = NULL;
81 static char *test_trap_last_stderr = NULL;
82 static char *test_uri_base = NULL;
83 static gboolean test_debug_log = FALSE;
84 static DestroyEntry *test_destroy_queue = NULL;
85 const GTestConfig *g_test_config_vars = NULL;
86 static GTestConfig mutable_test_config_vars = {
87 TRUE, /* test_quick */
88 FALSE, /* test_perf */
89 FALSE, /* test_verbose */
90 FALSE, /* test_quiet */
93 /* --- functions --- */
95 g_test_log_type_name (GTestLogType log_type)
99 case G_TEST_LOG_NONE: return "none";
100 case G_TEST_LOG_ERROR: return "error";
101 case G_TEST_LOG_START_BINARY: return "binary";
102 case G_TEST_LOG_LIST_CASE: return "list";
103 case G_TEST_LOG_SKIP_CASE: return "skip";
104 case G_TEST_LOG_START_CASE: return "start";
105 case G_TEST_LOG_STOP_CASE: return "stop";
106 case G_TEST_LOG_MIN_RESULT: return "minperf";
107 case G_TEST_LOG_MAX_RESULT: return "maxperf";
108 case G_TEST_LOG_MESSAGE: return "message";
114 g_test_log_send (guint n_bytes,
115 const guint8 *buffer)
117 if (test_log_fd >= 0)
121 r = write (test_log_fd, buffer, n_bytes);
122 while (r < 0 && errno == EINTR);
126 GTestLogBuffer *lbuffer = g_test_log_buffer_new();
129 g_test_log_buffer_push (lbuffer, n_bytes, buffer);
130 msg = g_test_log_buffer_pop (lbuffer);
131 g_assert (msg != NULL); // FIXME: should be g_awrn_if_fail
132 g_assert (lbuffer->data->len == 0); // FIXME: should be g_awrn_if_fail
133 g_test_log_buffer_free (lbuffer);
135 g_printerr ("{*LOG(%s)", g_test_log_type_name (msg->log_type));
136 for (ui = 0; ui < msg->n_strings; ui++)
137 g_printerr (":{%s}", msg->strings[ui]);
141 for (ui = 0; ui < msg->n_nums; ui++)
142 g_printerr ("%s%.16Lg", ui ? ";" : "", msg->nums[ui]);
145 g_printerr (":LOG*}\n");
146 g_test_log_msg_free (msg);
151 g_test_log (GTestLogType lbit,
152 const gchar *string1,
153 const gchar *string2,
157 gboolean fail = lbit == G_TEST_LOG_STOP_CASE && largs[0] != 0;
159 gchar *astrings[3] = { NULL, NULL, NULL };
165 case G_TEST_LOG_STOP_CASE:
167 g_print ("%s\n", fail ? "FAIL" : "OK");
168 if (fail && test_mode_fatal)
171 case G_TEST_LOG_MIN_RESULT:
172 if (g_test_verbose())
173 g_print ("(MINPERF:%s)\n", string1);
175 case G_TEST_LOG_MAX_RESULT:
176 if (g_test_verbose())
177 g_print ("(MAXPERF:%s)\n", string1);
179 case G_TEST_LOG_MESSAGE:
180 if (g_test_verbose())
181 g_print ("(MSG: %s)\n", string1);
187 msg.n_strings = (string1 != NULL) + (string1 && string2);
188 msg.strings = astrings;
189 astrings[0] = (gchar*) string1;
190 astrings[1] = astrings[0] ? (gchar*) string2 : NULL;
193 dbuffer = g_test_log_dump (&msg, &dbufferlen);
194 g_test_log_send (dbufferlen, dbuffer);
199 case G_TEST_LOG_START_CASE:
201 g_print ("%s: ", string1);
208 parse_args (gint *argc_p,
211 guint argc = *argc_p;
212 gchar **argv = *argv_p;
214 /* parse known args */
215 for (i = 1; i < argc; i++)
217 if (strcmp (argv[i], "--g-fatal-warnings") == 0)
219 GLogLevelFlags fatal_mask = (GLogLevelFlags) g_log_set_always_fatal ((GLogLevelFlags) G_LOG_FATAL_MASK);
220 fatal_mask = (GLogLevelFlags) (fatal_mask | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL);
221 g_log_set_always_fatal (fatal_mask);
224 else if (strcmp (argv[i], "--keep-going") == 0 ||
225 strcmp (argv[i], "-k") == 0)
227 test_mode_fatal = FALSE;
230 else if (strcmp (argv[i], "--debug-log") == 0)
232 test_debug_log = TRUE;
235 else if (strcmp ("--GTestLogFD", argv[i]) == 0 || strncmp ("--GTestLogFD=", argv[i], 13) == 0)
237 gchar *equal = argv[i] + 12;
239 test_log_fd = g_ascii_strtoull (equal + 1, NULL, 0);
240 else if (i + 1 < argc)
243 test_log_fd = g_ascii_strtoull (argv[i], NULL, 0);
247 else if (strcmp ("--GTestSkipCount", argv[i]) == 0 || strncmp ("--GTestSkipCount=", argv[i], 17) == 0)
249 gchar *equal = argv[i] + 16;
251 test_skip_count = g_ascii_strtoull (equal + 1, NULL, 0);
252 else if (i + 1 < argc)
255 test_skip_count = g_ascii_strtoull (argv[i], NULL, 0);
259 else if (strcmp ("-p", argv[i]) == 0 || strncmp ("-p=", argv[i], 3) == 0)
261 gchar *equal = argv[i] + 2;
263 test_paths = g_slist_prepend (test_paths, equal + 1);
264 else if (i + 1 < argc)
267 test_paths = g_slist_prepend (test_paths, argv[i]);
271 else if (strcmp ("-m", argv[i]) == 0 || strncmp ("-m=", argv[i], 3) == 0)
273 gchar *equal = argv[i] + 2;
274 const gchar *mode = "";
277 else if (i + 1 < argc)
282 if (strcmp (mode, "perf") == 0)
283 mutable_test_config_vars.test_perf = TRUE;
284 else if (strcmp (mode, "slow") == 0)
285 mutable_test_config_vars.test_quick = FALSE;
286 else if (strcmp (mode, "quick") == 0)
288 mutable_test_config_vars.test_quick = TRUE;
289 mutable_test_config_vars.test_perf = FALSE;
292 g_error ("unknown test mode: -m %s", mode);
295 else if (strcmp ("-q", argv[i]) == 0 || strcmp ("--quiet", argv[i]) == 0)
297 mutable_test_config_vars.test_quiet = TRUE;
298 mutable_test_config_vars.test_verbose = FALSE;
301 else if (strcmp ("--verbose", argv[i]) == 0)
303 mutable_test_config_vars.test_quiet = FALSE;
304 mutable_test_config_vars.test_verbose = TRUE;
307 else if (strcmp ("-l", argv[i]) == 0)
309 test_run_list = TRUE;
312 else if (strcmp ("--seed", argv[i]) == 0 || strncmp ("--seed=", argv[i], 7) == 0)
314 gchar *equal = argv[i] + 6;
316 test_run_seedstr = equal + 1;
317 else if (i + 1 < argc)
320 test_run_seedstr = argv[i];
327 for (i = 1; i < argc; i++)
339 * @argc: Address of the @argc parameter of the main() function.
340 * Changed if any arguments were handled.
341 * @argv: Address of the @argv parameter of main().
342 * Any parameters understood by g_test_init() stripped before return.
344 * Initialize the GLib testing framework, e.g. by seeding the
345 * test random number generator, the name for g_get_prgname()
346 * and parsing test related command line args.
347 * So far, the following arguments are understood:
349 * -l list test cases available in a test executable.
350 * --seed RANDOMSEED provide a random seed to reproduce test runs using random numbers.
351 * --verbose run tests verbosely.
352 * -q, --quiet run tests quietly.
353 * -p TESTPATH execute all tests matching TESTPATH.
354 * -m {perf|slow|quick} execute tests according to this test modes:
355 * perf - performance tests, may take long and report results.
356 * slow - slow and thorough tests, may take quite long and maximize coverage.
357 * quick - quick tests, should run really quickly and give good coverage.
358 * --debug-log debug test logging output.
359 * -k, --keep-going gtester specific argument.
360 * --GTestLogFD N gtester specific argument.
361 * --GTestSkipCount N gtester specific argument.
365 g_test_init (int *argc,
369 static char seedstr[4 + 4 * 8 + 1];
372 /* make warnings and criticals fatal for all test programs */
373 GLogLevelFlags fatal_mask = (GLogLevelFlags) g_log_set_always_fatal ((GLogLevelFlags) G_LOG_FATAL_MASK);
374 fatal_mask = (GLogLevelFlags) (fatal_mask | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL);
375 /* check caller args */
376 g_return_if_fail (argc != NULL);
377 g_return_if_fail (argv != NULL);
378 g_return_if_fail (g_test_config_vars == NULL);
379 g_test_config_vars = &mutable_test_config_vars;
381 va_start (args, argv);
382 vararg1 = va_arg (args, gpointer); /* reserved for future extensions */
384 g_return_if_fail (vararg1 == NULL);
386 /* setup random seed string */
387 g_snprintf (seedstr, sizeof (seedstr), "R02S%08x%08x%08x%08x", g_random_int(), g_random_int(), g_random_int(), g_random_int());
388 test_run_seedstr = seedstr;
390 /* parse args, sets up mode, changes seed, etc. */
391 parse_args (argc, argv);
392 if (!g_get_prgname())
393 g_set_prgname ((*argv)[0]);
395 /* verify GRand reliability, needed for reliable seeds */
398 GRand *rg = g_rand_new_with_seed (0xc8c49fb6);
399 guint32 t1 = g_rand_int (rg), t2 = g_rand_int (rg), t3 = g_rand_int (rg), t4 = g_rand_int (rg);
400 // g_print ("GRand-current: 0x%x 0x%x 0x%x 0x%x\n", t1, t2, t3, t4);
401 if (t1 != 0xfab39f9b || t2 != 0xb948fb0e || t3 != 0x3d31be26 || t4 != 0x43a19d66)
402 g_warning ("random numbers are not GRand-2.2 compatible, seeds may be broken (check $G_RANDOM_VERSION)");
406 /* check rand seed */
407 test_run_seed (test_run_seedstr);
409 /* report program start */
410 g_test_log (G_TEST_LOG_START_BINARY, g_get_prgname(), test_run_seedstr, 0, NULL);
414 test_run_seed (const gchar *rseed)
416 guint seed_failed = 0;
418 g_rand_free (test_run_rand);
419 test_run_rand = NULL;
420 while (strchr (" \t\v\r\n\f", *rseed))
422 if (strncmp (rseed, "R02S", 4) == 0) // seed for random generator 02 (GRand-2.2)
424 const char *s = rseed + 4;
425 if (strlen (s) >= 32) // require 4 * 8 chars
427 guint32 seedarray[4];
428 gchar *p, hexbuf[9] = { 0, };
429 memcpy (hexbuf, s + 0, 8);
430 seedarray[0] = g_ascii_strtoull (hexbuf, &p, 16);
431 seed_failed += p != NULL && *p != 0;
432 memcpy (hexbuf, s + 8, 8);
433 seedarray[1] = g_ascii_strtoull (hexbuf, &p, 16);
434 seed_failed += p != NULL && *p != 0;
435 memcpy (hexbuf, s + 16, 8);
436 seedarray[2] = g_ascii_strtoull (hexbuf, &p, 16);
437 seed_failed += p != NULL && *p != 0;
438 memcpy (hexbuf, s + 24, 8);
439 seedarray[3] = g_ascii_strtoull (hexbuf, &p, 16);
440 seed_failed += p != NULL && *p != 0;
443 test_run_rand = g_rand_new_with_seed_array (seedarray, 4);
448 g_error ("Unknown or invalid random seed: %s", rseed);
454 * Get a reproducable random integer number.
455 * The random numbers generate by the g_test_rand_*() family of functions
456 * change with every new test program start, unless the --seed option is
457 * given when starting test programs.
458 * For individual test cases however, the random number generator is
459 * reseeded, to avoid dependencies between tests and to make --seed
460 * effective for all test cases.
462 * Returns: a random number from the seeded random number generator.
465 g_test_rand_int (void)
467 return g_rand_int (test_run_rand);
471 * g_test_rand_int_range:
472 * @begin: the minimum value returned by this function
473 * @end: the smallest value not to be returned by this function
475 * Get a reproducable random integer number out of a specified range,
476 * see g_test_rand_int() for details on test case random numbers.
478 * Returns a number with @begin <= number < @end.
481 g_test_rand_int_range (gint32 begin,
484 return g_rand_int_range (test_run_rand, begin, end);
488 * g_test_rand_double:
490 * Get a reproducable random floating point number,
491 * see g_test_rand_int() for details on test case random numbers.
493 * Return a random number from the seeded random number generator.
496 g_test_rand_double (void)
498 return g_rand_double (test_run_rand);
502 * g_test_rand_double_range:
503 * @range_start: the minimum value returned by this function
504 * @range_end: the minimum value not returned by this function
506 * Get a reproducable random floating pointer number out of a specified range,
507 * see g_test_rand_int() for details on test case random numbers.
509 * Returns a number with @range_start <= number < @range_end.
512 g_test_rand_double_range (double range_start,
515 return g_rand_double_range (test_run_rand, range_start, range_end);
519 * g_test_timer_start:
521 * Start a timing test. Call g_test_timer_elapsed() when the task is supposed
522 * to be done. Call this function again to restart the timer.
525 g_test_timer_start (void)
527 if (!test_user_timer)
528 test_user_timer = g_timer_new();
530 g_timer_start (test_user_timer);
534 * g_test_timer_elapsed:
536 * Get the time since the last start of the timer with g_test_timer_start().
539 g_test_timer_elapsed (void)
541 test_user_stamp = test_user_timer ? g_timer_elapsed (test_user_timer, NULL) : 0;
542 return test_user_stamp;
548 * Report the last result of g_test_timer_elapsed().
551 g_test_timer_last (void)
553 return test_user_stamp;
557 * g_test_minimized_result:
558 * @minimized_quantity: the reported value
559 * @format: the format string of the report message
561 * Report the result of a performance or measurement test.
562 * The test should generally strive to minimize the reported
563 * quantities (smaller values are better than larger ones),
564 * this and @minimized_quantity can determine sorting
565 * order for test result reports.
568 g_test_minimized_result (double minimized_quantity,
572 long double largs = minimized_quantity;
575 va_start (args, format);
576 buffer = g_strdup_vprintf (format, args);
578 g_test_log (G_TEST_LOG_MIN_RESULT, buffer, NULL, 1, &largs);
583 * g_test_minimized_result:
584 * @maximized_quantity: the reported value
585 * @format: the format string of the report message
587 * Report the result of a performance or measurement test.
588 * The test should generally strive to maximize the reported
589 * quantities (larger values are better than smaller ones),
590 * this and @maximized_quantity can determine sorting
591 * order for test result reports.
594 g_test_maximized_result (double maximized_quantity,
598 long double largs = maximized_quantity;
601 va_start (args, format);
602 buffer = g_strdup_vprintf (format, args);
604 g_test_log (G_TEST_LOG_MAX_RESULT, buffer, NULL, 1, &largs);
610 * @format: the format string
611 * @...: printf-like arguments to @format
613 * Add a message to the test report.
616 g_test_message (const char *format,
621 va_start (args, format);
622 buffer = g_strdup_vprintf (format, args);
624 g_test_log (G_TEST_LOG_MESSAGE, buffer, NULL, 0, NULL);
630 * @uri_pattern: the base pattern for bug URIs
632 * Specify the base URI for bug reports.
633 * The base URI is used to construct bug report messages for
634 * g_test_message() when g_test_bug() is called.
635 * Calling this function outside of a test case sets the
636 * default base URI for all test cases. Calling it from within
637 * a test case changes the base URI for the scope of the test
639 * Bug URIs are constructed by appending a bug specific URI
640 * portion to @uri_pattern, or by replacing the special string
641 * '%s' within @uri_pattern if that is present.
644 g_test_bug_base (const char *uri_pattern)
646 g_free (test_uri_base);
647 test_uri_base = g_strdup (uri_pattern);
652 * @bug_uri_snippet: Bug specific bug tracker URI portion.
654 * This function adds a message to test reports that
655 * associates a bug URI with a test case.
656 * Bug URIs are constructed from a base URI set with g_test_bug_base()
657 * and @bug_uri_snippet.
660 g_test_bug (const char *bug_uri_snippet)
663 g_return_if_fail (test_uri_base != NULL);
664 g_return_if_fail (bug_uri_snippet != NULL);
665 c = strstr (test_uri_base, "%s");
668 char *b = g_strndup (test_uri_base, c - test_uri_base);
669 char *s = g_strconcat (b, bug_uri_snippet, c + 2, NULL);
671 g_test_message ("Bug Reference: %s", s);
675 g_test_message ("Bug Reference: %s%s", test_uri_base, bug_uri_snippet);
681 * Get the toplevel test suite for the test path API.
683 * Returns: the toplevel #GTestSuite
686 g_test_get_root (void)
688 if (!test_suite_root)
690 test_suite_root = g_test_create_suite ("root");
691 g_free (test_suite_root->name);
692 test_suite_root->name = g_strdup ("");
694 return test_suite_root;
700 * Runs all tests under the toplevel suite which can be retrieved
701 * with g_test_get_root(). Similar to g_test_run_suite(), the test
702 * cases to be run are filtered according to
703 * test path arguments (-p <testpath>) as parsed by g_test_init().
704 * g_test_run_suite() or g_test_run() may only be called once
710 return g_test_run_suite (g_test_get_root());
714 * g_test_create_case:
715 * @test_name: the name for the test case
716 * @data_size: the size of the fixture data structure
717 * @data_setup: the function to set up the fixture data
718 * @data_test: the actual test function
719 * @data_teardown: the function to teardown the fixture data
721 * Create a new #GTestCase, named @test_name, this API is fairly
722 * low level, calling g_test_add() or g_test_add_func() is preferable.
723 * When this test is executed, a fixture structure of size @data_size
724 * will be allocated and filled with 0s. Then data_setup() is called
725 * to initialize the fixture. After fixture setup, the actual test
726 * function data_test() is called. Once the test run completed, the
727 * fixture structure is torn down by calling data_teardown() and
728 * after that the memory is released.
729 * Splitting up a test run into fixture setup, test function and
730 * fixture teardown is most usful if the same fixture is used for
731 * multiple tests. In this cases, g_test_create_case() will be
732 * called with the same fixture, but varying @test_name and
733 * @data_test arguments.
735 * Returns a newly allocated #GTestCase.
738 g_test_create_case (const char *test_name,
740 void (*data_setup) (void),
741 void (*data_test) (void),
742 void (*data_teardown) (void))
744 g_return_val_if_fail (test_name != NULL, NULL);
745 g_return_val_if_fail (strchr (test_name, '/') == NULL, NULL);
746 g_return_val_if_fail (test_name[0] != 0, NULL);
747 g_return_val_if_fail (data_test != NULL, NULL);
748 GTestCase *tc = g_slice_new0 (GTestCase);
749 tc->name = g_strdup (test_name);
750 tc->fixture_size = data_size;
751 tc->fixture_setup = (void*) data_setup;
752 tc->fixture_test = (void*) data_test;
753 tc->fixture_teardown = (void*) data_teardown;
758 g_test_add_vtable (const char *testpath,
760 void (*data_setup) (void),
761 void (*fixture_test_func) (void),
762 void (*data_teardown) (void))
768 g_return_if_fail (testpath != NULL);
769 g_return_if_fail (testpath[0] == '/');
770 g_return_if_fail (fixture_test_func != NULL);
772 suite = g_test_get_root();
773 segments = g_strsplit (testpath, "/", -1);
774 for (ui = 0; segments[ui] != NULL; ui++)
776 const char *seg = segments[ui];
777 gboolean islast = segments[ui + 1] == NULL;
778 if (islast && !seg[0])
779 g_error ("invalid test case path: %s", testpath);
781 continue; // initial or duplicate slash
784 GTestSuite *csuite = g_test_create_suite (seg);
785 g_test_suite_add_suite (suite, csuite);
790 GTestCase *tc = g_test_create_case (seg, data_size, data_setup, fixture_test_func, data_teardown);
791 g_test_suite_add (suite, tc);
794 g_strfreev (segments);
799 * @testpath: Slash seperated test case path name for the test.
800 * @test_func: The test function to invoke for this test.
802 * Create a new test case, similar to g_test_create_case(). However
803 * the test is assumed to use no fixture, and test suites are automatically
804 * created on the fly and added to the root fixture, based on the
805 * slash seperated portions of @testpath.
808 g_test_add_func (const char *testpath,
809 void (*test_func) (void))
811 g_return_if_fail (testpath != NULL);
812 g_return_if_fail (testpath[0] == '/');
813 g_return_if_fail (test_func != NULL);
814 g_test_add_vtable (testpath, 0, NULL, test_func, NULL);
818 * g_test_create_suite:
819 * @suite_name: a name for the suite
821 * Create a new test suite with the name @suite_name.
823 * Returns: A newly allocated #GTestSuite instance.
826 g_test_create_suite (const char *suite_name)
828 g_return_val_if_fail (suite_name != NULL, NULL);
829 g_return_val_if_fail (strchr (suite_name, '/') == NULL, NULL);
830 g_return_val_if_fail (suite_name[0] != 0, NULL);
831 GTestSuite *ts = g_slice_new0 (GTestSuite);
832 ts->name = g_strdup (suite_name);
838 * @suite: a #GTestSuite
839 * @test_case: a #GTestCase
841 * Adds @test_case to @suite.
844 g_test_suite_add (GTestSuite *suite,
845 GTestCase *test_case)
847 g_return_if_fail (suite != NULL);
848 g_return_if_fail (test_case != NULL);
849 suite->cases = g_slist_prepend (suite->cases, test_case);
853 * g_test_suite_add_suite:
854 * @suite: a #GTestSuite
855 * @nestedsuite: another #GTestSuite
857 * Adds @nestedsuite to @suite.
860 g_test_suite_add_suite (GTestSuite *suite,
861 GTestSuite *nestedsuite)
863 g_return_if_fail (suite != NULL);
864 g_return_if_fail (nestedsuite != NULL);
865 suite->suites = g_slist_prepend (suite->suites, nestedsuite);
870 * @gfree_pointer: the pointer to be stored.
872 * Enqueue a pointer to be released with g_free() during the next
873 * teardown phase. This is equivalent to calling g_test_queue_destroy()
874 * with a destroy callback of g_free().
877 g_test_queue_free (gpointer gfree_pointer)
880 g_test_queue_destroy (g_free, gfree_pointer);
884 * g_test_queue_destroy:
885 * @destroy_func: Destroy callback for teardown phase.
886 * @destroy_data: Destroy callback data.
888 * This function enqueus a callback @destroy_func() to be executed
889 * during the next test case teardown phase. This is most useful
890 * to auto destruct allocted test resources at the end of a test run.
891 * Resources are released in reverse queue order, that means enqueueing
892 * callback A before callback B will cause B() to be called before
893 * A() during teardown.
896 g_test_queue_destroy (GDestroyNotify destroy_func,
897 gpointer destroy_data)
899 DestroyEntry *dentry;
900 g_return_if_fail (destroy_func != NULL);
901 dentry = g_slice_new0 (DestroyEntry);
902 dentry->destroy_func = destroy_func;
903 dentry->destroy_data = destroy_data;
904 dentry->next = test_destroy_queue;
905 test_destroy_queue = dentry;
909 test_case_run (GTestCase *tc)
911 gchar *old_name = test_run_name, *old_base = g_strdup (test_uri_base);
912 test_run_name = g_strconcat (old_name, "/", tc->name, NULL);
913 if (++test_run_count <= test_skip_count)
914 g_test_log (G_TEST_LOG_SKIP_CASE, test_run_name, NULL, 0, NULL);
915 else if (test_run_list)
917 g_print ("%s\n", test_run_name);
918 g_test_log (G_TEST_LOG_LIST_CASE, test_run_name, NULL, 0, NULL);
922 GTimer *test_run_timer = g_timer_new();
923 long double largs[3];
924 g_test_log (G_TEST_LOG_START_CASE, test_run_name, NULL, 0, NULL);
926 g_timer_start (test_run_timer);
927 void *fixture = g_malloc0 (tc->fixture_size);
928 test_run_seed (test_run_seedstr);
929 if (tc->fixture_setup)
930 tc->fixture_setup (fixture);
931 tc->fixture_test (fixture);
933 while (test_destroy_queue)
935 DestroyEntry *dentry = test_destroy_queue;
936 test_destroy_queue = dentry->next;
937 dentry->destroy_func (dentry->destroy_data);
938 g_slice_free (DestroyEntry, dentry);
940 if (tc->fixture_teardown)
941 tc->fixture_teardown (fixture);
943 g_timer_stop (test_run_timer);
945 largs[1] = test_run_forks;
946 largs[2] = g_timer_elapsed (test_run_timer, NULL);
947 g_test_log (G_TEST_LOG_STOP_CASE, NULL, NULL, G_N_ELEMENTS (largs), largs);
948 g_timer_destroy (test_run_timer);
950 g_free (test_run_name);
951 test_run_name = old_name;
952 g_free (test_uri_base);
953 test_uri_base = old_base;
958 g_test_run_suite_internal (GTestSuite *suite,
961 guint n_bad = 0, n_good = 0, bad_suite = 0, l;
962 gchar *rest, *old_name = test_run_name;
963 GSList *slist, *reversed;
964 g_return_val_if_fail (suite != NULL, -1);
965 while (path[0] == '/')
968 rest = strchr (path, '/');
969 l = rest ? MIN (l, rest - path) : l;
970 test_run_name = suite->name[0] == 0 ? g_strdup (test_run_name) : g_strconcat (old_name, "/", suite->name, NULL);
971 reversed = g_slist_reverse (g_slist_copy (suite->cases));
972 for (slist = reversed; slist; slist = slist->next)
974 GTestCase *tc = slist->data;
975 guint n = l ? strlen (tc->name) : 0;
976 if (l == n && strncmp (path, tc->name, n) == 0)
979 n_bad += test_case_run (tc) != 0;
982 g_slist_free (reversed);
983 reversed = g_slist_reverse (g_slist_copy (suite->suites));
984 for (slist = reversed; slist; slist = slist->next)
986 GTestSuite *ts = slist->data;
987 guint n = l ? strlen (ts->name) : 0;
988 if (l == n && strncmp (path, ts->name, n) == 0)
989 bad_suite += g_test_run_suite_internal (ts, rest ? rest : "") != 0;
991 g_slist_free (reversed);
992 g_free (test_run_name);
993 test_run_name = old_name;
994 return n_bad || bad_suite;
999 * @suite: a #GTestSuite
1001 * Execute the tests within @suite and all nested #GTestSuites.
1002 * The test suites to be executed are filtered according to
1003 * test path arguments (-p <testpath>) as parsed by g_test_init().
1004 * g_test_run_suite() or g_test_run() may only be called once
1008 g_test_run_suite (GTestSuite *suite)
1011 g_return_val_if_fail (g_test_config_vars != NULL, -1);
1012 g_return_val_if_fail (g_test_run_once == TRUE, -1);
1013 g_test_run_once = FALSE;
1015 test_paths = g_slist_prepend (test_paths, "");
1018 const char *rest, *path = test_paths->data;
1019 guint l, n = strlen (suite->name);
1020 test_paths = g_slist_delete_link (test_paths, test_paths);
1021 while (path[0] == '/')
1023 if (!n) /* root suite, run unconditionally */
1025 n_bad += 0 != g_test_run_suite_internal (suite, path);
1028 /* regular suite, match path */
1029 rest = strchr (path, '/');
1031 l = rest ? MIN (l, rest - path) : l;
1032 if ((!l || l == n) && strncmp (path, suite->name, n) == 0)
1033 n_bad += 0 != g_test_run_suite_internal (suite, rest ? rest : "");
1039 g_assertion_message (const char *domain,
1043 const char *message)
1046 g_snprintf (lstr, 32, "%d", line);
1047 char *s = g_strconcat (domain ? domain : "", domain && domain[0] ? ":" : "",
1048 file, ":", lstr, ":",
1049 func, func[0] ? ":" : "",
1050 " ", message, NULL);
1051 g_printerr ("**\n** %s\n", s);
1057 g_assertion_message_expr (const char *domain,
1063 char *s = g_strconcat ("assertion failed: (", expr, ")", NULL);
1064 g_assertion_message (domain, file, line, func, s);
1069 g_assertion_message_cmpnum (const char *domain,
1082 case 'i': s = g_strdup_printf ("assertion failed (%s): (%.0Lf %s %.0Lf)", expr, arg1, cmp, arg2); break;
1083 case 'x': s = g_strdup_printf ("assertion failed (%s): (0x%08Lx %s 0x%08Lx)", expr, (guint64) arg1, cmp, (guint64) arg2); break;
1084 case 'f': s = g_strdup_printf ("assertion failed (%s): (%.9Lg %s %.9Lg)", expr, arg1, cmp, arg2); break;
1085 /* ideally use: floats=%.7g double=%.17g */
1087 g_assertion_message (domain, file, line, func, s);
1092 g_assertion_message_cmpstr (const char *domain,
1101 char *a1, *a2, *s, *t1 = NULL, *t2 = NULL;
1102 a1 = arg1 ? g_strconcat ("\"", t1 = g_strescape (arg1, NULL), "\"", NULL) : g_strdup ("NULL");
1103 a2 = arg2 ? g_strconcat ("\"", t2 = g_strescape (arg2, NULL), "\"", NULL) : g_strdup ("NULL");
1106 s = g_strdup_printf ("assertion failed (%s): (%s %s %s)", expr, a1, cmp, a2);
1109 g_assertion_message (domain, file, line, func, s);
1115 * @str1: a C string or %NULL
1116 * @str2: another C string or %NULL
1118 * Compares @str1 and @str2 like strcmp(). Handles %NULL strings gracefully.
1121 g_strcmp0 (const char *str1,
1125 return -(str1 != str2);
1127 return str1 != str2;
1128 return strcmp (str1, str2);
1131 static int /* 0 on success */
1132 kill_child (int pid,
1137 if (patience >= 3) /* try graceful reap */
1139 if (waitpid (pid, status, WNOHANG) > 0)
1142 if (patience >= 2) /* try SIGHUP */
1145 if (waitpid (pid, status, WNOHANG) > 0)
1147 g_usleep (20 * 1000); /* give it some scheduling/shutdown time */
1148 if (waitpid (pid, status, WNOHANG) > 0)
1150 g_usleep (50 * 1000); /* give it some scheduling/shutdown time */
1151 if (waitpid (pid, status, WNOHANG) > 0)
1153 g_usleep (100 * 1000); /* give it some scheduling/shutdown time */
1154 if (waitpid (pid, status, WNOHANG) > 0)
1157 if (patience >= 1) /* try SIGTERM */
1159 kill (pid, SIGTERM);
1160 if (waitpid (pid, status, WNOHANG) > 0)
1162 g_usleep (200 * 1000); /* give it some scheduling/shutdown time */
1163 if (waitpid (pid, status, WNOHANG) > 0)
1165 g_usleep (400 * 1000); /* give it some scheduling/shutdown time */
1166 if (waitpid (pid, status, WNOHANG) > 0)
1170 kill (pid, SIGKILL);
1172 wr = waitpid (pid, status, 0);
1173 while (wr < 0 && errno == EINTR);
1178 g_string_must_read (GString *gstring,
1181 #define STRING_BUFFER_SIZE 4096
1182 char buf[STRING_BUFFER_SIZE];
1185 bytes = read (fd, buf, sizeof (buf));
1187 return 0; /* EOF, calling this function assumes data is available */
1190 g_string_append_len (gstring, buf, bytes);
1193 else if (bytes < 0 && errno == EINTR)
1195 else /* bytes < 0 */
1197 g_warning ("failed to read() from child process (%d): %s", test_trap_last_pid, g_strerror (errno));
1198 return 1; /* ignore error after warning */
1203 g_string_write_out (GString *gstring,
1207 if (*stringpos < gstring->len)
1211 r = write (outfd, gstring->str + *stringpos, gstring->len - *stringpos);
1212 while (r < 0 && errno == EINTR);
1213 *stringpos += MAX (r, 0);
1223 ret = dup2 (fd1, fd2);
1224 while (ret < 0 && errno == EINTR);
1229 test_trap_clear (void)
1231 test_trap_last_status = 0;
1232 test_trap_last_pid = 0;
1233 g_free (test_trap_last_stdout);
1234 test_trap_last_stdout = NULL;
1235 g_free (test_trap_last_stderr);
1236 test_trap_last_stderr = NULL;
1240 test_time_stamp (void)
1244 g_get_current_time (&tv);
1246 stamp = stamp * 1000000 + tv.tv_usec;
1252 * @usec_timeout: Timeout for the forked test in micro seconds.
1253 * @test_trap_flags: Flags to modify forking behaviour.
1255 * Fork the current test program to execute a test case that might
1256 * not return or that might abort. The forked test case is aborted
1257 * and considered failing if its run time exceeds @usec_timeout.
1258 * The forking behavior can be configured with the following flags:
1259 * %G_TEST_TRAP_SILENCE_STDOUT - redirect stdout of the test child
1260 * to /dev/null so it cannot be observed on the console during test
1261 * runs. The actual output is still captured though to allow later
1262 * tests with g_test_trap_assert_stdout().
1263 * %G_TEST_TRAP_SILENCE_STDERR - redirect stderr of the test child
1264 * to /dev/null so it cannot be observed on the console during test
1265 * runs. The actual output is still captured though to allow later
1266 * tests with g_test_trap_assert_stderr().
1267 * %G_TEST_TRAP_INHERIT_STDIN - if this flag is given, stdin of the
1268 * forked child process is shared with stdin of its parent process.
1269 * It is redirected to /dev/null otherwise.
1271 * In the following example, the test code forks, the forked child
1272 * process produces some sample output and exits successfully.
1273 * The forking parent process then asserts successfull child program
1274 * termination and validates cihld program outputs.
1276 * <informalexample><programlisting>
1278 * test_fork_patterns (void)
1280 * if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
1282 * g_print ("some stdout text: somagic17\n");
1283 * g_printerr ("some stderr text: semagic43\n");
1284 * exit (0); // successful test run
1286 * g_test_trap_assert_passed();
1287 * g_test_trap_assert_stdout ("*somagic17*");
1288 * g_test_trap_assert_stderr ("*semagic43*");
1290 * </programlisting></informalexample>
1292 * Returns: %TRUE for the forked child and %FALSE for the executing parent process.
1295 g_test_trap_fork (guint64 usec_timeout,
1296 GTestTrapFlags test_trap_flags)
1298 int stdout_pipe[2] = { -1, -1 };
1299 int stderr_pipe[2] = { -1, -1 };
1300 int stdtst_pipe[2] = { -1, -1 };
1302 if (pipe (stdout_pipe) < 0 || pipe (stderr_pipe) < 0 || pipe (stdtst_pipe) < 0)
1303 g_error ("failed to create pipes to fork test program: %s", g_strerror (errno));
1304 signal (SIGCHLD, SIG_DFL);
1305 test_trap_last_pid = fork ();
1306 if (test_trap_last_pid < 0)
1307 g_error ("failed to fork test program: %s", g_strerror (errno));
1308 if (test_trap_last_pid == 0) /* child */
1311 close (stdout_pipe[0]);
1312 close (stderr_pipe[0]);
1313 close (stdtst_pipe[0]);
1314 if (!(test_trap_flags & G_TEST_TRAP_INHERIT_STDIN))
1315 fd0 = open ("/dev/null", O_RDONLY);
1316 if (sane_dup2 (stdout_pipe[1], 1) < 0 || sane_dup2 (stderr_pipe[1], 2) < 0 || (fd0 >= 0 && sane_dup2 (fd0, 0) < 0))
1317 g_error ("failed to dup2() in forked test program: %s", g_strerror (errno));
1320 if (stdout_pipe[1] >= 3)
1321 close (stdout_pipe[1]);
1322 if (stderr_pipe[1] >= 3)
1323 close (stderr_pipe[1]);
1324 test_log_fd = stdtst_pipe[1];
1329 GString *sout = g_string_new (NULL);
1330 GString *serr = g_string_new (NULL);
1332 int soutpos = 0, serrpos = 0, wr, need_wait = TRUE;
1334 close (stdout_pipe[1]);
1335 close (stderr_pipe[1]);
1336 close (stdtst_pipe[1]);
1337 sstamp = test_time_stamp();
1338 /* read data until we get EOF on all pipes */
1339 while (stdout_pipe[0] >= 0 || stderr_pipe[0] >= 0 || stdtst_pipe[0] > 0)
1344 if (stdout_pipe[0] >= 0)
1345 FD_SET (stdout_pipe[0], &fds);
1346 if (stderr_pipe[0] >= 0)
1347 FD_SET (stderr_pipe[0], &fds);
1348 if (stdtst_pipe[0] >= 0)
1349 FD_SET (stdtst_pipe[0], &fds);
1351 tv.tv_usec = MIN (usec_timeout ? usec_timeout : 1000000, 100 * 1000); // sleep at most 0.5 seconds to catch clock skews, etc.
1352 int ret = select (MAX (MAX (stdout_pipe[0], stderr_pipe[0]), stdtst_pipe[0]) + 1, &fds, NULL, NULL, &tv);
1353 if (ret < 0 && errno != EINTR)
1355 g_warning ("Unexpected error in select() while reading from child process (%d): %s", test_trap_last_pid, g_strerror (errno));
1358 if (stdout_pipe[0] >= 0 && FD_ISSET (stdout_pipe[0], &fds) &&
1359 g_string_must_read (sout, stdout_pipe[0]) == 0)
1361 close (stdout_pipe[0]);
1362 stdout_pipe[0] = -1;
1364 if (stderr_pipe[0] >= 0 && FD_ISSET (stderr_pipe[0], &fds) &&
1365 g_string_must_read (serr, stderr_pipe[0]) == 0)
1367 close (stderr_pipe[0]);
1368 stderr_pipe[0] = -1;
1370 if (stdtst_pipe[0] >= 0 && FD_ISSET (stdtst_pipe[0], &fds))
1372 guint8 buffer[4096];
1373 gint l, r = read (stdtst_pipe[0], buffer, sizeof (buffer));
1374 if (r > 0 && test_log_fd > 0)
1376 l = write (test_log_fd, buffer, r);
1377 while (l < 0 && errno == EINTR);
1378 if (r == 0 || (r < 0 && errno != EINTR && errno != EAGAIN))
1380 close (stdtst_pipe[0]);
1381 stdtst_pipe[0] = -1;
1384 if (!(test_trap_flags & G_TEST_TRAP_SILENCE_STDOUT))
1385 g_string_write_out (sout, 1, &soutpos);
1386 if (!(test_trap_flags & G_TEST_TRAP_SILENCE_STDERR))
1387 g_string_write_out (serr, 2, &serrpos);
1390 guint64 nstamp = test_time_stamp();
1392 sstamp = MIN (sstamp, nstamp); // guard against backwards clock skews
1393 if (usec_timeout < nstamp - sstamp)
1395 /* timeout reached, need to abort the child now */
1396 kill_child (test_trap_last_pid, &status, 3);
1397 test_trap_last_status = 1024; /* timeout */
1398 if (0 && WIFSIGNALED (status))
1399 g_printerr ("%s: child timed out and received: %s\n", G_STRFUNC, g_strsignal (WTERMSIG (status)));
1405 close (stdout_pipe[0]);
1406 close (stderr_pipe[0]);
1407 close (stdtst_pipe[0]);
1412 wr = waitpid (test_trap_last_pid, &status, 0);
1413 while (wr < 0 && errno == EINTR);
1414 if (WIFEXITED (status)) /* normal exit */
1415 test_trap_last_status = WEXITSTATUS (status); /* 0..255 */
1416 else if (WIFSIGNALED (status))
1417 test_trap_last_status = (WTERMSIG (status) << 12); /* signalled */
1418 else /* WCOREDUMP (status) */
1419 test_trap_last_status = 512; /* coredump */
1421 test_trap_last_stdout = g_string_free (sout, FALSE);
1422 test_trap_last_stderr = g_string_free (serr, FALSE);
1428 * g_test_trap_has_passed:
1430 * Check the reuslt of the last g_test_trap_fork() call.
1432 * Returns: %TRUE if the last forked child terminated successfully.
1435 g_test_trap_has_passed (void)
1437 return test_trap_last_status == 0; /* exit_status == 0 && !signal && !coredump */
1441 * g_test_trap_reached_timeout:
1443 * Check the reuslt of the last g_test_trap_fork() call.
1445 * Returns: %TRUE if the last forked child got killed due to a fork timeout.
1448 g_test_trap_reached_timeout (void)
1450 return 0 != (test_trap_last_status & 1024); /* timeout flag */
1454 g_test_trap_assertions (const char *domain,
1460 const char *stdout_pattern,
1461 const char *stderr_pattern)
1463 if (test_trap_last_pid == 0)
1464 g_error ("child process failed to exit after g_test_trap_fork() and before g_test_trap_assert*()");
1465 if (must_pass && !g_test_trap_has_passed())
1467 char *msg = g_strdup_printf ("child process (%d) of test trap failed unexpectedly", test_trap_last_pid);
1468 g_assertion_message (domain, file, line, func, msg);
1471 if (must_fail && g_test_trap_has_passed())
1473 char *msg = g_strdup_printf ("child process (%d) did not fail as expected", test_trap_last_pid);
1474 g_assertion_message (domain, file, line, func, msg);
1477 if (stdout_pattern && !g_pattern_match_simple (stdout_pattern, test_trap_last_stdout))
1479 char *msg = g_strdup_printf ("stdout of child process (%d) failed to match: %s", test_trap_last_pid, stdout_pattern);
1480 g_assertion_message (domain, file, line, func, msg);
1483 if (stderr_pattern && !g_pattern_match_simple (stderr_pattern, test_trap_last_stderr))
1485 char *msg = g_strdup_printf ("stderr of child process (%d) failed to match: %s", test_trap_last_pid, stderr_pattern);
1486 g_assertion_message (domain, file, line, func, msg);
1492 gstring_overwrite_int (GString *gstring,
1496 vuint = g_htonl (vuint);
1497 g_string_overwrite_len (gstring, pos, (const gchar*) &vuint, 4);
1501 gstring_append_int (GString *gstring,
1504 vuint = g_htonl (vuint);
1505 g_string_append_len (gstring, (const gchar*) &vuint, 4);
1509 gstring_append_double (GString *gstring,
1512 union { double vdouble; guint64 vuint64; } u;
1513 u.vdouble = vdouble;
1514 u.vuint64 = GUINT64_TO_BE (u.vuint64);
1515 g_string_append_len (gstring, (const gchar*) &u.vuint64, 8);
1519 g_test_log_dump (GTestLogMsg *msg,
1522 GString *gstring = g_string_sized_new (1024);
1524 gstring_append_int (gstring, 0); /* message length */
1525 gstring_append_int (gstring, msg->log_type);
1526 gstring_append_int (gstring, msg->n_strings);
1527 gstring_append_int (gstring, msg->n_nums);
1528 gstring_append_int (gstring, 0); /* reserved */
1529 for (ui = 0; ui < msg->n_strings; ui++)
1531 guint l = strlen (msg->strings[ui]);
1532 gstring_append_int (gstring, l);
1533 g_string_append_len (gstring, msg->strings[ui], l);
1535 for (ui = 0; ui < msg->n_nums; ui++)
1536 gstring_append_double (gstring, msg->nums[ui]);
1537 *len = gstring->len;
1538 gstring_overwrite_int (gstring, 0, *len); /* message length */
1539 return (guint8*) g_string_free (gstring, FALSE);
1542 static inline long double
1543 net_double (const gchar **ipointer)
1545 union { guint64 vuint64; double vdouble; } u;
1546 guint64 aligned_int64;
1547 memcpy (&aligned_int64, *ipointer, 8);
1549 u.vuint64 = GUINT64_FROM_BE (aligned_int64);
1553 static inline guint32
1554 net_int (const gchar **ipointer)
1556 guint32 aligned_int;
1557 memcpy (&aligned_int, *ipointer, 4);
1559 return g_ntohl (aligned_int);
1563 g_test_log_extract (GTestLogBuffer *tbuffer)
1565 const gchar *p = tbuffer->data->str;
1568 if (tbuffer->data->len < 4 * 5)
1570 mlength = net_int (&p);
1571 if (tbuffer->data->len < mlength)
1573 msg.log_type = net_int (&p);
1574 msg.n_strings = net_int (&p);
1575 msg.n_nums = net_int (&p);
1576 if (net_int (&p) == 0)
1579 msg.strings = g_new0 (gchar*, msg.n_strings + 1);
1580 msg.nums = g_new0 (long double, msg.n_nums);
1581 for (ui = 0; ui < msg.n_strings; ui++)
1583 guint sl = net_int (&p);
1584 msg.strings[ui] = g_strndup (p, sl);
1587 for (ui = 0; ui < msg.n_nums; ui++)
1588 msg.nums[ui] = net_double (&p);
1589 if (p <= tbuffer->data->str + mlength)
1591 g_string_erase (tbuffer->data, 0, mlength);
1592 tbuffer->msgs = g_slist_prepend (tbuffer->msgs, g_memdup (&msg, sizeof (msg)));
1597 g_strfreev (msg.strings);
1598 g_error ("corrupt log stream from test program");
1603 * g_test_log_buffer_new:
1605 * Internal function for gtester to decode test log messages, no ABI guarantees provided.
1608 g_test_log_buffer_new (void)
1610 GTestLogBuffer *tb = g_new0 (GTestLogBuffer, 1);
1611 tb->data = g_string_sized_new (1024);
1616 * g_test_log_buffer_free
1618 * Internal function for gtester to free test log messages, no ABI guarantees provided.
1621 g_test_log_buffer_free (GTestLogBuffer *tbuffer)
1623 g_return_if_fail (tbuffer != NULL);
1624 while (tbuffer->msgs)
1625 g_test_log_msg_free (g_test_log_buffer_pop (tbuffer));
1626 g_string_free (tbuffer->data, TRUE);
1631 * g_test_log_buffer_push
1633 * Internal function for gtester to decode test log messages, no ABI guarantees provided.
1636 g_test_log_buffer_push (GTestLogBuffer *tbuffer,
1638 const guint8 *bytes)
1640 g_return_if_fail (tbuffer != NULL);
1643 gboolean more_messages;
1644 g_return_if_fail (bytes != NULL);
1645 g_string_append_len (tbuffer->data, (const gchar*) bytes, n_bytes);
1647 more_messages = g_test_log_extract (tbuffer);
1648 while (more_messages);
1653 * g_test_log_buffer_pop:
1655 * Internal function for gtester to retrieve test log messages, no ABI guarantees provided.
1658 g_test_log_buffer_pop (GTestLogBuffer *tbuffer)
1660 GTestLogMsg *msg = NULL;
1661 g_return_val_if_fail (tbuffer != NULL, NULL);
1664 GSList *slist = g_slist_last (tbuffer->msgs);
1666 tbuffer->msgs = g_slist_delete_link (tbuffer->msgs, slist);
1672 * g_test_log_msg_free:
1674 * Internal function for gtester to free test log messages, no ABI guarantees provided.
1677 g_test_log_msg_free (GTestLogMsg *tmsg)
1679 g_return_if_fail (tmsg != NULL);
1680 g_strfreev (tmsg->strings);
1681 g_free (tmsg->nums);
1685 /* --- macros docs START --- */
1688 * @testpath: The test path for a new test case.
1689 * @Fixture: The type of a fixture data structure.
1690 * @fsetup: The function to set up the fixture data.
1691 * @ftest: The actual test function.
1692 * @fteardown: The function to tear down the fixture data.
1694 * Hook up a new test case at @testpath, similar to g_test_add_func().
1695 * A fixture data structure with setup and teardown function may be provided
1696 * though, simmilar to g_test_create_case().
1697 * g_test_add() is implemented as a macro, so that the fsetup(), ftest() and
1698 * fteardown() callbacks can expect a @Fixture pointer as first argument in
1699 * a type safe manner.
1701 /* --- macros docs END --- */
1703 #define __G_TEST_UTILS_C__
1704 #include "galiasdef.c"