shared_lib_customizations.qbk 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. [/
  2. / Copyright (c) 2003 Boost.Test contributors
  3. /
  4. / Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. /]
  7. [section:shared_lib_customizations Shared-library variant customizations]
  8. [caution Macro __BOOST_TEST_DYN_LINK__ (which instructs the compiler/linker to dynamically link against a shared
  9. library variant) may be implicitly defined when macro `BOOST_ALL_DYN_LINK` is defined.]
  10. [caution In order to be able to run a test built with the dynamic variant, the operating system should be able
  11. to find the dynamic library of the __UTF__. This means, for example on Linux and MacOSX respectively, setting the environment
  12. variable `LD_LIBRARY_PATH` or `DYLD_LIBRARY_PATH` properly prior to the execution of the test module.]
  13. [section:entry_point Customizing the module's entry point]
  14. In this variant, in one of the source files, you now have to define your custom entry point, and invoke the default
  15. [link boost_test.adv_scenarios.test_module_runner_overview test runner] `unit_test_main` manually with the default
  16. [link boost_test.adv_scenarios.test_module_init_overview initialization function] `init_unit_test` as argument.
  17. You need to define __BOOST_TEST_NO_MAIN__ (its value is irrelevant) in the main file:
  18. [table
  19. [[In *exactly one* file][In all other files]]
  20. [[```#define BOOST_TEST_MODULE test module name
  21. #define BOOST_TEST_DYN_LINK
  22. #define BOOST_TEST_NO_MAIN
  23. #include <boost/test/unit_test.hpp>
  24. // entry point:
  25. int main(int argc, char* argv[], char* envp[])
  26. {
  27. return boost::unit_test::unit_test_main( &init_unit_test, argc, argv );
  28. }
  29. ```]
  30. [```#define BOOST_TEST_DYN_LINK
  31. #include <boost/test/unit_test.hpp>
  32. //
  33. // test cases
  34. //
  35. //
  36. // test cases
  37. //
  38. ```]]
  39. ]
  40. [endsect] [/section:entry_point]
  41. [section:init_func Customizing the module's initialization function]
  42. In the shared-library variant, it is impossible to customize the initialization function without
  43. [link boost_test.adv_scenarios.shared_lib_customizations.entry_point customizing the entry point]. We have
  44. to customize both. In one of the source files, you now have to define your custom entry point and
  45. [link boost_test.adv_scenarios.test_module_init_overview initialization function] `init_unit_test`; next invoke
  46. the default [link boost_test.adv_scenarios.test_module_runner_overview test runner] `unit_test_main` manually
  47. with `init_unit_test` as argument. You ['do not] define __BOOST_TEST_MODULE__ in the main file:
  48. [table
  49. [[In *exactly one* file][In all other files]]
  50. [[```#define BOOST_TEST_DYN_LINK
  51. #include <boost/test/unit_test.hpp>
  52. // initialization function:
  53. bool init_unit_test()
  54. {
  55. return true;
  56. }
  57. // entry point:
  58. int main(int argc, char* argv[])
  59. {
  60. return boost::unit_test::unit_test_main( &init_unit_test, argc, argv );
  61. }
  62. ```]
  63. [```#define BOOST_TEST_DYN_LINK
  64. #include <boost/test/unit_test.hpp>
  65. //
  66. // test cases
  67. //
  68. //
  69. // test cases
  70. //
  71. //
  72. // test cases
  73. //
  74. ```]]
  75. ]
  76. For reporting errors that may occur during the initialization,
  77. * either you return `false` (valid only for the new API only, see __BOOST_TEST_ALTERNATIVE_INIT_API__)
  78. * or you raise an exception such as `std::runtime_error` or [classref boost::unit_test::framework::setup_error]
  79. An error reported in this function aborts the execution of the test module.
  80. [endsect] [/section:init_func]
  81. [endsect] [/section:shared_lib_customizations]