gtestutils.h File Reference

__G_TEST_UTILS_H__

Typedef GTestCase

typedef typedefG_BEGIN_DECLS struct GTestCaseGTestCase

Typedef GTestSuite

typedef struct GTestSuiteGTestSuite

g_assert_cmpstr

g_assert_cmpint

g_assert_cmpuint

g_assert_cmphex

g_assert_cmpfloat

g_assert_no_error

g_assert_error

g_assert_not_reached

g_assert

g_strcmp0 ( const char *, const char * )

IMPORT_C intg_strcmp0(const char *str1,
const char *str2
)

g_strcmp0: : a C string or NULL : another C string or NULL

Compares and like strcmp(). Handles NULL gracefully by sorting it before non-NULL strings.

Returns: -1, 0 or 1, if is <, == or > than .

Since: 2.16

g_test_minimized_result ( double, const char *, ... )

IMPORT_C voidg_test_minimized_result(doubleminimized_quantity,
const char *format,
...
)

g_test_maximized_result ( double, const char *, ... )

IMPORT_C void IMPORT_C voidg_test_maximized_result(doublemaximized_quantity,
const char *format,
...
)

g_test_init ( int *, char ***, ... )

IMPORT_C void IMPORT_C void IMPORT_C voidg_test_init(int *argc,
char ***argv,
...
)

g_test_init: : Address of the parameter of the main() function. Changed if any arguments were handled. : Address of the 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: <variablelist> <varlistentry> <option>-l</option> <listitem>

list test cases available in a test executable.

</listitem> </varlistentry> <varlistentry> <option>--seed=<replaceable>RANDOMSEED</replaceable></option> <listitem>

provide a random seed to reproduce test runs using random numbers.

</listitem> </varlistentry> <varlistentry> <option>--verbose</option> <listitem>

run tests verbosely.

</listitem> </varlistentry> <varlistentry> <option>-q</option>, <option>--quiet</option> <listitem>

run tests quietly.

</listitem> </varlistentry> <varlistentry> <option>-p <replaceable>TESTPATH</replaceable></option> <listitem>

execute all tests matching <replaceable>TESTPATH</replaceable>.

</listitem> </varlistentry> <varlistentry> <option>-m {perf|slow|thorough|quick}</option> <listitem>

execute tests according to these test modes: <variablelist> <varlistentry> perf <listitem>

performance tests, may take long and report results.

</listitem> </varlistentry> <varlistentry> slow, thorough <listitem>

slow and thorough tests, may take quite long and maximize coverage.

</listitem> </varlistentry> <varlistentry> quick <listitem>

quick tests, should run really quickly and give good coverage.

</listitem> </varlistentry> </variablelist>

</listitem> </varlistentry> <varlistentry> <option>--debug-log</option> <listitem>

debug test logging output.

</listitem> </varlistentry> <varlistentry> <option>-k</option>, <option>--keep-going</option> <listitem>

gtester-specific argument.

</listitem> </varlistentry> <varlistentry> <option>--GTestLogFD <replaceable>N</replaceable></option> <listitem>

gtester-specific argument.

</listitem> </varlistentry> <varlistentry> <option>--GTestSkipCount <replaceable>N</replaceable></option> <listitem>

gtester-specific argument.

</listitem> </varlistentry> </variablelist>

Since: 2.16

g_test_quick

g_test_slow

g_test_thorough

g_test_perf

g_test_verbose

g_test_quiet

g_test_run ( void )

IMPORT_C intg_test_run(void)

g_test_run:

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 <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

g_test_add_func ( const char *, void(*)(void) )

IMPORT_C voidg_test_add_func(const char *testpath,
void(*)(void)test_func
)

g_test_add_func: : Slash-separated test case path name for the test. : 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 .

Since: 2.16

g_test_add_data_func ( const char *, gconstpointer, void(*)(gconstpointer) )

IMPORT_C voidg_test_add_data_func(const char *testpath,
gconstpointertest_data,
void(*)(gconstpointer)test_func
)

g_test_add_data_func: : Slash-separated test case path name for the test. : Test data argument for the test function. : 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 . The argument will be passed as first argument to .

Since: 2.16

g_test_add

g_test_message ( const char *, ... )

IMPORT_C voidg_test_message(const char *format,
...
)

g_test_bug_base ( const char * )

IMPORT_C void IMPORT_C voidg_test_bug_base(const char *uri_pattern)

g_test_bug_base: : 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 default base URI for all test cases. Calling it from within a test case changes the base URI for the scope of the test case only. Bug URIs are constructed by appending a bug specific URI portion to , or by replacing the special string 's' within if that is present.

Since: 2.16

g_test_bug ( const char * )

