Files
ViewDesignEngine/tests/plugin/test_plugin_abi17.cpp
T

135 lines
5.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// P4-40 / ABI 1.7:GEOM_OP 几何算子扩展点测试。
// 覆盖:ABI 1.7 布局/registration 80B、官方 geom_analyze 加载与调用、
// 旧 1.6 插件(ABI matrix abi1_6)兼容、错误/空模型处理。
#include <gtest/gtest.h>
#include <cstddef>
#include <cstring>
#include <string>
#include "vde/plugin/geometry_host_services.h"
#include "vde/plugin/plugin_manager.h"
#include "vde/plugin/vde_plugin_api.h"
#ifndef VDE_PLUGIN_DIRS
#define VDE_PLUGIN_DIRS ""
#endif
#ifndef VDE_ABI_MATRIX_DIR
#define VDE_ABI_MATRIX_DIR ""
#endif
namespace {
using vde::plugin::GeomOpInfo;
using vde::plugin::PluginManager;
constexpr const char* kPluginId = "com.vde.official.geom_analyze";
constexpr const char* kOpId = "geom_op.analyze";
bool contains(const std::string& text, const std::string& needle) {
return text.find(needle) != std::string::npos;
}
class Abi17Fixture : 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();
if (VDE_PLUGIN_DIRS[0] != '\0') manager.add_search_path(VDE_PLUGIN_DIRS);
manager.scan_search_paths();
body_ = host_.body_create_box(2.0, 3.0, 4.0);
ASSERT_NE(body_, nullptr);
ASSERT_EQ(host_.body_serialize(body_, &model_), VDE_PLUGIN_OK);
}
void TearDown() override {
if (model_.data) host_.free_buffer(model_.data);
if (body_) host_.body_destroy(body_);
PluginManager::instance().clear();
vde::plugin::release_geometry_host_services(&host_);
}
VdePluginHost host_{};
VdeBody body_ = nullptr;
VdeBuffer model_{};
};
TEST(Abi17LayoutTest, RegistrationAndStructSizes) {
static_assert(VDE_PLUGIN_ABI_MAJOR == 1, "ABI major must stay 1");
EXPECT_EQ(VDE_PLUGIN_ABI_MINOR, 9);
EXPECT_EQ(offsetof(VdeGeomOpPlugin, struct_size), 0u);
EXPECT_EQ(offsetof(VdeGeomOpPlugin, apply), 24u);
EXPECT_EQ(offsetof(VdeGeomOpPlugin, describe), 32u);
if (sizeof(void*) == 8) {
EXPECT_EQ(sizeof(VdeGeomOpPlugin), 40u);
EXPECT_EQ(sizeof(VdePluginRegistration), 96u);
EXPECT_EQ(offsetof(VdePluginRegistration, geom_op), 72u);
}
}
TEST_F(Abi17Fixture, LoadsGeomOpAndInvokesVolume) {
PluginManager& manager = PluginManager::instance();
std::string error;
ASSERT_TRUE(manager.load(kPluginId, &error)) << error;
const auto manifest = manager.manifest(kPluginId);
ASSERT_TRUE(manifest.has_value());
EXPECT_EQ(manifest->kind, vde::plugin::PluginKind::GeomOp);
EXPECT_EQ(manifest->abi_minor, 7);
const std::vector<GeomOpInfo> ops = manager.geom_ops();
ASSERT_EQ(ops.size(), 1u);
EXPECT_EQ(ops[0].op_id, kOpId);
EXPECT_TRUE(contains(ops[0].capabilities_json, "bbox"));
std::string result;
ASSERT_TRUE(manager.invoke_geometry_op(kOpId, model_.data, model_.size,
"{\"op\":\"volume\"}", &result, &error))
<< error;
EXPECT_TRUE(contains(result, "\"op\":\"volume\"")) << result;
EXPECT_TRUE(contains(result, "\"volume\":24")) << result;
EXPECT_TRUE(contains(result, "\"num_faces\":6")) << result;
}
TEST_F(Abi17Fixture, AnalyzeBboxAreaCentroidAndErrors) {
PluginManager& manager = PluginManager::instance();
std::string error;
ASSERT_TRUE(manager.load(kPluginId, &error)) << error;
for (const char* op : {"bbox", "area", "centroid"}) {
std::string params = std::string("{\"op\":\"") + op + "\"}";
std::string result;
ASSERT_TRUE(manager.invoke_geometry_op(kOpId, model_.data, model_.size, params,
&result, &error))
<< op << ": " << error;
EXPECT_TRUE(contains(result, std::string("\"op\":\"") + op + "\"")) << result;
if (std::strcmp(op, "centroid") == 0) EXPECT_TRUE(contains(result, "\"x\":0"));
if (std::strcmp(op, "area") == 0) EXPECT_TRUE(contains(result, "\"surface_area\":52"));
}
std::string ignored_result;
error.clear();
EXPECT_FALSE(manager.invoke_geometry_op("geom_op.unknown", model_.data, model_.size,
"{}", &ignored_result, &error));
EXPECT_TRUE(contains(error, "not registered")) << error;
error.clear();
EXPECT_FALSE(manager.invoke_geometry_op(kOpId, nullptr, 0, "{}", &ignored_result, &error));
EXPECT_TRUE(contains(error, "empty model")) << error;
error.clear();
EXPECT_FALSE(manager.invoke_geometry_op(kOpId, model_.data, model_.size,
"{\"op\":\"nope\"}", &ignored_result, &error));
EXPECT_TRUE(contains(error, "rc=")) << error;
}
TEST_F(Abi17Fixture, LegacyAbi16PluginStillLoads) {
if (VDE_ABI_MATRIX_DIR[0] == '\0') GTEST_SKIP() << "VDE_ABI_MATRIX_DIR not set";
PluginManager& manager = PluginManager::instance();
manager.clear();
manager.set_host_services(host_);
manager.clear_search_paths();
manager.add_search_path(std::string(VDE_ABI_MATRIX_DIR) + "/abi1_6");
manager.scan_search_paths();
std::string error;
ASSERT_TRUE(manager.load("com.vde.sample.vbox", &error)) << error;
EXPECT_EQ(manager.manifest("com.vde.sample.vbox")->abi_minor, 6);
EXPECT_TRUE(manager.geom_ops().empty());
}
} // namespace