📄 glib-testing.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"><title>Testing</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="GLib Reference Manual"><link rel="up" href="glib-utilities.html" title="GLib Utilities"><link rel="prev" href="glib-Bookmark-file-parser.html" title="Bookmark file parser"><link rel="next" href="glib-Windows-Compatibility-Functions.html" title="Windows Compatibility Functions"><meta name="generator" content="GTK-Doc V1.9 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"><link rel="chapter" href="glib.html" title="GLib Overview"><link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals"><link rel="chapter" href="glib-core.html" title="GLib Core Application Support"><link rel="chapter" href="glib-utilities.html" title="GLib Utilities"><link rel="chapter" href="glib-data-types.html" title="GLib Data Types"><link rel="chapter" href="tools.html" title="GLib Tools"><link rel="index" href="ix01.html" title="Index"><link rel="index" href="ix02.html" title="Index of deprecated symbols"><link rel="index" href="ix03.html" title="Index of new symbols in 2.2"><link rel="index" href="ix04.html" title="Index of new symbols in 2.4"><link rel="index" href="ix05.html" title="Index of new symbols in 2.6"><link rel="index" href="ix06.html" title="Index of new symbols in 2.8"><link rel="index" href="ix07.html" title="Index of new symbols in 2.10"><link rel="index" href="ix08.html" title="Index of new symbols in 2.12"><link rel="index" href="ix09.html" title="Index of new symbols in 2.14"><link rel="index" href="ix10.html" title="Index of new symbols in 2.16"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="glib-Bookmark-file-parser.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="glib-utilities.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td><td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td><th width="100%" align="center">GLib Reference Manual</th><td><a accesskey="n" href="glib-Windows-Compatibility-Functions.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td></tr><tr><td colspan="5" class="shortcuts"><nobr><a href="#id3216660" class="shortcut">Top</a>  |  <a href="#id3217436" class="shortcut">Description</a></nobr></td></tr></table><div class="refentry" lang="en"><a name="glib-Testing"></a><div class="titlepage"></div><div class="refnamediv"><table width="100%"><tr><td valign="top"><h2><a name="id3216660"></a><span class="refentrytitle">Testing</span></h2><p>Testing</p></td><td valign="top" align="right"></td></tr></table></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">#include <glib.h>typedef <a class="link" href="glib-Testing.html#GTestCase">GTestCase</a>;typedef <a class="link" href="glib-Testing.html#GTestSuite">GTestSuite</a>;void <a class="link" href="glib-Testing.html#g-test-minimized-result">g_test_minimized_result</a> (double minimized_quantity, const char *format, ...);void <a class="link" href="glib-Testing.html#g-test-maximized-result">g_test_maximized_result</a> (double maximized_quantity, const char *format, ...);void <a class="link" href="glib-Testing.html#g-test-init">g_test_init</a> (int *argc, char ***argv, ...);#define <a class="link" href="glib-Testing.html#g-test-quick">g_test_quick</a> ()#define <a class="link" href="glib-Testing.html#g-test-slow">g_test_slow</a> ()#define <a class="link" href="glib-Testing.html#g-test-thorough">g_test_thorough</a> ()#define <a class="link" href="glib-Testing.html#g-test-perf">g_test_perf</a> ()#define <a class="link" href="glib-Testing.html#g-test-verbose">g_test_verbose</a> ()#define <a class="link" href="glib-Testing.html#g-test-quiet">g_test_quiet</a> ()int <a class="link" href="glib-Testing.html#g-test-run">g_test_run</a> (void);void <a class="link" href="glib-Testing.html#g-test-add-func">g_test_add_func</a> (const char *testpath, void (test_funcvoid) ());void <a class="link" href="glib-Testing.html#g-test-add-data-func">g_test_add_data_func</a> (const char *testpath, <a class="link" href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> test_data, void (test_funcgconstpointer) ());#define <a class="link" href="glib-Testing.html#g-test-add">g_test_add</a> (testpath, Fixture, tdata, fsetup, ftest, fteardown)void <a class="link" href="glib-Testing.html#g-test-message">g_test_message</a> (const char *format, ...);void <a class="link" href="glib-Testing.html#g-test-bug-base">g_test_bug_base</a> (const char *uri_pattern);void <a class="link" href="glib-Testing.html#g-test-bug">g_test_bug</a> (const char *bug_uri_snippet);void <a class="link" href="glib-Testing.html#g-test-timer-start">g_test_timer_start</a> (void);double <a class="link" href="glib-Testing.html#g-test-timer-elapsed">g_test_timer_elapsed</a> (void);double <a class="link" href="glib-Testing.html#g-test-timer-last">g_test_timer_last</a> (void);void <a class="link" href="glib-Testing.html#g-test-queue-free">g_test_queue_free</a> (<a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> gfree_pointer);void <a class="link" href="glib-Testing.html#g-test-queue-destroy">g_test_queue_destroy</a> (<a class="link" href="glib-Datasets.html#GDestroyNotify">GDestroyNotify</a> destroy_func, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> destroy_data);#define <a class="link" href="glib-Testing.html#g-test-queue-unref">g_test_queue_unref</a> (gobject)enum <a class="link" href="glib-Testing.html#GTestTrapFlags">GTestTrapFlags</a>;<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="glib-Testing.html#g-test-trap-fork">g_test_trap_fork</a> (<a class="link" href="glib-Basic-Types.html#guint64">guint64</a> usec_timeout, <a class="link" href="glib-Testing.html#GTestTrapFlags">GTestTrapFlags</a> test_trap_flags);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="glib-Testing.html#g-test-trap-has-passed">g_test_trap_has_passed</a> (void);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="glib-Testing.html#g-test-trap-reached-timeout">g_test_trap_reached_timeout</a> (void);#define <a class="link" href="glib-Testing.html#g-test-trap-assert-passed">g_test_trap_assert_passed</a> ()#define <a class="link" href="glib-Testing.html#g-test-trap-assert-failed">g_test_trap_assert_failed</a> ()#define <a class="link" href="glib-Testing.html#g-test-trap-assert-stdout">g_test_trap_assert_stdout</a> (soutpattern)#define <a class="link" href="glib-Testing.html#g-test-trap-assert-stdout-unmatched">g_test_trap_assert_stdout_unmatched</a> (soutpattern)#define <a class="link" href="glib-Testing.html#g-test-trap-assert-stderr">g_test_trap_assert_stderr</a> (serrpattern)#define <a class="link" href="glib-Testing.html#g-test-trap-assert-stderr-unmatched">g_test_trap_assert_stderr_unmatched</a> (serrpattern)#define <a class="link" href="glib-Testing.html#g-test-rand-bit">g_test_rand_bit</a> ()<a class="link" href="glib-Basic-Types.html#gint32">gint32</a> <a class="link" href="glib-Testing.html#g-test-rand-int">g_test_rand_int</a> (void);<a class="link" href="glib-Basic-Types.html#gint32">gint32</a> <a class="link" href="glib-Testing.html#g-test-rand-int-range">g_test_rand_int_range</a> (<a class="link" href="glib-Basic-Types.html#gint32">gint32</a> begin, <a class="link" href="glib-Basic-Types.html#gint32">gint32</a> end);double <a class="link" href="glib-Testing.html#g-test-rand-double">g_test_rand_double</a> (void);double <a class="link" href="glib-Testing.html#g-test-rand-double-range">g_test_rand_double_range</a> (double range_start, double range_end);#define <a class="link" href="glib-Testing.html#g-assert">g_assert</a> (expr)#define <a class="link" href="glib-Testing.html#g-assert-not-reached">g_assert_not_reached</a> ()#define <a class="link" href="glib-Testing.html#g-assert-cmpstr">g_assert_cmpstr</a> (s1, cmp, s2)#define <a class="link" href="glib-Testing.html#g-assert-cmpint">g_assert_cmpint</a> (n1, cmp, n2)#define <a class="link" href="glib-Testing.html#g-assert-cmpuint">g_assert_cmpuint</a> (n1, cmp, n2)#define <a class="link" href="glib-Testing.html#g-assert-cmphex">g_assert_cmphex</a> (n1, cmp, n2)#define <a class="link" href="glib-Testing.html#g-assert-cmpfloat">g_assert_cmpfloat</a> (n1,cmp,n2)int <a class="link" href="glib-Testing.html#g-strcmp0">g_strcmp0</a> (const char *str1, const char *str2);</pre></div><div class="refsect1" lang="en"><a name="id3217436"></a><h2>Description</h2><p></p></div><div class="refsect1" lang="en"><a name="id3217451"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id3217461"></a><h3><a name="GTestCase"></a>GTestCase</h3><a class="indexterm" name="id3217473"></a><pre class="programlisting">typedef struct GTestCase GTestCase;</pre><p></p></div><hr><div class="refsect2" lang="en"><a name="id3217488"></a><h3><a name="GTestSuite"></a>GTestSuite</h3><a class="indexterm" name="id3217501"></a><pre class="programlisting">typedef struct GTestSuite GTestSuite;</pre><p></p></div><hr><div class="refsect2" lang="en"><a name="id3217516"></a><h3><a name="g-test-minimized-result"></a>g_test_minimized_result ()</h3><a class="indexterm" name="id3217532"></a><pre class="programlisting">void g_test_minimized_result (double minimized_quantity, const char *format, ...);</pre><p>Report the result of a performance or measurement test.The test should generally strive to minimize the reportedquantities (smaller values are better than larger ones),this and <em class="parameter"><code>minimized_quantity</code></em> can determine sortingorder for test result reports.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>minimized_quantity</code></em> :</span></p></td><td> the reported value</td></tr><tr><td><p><span class="term"><em class="parameter"><code>format</code></em> :</span></p></td><td> the format string of the report message</td></tr><tr><td><p><span class="term"><em class="parameter"><code>...</code></em> :</span></p></td><td> arguments to pass to the <code class="function">printf()</code> function</td></tr></tbody></table></div><p class="since">Since 2.16</p></div><hr><div class="refsect2" lang="en"><a name="id3217647"></a><h3><a name="g-test-maximized-result"></a>g_test_maximized_result ()</h3><a class="indexterm" name="id3217662"></a><pre class="programlisting">void g_test_maximized_result (double maximized_quantity, const char *format, ...);</pre><p>Report the result of a performance or measurement test.The test should generally strive to maximize the reportedquantities (larger values are better than smaller ones),this and <em class="parameter"><code>maximized_quantity</code></em> can determine sortingorder for test result reports.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>maximized_quantity</code></em> :</span></p></td><td> the reported value</td></tr><tr><td><p><span class="term"><em class="parameter"><code>format</code></em> :</span></p></td><td> the format string of the report message</td></tr><tr><td><p><span class="term"><em class="parameter"><code>...</code></em> :</span></p></td><td> arguments to pass to the <code class="function">printf()</code> function</td></tr></tbody></table></div><p class="since">Since 2.16</p></div><hr><div class="refsect2" lang="en"><a name="id3217777"></a><h3><a name="g-test-init"></a>g_test_init ()</h3><a class="indexterm" name="id3217792"></a><pre class="programlisting">void g_test_init (int *argc, char ***argv, ...);</pre><p>Initialize the GLib testing framework, e.g. by seeding thetest random number generator, the name for <a class="link" href="glib-Miscellaneous-Utility-Functions.html#g-get-prgname"><code class="function">g_get_prgname()</code></a>and parsing test related command line args.So far, the following arguments are understood:</p><div class="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|thorough|quick} execute tests according to these test modes: perf - performance tests, may take long and report results. slow - slow and thorough tests, may take quite long and maximize coverage. thorough - currently an alias for "slow". 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.</div><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>argc</code></em> :</span></p></td><td> Address of the <em class="parameter"><code>argc</code></em> parameter of the <code class="function">main()</code> function. Changed if any arguments were handled.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>argv</code></em> :</span></p></td><td> Address of the <em class="parameter"><code>argv</code></em> parameter of <code class="function">main()</code>. Any parameters understood by <a class="link" href="glib-Testing.html#g-test-init"><code class="function">g_test_init()</code></a> stripped before return.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>...</code></em> :</span></p></td><td> Reserved for future extension. Currently, you must pass <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.</td></tr></tbody></table></div><p class="since">Since 2.16</p></div><hr><div class="refsect2" lang="en"><a name="id3217971"></a><h3><a name="g-test-quick"></a>g_test_quick()</h3><a class="indexterm" name="id3217984"></a><pre class="programlisting">#define g_test_quick()</pre><p></p></div><hr><div class="refsect2" lang="en"><a name="id3218000"></a><h3><a name="g-test-slow"></a>g_test_slow()</h3><a class="indexterm" name="id3218012"></a><pre class="programlisting">#define g_test_slow()</pre><p></p></div><hr><div class="refsect2" lang="en"><a name="id3218027"></a><h3><a name="g-test-thorough"></a>g_test_thorough()</h3><a class="indexterm" name="id3218039"></a><pre class="programlisting">#define g_test_thorough()</pre><p></p></div><hr><div class="refsect2" lang="en"><a name="id3218055"></a><h3><a name="g-test-perf"></a>g_test_perf()</h3><a class="indexterm" name="id3218067"></a><pre class="programlisting">#define g_test_perf()</pre><p></p></div><hr>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -