9 #ifndef BOOST_TEST_DYN_LINK
10 #define BOOST_TEST_DYN_LINK
14 #pragma warning ( disable: 6031 )
15 #pragma warning ( disable: 6011 )
16 #pragma warning ( disable: 6001 )
18 #include <boost/test/unit_test.hpp>
21 #include <boost/test/utils/runtime/cla/named_parameter.hpp>
22 #include <boost/test/utils/runtime/cla/parser.hpp>
25 #pragma warning ( default: 6031 )
26 #pragma warning ( default: 6011 )
27 #pragma warning ( default: 6001 )
29 namespace rt = boost::runtime;
30 namespace cla = boost::runtime::cla;
35 #include <boost/cstdlib.hpp>
47 #if defined(BOOST_WINDOWS) && !defined(BOOST_DISABLE_WIN32) // WIN32 API
51 typedef HINSTANCE handle;
57 open(std::string
const& file_name)
59 return LoadLibrary(file_name.c_str());
69 template<
typename TargType>
71 locate_symbol(handle h, std::string
const& symbol)
73 return reinterpret_cast<TargType
>(GetProcAddress(h, symbol.c_str()));
97 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
100 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
117 #elif defined(BOOST_HAS_UNISTD_H) // POSIX API
121 #include <sys/types.h>
122 #include <sys/stat.h>
125 typedef void* handle;
131 open(std::string
const& file_name)
133 return dlopen(file_name.c_str(), RTLD_LOCAL | RTLD_LAZY);
140 template<
typename TargType>
142 locate_symbol(handle h, std::string
const& symbol)
144 return reinterpret_cast<TargType
>(dlsym(h, symbol.c_str()));
172 #error "Dynamic library API is unknown"
203 throw std::logic_error(std::string(
"Fail to load test library: ")
204 .append(dyn_lib::error()));
220 return (init_func ==
nullptr) || ((*init_func)());
233 assign_op(listOut, P.get(arg), 0);
235 if (!listOut.empty())
237 return std::unique_ptr<std::ofstream>(
new std::ofstream(listOut, (std::ios_base::out | std::ios_base::trunc)));
240 return std::unique_ptr<std::ofstream>();
257 out = (out ==
nullptr) ? &std::cout : out;
278 std::ostream&
WriteError(std::ostream& out,
const std::string& dll,
const std::string& error = std::string())
280 out <<
"<![CDATA[Error: Could not load " << dll <<
'.';
284 out <<
" Detail: " << error;
301 int res = ::boost::exit_success;
303 std::string arg = (P[
"list"]) ?
"list" :
"list-debug";
308 if (lister !=
nullptr)
310 std::ostream& listing = lister->WriteHeader();
321 ::boost::unit_test::traverse_test_tree(::boost::unit_test::framework::master_test_suite(), *lister);
324 catch (std::exception& ex)
327 res = ::boost::exit_failure;
332 res = ::boost::exit_failure;
335 lister->WriteTrailer();
471 int main(
int argc,
char* argv[])
477 P - cla::ignore_mismatch
478 << cla::named_parameter<rt::cstring>(
"test") - (cla::prefix =
"--")
479 << cla::named_parameter<rt::cstring>(
"list") - (cla::prefix =
"--", cla::optional)
480 << cla::named_parameter<rt::cstring>(
"list-debug") - (cla::prefix =
"--", cla::optional)
481 << cla::named_parameter<rt::cstring>(
"init") - (cla::prefix =
"--", cla::optional);
492 int res = ::boost::exit_success;
496 if (P[
"list"] || P[
"list-debug"])
503 res = ::boost::unit_test::unit_test_main(&
load_test_lib, argc, argv);
506 ::boost::unit_test::framework::clear();
511 catch (rt::logic_error
const& ex)
513 std::cout <<
"Fail to parse command line arguments: " << ex.msg() << std::endl;
std::unique_ptr<::etas::boost::unit_test::CBoostTestTreeLister > TBoostTestTreeListerPtr
static std::string test_lib_name
int main(int argc, char *argv[])
Entry point of the program.
int ListTests(const cla::parser &P)
Method handling the enumeration of the tests.
std::unique_ptr< std::ofstream > GetListOutputStream(const cla::parser &P, const std::string &arg)
Generates an object of type ofstream so as to write to file.
TBoostTestTreeListerPtr GetTestTreeLister(const std::string &arg, const std::string dll, std::ostream *out=nullptr)
std::ostream & WriteError(std::ostream &out, const std::string &dll, const std::string &error=std::string())
Method utilized to format and write any exceptions to the output stream.
dyn_lib::handle test_lib_handle
bool load_test_lib()
Load the Boost UTF dll containing the tests, locate the initialization method (either the default "in...
static std::string init_func_name("init_unit_test")