1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Test module's entry point</title> 5<link rel="stylesheet" href="../../boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../index.html" title="Boost.Test"> 8<link rel="up" href="../adv_scenarios.html" title="Advanced Usage Scenarios"> 9<link rel="prev" href="build_utf.html" title="Building the Unit Test Framework"> 10<link rel="next" href="test_module_init_overview.html" title="Test module's initialization"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="build_utf.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../adv_scenarios.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="test_module_init_overview.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h3 class="title"> 27<a name="boost_test.adv_scenarios.entry_point_overview"></a><a class="link" href="entry_point_overview.html" title="Test module's entry point">Test module's 28 entry point</a> 29</h3></div></div></div> 30<p> 31 Typically, every C++ program contains exactly one definition of function 32 <code class="computeroutput"><span class="identifier">main</span></code>: the program's <span class="emphasis"><em>entry 33 point</em></span>. When using the <span class="emphasis"><em>Unit Test Framework</em></span> 34 you do not have to define one. Function <code class="computeroutput"><span class="identifier">main</span></code> 35 will be generated for you by the framework. The only thing you are required 36 to do in case your program consists of more than one translation unit (<code class="computeroutput"><span class="identifier">cpp</span></code> file) is to indicate to the framework 37 in which of the files it is supposed to generate function <code class="computeroutput"><span class="identifier">main</span></code>. 38 You do it by defining macro <a class="link" href="../utf_reference/link_references/link_boost_test_module_macro.html" title="BOOST_TEST_MODULE"><code class="computeroutput"><span class="identifier">BOOST_TEST_MODULE</span></code></a> before the inclusion 39 of any of the framework files. The value of this macro is used as a name 40 of the <a class="link" href="../section_glossary.html#ref_test_module">test module</a> as well as the 41 <a class="link" href="../tests_organization/test_tree/master_test_suite.html" title="Master test suite">master 42 test suite</a>. 43 </p> 44<p> 45 The reason for defining function <code class="computeroutput"><span class="identifier">main</span></code> 46 for you is twofold: 47 </p> 48<div class="orderedlist"><ol class="orderedlist" type="1"> 49<li class="listitem"> 50 This allows the <span class="emphasis"><em>Unit Test Framework</em></span> to perform some 51 custom <a class="link" href="test_module_init_overview.html" title="Test module's initialization"><span class="emphasis"><em>test 52 module initialization</em></span></a>. 53 </li> 54<li class="listitem"> 55 This prevents you defining <code class="computeroutput"><span class="identifier">main</span></code>, 56 and accidentally forgetting to run all the test (in which case running 57 the program would incorrectly indicate a clean run). 58 </li> 59</ol></div> 60<p> 61 By default, the test module's entry point is defined with signature: 62 </p> 63<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">argc</span><span class="special">,</span> <span class="keyword">char</span><span class="special">*</span> <span class="identifier">argv</span><span class="special">[]);</span> 64</pre> 65<p> 66 It calls <a class="link" href="test_module_init_overview.html" title="Test module's initialization"><span class="emphasis"><em>test 67 module initialization</em></span></a> function, then calls the <a class="link" href="test_module_runner_overview.html" title="Test module runner"><span class="emphasis"><em>test 68 module runner</em></span></a> and forwards its return value to environment. 69 </p> 70<p> 71 The default entry point is sufficient in most of the cases. Occasionally, 72 a need may arise to declare an entry point with a different name or signature. 73 For overriding the definition of the default test module's entry point: 74 </p> 75<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 76<li class="listitem"> 77 <a class="link" href="single_header_customizations/entry_point.html" title="Customizing the module's entry point">see 78 here</a>, for header-only usage variant, 79 </li> 80<li class="listitem"> 81 <a class="link" href="static_lib_customizations/entry_point.html" title="Customizing the module's entry point">see 82 here</a>, for static library usage variant, 83 </li> 84<li class="listitem"> 85 <a class="link" href="shared_lib_customizations/entry_point.html" title="Customizing the module's entry point">see 86 here</a>, for shared library usage variant. 87 </li> 88</ul></div> 89</div> 90<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 91<td align="left"></td> 92<td align="right"><div class="copyright-footer">Copyright © 2001-2020 Boost.Test contributors<p> 93 Distributed under the Boost Software License, Version 1.0. (See accompanying 94 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 95 </p> 96</div></td> 97</tr></table> 98<hr> 99<div class="spirit-nav"> 100<a accesskey="p" href="build_utf.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../adv_scenarios.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="test_module_init_overview.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 101</div> 102</body> 103</html> 104