forked from 1b-agent/opencadstudio-upstream
Add demo_plugin and plugin host integration tests
Minimal in-tree add-on (DP_HELLO) validates registry, ribbon merge, and try_dispatch. Five new lib tests; EntryKind gains PartialEq for test helpers.
This commit is contained in:
1 parent
9f35456205
commit
82993bc1db
12 files changed
+214
-2
No files matched your search
@@ -0,0 +1,11 @@
|
||||
use crate::plugin::host::HostSession;
|
||||
|
||||
pub fn handle(host: &mut HostSession<'_>, cmd: &str) -> bool {
|
||||
match cmd {
|
||||
"DP_HELLO" => {
|
||||
host.push_info("Hello from demo_plugin (plugin host OK).");
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
use crate::plugin::manifest::{ApiVersion, PluginManifest};
|
||||
|
||||
pub const PLUGIN_ID: &str = "opencad.demo_plugin";
|
||||
|
||||
pub static MANIFEST: PluginManifest = PluginManifest {
|
||||
id: PLUGIN_ID,
|
||||
name: "Demo Plugin",
|
||||
version: "0.1.0",
|
||||
description: "Minimal add-on for plugin-host integration tests",
|
||||
api_version: ApiVersion::CURRENT,
|
||||
ribbon_order: 99,
|
||||
xdata_apps: &[],
|
||||
command_prefixes: &["DP_"],
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
// Minimal in-tree add-on — validates plugin host on `feature/plugin-host`.
|
||||
|
||||
pub mod dispatch;
|
||||
pub mod manifest;
|
||||
pub mod plugin;
|
||||
pub mod register;
|
||||
|
||||
use crate::modules::{CadModule, IconKind, ModuleEvent, RibbonGroup, RibbonItem, ToolDef};
|
||||
|
||||
inventory::submit!(crate::command::CommandRegistration {
|
||||
names: &["DP_HELLO"]
|
||||
});
|
||||
|
||||
pub struct DemoPluginModule;
|
||||
|
||||
impl CadModule for DemoPluginModule {
|
||||
fn id(&self) -> &'static str {
|
||||
"demo_plugin"
|
||||
}
|
||||
|
||||
fn title(&self) -> &'static str {
|
||||
"Demo Plugin"
|
||||
}
|
||||
|
||||
fn ribbon_groups(&self) -> Vec<RibbonGroup> {
|
||||
vec![RibbonGroup {
|
||||
title: "Smoke",
|
||||
tools: vec![RibbonItem::LargeTool(ToolDef {
|
||||
id: "DP_HELLO",
|
||||
label: "Hello",
|
||||
icon: IconKind::Glyph("★"),
|
||||
event: ModuleEvent::Command("DP_HELLO".to_string()),
|
||||
})],
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::plugin::all_ribbon_modules;
|
||||
|
||||
#[test]
|
||||
fn ribbon_tab_is_registered() {
|
||||
let titles: Vec<&str> = all_ribbon_modules().iter().map(|m| m.title()).collect();
|
||||
assert!(titles.contains(&"Demo Plugin"), "tabs: {titles:?}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
use crate::plugin::host::{BuiltinPlugin, HostSession};
|
||||
use crate::plugin::manifest::PluginManifest;
|
||||
|
||||
use super::dispatch;
|
||||
use super::manifest;
|
||||
|
||||
pub struct DemoPlugin;
|
||||
|
||||
impl BuiltinPlugin for DemoPlugin {
|
||||
fn manifest(&self) -> &'static PluginManifest {
|
||||
&manifest::MANIFEST
|
||||
}
|
||||
|
||||
fn ribbon(&self) -> Box<dyn crate::modules::CadModule> {
|
||||
Box::new(super::DemoPluginModule)
|
||||
}
|
||||
|
||||
fn dispatch(&self, host: &mut HostSession<'_>, cmd: &str) -> bool {
|
||||
dispatch::handle(host, cmd)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
[plugin]
|
||||
id = "opencad.demo_plugin"
|
||||
name = "Demo Plugin"
|
||||
version = "0.1.0"
|
||||
description = "Minimal add-on for plugin-host integration tests"
|
||||
author = "Open CAD Studio contributors"
|
||||
license = "GPL-3.0-only"
|
||||
|
||||
[opencad]
|
||||
api_version = 1
|
||||
ribbon_order = 99
|
||||
command_prefixes = ["DP_"]
|
||||
xdata_apps = []
|
||||
@@ -0,0 +1,7 @@
|
||||
use super::plugin::DemoPlugin;
|
||||
|
||||
inventory::submit! {
|
||||
crate::plugin::registry::PluginRegistration {
|
||||
construct: || Box::new(DemoPlugin),
|
||||
}
|
||||
}
|
||||
@@ -139,6 +139,7 @@ pub mod home;
|
||||
pub mod insert;
|
||||
pub mod model;
|
||||
pub mod layout;
|
||||
pub mod demo_plugin;
|
||||
pub mod manage;
|
||||
pub mod view;
|
||||
|
||||
|
||||
Reference in new issue
Block a user