Add undefined/no-undefined mode options to GTester
[platform/upstream/glib.git] / glib / gtestutils.c
index 8335a58..3406d43 100644 (file)
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */
+
 #include "config.h"
+
 #include "gtestutils.h"
-#include "galias.h"
+
 #include <sys/types.h>
+#ifdef G_OS_UNIX
 #include <sys/wait.h>
+#include <sys/time.h>
 #include <fcntl.h>
+#endif
 #include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
+#ifdef G_OS_WIN32
+#include <io.h>
+#endif
 #include <errno.h>
 #include <signal.h>
 #ifdef HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #endif /* HAVE_SYS_SELECT_H */
 
+#include "gmain.h"
+#include "gpattern.h"
+#include "grand.h"
+#include "gstrfuncs.h"
+#include "gtimer.h"
+#include "gslice.h"
+
+
+/**
+ * SECTION:testing
+ * @title: Testing
+ * @short_description: a test framework
+ * @see_also: <link linkend="gtester">gtester</link>,
+ *            <link linkend="gtester-report">gtester-report</link>
+ *
+ * GLib provides a framework for writing and maintaining unit tests
+ * in parallel to the code they are testing. The API is designed according
+ * to established concepts found in the other test frameworks (JUnit, NUnit,
+ * RUnit), which in turn is based on smalltalk unit testing concepts.
+ *
+ * <variablelist>
+ *   <varlistentry>
+ *     <term>Test case</term>
+ *     <listitem>Tests (test methods) are grouped together with their
+ *       fixture into test cases.</listitem>
+ *   </varlistentry>
+ *   <varlistentry>
+ *     <term>Fixture</term>
+ *     <listitem>A test fixture consists of fixture data and setup and
+ *       teardown methods to establish the environment for the test
+ *       functions. We use fresh fixtures, i.e. fixtures are newly set
+ *       up and torn down around each test invocation to avoid dependencies
+ *       between tests.</listitem>
+ *   </varlistentry>
+ *   <varlistentry>
+ *     <term>Test suite</term>
+ *     <listitem>Test cases can be grouped into test suites, to allow
+ *       subsets of the available tests to be run. Test suites can be
+ *       grouped into other test suites as well.</listitem>
+ *   </varlistentry>
+ * </variablelist>
+ * The API is designed to handle creation and registration of test suites
+ * and test cases implicitly. A simple call like
+ * |[
+ *   g_test_add_func ("/misc/assertions", test_assertions);
+ * ]|
+ * creates a test suite called "misc" with a single test case named
+ * "assertions", which consists of running the test_assertions function.
+ *
+ * In addition to the traditional g_assert(), the test framework provides
+ * an extended set of assertions for string and numerical comparisons:
+ * g_assert_cmpfloat(), g_assert_cmpint(), g_assert_cmpuint(),
+ * g_assert_cmphex(), g_assert_cmpstr(). The advantage of these variants
+ * over plain g_assert() is that the assertion messages can be more
+ * elaborate, and include the values of the compared entities.
+ *
+ * GLib ships with two utilities called gtester and gtester-report to
+ * facilitate running tests and producing nicely formatted test reports.
+ */
+
+/**
+ * g_test_quick:
+ *
+ * Returns %TRUE if tests are run in quick mode.
+ * Exactly one of g_test_quick() and g_test_slow() is active in any run;
+ * there is no "medium speed".
+ *
+ * Returns: %TRUE if in quick mode
+ */
+
+/**
+ * g_test_slow:
+ *
+ * Returns %TRUE if tests are run in slow mode.
+ * Exactly one of g_test_quick() and g_test_slow() is active in any run;
+ * there is no "medium speed".
+ *
+ * Returns: the opposite of g_test_quick()
+ */
+
+/**
+ * g_test_thorough:
+ *
+ * Returns %TRUE if tests are run in thorough mode, equivalent to
+ * g_test_slow().
+ *
+ * Returns: the same thing as g_test_slow()
+ */
+
+/**
+ * g_test_perf:
+ *
+ * Returns %TRUE if tests are run in performance mode.
+ *
+ * Returns: %TRUE if in performance mode
+ */
+
+/**
+ * g_test_undefined:
+ *
+ * Returns %TRUE if tests may provoke assertions and other formally-undefined
+ * behaviour under g_test_trap_fork(), to verify that appropriate warnings
+ * are given. It can be useful to turn this off if running tests under
+ * valgrind.
+ *
+ * Returns: %TRUE if tests may provoke programming errors
+ */
+
+/**
+ * g_test_verbose:
+ *
+ * Returns %TRUE if tests are run in verbose mode.
+ * The default is neither g_test_verbose() nor g_test_quiet().
+ *
+ * Returns: %TRUE if in verbose mode
+ */
+
+/**
+ * g_test_quiet:
+ *
+ * Returns %TRUE if tests are run in quiet mode.
+ * The default is neither g_test_verbose() nor g_test_quiet().
+ *
+ * Returns: %TRUE if in quiet mode
+ */
+
+/**
+ * g_test_queue_unref:
+ * @gobject: the object to unref
+ *
+ * Enqueue an object to be released with g_object_unref() during
+ * the next teardown phase. This is equivalent to calling
+ * g_test_queue_destroy() with a destroy callback of g_object_unref().
+ *
+ * Since: 2.16
+ */
+
+/**
+ * GTestTrapFlags:
+ * @G_TEST_TRAP_SILENCE_STDOUT: Redirect stdout of the test child to
+ *     <filename>/dev/null</filename> so it cannot be observed on the
+ *     console during test runs. The actual output is still captured
+ *     though to allow later tests with g_test_trap_assert_stdout().
+ * @G_TEST_TRAP_SILENCE_STDERR: Redirect stderr of the test child to
+ *     <filename>/dev/null</filename> so it cannot be observed on the
+ *     console during test runs. The actual output is still captured
+ *     though to allow later tests with g_test_trap_assert_stderr().
+ * @G_TEST_TRAP_INHERIT_STDIN: If this flag is given, stdin of the
+ *     forked child process is shared with stdin of its parent process.
+ *     It is redirected to <filename>/dev/null</filename> otherwise.
+ *
+ * Test traps are guards around forked tests.
+ * These flags determine what traps to set.
+ */
+
+/**
+ * g_test_trap_assert_passed:
+ *
+ * Assert that the last forked test passed.
+ * See g_test_trap_fork().
+ *
+ * Since: 2.16
+ */
+
+/**
+ * g_test_trap_assert_failed:
+ *
+ * Assert that the last forked test failed.
+ * See g_test_trap_fork().
+ *
+ * Since: 2.16
+ */
+
+/**
+ * g_test_trap_assert_stdout:
+ * @soutpattern: a glob-style
+ *     <link linkend="glib-Glob-style-pattern-matching">pattern</link>
+ *
+ * Assert that the stdout output of the last forked test matches
+ * @soutpattern. See g_test_trap_fork().
+ *
+ * Since: 2.16
+ */
+
+/**
+ * g_test_trap_assert_stdout_unmatched:
+ * @soutpattern: a glob-style
+ *     <link linkend="glib-Glob-style-pattern-matching">pattern</link>
+ *
+ * Assert that the stdout output of the last forked test
+ * does not match @soutpattern. See g_test_trap_fork().
+ *
+ * Since: 2.16
+ */
+
+/**
+ * g_test_trap_assert_stderr:
+ * @serrpattern: a glob-style
+ *     <link linkend="glib-Glob-style-pattern-matching">pattern</link>
+ *
+ * Assert that the stderr output of the last forked test
+ * matches @serrpattern. See  g_test_trap_fork().
+ *
+ * Since: 2.16
+ */
+
+/**
+ * g_test_trap_assert_stderr_unmatched:
+ * @serrpattern: a glob-style
+ *     <link linkend="glib-Glob-style-pattern-matching">pattern</link>
+ *
+ * Assert that the stderr output of the last forked test
+ * does not match @serrpattern. See g_test_trap_fork().
+ *
+ * Since: 2.16
+ */
+
+/**
+ * g_test_rand_bit:
+ *
+ * Get a reproducible random bit (0 or 1), see g_test_rand_int()
+ * for details on test case random numbers.
+ *
+ * Since: 2.16
+ */
+
+/**
+ * g_assert:
+ * @expr: the expression to check
+ *
+ * Debugging macro to terminate the application if the assertion
+ * fails. If the assertion fails (i.e. the expression is not true),
+ * an error message is logged and the application is terminated.
+ *
+ * The macro can be turned off in final releases of code by defining
+ * <envar>G_DISABLE_ASSERT</envar> when compiling the application.
+ */
+
+/**
+ * g_assert_not_reached:
+ *
+ * Debugging macro to terminate the application if it is ever
+ * reached. If it is reached, an error message is logged and the
+ * application is terminated.
+ *
+ * The macro can be turned off in final releases of code by defining
+ * <envar>G_DISABLE_ASSERT</envar> when compiling the application.
+ */
+
+/**
+ * g_assert_cmpstr:
+ * @s1: a string (may be %NULL)
+ * @cmp: The comparison operator to use.
+ *     One of ==, !=, &lt;, &gt;, &lt;=, &gt;=.
+ * @s2: another string (may be %NULL)
+ *
+ * Debugging macro to terminate the application with a warning
+ * message if a string comparison fails. The strings are compared
+ * using g_strcmp0().
+ *
+ * The effect of <literal>g_assert_cmpstr (s1, op, s2)</literal> is
+ * the same as <literal>g_assert (g_strcmp0 (s1, s2) op 0)</literal>.
+ * The advantage of this macro is that it can produce a message that
+ * includes the actual values of @s1 and @s2.
+ *
+ * |[
+ *   g_assert_cmpstr (mystring, ==, "fubar");
+ * ]|
+ *
+ * Since: 2.16
+ */
+
+/**
+ * g_assert_cmpint:
+ * @n1: an integer
+ * @cmp: The comparison operator to use.
+ *     One of ==, !=, &lt;, &gt;, &lt;=, &gt;=.
+ * @n2: another integer
+ *
+ * Debugging macro to terminate the application with a warning
+ * message if an integer comparison fails.
+ *
+ * The effect of <literal>g_assert_cmpint (n1, op, n2)</literal> is
+ * the same as <literal>g_assert (n1 op n2)</literal>. The advantage
+ * of this macro is that it can produce a message that includes the
+ * actual values of @n1 and @n2.
+ *
+ * Since: 2.16
+ */
+
+/**
+ * g_assert_cmpuint:
+ * @n1: an unsigned integer
+ * @cmp: The comparison operator to use.
+ *     One of ==, !=, &lt;, &gt;, &lt;=, &gt;=.
+ * @n2: another unsigned integer
+ *
+ * Debugging macro to terminate the application with a warning
+ * message if an unsigned integer comparison fails.
+ *
+ * The effect of <literal>g_assert_cmpuint (n1, op, n2)</literal> is
+ * the same as <literal>g_assert (n1 op n2)</literal>. The advantage
+ * of this macro is that it can produce a message that includes the
+ * actual values of @n1 and @n2.
+ *
+ * Since: 2.16
+ */
+
+/**
+ * g_assert_cmphex:
+ * @n1: an unsigned integer
+ * @cmp: The comparison operator to use.
+ *     One of ==, !=, &lt;, &gt;, &lt;=, &gt;=.
+ * @n2: another unsigned integer
+ *
+ * Debugging macro to terminate the application with a warning
+ * message if an unsigned integer comparison fails.
+ *
+ * This is a variant of g_assert_cmpuint() that displays the numbers
+ * in hexadecimal notation in the message.
+ *
+ * Since: 2.16
+ */
+
+/**
+ * g_assert_cmpfloat:
+ * @n1: an floating point number
+ * @cmp: The comparison operator to use.
+ *     One of ==, !=, &lt;, &gt;, &lt;=, &gt;=.
+ * @n2: another floating point number
+ *
+ * Debugging macro to terminate the application with a warning
+ * message if a floating point number comparison fails.
+ *
+ * The effect of <literal>g_assert_cmpfloat (n1, op, n2)</literal> is
+ * the same as <literal>g_assert (n1 op n2)</literal>. The advantage
+ * of this macro is that it can produce a message that includes the
+ * actual values of @n1 and @n2.
+ *
+ * Since: 2.16
+ */
+
+/**
+ * g_assert_no_error:
+ * @err: a #GError, possibly %NULL
+ *
+ * Debugging macro to terminate the application with a warning
+ * message if a method has returned a #GError.
+ *
+ * The effect of <literal>g_assert_no_error (err)</literal> is
+ * the same as <literal>g_assert (err == NULL)</literal>. The advantage
+ * of this macro is that it can produce a message that includes
+ * the error message and code.
+ *
+ * Since: 2.20
+ */
+
+/**
+ * g_assert_error:
+ * @err: a #GError, possibly %NULL
+ * @dom: the expected error domain (a #GQuark)
+ * @c: the expected error code
+ *
+ * Debugging macro to terminate the application with a warning
+ * message if a method has not returned the correct #GError.
+ *
+ * The effect of <literal>g_assert_error (err, dom, c)</literal> is
+ * the same as <literal>g_assert (err != NULL &amp;&amp; err->domain
+ * == dom &amp;&amp; err->code == c)</literal>. The advantage of this
+ * macro is that it can produce a message that includes the incorrect
+ * error message and code.
+ *
+ * This can only be used to test for a specific error. If you want to
+ * test that @err is set, but don't care what it's set to, just use
+ * <literal>g_assert (err != NULL)</literal>
+ *
+ * Since: 2.20
+ */
+
+/**
+ * GTestCase:
+ *
+ * An opaque structure representing a test case.
+ */
+
+/**
+ * GTestSuite:
+ *
+ * An opaque structure representing a test suite.
+ */
+
+
+/* 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
 {
   gchar  *name;
   guint   fixture_size;
-  void (*fixture_setup) (void*);
-  void (*fixture_test) (void*);
-  void (*fixture_teardown) (void*);
+  void   (*fixture_setup)    (void*, gconstpointer);
+  void   (*fixture_test)     (void*, gconstpointer);
+  void   (*fixture_teardown) (void*, gconstpointer);
+  gpointer test_data;
 };
 struct GTestSuite
 {
@@ -56,10 +467,15 @@ struct DestroyEntry
 };
 
 /* --- prototypes --- */