IMPORT_C voidg_test_bug(const char *bug_uri_snippet)

g_test_bug: : Bug specific bug tracker URI portion.

This function adds a message to test reports that associates a bug URI with a test case. Bug URIs are constructed from a base URI set with g_test_bug_base() and .

Since: 2.16

g_test_timer_start ( void )

IMPORT_C voidg_test_timer_start(void)

g_test_timer_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

g_test_timer_elapsed ( void )

IMPORT_C doubleg_test_timer_elapsed(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

g_test_timer_last ( void )

IMPORT_C doubleg_test_timer_last(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

g_test_queue_free ( gpointer )

IMPORT_C voidg_test_queue_free(gpointergfree_pointer)

g_test_queue_free: : the pointer to be stored.

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

g_test_queue_destroy ( GDestroyNotify, gpointer )

IMPORT_C voidg_test_queue_destroy(GDestroyNotifydestroy_func,
gpointerdestroy_data
)

g_test_queue_destroy: : Destroy callback for teardown phase. : Destroy callback data.

This function enqueus a callback () 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

g_test_queue_unref

Enum GTestTrapFlags

g_test_trap_fork ( guint64, GTestTrapFlags )

IMPORT_C gbooleang_test_trap_fork(guint64usec_timeout,
GTestTrapFlagstest_trap_flags
)

g_test_trap_fork: : Timeout for the forked test in micro seconds. : Flags to modify forking behaviour.

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 .

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 successful child program termination and validates child program outputs.

|[ static void test_fork_patterns (void) { if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR)) { g_print ("some stdout text: somagic17\n"); g_printerr ("some stderr text: semagic43\n"); exit (0); / successful test run / } g_test_trap_assert_passed(); g_test_trap_assert_stdout ("*somagic17*"); g_test_trap_assert_stderr ("*semagic43*"); } ]|

This function is implemented only on Unix platforms.

Returns: TRUE for the forked child and FALSE for the executing parent process.

Since: 2.16

g_test_trap_has_passed ( void )

IMPORT_C gbooleang_test_trap_has_passed(void)

g_test_trap_has_passed:

Check the result of the last g_test_trap_fork() call.

Returns: TRUE if the last forked child terminated successfully.

Since: 2.16

g_test_trap_reached_timeout ( void )

IMPORT_C gbooleang_test_trap_reached_timeout(void)

g_test_trap_reached_timeout:

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

g_test_trap_assert_passed

g_test_trap_assert_failed

g_test_trap_assert_stdout

g_test_trap_assert_stdout_unmatched

g_test_trap_assert_stderr

g_test_trap_assert_stderr_unmatched

g_test_rand_bit

g_test_rand_int ( void )

IMPORT_C gint32g_test_rand_int(void)

g_test_rand_int:

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

g_test_rand_int_range ( gint32, gint32 )

IMPORT_C gint32g_test_rand_int_range(gint32begin,
gint32end
)

g_test_rand_int_range: : the minimum value returned by this function : the smallest value not to be returned by this function

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 <= number < .

Since: 2.16

g_test_rand_double ( void )

IMPORT_C doubleg_test_rand_double(void)

g_test_rand_double:

Get a reproducible random floating point number, see g_test_rand_int() for details on test case random numbers.

Returns: a random number from the seeded random number generator.

Since: 2.16

g_test_rand_double_range ( double, double )

IMPORT_C doubleg_test_rand_double_range(doublerange_start,
doublerange_end
)

g_test_rand_double_range: : the minimum value returned by this function : the minimum value not returned by this function

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 <= number < .

Since: 2.16

g_test_create_case ( const char *, gsize, gconstpointer, void(*)(void), void(*)(void), void(*)(void) )

IMPORT_C GTestCase *g_test_create_case(const char *test_name,
gsizedata_size,
gconstpointertest_data,
void(*)(void)data_setup,
void(*)(void)data_test,
void(*)(void)data_teardown
)

g_test_create_case: : the name for the test case : the size of the fixture data structure : test data argument for the test functions : the function to set up the fixture data : the actual test function : the function to teardown the fixture data

Create a new GTestCase, named , 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 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 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 and arguments.

Returns: a newly allocated GTestCase.

Since: 2.16

g_test_create_suite ( const char * )

IMPORT_C GTestSuite *g_test_create_suite(const char *suite_name)

g_test_create_suite: : a name for the suite

Create a new test suite with the name .

Returns: A newly allocated GTestSuite instance.

Since: 2.16

g_test_get_root ( void )

IMPORT_C GTestSuite *g_test_get_root(void)

g_test_get_root:

Get the toplevel test suite for the test path API.

Returns: the toplevel GTestSuite

