2020using namespace boost ::openmethod;
2121namespace mp11 = boost::mp11;
2222
23- constexpr auto n_policies = mp11::mp_size<default_registry::policy_list>::value;
24-
2523using policy_ids_fn = const void **();
2624using method_fn = const void *();
2725
@@ -59,21 +57,47 @@ bool same_ids(const void** ids1, const void** ids2) {
5957
6058BOOST_AUTO_TEST_CASE (test_shared_state) {
6159 namespace dll = boost::dll;
62- auto lib_dir = dll::program_location ().parent_path ();
60+ namespace fs = boost::filesystem;
61+ namespace ut = boost::unit_test;
62+
63+ // b2 passes input-files as extra argv in alphabetical-path order (not
64+ // necessarily the order listed in the Jamfile). CMake puts all outputs in
65+ // one directory, found via program_location(), with no extra argv.
66+ auto & mts = ut::framework::master_test_suite ();
67+ fs::path method_path, overrider_path;
68+ dll::load_mode::type load_flags;
69+
70+ // Search argv for paths containing the library names (b2 mode).
71+ for (int i = 1 ; i < mts.argc ; ++i) {
72+ std::string arg = mts.argv [i];
73+ if (arg.find (" dl_test_method" ) != std::string::npos) {
74+ method_path = arg;
75+ } else if (arg.find (" dl_test_overrider" ) != std::string::npos) {
76+ overrider_path = arg;
77+ }
78+ }
79+
80+ if (!method_path.empty ()) {
81+ // b2 mode: full versioned paths passed as argv (e.g. libfoo.so.1.91.0)
82+ load_flags = dll::load_mode::default_mode;
83+ } else {
84+ // CMake mode: libraries are alongside the executable, use decorations
85+ auto lib_dir = dll::program_location ().parent_path ();
86+ method_path = lib_dir / " boost_openmethod-dl_test_method" ;
87+ overrider_path = lib_dir / " boost_openmethod-dl_test_overrider" ;
88+ load_flags = dll::load_mode::append_decorations;
89+ }
6390
6491 // Load all three shared libraries via Boost.DLL.
6592 // Use rtld_global for registry and method so their symbols (fn, policy
6693 // statics) are visible globally and win over any locally-instantiated
6794 // copies when the overrider library is subsequently loaded.
68- dll::shared_library method_lib (
69- lib_dir / " boost_openmethod-dl_test_method" ,
70- dll::load_mode::append_decorations);
71- auto & method_get_ids = method_lib.get_alias <policy_ids_fn>(" get_ids" );
95+ dll::shared_library method_lib (method_path, load_flags);
96+ auto & method_get_ids = method_lib.get_alias <policy_ids_fn>(" method_get_ids" );
7297 auto & method_speak =
73- method_lib.get_alias <const char *(virtual_ptr<Animal>)>(" call_speak " );
98+ method_lib.get_alias <const char *(virtual_ptr<Animal>)>(" method_call_speak " );
7499 auto & method_make_dog =
75- method_lib.get_alias <unique_virtual_ptr<Animal>()>(" make_dog" );
76- auto & method_get_fn = method_lib.get_alias <method_fn>(" get_fn" );
100+ method_lib.get_alias <unique_virtual_ptr<Animal>()>(" method_make_dog" );
77101
78102 BOOST_TEST (same_ids (get_ids (), method_get_ids ()));
79103
@@ -88,15 +112,12 @@ BOOST_AUTO_TEST_CASE(test_shared_state) {
88112 BOOST_TEST (method_speak (main_dog) == " ?" );
89113 BOOST_TEST (method_speak (method_dog) == " ?" );
90114
91- dll::shared_library overrider_lib (
92- lib_dir / " boost_openmethod-dl_test_overrider" ,
93- dll::load_mode::append_decorations);
94- auto & overrider_get_ids = overrider_lib.get_alias <policy_ids_fn>(" get_ids" );
115+ dll::shared_library overrider_lib (overrider_path, load_flags);
116+ auto & overrider_get_ids = overrider_lib.get_alias <policy_ids_fn>(" overrider_get_ids" );
95117 auto & overrider_speak =
96- overrider_lib.get_alias <const char *(virtual_ptr<Animal>)>(" call_speak " );
118+ overrider_lib.get_alias <const char *(virtual_ptr<Animal>)>(" overrider_call_speak " );
97119 auto & overrider_make_dog =
98- overrider_lib.get_alias <unique_virtual_ptr<Animal>()>(" make_dog" );
99- auto & overrider_get_fn = overrider_lib.get_alias <method_fn>(" get_fn" );
120+ overrider_lib.get_alias <unique_virtual_ptr<Animal>()>(" overrider_make_dog" );
100121
101122 BOOST_TEST (same_ids (get_ids (), overrider_get_ids ()));
102123
0 commit comments