|
11 | 11 |
|
12 | 12 | namespace { |
13 | 13 |
|
| 14 | + // Returns the bundle name of a plugin library, which excludes the debug postfix of MSVC that |
| 15 | + // BundlePluginFactory appends. |
| 16 | + std::string bundleName(const std::filesystem::path &library) { |
| 17 | + auto name = library.stem().string(); |
| 18 | +#if defined(_MSC_VER) && defined(_DEBUG) |
| 19 | + name.pop_back(); |
| 20 | +#endif |
| 21 | + return name; |
| 22 | + } |
| 23 | + |
14 | 24 | class RuntimePlugin : public stdc::plugin::Plugin {}; |
15 | 25 |
|
16 | 26 | class DefaultPluginFactoryProbe : public stdc::plugin::PluginFactory { |
@@ -100,13 +110,19 @@ namespace { |
100 | 110 | } |
101 | 111 |
|
102 | 112 | std::filesystem::path addBundle() const { |
| 113 | + const auto source = std::filesystem::path(TEST_PLUGINLOADER_PLUGIN_PATH); |
| 114 | + return addBundle(source.filename()); |
| 115 | + } |
| 116 | + |
| 117 | + // Adds a bundle whose library is the test plugin copied to fileName. |
| 118 | + std::filesystem::path addBundle(const std::filesystem::path &fileName) const { |
103 | 119 | const auto source = std::filesystem::path(TEST_PLUGINLOADER_PLUGIN_PATH); |
104 | 120 | const auto bundle = _path / "bundle"; |
105 | 121 | std::filesystem::create_directory(bundle); |
106 | | - std::filesystem::copy_file(source, bundle / source.filename()); |
| 122 | + std::filesystem::copy_file(source, bundle / fileName); |
107 | 123 |
|
108 | 124 | std::ofstream metadata(bundle / "plugin.json"); |
109 | | - metadata << R"({"name":")" << source.stem().string() << R"(","answer":42})"; |
| 125 | + metadata << R"({"name":")" << bundleName(source) << R"(","answer":42})"; |
110 | 126 | return bundle; |
111 | 127 | } |
112 | 128 |
|
@@ -284,6 +300,45 @@ BOOST_AUTO_TEST_CASE(test_bundle_scan_and_resolve) { |
284 | 300 | BOOST_CHECK_EQUAL(plugins.front()->metadata()["answer"].toInt(), 42); |
285 | 301 | } |
286 | 302 |
|
| 303 | +#ifdef _MSC_VER |
| 304 | +BOOST_AUTO_TEST_CASE(test_bundle_debug_postfix) { |
| 305 | + const auto source = std::filesystem::path(TEST_PLUGINLOADER_PLUGIN_PATH); |
| 306 | + const auto name = bundleName(source); |
| 307 | + const auto extension = source.extension().string(); |
| 308 | + |
| 309 | +# ifdef _DEBUG |
| 310 | + // The name alone resolves if the library has no postfix. |
| 311 | + { |
| 312 | + TemporaryPluginDirectory directory; |
| 313 | + directory.addBundle(name + extension); |
| 314 | + |
| 315 | + stdc::plugin::BundlePluginFactory factory; |
| 316 | + factory.addPluginPath("org.stdcorelib.LoaderTest", directory.path()); |
| 317 | + BOOST_CHECK_EQUAL(factory.plugins("org.stdcorelib.LoaderTest").size(), 1u); |
| 318 | + } |
| 319 | + |
| 320 | + // The postfix precedes the name alone, which is a library without plugin metadata here. |
| 321 | + { |
| 322 | + TemporaryPluginDirectory directory; |
| 323 | + const auto bundle = directory.addBundle(name + "d" + extension); |
| 324 | + std::filesystem::copy_file(TEST_PLUGINLOADER_LIBRARY_PATH, bundle / (name + extension)); |
| 325 | + |
| 326 | + stdc::plugin::BundlePluginFactory factory; |
| 327 | + factory.addPluginPath("org.stdcorelib.LoaderTest", directory.path()); |
| 328 | + BOOST_CHECK_EQUAL(factory.plugins("org.stdcorelib.LoaderTest").size(), 1u); |
| 329 | + } |
| 330 | +# else |
| 331 | + // A release build does not resolve a debug library. |
| 332 | + TemporaryPluginDirectory directory; |
| 333 | + directory.addBundle(name + "d" + extension); |
| 334 | + |
| 335 | + stdc::plugin::BundlePluginFactory factory; |
| 336 | + factory.addPluginPath("org.stdcorelib.LoaderTest", directory.path()); |
| 337 | + BOOST_CHECK(factory.plugins("org.stdcorelib.LoaderTest").empty()); |
| 338 | +# endif |
| 339 | +} |
| 340 | +#endif |
| 341 | + |
287 | 342 | BOOST_AUTO_TEST_CASE(test_ignores_runtime_plugin_without_iid) { |
288 | 343 | RuntimePlugin plugin; |
289 | 344 | stdc::plugin::PluginFactory factory; |
|
0 commit comments