entry_point.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
  4. <title>Customizing the 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="../static_lib_customizations.html" title="Static-library variant customizations">
  9. <link rel="prev" href="../static_lib_customizations.html" title="Static-library variant customizations">
  10. <link rel="next" href="init_func.html" title="Customizing the module's initialization function">
  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="../static_lib_customizations.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../static_lib_customizations.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="init_func.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
  24. </div>
  25. <div class="section">
  26. <div class="titlepage"><div><div><h4 class="title">
  27. <a name="boost_test.adv_scenarios.static_lib_customizations.entry_point"></a><a class="link" href="entry_point.html" title="Customizing the module's entry point">Customizing
  28. the module's entry point</a>
  29. </h4></div></div></div>
  30. <p>
  31. In the static library variant, customizing the main entry point is quite
  32. troublesome, because the definition of function <code class="computeroutput"><span class="identifier">main</span></code>
  33. is already compiled into the static library. This requires you to rebuild
  34. the <span class="emphasis"><em>Unit Test Framework</em></span> static library with the defined
  35. symbol <a class="link" href="../../utf_reference/link_references/link_boost_test_no_main.html" title="BOOST_TEST_NO_MAIN"><code class="computeroutput"><span class="identifier">BOOST_TEST_NO_MAIN</span></code></a>. In the Boost
  36. root directory you need to invoke command
  37. </p>
  38. <pre class="programlisting"><span class="special">&gt;</span> <span class="identifier">b2</span> <span class="special">--</span><span class="identifier">with</span><span class="special">-</span><span class="identifier">test</span> <span class="identifier">link</span><span class="special">=</span><span class="keyword">static</span> <span class="identifier">define</span><span class="special">=</span><a class="link" href="../../utf_reference/link_references/link_boost_test_no_main.html" title="BOOST_TEST_NO_MAIN"><code class="computeroutput"><span class="identifier">BOOST_TEST_NO_MAIN</span></code></a> <span class="identifier">define</span><span class="special">=</span><a class="link" href="../../utf_reference/link_references/link_boost_test_alternative_init_macro.html" title="BOOST_TEST_ALTERNATIVE_INIT_API"><code class="computeroutput"><span class="identifier">BOOST_TEST_ALTERNATIVE_INIT_API</span></code></a> <span class="identifier">install</span>
  39. </pre>
  40. <div class="warning"><table border="0" summary="Warning">
  41. <tr>
  42. <td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../../doc/src/images/warning.png"></td>
  43. <th align="left">Warning</th>
  44. </tr>
  45. <tr><td align="left" valign="top"><p>
  46. This removal of entry point definition from the static library will affect
  47. everybody else who is linking against the library. It may be less intrusive
  48. to switch to the <a class="link" href="../shared_lib_customizations.html" title="Shared-library variant customizations">shared
  49. library usage variant</a> instead.
  50. </p></td></tr>
  51. </table></div>
  52. <p>
  53. In one of the source files, you now have to define your custom entry point,
  54. and invoke the default <a class="link" href="../test_module_runner_overview.html" title="Test module runner">test
  55. runner</a> <code class="computeroutput"><span class="identifier">unit_test_main</span></code>
  56. manually with the default <a class="link" href="../test_module_init_overview.html" title="Test module's initialization">initialization
  57. function</a> <code class="computeroutput"><span class="identifier">init_unit_test</span></code>
  58. as the first argument. There is no need to define <a class="link" href="../../utf_reference/link_references/link_boost_test_no_main.html" title="BOOST_TEST_NO_MAIN"><code class="computeroutput"><span class="identifier">BOOST_TEST_NO_MAIN</span></code></a> in your source
  59. code, but you need to define <a class="link" href="../../utf_reference/link_references/link_boost_test_alternative_init_macro.html" title="BOOST_TEST_ALTERNATIVE_INIT_API"><code class="computeroutput"><span class="identifier">BOOST_TEST_ALTERNATIVE_INIT_API</span></code></a>
  60. in the main file:
  61. </p>
  62. <div class="informaltable"><table class="table">
  63. <colgroup>
  64. <col>
  65. <col>
  66. </colgroup>
  67. <thead><tr>
  68. <th>
  69. <p>
  70. In <span class="bold"><strong>exactly one</strong></span> file
  71. </p>
  72. </th>
  73. <th>
  74. <p>
  75. In all other files
  76. </p>
  77. </th>
  78. </tr></thead>
  79. <tbody><tr>
  80. <td>
  81. <pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_MODULE</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="identifier">name</span>
  82. <span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_ALTERNATIVE_INIT_API</span>
  83. <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
  84. <span class="comment">// entry point:</span>
  85. <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> <span class="keyword">char</span><span class="special">*</span> <span class="identifier">envp</span><span class="special">[])</span>
  86. <span class="special">{</span>
  87. <span class="keyword">return</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">unit_test_main</span><span class="special">(</span><span class="identifier">init_unit_test</span><span class="special">,</span> <span class="identifier">argc</span><span class="special">,</span> <span class="identifier">argv</span><span class="special">);</span>
  88. <span class="special">}</span>
  89. </pre>
  90. </td>
  91. <td>
  92. <pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
  93. <span class="comment">//</span>
  94. <span class="comment">// test cases</span>
  95. <span class="comment">//</span>
  96. <span class="comment">//</span>
  97. <span class="comment">// test cases</span>
  98. <span class="comment">//</span>
  99. </pre>
  100. </td>
  101. </tr></tbody>
  102. </table></div>
  103. <div class="note"><table border="0" summary="Note">
  104. <tr>
  105. <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
  106. <th align="left">Note</th>
  107. </tr>
  108. <tr><td align="left" valign="top"><p>
  109. The reason for defining <a class="link" href="../../utf_reference/link_references/link_boost_test_alternative_init_macro.html" title="BOOST_TEST_ALTERNATIVE_INIT_API"><code class="computeroutput"><span class="identifier">BOOST_TEST_ALTERNATIVE_INIT_API</span></code></a>
  110. is described <a class="link" href="../obsolete_init_func.html" title="The obsolete initialization function">here</a>.
  111. </p></td></tr>
  112. </table></div>
  113. </div>
  114. <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
  115. <td align="left"></td>
  116. <td align="right"><div class="copyright-footer">Copyright &#169; 2001-2019 Boost.Test
  117. contributors<p>
  118. Distributed under the Boost Software License, Version 1.0. (See accompanying
  119. 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>)
  120. </p>
  121. </div></td>
  122. </tr></table>
  123. <hr>
  124. <div class="spirit-nav">
  125. <a accesskey="p" href="../static_lib_customizations.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../static_lib_customizations.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="init_func.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
  126. </div>
  127. </body>
  128. </html>