-static void                     test_run_seed           (const gchar *rseed);
-static void                     test_trap_clear         (void);
-static guint8*                  g_test_log_dump         (GTestLogMsg *msg,
-                                                         guint       *len);
+static void     test_run_seed                   (const gchar *rseed);
+static void     test_trap_clear                 (void);
+static guint8*  g_test_log_dump                 (GTestLogMsg *msg,
+                                                 guint       *len);
+static void     gtest_default_log_handler       (const gchar    *log_domain,
+                                                 GLogLevelFlags  log_level,
+                                                 const gchar    *message,
+                                                 gpointer        unused_data);
+
 
 /* --- variables --- */
 static int         test_log_fd = -1;
@@ -71,10 +487,12 @@ static GRand      *test_run_rand = NULL;
 static gchar      *test_run_name = "";
 static guint       test_run_forks = 0;
 static guint       test_run_count = 0;
+static guint       test_run_success = FALSE;
 static guint       test_skip_count = 0;
 static GTimer     *test_user_timer = NULL;
 static double      test_user_stamp = 0;
 static GSList     *test_paths = NULL;
+static GSList     *test_paths_skipped = NULL;
 static GTestSuite *test_suite_root = NULL;
 static int         test_trap_last_status = 0;
 static int         test_trap_last_pid = 0;
@@ -89,6 +507,7 @@ static GTestConfig mutable_test_config_vars = {
   FALSE,        /* test_perf */
   FALSE,        /* test_verbose */
   FALSE,        /* test_quiet */
+  TRUE,         /* test_undefined */
 };
 const GTestConfig * const g_test_config_vars = &mutable_test_config_vars;
 
@@ -125,13 +544,13 @@ g_test_log_send (guint         n_bytes,
     }
   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));
