⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testing.sgml

📁 this is a glib for c language
💻 SGML
字号:
<!-- ##### SECTION Title ##### -->Testing<!-- ##### SECTION Short_Description ##### -->a test framework<!-- ##### SECTION Long_Description ##### --><para>GLib provides a framework for writing and maintaining unit testsin 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><para>      Tests (test methods) are grouped together with their       fixture into test cases.    </para></listitem>  </varlistentry>  <varlistentry>    <term>Fixture</term>    <listitem><para>      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       invokation to avoid dependencies between tests.    </para></listitem>  </varlistentry>  <varlistentry>    <term>Test suite</term>    <listitem><para>      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.    </para></listitem>  </varlistentry></variablelist>The API is designed to handle creation and registration of test suites andtest cases implicitly. A simple call like<informalexample><programlisting>  g_test_add_func ("/misc/assertions", test_assertions);</programlisting></informalexample>creates a test suite called "misc" with a single test case named "assertions",which consists of running the test_assertions function.</para><para>In addition to the traditional g_assert(), the test framework providesan 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 thevalues of the compared entities.</para><para>GLib ships with two utilites called gtester and gtester-report to facilitate running tests and producing nicely formatted test reports. </para><!-- ##### SECTION See_Also ##### --><para><link linkend="gtester">gtester</link>,<link linkend="gtester-report">gtester-report</link></para><!-- ##### SECTION Stability_Level ##### --><!-- ##### FUNCTION g_test_minimized_result ##### --><para></para>@minimized_quantity: @format: @Varargs: <!-- ##### FUNCTION g_test_maximized_result ##### --><para></para>@maximized_quantity: @format: @Varargs: <!-- ##### FUNCTION g_test_init ##### --><para></para>@argc: @argv: @Varargs: <!-- ##### MACRO g_test_quick ##### --><para>Returns %TRUE if tests are run in quick mode.</para><!-- ##### MACRO g_test_slow ##### --><para>Returns %TRUE if tests are run in slow mode.</para><!-- ##### MACRO g_test_thorough ##### --><para>Returns %TRUE if tests are run in thorough mode.</para><!-- ##### MACRO g_test_perf ##### --><para>Returns %TRUE if tests are run in performance mode.</para><!-- ##### MACRO g_test_verbose ##### --><para>Returns %TRUE if tests are run in verbose mode.</para><!-- ##### MACRO g_test_quiet ##### --><para>Returns %TRUE if tests are run in quiet mode.</para><!-- ##### FUNCTION g_test_run ##### --><para></para>@Returns: <!-- ##### FUNCTION g_test_add_func ##### --><para></para>@testpath: @test_func: <!-- ##### FUNCTION g_test_add_data_func ##### --><para></para>@testpath: @test_data: @test_func: <!-- ##### MACRO g_test_add ##### --><para></para>@testpath: @Fixture: @tdata: @fsetup: @ftest: @fteardown: <!-- ##### FUNCTION g_test_message ##### --><para></para>@format: @Varargs: <!-- ##### FUNCTION g_test_bug_base ##### --><para></para>@uri_pattern: <!-- ##### FUNCTION g_test_bug ##### --><para></para>@bug_uri_snippet: <!-- ##### FUNCTION g_test_timer_start ##### --><para></para><!-- ##### FUNCTION g_test_timer_elapsed ##### --><para></para>@Returns: <!-- ##### FUNCTION g_test_timer_last ##### --><para></para>@Returns: <!-- ##### FUNCTION g_test_queue_free ##### --><para></para>@gfree_pointer: <!-- ##### FUNCTION g_test_queue_destroy ##### --><para></para>@destroy_func: @destroy_data: <!-- ##### MACRO g_test_queue_unref ##### --><para>Enqueue an object to be released with g_object_unref() duringthe next teardown phase. This is equivalent to calling g_test_queue_destroy()with a destroy callback of g_object_unref().</para>@gobject: the object to unref@Since: 2.16<!-- ##### ENUM GTestTrapFlags ##### --><para>Test traps are guards around forked tests. These flagsdetermine what traps to set.</para>@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.<!-- ##### FUNCTION g_test_trap_fork ##### --><para></para>@usec_timeout: @test_trap_flags: @Returns: <!-- ##### FUNCTION g_test_trap_has_passed ##### --><para></para>@Returns: <!-- ##### FUNCTION g_test_trap_reached_timeout ##### --><para></para>@Returns: <!-- ##### MACRO g_test_trap_assert_passed ##### --><para>Assert that the last forked test passed. See g_test_trap_fork().</para>@Since: 2.16<!-- ##### MACRO g_test_trap_assert_failed ##### --><para>Assert that the last forked test failed. See g_test_trap_fork().</para>@Since: 2.16<!-- ##### MACRO g_test_trap_assert_stdout ##### --><para>Assert that the stdout output of the last forked test matches @soutpattern. See g_test_trap_fork().</para>@soutpattern: a glob-style <link linkend="glib-Glob-style-pattern-matching">pattern</link>@Since: 2.16<!-- ##### MACRO g_test_trap_assert_stdout_unmatched ##### --><para>Assert that the stdout output of the last forked test does not match @soutpattern.  See g_test_trap_fork().</para>@soutpattern: a glob-style <link linkend="glib-Glob-style-pattern-matching">pattern</link>@Since: 2.16<!-- ##### MACRO g_test_trap_assert_stderr ##### --><para>Assert that the stderr output of the last forked test matches @serrpattern. See g_test_trap_fork().</para>@serrpattern: a glob-style <link linkend="glib-Glob-style-pattern-matching">pattern</link>@Since: 2.16<!-- ##### MACRO g_test_trap_assert_stderr_unmatched ##### --><para>Assert that the stderr output of the last forked test does not match @serrpattern.  See g_test_trap_fork().</para>@serrpattern: a glob-style <link linkend="glib-Glob-style-pattern-matching">pattern</link>@Since: 2.16<!-- ##### MACRO g_test_rand_bit ##### --><para>Get a reproducible random bit (0 or 1),see g_test_rand_int() for details on test case random numbers.</para>@Since: 2.16<!-- ##### FUNCTION g_test_rand_int ##### --><para></para>@Returns: <!-- ##### FUNCTION g_test_rand_int_range ##### --><para></para>@begin: @end: @Returns: <!-- ##### FUNCTION g_test_rand_double ##### --><para></para>@Returns: <!-- ##### FUNCTION g_test_rand_double_range ##### --><para></para>@range_start: @range_end: @Returns: <!-- ##### MACRO g_assert ##### --><para>Debugging macro to terminate the application if the assertion fails.If the assertion fails (i.e. the expression is not true), an error messageis logged and the application is terminated.</para><para>The macro can be turned off in final releases of code by defining#G_DISABLE_ASSERT when compiling the application.</para>@expr: the expression to check.<!-- ##### MACRO g_assert_not_reached ##### --><para>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.</para><para>The macro can be turned off in final releases of code by defining#G_DISABLE_ASSERT when compiling the application.</para><!-- ##### MACRO g_assert_cmpstr ##### --><para>Debugging macro to terminate the application with a warning message if a string comparison fails.The strings are compared using g_strcmp0().</para><para>The effect of <literal>g_assert_cmpstr (s1, op, s2)</literal> is the sameas <literal>g_assert (s1 op s2)</literal>. The advantage of this macrois that it can produce a message that includes the actual values of @s1and @s2.</para><informalexample><programlisting>  g_assert_cmpstr (mystring, ==, "fubar");</programlisting></informalexample>@s1: a string (may be %NULL)@cmp: The comparsion operator to use. One of ==, !=, &lt;, &gt;, &lt;=, &gt;=.@s2: another string (may be %NULL)@Since: 2.16<!-- ##### MACRO g_assert_cmpint ##### --><para>Debugging macro to terminate the application with a warning message if an integer comparison fails.</para><para>The effect of <literal>g_assert_cmpint (n1, op, n2)</literal> is the sameas <literal>g_assert (n1 op n2)</literal>. The advantage of this macrois that it can produce a message that includes the actual values of @n1and @n2.</para>@n1: an integer@cmp: The comparsion operator to use. One of ==, !=, &lt;, &gt;, &lt;=, &gt;=.@n2: another integer@Since: 2.16<!-- ##### MACRO g_assert_cmpuint ##### --><para>Debugging macro to terminate the application with a warning message if an unsigned integer comparison fails.</para><para>The effect of <literal>g_assert_cmpuint (n1, op, n2)</literal> is the sameas <literal>g_assert (n1 op n2)</literal>. The advantage of this macrois that it can produce a message that includes the actual values of @n1and @n2.</para>@n1: an unsigned integer@cmp: The comparsion operator to use. One of ==, !=, &lt;, &gt;, &lt;=, &gt;=.@n2: another unsigned integer@Since: 2.16<!-- ##### MACRO g_assert_cmphex ##### --><para>Debugging macro to terminate the application with a warning message if an unsigned integer comparison fails. This is a variant ofg_assert_cmpuint() that displays the numbers in hexadecimal notationin the message.</para>@n1: an unsigned integer@cmp: The comparsion operator to use. One of ==, !=, &lt;, &gt;, &lt;=, &gt;=.@n2: another unsigned integer@Since: 2.16<!-- ##### MACRO g_assert_cmpfloat ##### --><para>Debugging macro to terminate the application with a warning message if a floating point number comparison fails.</para><para>The effect of <literal>g_assert_cmpflott (n1, op, n2)</literal> is the sameas <literal>g_assert (n1 op n2)</literal>. The advantage of this functionis that it can produce a message that includes the actual values of @n1and @n2.</para>@n1: an floating point number@cmp: The comparsion operator to use. One of ==, !=, &lt;, &gt;, &lt;=, &gt;=.@n2: another floating point number@Since: 2.16<!-- ##### TYPEDEF GTestCase ##### --><para>An opaque structure representing a test case.</para><!-- ##### TYPEDEF GTestSuite ##### --><para>An opaque structure representing a test suite.</para><!-- ##### FUNCTION g_test_create_case ##### --><para></para>@test_name: @data_size: @test_data: @data_setup: @data_test: @data_teardown: @Returns: <!-- ##### FUNCTION g_test_create_suite ##### --><para></para>@suite_name: @Returns: <!-- ##### FUNCTION g_test_get_root ##### --><para></para>@Returns: <!-- ##### FUNCTION g_test_suite_add ##### --><para></para>@suite: @test_case: <!-- ##### FUNCTION g_test_suite_add_suite ##### --><para></para>@suite: @nestedsuite: <!-- ##### FUNCTION g_test_run_suite ##### --><para></para>@suite: @Returns: 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -