Files
ViewDesignEngine/tests/plugin/test_plugin_ecosystem.cpp

103 lines
3.9 KiB
C++

// P4-53:真实 PluginManager 加载全部官方插件(生态覆盖矩阵 e2e)。
// 覆盖:VDE 官方提供的 8 个 PluginKind;GCS/CAE 求解器由外部工程提供(ABI 保留)。
// id/capability 无重复、manifest ABI ≤ host、全部插件 query/init/load 正常、
// stats/loaded 正确、reload 成功。
#include <gtest/gtest.h>
#include <algorithm>
#include <set>
#include <string>
#include <vector>
#include "vde/plugin/geometry_host_services.h"
#include "vde/plugin/plugin_manager.h"
#include "vde/plugin/vde_plugin_api.h"
#ifndef VDE_PLUGIN_OFFICIAL_DIR
#define VDE_PLUGIN_OFFICIAL_DIR ""
#endif
namespace {
using vde::plugin::PluginKind;
using vde::plugin::PluginManager;
class EcosystemFixture : public ::testing::Test {
protected:
void SetUp() override {
host_ = vde::plugin::make_geometry_host_services();
PluginManager& manager = PluginManager::instance();
manager.clear();
manager.set_host_services(host_);
manager.clear_search_paths();
ASSERT_TRUE(VDE_PLUGIN_OFFICIAL_DIR[0] != '\0') << "VDE_PLUGIN_OFFICIAL_DIR not set";
manager.add_search_path(VDE_PLUGIN_OFFICIAL_DIR);
std::string error;
manager.scan_search_paths(&error);
}
void TearDown() override {
PluginManager::instance().clear();
vde::plugin::release_geometry_host_services(&host_);
}
VdePluginHost host_{};
};
TEST_F(EcosystemFixture, LoadsAllOfficialPluginsAndCoversOfficialKinds) {
PluginManager& manager = PluginManager::instance();
const std::vector<vde::plugin::PluginManifest> manifests = manager.plugins();
ASSERT_FALSE(manifests.empty()) << "no official plugins discovered";
std::set<int> kinds;
std::set<std::string> ids;
std::size_t loaded_count = 0;
for (const auto& manifest : manifests) {
EXPECT_TRUE(ids.insert(manifest.id).second) << "duplicate id: " << manifest.id;
EXPECT_EQ(manifest.abi_major, VDE_PLUGIN_ABI_MAJOR) << manifest.id;
EXPECT_LE(manifest.abi_minor, VDE_PLUGIN_ABI_MINOR) << manifest.id;
kinds.insert(static_cast<int>(manifest.kind));
std::string error;
EXPECT_TRUE(manager.load(manifest.id, &error))
<< manifest.id << ": " << error;
if (!manager.is_loaded(manifest.id)) continue;
++loaded_count;
const auto stats = manager.plugin_stats(manifest.id);
ASSERT_TRUE(stats.has_value()) << manifest.id;
EXPECT_TRUE(stats->loaded) << manifest.id;
EXPECT_GE(stats->load_count, 1u) << manifest.id;
EXPECT_EQ(stats->kind, vde::plugin::plugin_kind_name(manifest.kind)) << manifest.id;
}
EXPECT_EQ(kinds.size(), 8u)
<< "expected 8 VDE-provided PluginKind values in official ecosystem "
"(gcs_solver/CAE solver are provided by external projects)";
EXPECT_EQ(loaded_count, manifests.size());
EXPECT_TRUE(manager.capabilities().conflicts().empty());
EXPECT_EQ(manager.plugin_stats().size(), manifests.size());
}
TEST_F(EcosystemFixture, ReloadOfficialPluginUpdatesStats) {
PluginManager& manager = PluginManager::instance();
const std::vector<vde::plugin::PluginManifest> manifests = manager.plugins();
ASSERT_FALSE(manifests.empty());
std::string target;
for (const auto& manifest : manifests) {
if (manifest.kind == PluginKind::Format) {
target = manifest.id;
break;
}
}
if (target.empty()) target = manifests.front().id;
std::string error;
ASSERT_TRUE(manager.load(target, &error)) << error;
const auto before = manager.plugin_stats(target);
ASSERT_TRUE(before.has_value());
ASSERT_TRUE(manager.reload(target, &error)) << error;
const auto after = manager.plugin_stats(target);
ASSERT_TRUE(after.has_value());
EXPECT_TRUE(after->loaded);
EXPECT_GE(after->reload_count, 1u);
EXPECT_GT(after->load_count, before->load_count);
EXPECT_GE(after->last_load_ms, 0.0);
}
} // namespace