@@ -164,8 +583,14 @@ g_test_log (GTestLogType lbit,
 
   switch (lbit)
     {
+    case G_TEST_LOG_START_BINARY:
+      if (g_test_verbose())
+        g_print ("GTest: random seed: %s\n", string2);
+      break;
     case G_TEST_LOG_STOP_CASE:
-      if (!g_test_quiet())
+      if (g_test_verbose())
+        g_print ("GTest: result: %s\n", fail ? "FAIL" : "OK");
+      else if (!g_test_quiet())
         g_print ("%s\n", fail ? "FAIL" : "OK");
       if (fail && test_mode_fatal)
         abort();
@@ -199,13 +624,18 @@ g_test_log (GTestLogType lbit,
   switch (lbit)
     {
     case G_TEST_LOG_START_CASE:
-      if (!g_test_quiet())
+      if (g_test_verbose())
+        g_print ("GTest: run: %s\n", string1);
+      else if (!g_test_quiet())
         g_print ("%s: ", string1);
       break;
     default: ;
     }
 }
 
+/* We intentionally parse the command line without GOptionContext
+ * because otherwise you would never be able to test it.
+ */
 static void
 parse_args (gint    *argc_p,
             gchar ***argv_p)
@@ -270,6 +700,18 @@ parse_args (gint    *argc_p,
             }
           argv[i] = NULL;
         }
+      else if (strcmp ("-s", argv[i]) == 0 || strncmp ("-s=", argv[i], 3) == 0)
+        {
+          gchar *equal = argv[i] + 2;
+          if (*equal == '=')
+            test_paths_skipped = g_slist_prepend (test_paths_skipped, equal + 1);
+          else if (i + 1 < argc)
+            {
+              argv[i++] = NULL;
+              test_paths_skipped = g_slist_prepend (test_paths_skipped, argv[i]);
+            }
+          argv[i] = NULL;
+        }
       else if (strcmp ("-m", argv[i]) == 0 || strncmp ("-m=", argv[i], 3) == 0)
         {
           gchar *equal = argv[i] + 2;
@@ -285,11 +727,17 @@ parse_args (gint    *argc_p,
             mutable_test_config_vars.test_perf = TRUE;
           else if (strcmp (mode, "slow") == 0)
             mutable_test_config_vars.test_quick = FALSE;
+          else if (strcmp (mode, "thorough") == 0)
+            mutable_test_config_vars.test_quick = FALSE;
           else if (strcmp (mode, "quick") == 0)
             {
               mutable_test_config_vars.test_quick = TRUE;
               mutable_test_config_vars.test_perf = FALSE;
             }
+          else if (strcmp (mode, "undefined") == 0)
+            mutable_test_config_vars.test_undefined = TRUE;
+          else if (strcmp (mode, "no-undefined") == 0)
+            mutable_test_config_vars.test_undefined = FALSE;
           else
             g_error ("unknown test mode: -m %s", mode);
           argv[i] = NULL;
@@ -323,6 +771,29 @@ parse_args (gint    *argc_p,
             }
           argv[i] = NULL;
         }
+      else if (strcmp ("-?", argv[i]) == 0 || strcmp ("--help", argv[i]) == 0)
+        {
+          printf ("Usage:\n"
+                  "  %s [OPTION...]\n\n"
+                  "Help Options:\n"
+                  "  -?, --help                     Show help options\n"
+                  "Test Options:\n"
+                  "  -l                             List test cases available in a test executable\n"
+                  "  -seed=RANDOMSEED               Provide a random seed to reproduce test\n"
+                  "                                 runs using random numbers\n"
+                  "  --verbose                      Run tests verbosely\n"
+                  "  -q, --quiet                    Run tests quietly\n"
+                  "  -p TESTPATH                    execute all tests matching TESTPATH\n"
+                  "  -s TESTPATH                    skip all tests matching TESTPATH\n"
+                  "  -m {perf|slow|thorough|quick}  Execute tests according modes\n"
+                  "  -m {undefined|no-undefined}    Execute tests according modes\n"
+                  "  --debug-log                    debug test logging output\n"
+                  "  -k, --keep-going               gtester-specific argument\n"
+                  "  --GTestLogFD=N                 gtester-specific argument\n"
+                  "  --GTestSkipCount=N             gtester-specific argument\n",
+                  argv[0]);
+          exit (0);
+        }
     }
   /* collapse argv */
   e = 1;
@@ -342,26 +813,99 @@ parse_args (gint    *argc_p,
  *        Changed if any arguments were handled.
  * @argv: Address of the @argv parameter of main().
  *        Any parameters understood by g_test_init() stripped before return.
+ * @...: Reserved for future extension. Currently, you must pass %NULL.
  *
  * Initialize the GLib testing framework, e.g. by seeding the
  * test random number generator, the name for g_get_prgname()
  * and parsing test related command line args.
  * So far, the following arguments are understood:
- * <informalexample>
- * -l                   list test cases available in a test executable.
- * --seed RANDOMSEED    provide a random seed to reproduce test runs using random numbers.
- * --verbose            run tests verbosely.
- * -q, --quiet          run tests quietly.
- * -p TESTPATH          execute all tests matching TESTPATH.
- * -m {perf|slow|quick} execute tests according to this test modes:
- *                      perf - performance tests, may take long and report results.
- *                      slow - slow and thorough tests, may take quite long and maximize coverage.
- *                      quick - quick tests, should run really quickly and give good coverage.
- * --debug-log          debug test logging output.
- * -k, --keep-going     gtester specific argument.
- * --GTestLogFD N       gtester specific argument.
- * --GTestSkipCount N   gtester specific argument.
- * </informalexample>
+ * <variablelist>
+ *   <varlistentry>
+ *     <term><option>-l</option></term>
+ *     <listitem><para>
+ *       list test cases available in a test executable.
+ *     </para></listitem>
+ *   </varlistentry>
+ *   <varlistentry>
+ *     <term><option>--seed=<replaceable>RANDOMSEED</replaceable></option></term>
+ *     <listitem><para>
+ *       provide a random seed to reproduce test runs using random numbers.
+ *     </para></listitem>
+ *     </varlistentry>
+ *     <varlistentry>
+ *       <term><option>--verbose</option></term>
+ *       <listitem><para>run tests verbosely.</para></listitem>
+ *     </varlistentry>
+ *     <varlistentry>
+ *       <term><option>-q</option>, <option>--quiet</option></term>
+ *       <listitem><para>run tests quietly.</para></listitem>
+ *     </varlistentry>
+ *     <varlistentry>
+ *       <term><option>-p <replaceable>TESTPATH</replaceable></option></term>
+ *       <listitem><para>
+ *         execute all tests matching <replaceable>TESTPATH</replaceable>.
+ *       </para></listitem>
+ *     </varlistentry>
+ *     <varlistentry>
+ *       <term><option>-m {perf|slow|thorough|quick|undefined|no-undefined}</option></term>
+ *       <listitem><para>
+ *         execute tests according to these test modes:
+ *         <variablelist>
+ *           <varlistentry>
+ *             <term>perf</term>
+ *             <listitem><para>
+ *               performance tests, may take long and report results.
+ *             </para></listitem>
+ *           </varlistentry>
+ *           <varlistentry>
+ *             <term>slow, thorough</term>
+ *             <listitem><para>
+ *               slow and thorough tests, may take quite long and 
+ *               maximize coverage.
+ *             </para></listitem>
+ *           </varlistentry>
+ *           <varlistentry>
+ *             <term>quick</term>
+ *             <listitem><para>
+ *               quick tests, should run really quickly and give good coverage.
+ *             </para></listitem>
+ *           </varlistentry>
+ *           <varlistentry>
+ *             <term>undefined</term>
+ *             <listitem><para>
+ *               tests for undefined behaviour, may provoke programming errors
+ *               under g_test_trap_fork() to check that appropriate assertions
+ *               or warnings are given
+ *             </para></listitem>
+ *           </varlistentry>
+ *           <varlistentry>
+ *             <term>no-undefined</term>
+ *             <listitem><para>
+ *               avoid tests for undefined behaviour
+ *             </para></listitem>
+ *           </varlistentry>
+ *         </variablelist>
+ *       </para></listitem>
+ *     </varlistentry>
+ *     <varlistentry>
+ *       <term><option>--debug-log</option></term>
+ *       <listitem><para>debug test logging output.</para></listitem>
+ *     </varlistentry>
+ *     <varlistentry>
+ *       <term><option>-k</option>, <option>--keep-going</option></term>
+ *       <listitem><para>gtester-specific argument.</para></listitem>
+ *     </varlistentry>
+ *     <varlistentry>
+ *       <term><option>--GTestLogFD <replaceable>N</replaceable></option></term>
+ *       <listitem><para>gtester-specific argument.</para></listitem>
+ *     </varlistentry>
+ *     <varlistentry>
+ *       <term><option>--GTestSkipCount <replaceable>N</replaceable></option></term>
+ *       <listitem><para>gtester-specific argument.</para></listitem>
+ *     </varlistentry>
+ *  </variablelist>
+ *
+ * Since: 2.16
  */
 void
 g_test_init (int    *argc,
@@ -374,6 +918,7 @@ g_test_init (int    *argc,
   /* make warnings and criticals fatal for all test programs */
   GLogLevelFlags fatal_mask = (GLogLevelFlags) g_log_set_always_fatal ((GLogLevelFlags) G_LOG_FATAL_MASK);
   fatal_mask = (GLogLevelFlags) (fatal_mask | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL);
+  g_log_set_always_fatal (fatal_mask);
   /* check caller args */
   g_return_if_fail (argc != NULL);
   g_return_if_fail (argv != NULL);
@@ -399,7 +944,7 @@ g_test_init (int    *argc,
     {
       GRand *rg = g_rand_new_with_seed (0xc8c49fb6);
       guint32 t1 = g_rand_int (rg), t2 = g_rand_int (rg), t3 = g_rand_int (rg), t4 = g_rand_int (rg);
-      // g_print ("GRand-current: 0x%x 0x%x 0x%x 0x%x\n", t1, t2, t3, t4);
+      /* g_print ("GRand-current: 0x%x 0x%x 0x%x 0x%x\n", t1, t2, t3, t4); */
       if (t1 != 0xfab39f9b || t2 != 0xb948fb0e || t3 != 0x3d31be26 || t4 != 0x43a19d66)
         g_warning ("random numbers are not GRand-2.2 compatible, seeds may be broken (check $G_RANDOM_VERSION)");
       g_rand_free (rg);
@@ -409,6 +954,7 @@ g_test_init (int    *argc,
   test_run_seed (test_run_seedstr);
 
   /* report program start */
+  g_log_set_default_handler (gtest_default_log_handler, NULL);
   g_test_log (G_TEST_LOG_START_BINARY, g_get_prgname(), test_run_seedstr, 0, NULL);
 }
 
@@ -421,10 +967,10 @@ test_run_seed (const gchar *rseed)
   test_run_rand = NULL;
   while (strchr (" \t\v\r\n\f", *rseed))
     rseed++;
-  if (strncmp (rseed, "R02S", 4) == 0)  // seed for random generator 02 (GRand-2.2)
+  if (strncmp (rseed, "R02S", 4) == 0)  /* seed for random generator 02 (GRand-2.2) */
     {
       const char *s = rseed + 4;
-      if (strlen (s) >= 32)             // require 4 * 8 chars
+      if (strlen (s) >= 32)             /* require 4 * 8 chars */
         {
           guint32 seedarray[4];
           gchar *p, hexbuf[9] = { 0, };
@@ -453,15 +999,19 @@ test_run_seed (const gchar *rseed)
 /**
  * g_test_rand_int:
  *
- * Get a reproducable random integer number.
- * The random numbers generate by the g_test_rand_*() family of functions
+ * Get a reproducible random integer number.
+ *
+ * The random numbers generated by the g_test_rand_*() family of functions
  * change with every new test program start, unless the --seed option is
  * given when starting test programs.
+ *
  * For individual test cases however, the random number generator is
  * reseeded, to avoid dependencies between tests and to make --seed
  * effective for all test cases.
  *
  * Returns: a random number from the seeded random number generator.
+ *
+ * Since: 2.16
  */
 gint32
 g_test_rand_int (void)
@@ -474,10 +1024,12 @@ g_test_rand_int (void)
  * @begin: the minimum value returned by this function
  * @end:   the smallest value not to be returned by this function
  *
- * Get a reproducable random integer number out of a specified range,
+ * Get a reproducible random integer number out of a specified range,
  * see g_test_rand_int() for details on test case random numbers.
  *
- * Returns a number with @begin <= number < @end.
+ * Returns: a number with @begin <= number < @end.
+ * 
+ * Since: 2.16
  */
 gint32
 g_test_rand_int_range (gint32          begin,
@@ -489,10 +1041,12 @@ g_test_rand_int_range (gint32          begin,
 /**
  * g_test_rand_double:
  *
- * Get a reproducable random floating point number,
+ * Get a reproducible random floating point number,
  * see g_test_rand_int() for details on test case random numbers.
  *
- * Return a random number from the seeded random number generator.
+ * Returns: a random number from the seeded random number generator.
+ *
+ * Since: 2.16
  */
 double
 g_test_rand_double (void)
@@ -505,10 +1059,12 @@ g_test_rand_double (void)
  * @range_start: the minimum value returned by this function
  * @range_end: the minimum value not returned by this function
  *
- * Get a reproducable random floating pointer number out of a specified range,
+ * Get a reproducible random floating pointer number out of a specified range,
  * see g_test_rand_int() for details on test case random numbers.
  *
- * Returns a number with @range_start <= number < @range_end.
+ * Returns: a number with @range_start <= number < @range_end.
+ *
+ * Since: 2.16
  */
 double
 g_test_rand_double_range (double          range_start,
@@ -522,6 +1078,8 @@ g_test_rand_double_range (double          range_start,
  *
  * Start a timing test. Call g_test_timer_elapsed() when the task is supposed
  * to be done. Call this function again to restart the timer.
+ *
+ * Since: 2.16
  */
 void
 g_test_timer_start (void)
@@ -536,6 +1094,10 @@ g_test_timer_start (void)
  * g_test_timer_elapsed:
  *
  * Get the time since the last start of the timer with g_test_timer_start().
+ *
+ * Returns: the time since the last start of the timer, as a double
+ *
+ * Since: 2.16
  */
 double
 g_test_timer_elapsed (void)
@@ -548,6 +1110,10 @@ g_test_timer_elapsed (void)
  * g_test_timer_last:
  *
  * Report the last result of g_test_timer_elapsed().
+ *
+ * Returns: the last result of g_test_timer_elapsed(), as a double
+ *
+ * Since: 2.16
  */
 double
 g_test_timer_last (void)
@@ -559,12 +1125,15 @@ g_test_timer_last (void)
  * g_test_minimized_result:
  * @minimized_quantity: the reported value
  * @format: the format string of the report message
+ * @...: arguments to pass to the printf() function
  *
  * Report the result of a performance or measurement test.
  * The test should generally strive to minimize the reported
  * quantities (smaller values are better than larger ones),
  * this and @minimized_quantity can determine sorting
  * order for test result reports.
+ *
+ * Since: 2.16
  */
 void
 g_test_minimized_result (double          minimized_quantity,
@@ -574,23 +1143,28 @@ g_test_minimized_result (double          minimized_quantity,
   long double largs = minimized_quantity;
   gchar *buffer;
   va_list args;
+
   va_start (args, format);
   buffer = g_strdup_vprintf (format, args);
   va_end (args);
+
   g_test_log (G_TEST_LOG_MIN_RESULT, buffer, NULL, 1, &largs);
   g_free (buffer);
 }
 
 /**
- * g_test_minimized_result:
+ * g_test_maximized_result:
  * @maximized_quantity: the reported value
  * @format: the format string of the report message
+ * @...: arguments to pass to the printf() function
  *
  * Report the result of a performance or measurement test.
  * The test should generally strive to maximize the reported
  * quantities (larger values are better than smaller ones),
  * this and @maximized_quantity can determine sorting
  * order for test result reports.
+ *
+ * Since: 2.16
  */
 void
 g_test_maximized_result (double          maximized_quantity,
@@ -600,9 +1174,11 @@ g_test_maximized_result (double          maximized_quantity,
   long double largs = maximized_quantity;
   gchar *buffer;
   va_list args;
+
   va_start (args, format);
   buffer = g_strdup_vprintf (format, args);
   va_end (args);
+
   g_test_log (G_TEST_LOG_MAX_RESULT, buffer, NULL, 1, &largs);
   g_free (buffer);
 }
@@ -613,6 +1189,8 @@ g_test_maximized_result (double          maximized_quantity,
  * @...:    printf-like arguments to @format
  *
  * Add a message to the test report.
+ *
+ * Since: 2.16
  */
 void
 g_test_message (const char *format,
@@ -620,9 +1198,11 @@ g_test_message (const char *format,
 {
   gchar *buffer;
   va_list args;
+
   va_start (args, format);
   buffer = g_strdup_vprintf (format, args);
   va_end (args);
+
   g_test_log (G_TEST_LOG_MESSAGE, buffer, NULL, 0, NULL);
   g_free (buffer);
 }
@@ -632,6 +1212,7 @@ g_test_message (const char *format,
  * @uri_pattern: the base pattern for bug URIs
  *
  * Specify the base URI for bug reports.
+ *
  * The base URI is used to construct bug report messages for
  * g_test_message() when g_test_bug() is called.
  * Calling this function outside of a test case sets the
@@ -640,7 +1221,9 @@ g_test_message (const char *format,
  * case only.
  * Bug URIs are constructed by appending a bug specific URI
  * portion to @uri_pattern, or by replacing the special string
- * '%s' within @uri_pattern if that is present.
+ * '\%s' within @uri_pattern if that is present.
+ *
+ * Since: 2.16
  */
 void
 g_test_bug_base (const char *uri_pattern)
@@ -657,13 +1240,17 @@ g_test_bug_base (const char *uri_pattern)
  * associates a bug URI with a test case.
  * Bug URIs are constructed from a base URI set with g_test_bug_base()
  * and @bug_uri_snippet.
+ *
+ * Since: 2.16
  */
 void
 g_test_bug (const char *bug_uri_snippet)
 {
   char *c;
+
   g_return_if_fail (test_uri_base != NULL);
   g_return_if_fail (bug_uri_snippet != NULL);
+
   c = strstr (test_uri_base, "%s");
   if (c)
     {
@@ -683,6 +1270,8 @@ g_test_bug (const char *bug_uri_snippet)
  * Get the toplevel test suite for the test path API.
  *
  * Returns: the toplevel #GTestSuite
+ *
+ * Since: 2.16
  */
 GTestSuite*
 g_test_get_root (void)
@@ -693,6 +1282,7 @@ g_test_get_root (void)
       g_free (test_suite_root->name);
       test_suite_root->name = g_strdup ("");
     }
+
   return test_suite_root;
 }
 
@@ -702,9 +1292,14 @@ g_test_get_root (void)
  * Runs all tests under the toplevel suite which can be retrieved
  * with g_test_get_root(). Similar to g_test_run_suite(), the test
  * cases to be run are filtered according to
- * test path arguments (-p <testpath>) as parsed by g_test_init().
+ * test path arguments (-p <replaceable>testpath</replaceable>) as 
+ * parsed by g_test_init().
  * g_test_run_suite() or g_test_run() may only be called once
  * in a program.
+ *
+ * Returns: 0 on success
+ *
+ * Since: 2.16
  */
 int
 g_test_run (void)
@@ -716,6 +1311,7 @@ g_test_run (void)
  * g_test_create_case:
  * @test_name:     the name for the test case
  * @data_size:     the size of the fixture data structure
+ * @test_data:     test data argument for the test functions
  * @data_setup:    the function to set up the fixture data
  * @data_test:     the actual test function
  * @data_teardown: the function to teardown the fixture data
@@ -723,45 +1319,73 @@ g_test_run (void)
  * Create a new #GTestCase, named @test_name, this API is fairly
  * low level, calling g_test_add() or g_test_add_func() is preferable.
  * When this test is executed, a fixture structure of size @data_size
- * will be allocated and filled with 0s. Then data_setup() is called
+ * will be allocated and filled with 0s. Then @data_setup is called
  * to initialize the fixture. After fixture setup, the actual test
- * function data_test() is called. Once the test run completed, the
- * fixture structure is torn down  by calling data_teardown() and
+ * function @data_test is called. Once the test run completed, the
+ * fixture structure is torn down  by calling @data_teardown and
  * after that the memory is released.
+ *
  * Splitting up a test run into fixture setup, test function and
  * fixture teardown is most usful if the same fixture is used for
  * multiple tests. In this cases, g_test_create_case() will be
  * called with the same fixture, but varying @test_name and
  * @data_test arguments.
  *
- * Returns a newly allocated #GTestCase.
+ * Returns: a newly allocated #GTestCase.
+ *
+ * Since: 2.16
  */
 GTestCase*
-g_test_create_case (const char     *test_name,
-                    gsize           data_size,
-                    void          (*data_setup) (void),
-                    void          (*data_test) (void),
-                    void          (*data_teardown) (void))
+g_test_create_case (const char       *test_name,
+                    gsize             data_size,
+                    gconstpointer     test_data,
+                    GTestFixtureFunc  data_setup,
+                    GTestFixtureFunc  data_test,
+                    GTestFixtureFunc  data_teardown)
 {
+  GTestCase *tc;
+
   g_return_val_if_fail (test_name != NULL, NULL);
   g_return_val_if_fail (strchr (test_name, '/') == NULL, NULL);
   g_return_val_if_fail (test_name[0] != 0, NULL);
   g_return_val_if_fail (data_test != NULL, NULL);
-  GTestCase *tc = g_slice_new0 (GTestCase);
+
+  tc = g_slice_new0 (GTestCase);
   tc->name = g_strdup (test_name);
+  tc->test_data = (gpointer) test_data;
   tc->fixture_size = data_size;
   tc->fixture_setup = (void*) data_setup;
   tc->fixture_test = (void*) data_test;
   tc->fixture_teardown = (void*) data_teardown;
+
   return tc;
 }
 
+/**
+ * GTestFixtureFunc:
+ * @fixture: the test fixture
+ * @user_data: the data provided when registering the test
+ *
+ * The type used for functions that operate on test fixtures.  This is
+ * used for the fixture setup and teardown functions as well as for the
+ * testcases themselves.
+ *
+ * @user_data is a pointer to the data that was given when registering
+ * the test case.
+ *
+ * @fixture will be a pointer to the area of memory allocated by the
+ * test framework, of the size requested.  If the requested size was
+ * zero then @fixture will be equal to @user_data.
+ *
+ * Since: 2.28
+ */
 void
-g_test_add_vtable (const char     *testpath,
-                   gsize           data_size,
-                   void          (*data_setup)    (void),
-                   void          (*fixture_test_func) (void),
-                   void          (*data_teardown) (void))
+g_test_add_vtable (const char       *testpath,
+                   gsize             data_size,
+                   gconstpointer     test_data,
+                   GTestFixtureFunc  data_setup,
+                   GTestFixtureFunc  fixture_test_func,
+                   GTestFixtureFunc  data_teardown)
 {
   gchar **segments;
   guint ui;
@@ -771,6 +1395,9 @@ g_test_add_vtable (const char     *testpath,
   g_return_if_fail (testpath[0] == '/');
   g_return_if_fail (fixture_test_func != NULL);
 
+  if (g_slist_find_custom (test_paths_skipped, testpath, (GCompareFunc)g_strcmp0))
+    return;
+
   suite = g_test_get_root();
   segments = g_strsplit (testpath, "/", -1);
   for (ui = 0; segments[ui] != NULL; ui++)
@@ -780,7 +1407,7 @@ g_test_add_vtable (const char     *testpath,
       if (islast && !seg[0])
         g_error ("invalid test case path: %s", testpath);
       else if (!seg[0])
-        continue;       // initial or duplicate slash
+        continue;       /* initial or duplicate slash */
       else if (!islast)
         {
           GTestSuite *csuite = g_test_create_suite (seg);
@@ -789,7 +1416,7 @@ g_test_add_vtable (const char     *testpath,
         }
       else /* islast */
         {
-          GTestCase *tc = g_test_create_case (seg, data_size, data_setup, fixture_test_func, data_teardown);
+          GTestCase *tc = g_test_create_case (seg, data_size, test_data, data_setup, fixture_test_func, data_teardown);
           g_test_suite_add (suite, tc);
         }
     }
@@ -797,23 +1424,93 @@ g_test_add_vtable (const char     *testpath,
 }
 
 /**
+ * g_test_fail:
+ *
+ * Indicates that a test failed. This function can be called
+ * multiple times from the same test. You can use this function
+ * if your test failed in a recoverable way.
+ * 
+ * Do not use this function if the failure of a test could cause
+ * other tests to malfunction.
+ *
+ * Calling this function will not stop the test from running, you
+ * need to return from the test function yourself. So you can
+ * produce additional diagnostic messages or even continue running
+ * the test.
+ *
+ * If not called from inside a test, this function does nothing.
+ *
+ * Since: 2.30
+ **/
+void
+g_test_fail (void)
+{
+  test_run_success = FALSE;
+}
+
+/**
+ * GTestFunc:
+ *
+ * The type used for test case functions.
+ *
+ * Since: 2.28
+ */
+
+/**
  * g_test_add_func:
- * @testpath:   Slash seperated test case path name for the test.
+ * @testpath:   Slash-separated test case path name for the test.
  * @test_func:  The test function to invoke for this test.
  *
  * Create a new test case, similar to g_test_create_case(). However
  * the test is assumed to use no fixture, and test suites are automatically
  * created on the fly and added to the root fixture, based on the
- * slash seperated portions of @testpath.
+ * slash-separated portions of @testpath.
+ *
+ * Since: 2.16
  */
 void
-g_test_add_func (const char     *testpath,
-                 void          (*test_func) (void))
+g_test_add_func (const char *testpath,
+                 GTestFunc   test_func)
 {
   g_return_if_fail (testpath != NULL);
   g_return_if_fail (testpath[0] == '/');
   g_return_if_fail (test_func != NULL);
-  g_test_add_vtable (testpath, 0, NULL, test_func, NULL);
+  g_test_add_vtable (testpath, 0, NULL, NULL, (GTestFixtureFunc) test_func, NULL);
+}
+
+/**
+ * GTestDataFunc:
+ * @user_data: the data provided when registering the test
+ *
+ * The type used for test case functions that take an extra pointer
+ * argument.
+ *
+ * Since: 2.28
+ */
+
+/**
+ * g_test_add_data_func:
+ * @testpath:   Slash-separated test case path name for the test.
+ * @test_data:  Test data argument for the test function.
+ * @test_func:  The test function to invoke for this test.
+ *
+ * Create a new test case, similar to g_test_create_case(). However
+ * the test is assumed to use no fixture, and test suites are automatically
+ * created on the fly and added to the root fixture, based on the
+ * slash-separated portions of @testpath. The @test_data argument
+ * will be passed as first argument to @test_func.
+ *
+ * Since: 2.16
+ */
+void
+g_test_add_data_func (const char     *testpath,
+                      gconstpointer   test_data,
+                      GTestDataFunc   test_func)
+{
+  g_return_if_fail (testpath != NULL);
+  g_return_if_fail (testpath[0] == '/');
+  g_return_if_fail (test_func != NULL);
+  g_test_add_vtable (testpath, 0, test_data, NULL, (GTestFixtureFunc) test_func, NULL);
 }
 
 /**
@@ -823,14 +1520,17 @@ g_test_add_func (const char     *testpath,
  * Create a new test suite with the name @suite_name.
  *
  * Returns: A newly allocated #GTestSuite instance.
+ *
+ * Since: 2.16
  */
 GTestSuite*
 g_test_create_suite (const char *suite_name)
 {
+  GTestSuite *ts;
   g_return_val_if_fail (suite_name != NULL, NULL);
   g_return_val_if_fail (strchr (suite_name, '/') == NULL, NULL);
   g_return_val_if_fail (suite_name[0] != 0, NULL);
-  GTestSuite *ts = g_slice_new0 (GTestSuite);
+  ts = g_slice_new0 (GTestSuite);
   ts->name = g_strdup (suite_name);
   return ts;
 }
@@ -841,6 +1541,8 @@ g_test_create_suite (const char *suite_name)
  * @test_case: a #GTestCase
  *
  * Adds @test_case to @suite.
+ *
+ * Since: 2.16
  */
 void
 g_test_suite_add (GTestSuite     *suite,
@@ -848,6 +1550,7 @@ g_test_suite_add (GTestSuite     *suite,
 {
   g_return_if_fail (suite != NULL);
   g_return_if_fail (test_case != NULL);
+
   suite->cases = g_slist_prepend (suite->cases, test_case);
 }
 
@@ -857,6 +1560,8 @@ g_test_suite_add (GTestSuite     *suite,
  * @nestedsuite: another #GTestSuite
  *
  * Adds @nestedsuite to @suite.
+ *
+ * Since: 2.16
  */
 void
 g_test_suite_add_suite (GTestSuite     *suite,
@@ -864,6 +1569,7 @@ g_test_suite_add_suite (GTestSuite     *suite,
 {
   g_return_if_fail (suite != NULL);
   g_return_if_fail (nestedsuite != NULL);
+
   suite->suites = g_slist_prepend (suite->suites, nestedsuite);
 }
 
@@ -874,6 +1580,8 @@ g_test_suite_add_suite (GTestSuite     *suite,
  * Enqueue a pointer to be released with g_free() during the next
  * teardown phase. This is equivalent to calling g_test_queue_destroy()
  * with a destroy callback of g_free().
+ *
+ * Since: 2.16
  */
 void
 g_test_queue_free (gpointer gfree_pointer)
@@ -887,19 +1595,23 @@ g_test_queue_free (gpointer gfree_pointer)
  * @destroy_func:       Destroy callback for teardown phase.
  * @destroy_data:       Destroy callback data.
  *
- * This function enqueus a callback @destroy_func() to be executed
+ * This function enqueus a callback @destroy_func to be executed
  * during the next test case teardown phase. This is most useful
  * to auto destruct allocted test resources at the end of a test run.
  * Resources are released in reverse queue order, that means enqueueing
  * callback A before callback B will cause B() to be called before
  * A() during teardown.
+ *
+ * Since: 2.16
  */
 void
 g_test_queue_destroy (GDestroyNotify destroy_func,
                       gpointer       destroy_data)
 {
   DestroyEntry *dentry;
+
   g_return_if_fail (destroy_func != NULL);
+
   dentry = g_slice_new0 (DestroyEntry);
   dentry->destroy_func = destroy_func;
   dentry->destroy_data = destroy_data;
@@ -907,10 +1619,12 @@ g_test_queue_destroy (GDestroyNotify destroy_func,
   test_destroy_queue = dentry;
 }
 
-static int
+static gboolean
 test_case_run (GTestCase *tc)
 {
   gchar *old_name = test_run_name, *old_base = g_strdup (test_uri_base);
+  gboolean success = TRUE;
+
   test_run_name = g_strconcat (old_name, "/", tc->name, NULL);
   if (++test_run_count <= test_skip_count)
     g_test_log (G_TEST_LOG_SKIP_CASE, test_run_name, NULL, 0, NULL);
@@ -923,14 +1637,17 @@ test_case_run (GTestCase *tc)
     {
       GTimer *test_run_timer = g_timer_new();
       long double largs[3];
+      void *fixture;
       g_test_log (G_TEST_LOG_START_CASE, test_run_name, NULL, 0, NULL);
       test_run_forks = 0;
+      test_run_success = TRUE;
+      g_test_log_set_fatal_handler (NULL, NULL);
       g_timer_start (test_run_timer);
-      void *fixture = g_malloc0 (tc->fixture_size);
+      fixture = tc->fixture_size ? g_malloc0 (tc->fixture_size) : tc->test_data;
       test_run_seed (test_run_seedstr);
       if (tc->fixture_setup)
-        tc->fixture_setup (fixture);
-      tc->fixture_test (fixture);
+        tc->fixture_setup (fixture, tc->test_data);
+      tc->fixture_test (fixture, tc->test_data);
       test_trap_clear();
       while (test_destroy_queue)
         {
@@ -940,10 +1657,13 @@ test_case_run (GTestCase *tc)
           g_slice_free (DestroyEntry, dentry);
         }
       if (tc->fixture_teardown)
-        tc->fixture_teardown (fixture);
-      g_free (fixture);
+        tc->fixture_teardown (fixture, tc->test_data);
+      if (tc->fixture_size)
+        g_free (fixture);
       g_timer_stop (test_run_timer);
-      largs[0] = 0; // OK
+      success = test_run_success;
+      test_run_success = FALSE;
+      largs[0] = success ? 0 : 1; /* OK */
       largs[1] = test_run_forks;
       largs[2] = g_timer_elapsed (test_run_timer, NULL);
       g_test_log (G_TEST_LOG_STOP_CASE, NULL, NULL, G_N_ELEMENTS (largs), largs);
@@ -953,17 +1673,20 @@ test_case_run (GTestCase *tc)
   test_run_name = old_name;
   g_free (test_uri_base);
   test_uri_base = old_base;
-  return 0;
+
+  return success;
 }
 
 static int
 g_test_run_suite_internal (GTestSuite *suite,
                            const char *path)
 {
-  guint n_bad = 0, n_good = 0, bad_suite = 0, l;
+  guint n_bad = 0, l;
   gchar *rest, *old_name = test_run_name;
   GSList *slist, *reversed;
+
   g_return_val_if_fail (suite != NULL, -1);
+
   while (path[0] == '/')
     path++;
   l = strlen (path);
@@ -977,8 +1700,8 @@ g_test_run_suite_internal (GTestSuite *suite,
       guint n = l ? strlen (tc->name) : 0;
       if (l == n && strncmp (path, tc->name, n) == 0)
         {
-          n_good++;
-          n_bad += test_case_run (tc) != 0;
+          if (!test_case_run (tc))
+            n_bad++;
         }
     }
   g_slist_free (reversed);
@@ -988,12 +1711,13 @@ g_test_run_suite_internal (GTestSuite *suite,
       GTestSuite *ts = slist->data;
       guint n = l ? strlen (ts->name) : 0;
       if (l == n && strncmp (path, ts->name, n) == 0)
-        bad_suite += g_test_run_suite_internal (ts, rest ? rest : "") != 0;
+        n_bad += g_test_run_suite_internal (ts, rest ? rest : "");
     }
   g_slist_free (reversed);
   g_free (test_run_name);
   test_run_name = old_name;
-  return n_bad || bad_suite;
+
+  return n_bad;
 }
 
 /**
@@ -1002,17 +1726,25 @@ g_test_run_suite_internal (GTestSuite *suite,
  *
  * Execute the tests within @suite and all nested #GTestSuites.
  * The test suites to be executed are filtered according to
- * test path arguments (-p <testpath>) as parsed by g_test_init().
+ * test path arguments (-p <replaceable>testpath</replaceable>) 
+ * as parsed by g_test_init().
  * g_test_run_suite() or g_test_run() may only be called once
  * in a program.
+ *
+ * Returns: 0 on success
+ *
+ * Since: 2.16
  */
 int
 g_test_run_suite (GTestSuite *suite)
 {
   guint n_bad = 0;
+
   g_return_val_if_fail (g_test_config_vars->test_initialized, -1);
   g_return_val_if_fail (g_test_run_once == TRUE, -1);
+
   g_test_run_once = FALSE;
+
   if (!test_paths)
     test_paths = g_slist_prepend (test_paths, "");
   while (test_paths)
@@ -1024,7 +1756,7 @@ g_test_run_suite (GTestSuite *suite)
         path++;
       if (!n) /* root suite, run unconditionally */
         {
-          n_bad += 0 != g_test_run_suite_internal (suite, path);
+          n_bad += g_test_run_suite_internal (suite, path);
           continue;
         }
       /* regular suite, match path */
@@ -1032,11 +1764,58 @@ g_test_run_suite (GTestSuite *suite)
       l = strlen (path);
       l = rest ? MIN (l, rest - path) : l;
       if ((!l || l == n) && strncmp (path, suite->name, n) == 0)
-        n_bad += 0 != g_test_run_suite_internal (suite, rest ? rest : "");
+        n_bad += g_test_run_suite_internal (suite, rest ? rest : "");
     }
+
   return n_bad;
 }
 
+static void
+gtest_default_log_handler (const gchar    *log_domain,
+                           GLogLevelFlags  log_level,
+                           const gchar    *message,
+                           gpointer        unused_data)
+{
+  const gchar *strv[16];
+  gboolean fatal = FALSE;
+  gchar *msg;
+  guint i = 0;
+
+  if (log_domain)
+    {
+      strv[i++] = log_domain;
+      strv[i++] = "-";
+    }
+  if (log_level & G_LOG_FLAG_FATAL)
+    {
+      strv[i++] = "FATAL-";
+      fatal = TRUE;
+    }
+  if (log_level & G_LOG_FLAG_RECURSION)
+    strv[i++] = "RECURSIVE-";
+  if (log_level & G_LOG_LEVEL_ERROR)
+    strv[i++] = "ERROR";
+  if (log_level & G_LOG_LEVEL_CRITICAL)
+    strv[i++] = "CRITICAL";
+  if (log_level & G_LOG_LEVEL_WARNING)
+    strv[i++] = "WARNING";
+  if (log_level & G_LOG_LEVEL_MESSAGE)
+    strv[i++] = "MESSAGE";
+  if (log_level & G_LOG_LEVEL_INFO)
+    strv[i++] = "INFO";
+  if (log_level & G_LOG_LEVEL_DEBUG)
+    strv[i++] = "DEBUG";
+  strv[i++] = ": ";
+  strv[i++] = message;
+  strv[i++] = NULL;
+
+  msg = g_strjoinv ("", (gchar**) strv);
+  g_test_log (fatal ? G_TEST_LOG_ERROR : G_TEST_LOG_MESSAGE, msg, NULL, 0, NULL);
+  g_log_default_handler (log_domain, log_level, message, unused_data);
+
+  g_free (msg);
+}
+
 void
 g_assertion_message (const char     *domain,
                      const char     *file,
@@ -1045,12 +1824,26 @@ g_assertion_message (const char     *domain,
                      const char     *message)
 {
   char lstr[32];
+  char *s;
+
+  if (!message)
+    message = "code should not be reached";
   g_snprintf (lstr, 32, "%d", line);
-  char *s = g_strconcat (domain ? domain : "", domain && domain[0] ? ":" : "",
-                         file, ":", lstr, ":",
-                         func, func[0] ? ":" : "",
-                         " ", message, NULL);
-  g_printerr ("**\n** %s\n", s);
+  s = g_strconcat (domain ? domain : "", domain && domain[0] ? ":" : "",
+                   "ERROR:", file, ":", lstr, ":",
+                   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();
 }
@@ -1082,7 +1875,7 @@ g_assertion_message_cmpnum (const char     *domain,
   switch (numtype)
     {
     case 'i':   s = g_strdup_printf ("assertion failed (%s): (%.0Lf %s %.0Lf)", expr, arg1, cmp, arg2); break;
-    case 'x':   s = g_strdup_printf ("assertion failed (%s): (0x%08Lx %s 0x%08Lx)", expr, (guint64) arg1, cmp, (guint64) arg2); break;
+    case 'x':   s = g_strdup_printf ("assertion failed (%s): (0x%08" G_GINT64_MODIFIER "x %s 0x%08" G_GINT64_MODIFIER "x)", expr, (guint64) arg1, cmp, (guint64) arg2); break;
     case 'f':   s = g_strdup_printf ("assertion failed (%s): (%.9Lg %s %.9Lg)", expr, arg1, cmp, arg2); break;
       /* ideally use: floats=%.7g double=%.17g */
     }
@@ -1112,12 +1905,52 @@ g_assertion_message_cmpstr (const char     *domain,
   g_free (s);
 }
 
+void
+g_assertion_message_error (const char     *domain,
+                          const char     *file,
+                          int             line,
+                          const char     *func,
+                          const char     *expr,
+                          const 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.
+ * Comparing two %NULL pointers returns 0.
+ *
+ * Returns: -1, 0 or 1, if @str1 is <, == or > than @str2.
+ *
+ * Since: 2.16
  */
 int
 g_strcmp0 (const char     *str1,
@@ -1130,6 +1963,7 @@ g_strcmp0 (const char     *str1,
   return strcmp (str1, str2);
 }
 
+#ifdef G_OS_UNIX
 static int /* 0 on success */
 kill_child (int  pid,
             int *status,
@@ -1175,6 +2009,7 @@ kill_child (int  pid,
   while (wr < 0 && errno == EINTR);
   return wr;
 }
+#endif
 
 static inline int
 g_string_must_read (GString *gstring,
@@ -1216,17 +2051,6 @@ g_string_write_out (GString *gstring,
     }
 }
 
-static int
-sane_dup2 (int fd1,
-           int fd2)
-{
-  int ret;
-  do
-    ret = dup2 (fd1, fd2);
-  while (ret < 0 && errno == EINTR);
-  return ret;
-}
-
 static void
 test_trap_clear (void)
 {
@@ -1238,6 +2062,19 @@ test_trap_clear (void)
   test_trap_last_stderr = NULL;
 }
 
+#ifdef G_OS_UNIX
+
+static int
+sane_dup2 (int fd1,
+           int fd2)
+{
+  int ret;
+  do
+    ret = dup2 (fd1, fd2);
+  while (ret < 0 && errno == EINTR);
+  return ret;
+}
+
 static guint64
 test_time_stamp (void)
 {
@@ -1249,6 +2086,8 @@ test_time_stamp (void)
   return stamp;
 }
 
+#endif
+
 /**
  * g_test_trap_fork:
  * @usec_timeout:    Timeout for the forked test in micro seconds.
@@ -1257,25 +2096,15 @@ test_time_stamp (void)
  * Fork the current test program to execute a test case that might
  * not return or that might abort. The forked test case is aborted
  * and considered failing if its run time exceeds @usec_timeout.
- * The forking behavior can be configured with the following flags:
- * %G_TEST_TRAP_SILENCE_STDOUT - redirect stdout of the test child
- * to /dev/null so it cannot be observed on the console during test
- * runs. The actual output is still captured though to allow later
- * tests with g_test_trap_assert_stdout().
- * %G_TEST_TRAP_SILENCE_STDERR - redirect stderr of the test child
- * to /dev/null so it cannot be observed on the console during test
- * runs. The actual output is still captured though to allow later
- * tests with g_test_trap_assert_stderr().
- * %G_TEST_TRAP_INHERIT_STDIN - if this flag is given, stdin of the
- * forked child process is shared with stdin of its parent process.
- * It is redirected to /dev/null otherwise.
+ *
+ * The forking behavior can be configured with the #GTestTrapFlags flags.
  *
  * In the following example, the test code forks, the forked child
  * process produces some sample output and exits successfully.
- * The forking parent process then asserts successfull child program
- * termination and validates cihld program outputs.
+ * The forking parent process then asserts successful child program
+ * termination and validates child program outputs.
  *
- * <informalexample><programlisting>
+ * |[
  *   static void
  *   test_fork_patterns (void)
  *   {
@@ -1283,20 +2112,26 @@ test_time_stamp (void)
  *       {
  *         g_print ("some stdout text: somagic17\n");
  *         g_printerr ("some stderr text: semagic43\n");
- *         exit (0); // successful test run
+ *         exit (0); /&ast; successful test run &ast;/
  *       }
  *     g_test_trap_assert_passed();
  *     g_test_trap_assert_stdout ("*somagic17*");
  *     g_test_trap_assert_stderr ("*semagic43*");
  *   }
- * </programlisting></informalexample>
+ * ]|
+ *
+ * This function is implemented only on Unix platforms.
  *
  * Returns: %TRUE for the forked child and %FALSE for the executing parent process.
+ *
+ * Since: 2.16
  */
 gboolean
 g_test_trap_fork (guint64        usec_timeout,
                   GTestTrapFlags test_trap_flags)
 {
+#ifdef G_OS_UNIX
+  gboolean pass_on_forked_log = FALSE;
   int stdout_pipe[2] = { -1, -1 };
   int stderr_pipe[2] = { -1, -1 };
   int stdtst_pipe[2] = { -1, -1 };
@@ -1342,6 +2177,7 @@ g_test_trap_fork (guint64        usec_timeout,
         {
           fd_set fds;
           struct timeval tv;
+          int ret;
           FD_ZERO (&fds);
           if (stdout_pipe[0] >= 0)
             FD_SET (stdout_pipe[0], &fds);
@@ -1350,8 +2186,8 @@ g_test_trap_fork (guint64        usec_timeout,
           if (stdtst_pipe[0] >= 0)
             FD_SET (stdtst_pipe[0], &fds);
           tv.tv_sec = 0;
-          tv.tv_usec = MIN (usec_timeout ? usec_timeout : 1000000, 100 * 1000); // sleep at most 0.5 seconds to catch clock skews, etc.
-          int ret = select (MAX (MAX (stdout_pipe[0], stderr_pipe[0]), stdtst_pipe[0]) + 1, &fds, NULL, NULL, &tv);
+          tv.tv_usec = MIN (usec_timeout ? usec_timeout : 1000000, 100 * 1000); /* sleep at most 0.5 seconds to catch clock skews, etc. */
+          ret = select (MAX (MAX (stdout_pipe[0], stderr_pipe[0]), stdtst_pipe[0]) + 1, &fds, NULL, NULL, &tv);
           if (ret < 0 && errno != EINTR)
             {
               g_warning ("Unexpected error in select() while reading from child process (%d): %s", test_trap_last_pid, g_strerror (errno));
@@ -1375,7 +2211,7 @@ g_test_trap_fork (guint64        usec_timeout,
               gint l, r = read (stdtst_pipe[0], buffer, sizeof (buffer));
               if (r > 0 && test_log_fd > 0)
                 do
-                  l = write (test_log_fd, buffer, r);
+                  l = write (pass_on_forked_log ? test_log_fd : -1, buffer, r);
                 while (l < 0 && errno == EINTR);
               if (r == 0 || (r < 0 && errno != EINTR && errno != EAGAIN))
                 {
@@ -1391,7 +2227,7 @@ g_test_trap_fork (guint64        usec_timeout,
             {
               guint64 nstamp = test_time_stamp();
               int status = 0;
-              sstamp = MIN (sstamp, nstamp); // guard against backwards clock skews
+              sstamp = MIN (sstamp, nstamp); /* guard against backwards clock skews */
               if (usec_timeout < nstamp - sstamp)
                 {
                   /* timeout reached, need to abort the child now */
@@ -1404,9 +2240,12 @@ g_test_trap_fork (guint64        usec_timeout,
                 }
             }
         }
-      close (stdout_pipe[0]);
-      close (stderr_pipe[0]);
-      close (stdtst_pipe[0]);
+      if (stdout_pipe[0] != -1)
+        close (stdout_pipe[0]);
+      if (stderr_pipe[0] != -1)
+        close (stderr_pipe[0]);
+      if (stdtst_pipe[0] != -1)
+        close (stdtst_pipe[0]);
       if (need_wait)
         {
           int status = 0;
@@ -1424,14 +2263,21 @@ g_test_trap_fork (guint64        usec_timeout,
       test_trap_last_stderr = g_string_free (serr, FALSE);
       return FALSE;
     }
+#else
+  g_message ("Not implemented: g_test_trap_fork");
+
+  return FALSE;
+#endif
 }
 
 /**
  * g_test_trap_has_passed:
  *
- * Check the reuslt of the last g_test_trap_fork() call.
+ * Check the result of the last g_test_trap_fork() call.
  *
  * Returns: %TRUE if the last forked child terminated successfully.
+ *
+ * Since: 2.16
  */
 gboolean
 g_test_trap_has_passed (void)
@@ -1442,9 +2288,11 @@ g_test_trap_has_passed (void)
 /**
  * g_test_trap_reached_timeout:
  *
- * Check the reuslt of the last g_test_trap_fork() call.
+ * Check the result of the last g_test_trap_fork() call.
  *
  * Returns: %TRUE if the last forked child got killed due to a fork timeout.
+ *
+ * Since: 2.16
  */
 gboolean
 g_test_trap_reached_timeout (void)
@@ -1457,11 +2305,16 @@ g_test_trap_assertions (const char     *domain,
                         const char     *file,
                         int             line,
                         const char     *func,
-                        gboolean        must_pass,
-                        gboolean        must_fail,
-                        const char     *stdout_pattern,
-                        const char     *stderr_pattern)
+                        guint64         assertion_flags, /* 0-pass, 1-fail, 2-outpattern, 4-errpattern */
+                        const char     *pattern)
 {
+#ifdef G_OS_UNIX
+  gboolean must_pass = assertion_flags == 0;
+  gboolean must_fail = assertion_flags == 1;
+  gboolean match_result = 0 == (assertion_flags & 1);
+  const char *stdout_pattern = (assertion_flags & 2) ? pattern : NULL;
+  const char *stderr_pattern = (assertion_flags & 4) ? pattern : NULL;
+  const char *match_error = match_result ? "failed to match" : "contains invalid match";
   if (test_trap_last_pid == 0)
     g_error ("child process failed to exit after g_test_trap_fork() and before g_test_trap_assert*()");
   if (must_pass && !g_test_trap_has_passed())
@@ -1476,18 +2329,19 @@ g_test_trap_assertions (const char     *domain,
       g_assertion_message (domain, file, line, func, msg);
       g_free (msg);
     }
-  if (stdout_pattern && !g_pattern_match_simple (stdout_pattern, test_trap_last_stdout))
+  if (stdout_pattern && match_result == !g_pattern_match_simple (stdout_pattern, test_trap_last_stdout))
     {
-      char *msg = g_strdup_printf ("stdout of child process (%d) failed to match: %s", test_trap_last_pid, stdout_pattern);
+      char *msg = g_strdup_printf ("stdout of child process (%d) %s: %s", test_trap_last_pid, match_error, stdout_pattern);
       g_assertion_message (domain, file, line, func, msg);
       g_free (msg);
     }
-  if (stderr_pattern && !g_pattern_match_simple (stderr_pattern, test_trap_last_stderr))
+  if (stderr_pattern && match_result == !g_pattern_match_simple (stderr_pattern, test_trap_last_stderr))
     {
-      char *msg = g_strdup_printf ("stderr of child process (%d) failed to match: %s", test_trap_last_pid, stderr_pattern);
+      char *msg = g_strdup_printf ("stderr of child process (%d) %s: %s", test_trap_last_pid, match_error, stderr_pattern);
       g_assertion_message (domain, file, line, func, msg);
       g_free (msg);
     }
+#endif
 }
 
 static void
@@ -1689,18 +2543,18 @@ g_test_log_msg_free (GTestLogMsg *tmsg)
  * g_test_add:
  * @testpath:  The test path for a new test case.
  * @Fixture:   The type of a fixture data structure.
+ * @tdata:     Data argument for the test functions.
  * @fsetup:    The function to set up the fixture data.
  * @ftest:     The actual test function.
  * @fteardown: The function to tear down the fixture data.
  *
  * Hook up a new test case at @testpath, similar to g_test_add_func().
  * A fixture data structure with setup and teardown function may be provided
- * though, simmilar to g_test_create_case().
+ * though, similar to g_test_create_case().
  * g_test_add() is implemented as a macro, so that the fsetup(), ftest() and
  * fteardown() callbacks can expect a @Fixture pointer as first argument in
  * a type safe manner.
+ *
+ * Since: 2.16
  **/
 /* --- macros docs END --- */
-
-#define __G_TEST_UTILS_C__
-#include "galiasdef.c"