Since: 2.16

g_test_suite_add ( GTestSuite *, GTestCase * )

IMPORT_C voidg_test_suite_add(GTestSuite *suite,
GTestCase *test_case
)

g_test_suite_add: : a GTestSuite : a GTestCase

Adds to .

Since: 2.16

g_test_suite_add_suite ( GTestSuite *, GTestSuite * )

IMPORT_C voidg_test_suite_add_suite(GTestSuite *suite,
GTestSuite *nestedsuite
)

g_test_suite_add_suite: : a GTestSuite : another GTestSuite

Adds to .

Since: 2.16

g_test_run_suite ( GTestSuite * )

IMPORT_C intg_test_run_suite(GTestSuite *suite)

g_test_run_suite: : a GTestSuite

Execute the tests within and all nested #GTestSuites. The test suites to be executed are filtered according to 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

g_test_trap_assertions ( const char *, const char *, int, const char *, guint64, const char * )

IMPORT_C voidg_test_trap_assertions(const char *domain,
const char *file,
intline,
const char *func,
guint64assertion_flags,
const char *pattern
)

g_assertion_message ( const char *, const char *, int, const char *, const char * )

IMPORT_C voidg_assertion_message(const char *domain,
const char *file,
intline,
const char *func,
const char *message
)

g_assertion_message_expr ( const char *, const char *, int, const char *, const char * )

IMPORT_C voidg_assertion_message_expr(const char *domain,
const char *file,
intline,
const char *func,
const char *expr
)

g_assertion_message_cmpstr ( const char *, const char *, int, const char *, const char *, const char *, const char *, const char * )

IMPORT_C voidg_assertion_message_cmpstr(const char *domain,
const char *file,
intline,
const char *func,
const char *expr,
const char *arg1,
const char *cmp,
const char *arg2
)

g_assertion_message_cmpnum ( const char *, const char *, int, const char *, const char *, long double, const char *, long double, char )

IMPORT_C voidg_assertion_message_cmpnum(const char *domain,
const char *file,
intline,
const char *func,
const char *expr,
long doublearg1,
const char *cmp,
long doublearg2,
charnumtype
)

g_assertion_message_error ( const char *, const char *, int, const char *, const char *, GError *, GQuark, int )

IMPORT_C voidg_assertion_message_error(const char *domain,
const char *file,
intline,
const char *func,
const char *expr,
GError *error,
GQuarkerror_domain,
interror_code
)

g_test_add_vtable ( const char *, gsize, gconstpointer, void(*)(void), void(*)(void), void(*)(void) )

IMPORT_C voidg_test_add_vtable(const char *testpath,
gsizedata_size,
gconstpointertest_data,
void(*)(void)data_setup,
void(*)(void)data_test,
void(*)(void)data_teardown
)

g_test_config_vars

GLIB_VAR const GTestConfig *constg_test_config_vars

_g_test_config_vars ( void )

IMPORT_C const GTestConfig *const *_g_test_config_vars(void)

Enum GTestLogType

Typedef GTestLogMsg

typedef struct GTestLogMsgGTestLogMsg

Typedef GTestLogBuffer

typedef struct GTestLogBufferGTestLogBuffer

g_test_log_type_name ( GTestLogType )

IMPORT_C const char *g_test_log_type_name(GTestLogTypelog_type)

g_test_log_buffer_new ( void )

IMPORT_C GTestLogBuffer *g_test_log_buffer_new(void)

g_test_log_buffer_new:

Internal function for gtester to decode test log messages, no ABI guarantees provided.

g_test_log_buffer_free ( GTestLogBuffer * )

IMPORT_C voidg_test_log_buffer_free(GTestLogBuffer *tbuffer)

g_test_log_buffer_free

Internal function for gtester to free test log messages, no ABI guarantees provided.

g_test_log_buffer_push ( GTestLogBuffer *, guint, const guint8 * )

IMPORT_C voidg_test_log_buffer_push(GTestLogBuffer *tbuffer,
guintn_bytes,
const guint8 *bytes
)

g_test_log_buffer_push

Internal function for gtester to decode test log messages, no ABI guarantees provided.

g_test_log_buffer_pop ( GTestLogBuffer * )

IMPORT_C GTestLogMsg *g_test_log_buffer_pop(GTestLogBuffer *tbuffer)

g_test_log_buffer_pop:

Internal function for gtester to retrieve test log messages, no ABI guarantees provided.

g_test_log_msg_free ( GTestLogMsg * )

IMPORT_C voidg_test_log_msg_free(GTestLogMsg *tmsg)

g_test_log_msg_free:

Internal function for gtester to free test log messages, no ABI guarantees provided.