2025-08-17 22:52:17 +09:00
|
|
|
|
//! プラグインシステム統合テスト
|
2025-09-17 07:43:07 +09:00
|
|
|
|
//!
|
2025-08-17 22:52:17 +09:00
|
|
|
|
//! プラグインBoxの透過的切り替えをテスト
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
|
mod tests {
|
2025-09-17 07:43:07 +09:00
|
|
|
|
use super::super::{BoxFactoryRegistry, PluginConfig};
|
2025-08-17 22:52:17 +09:00
|
|
|
|
use crate::bid::{BidHandle, BoxTypeId};
|
2025-09-17 07:43:07 +09:00
|
|
|
|
use crate::box_trait::{NyashBox, StringBox};
|
|
|
|
|
|
use crate::runtime::box_registry::BoxProvider;
|
|
|
|
|
|
|
2025-08-17 22:52:17 +09:00
|
|
|
|
fn dummy_filebox_constructor(args: &[Box<dyn NyashBox>]) -> Result<Box<dyn NyashBox>, String> {
|
|
|
|
|
|
// ダミーFileBox作成(ビルトイン版シミュレーション)
|
|
|
|
|
|
if args.is_empty() {
|
|
|
|
|
|
Ok(Box::new(StringBox::new("DummyFileBox")))
|
|
|
|
|
|
} else {
|
2025-09-17 07:43:07 +09:00
|
|
|
|
Ok(Box::new(StringBox::new(&format!(
|
|
|
|
|
|
"DummyFileBox({})",
|
|
|
|
|
|
args[0].to_string_box().value
|
|
|
|
|
|
))))
|
2025-08-17 22:52:17 +09:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-17 22:52:17 +09:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_plugin_config_parsing() {
|
|
|
|
|
|
let toml = r#"
|
|
|
|
|
|
[plugins]
|
|
|
|
|
|
FileBox = "filebox"
|
|
|
|
|
|
StringBox = "custom_string"
|
|
|
|
|
|
"#;
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-17 22:52:17 +09:00
|
|
|
|
let config = PluginConfig::parse(toml).unwrap();
|
|
|
|
|
|
assert_eq!(config.plugins.get("FileBox"), Some(&"filebox".to_string()));
|
2025-09-17 07:43:07 +09:00
|
|
|
|
assert_eq!(
|
|
|
|
|
|
config.plugins.get("StringBox"),
|
|
|
|
|
|
Some(&"custom_string".to_string())
|
|
|
|
|
|
);
|
2025-08-17 22:52:17 +09:00
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-17 22:52:17 +09:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_box_registry_builtin() {
|
|
|
|
|
|
let registry = BoxFactoryRegistry::new();
|
|
|
|
|
|
registry.register_builtin("FileBox", dummy_filebox_constructor);
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-17 22:52:17 +09:00
|
|
|
|
let result = registry.create_box("FileBox", &[]).unwrap();
|
|
|
|
|
|
assert_eq!(result.to_string_box().value, "DummyFileBox");
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-17 22:52:17 +09:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_box_registry_plugin_override() {
|
|
|
|
|
|
let registry = BoxFactoryRegistry::new();
|
|
|
|
|
|
registry.register_builtin("FileBox", dummy_filebox_constructor);
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-17 22:52:17 +09:00
|
|
|
|
// プラグイン設定でビルトインを上書き
|
|
|
|
|
|
let mut config = PluginConfig::default();
|
2025-09-17 07:43:07 +09:00
|
|
|
|
config
|
|
|
|
|
|
.plugins
|
|
|
|
|
|
.insert("FileBox".to_string(), "filebox".to_string());
|
2025-08-17 22:52:17 +09:00
|
|
|
|
registry.apply_plugin_config(&config);
|
2025-08-20 04:45:26 +09:00
|
|
|
|
|
|
|
|
|
|
// 生成までは行わず、プロバイダーがプラグインに切り替わったことを確認
|
|
|
|
|
|
match registry.get_provider("FileBox").unwrap() {
|
|
|
|
|
|
BoxProvider::Plugin(name) => assert_eq!(name, "filebox"),
|
|
|
|
|
|
_ => panic!("Expected plugin provider for FileBox"),
|
|
|
|
|
|
}
|
2025-08-17 22:52:17 +09:00
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-20 04:45:26 +09:00
|
|
|
|
// TODO: PluginBox型が削除されたためこのテストはコメントアウト
|
|
|
|
|
|
// #[test]
|
|
|
|
|
|
// fn test_plugin_box_creation() {
|
|
|
|
|
|
// let handle = BidHandle::new(BoxTypeId::FileBox as u32, 123);
|
|
|
|
|
|
// let plugin_box = PluginBox::new("filebox".to_string(), handle);
|
2025-09-17 07:43:07 +09:00
|
|
|
|
//
|
2025-08-20 04:45:26 +09:00
|
|
|
|
// assert_eq!(plugin_box.plugin_name(), "filebox");
|
|
|
|
|
|
// assert_eq!(plugin_box.handle().type_id, BoxTypeId::FileBox as u32);
|
|
|
|
|
|
// assert_eq!(plugin_box.handle().instance_id, 123);
|
|
|
|
|
|
// }
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-20 04:45:26 +09:00
|
|
|
|
// 旧PluginBox直接生成テストは削除(v2統合により不要)
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-17 22:52:17 +09:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_transparent_box_switching() {
|
|
|
|
|
|
let registry = BoxFactoryRegistry::new();
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-17 22:52:17 +09:00
|
|
|
|
// 1. ビルトイン版を登録
|
|
|
|
|
|
registry.register_builtin("FileBox", dummy_filebox_constructor);
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-20 04:45:26 +09:00
|
|
|
|
// 2. 現在のプロバイダーはビルトイン
|
|
|
|
|
|
match registry.get_provider("FileBox").unwrap() {
|
|
|
|
|
|
BoxProvider::Builtin(_) => {}
|
|
|
|
|
|
_ => panic!("Expected builtin provider before plugin override"),
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-17 22:52:17 +09:00
|
|
|
|
// 3. プラグイン設定を適用
|
|
|
|
|
|
let mut config = PluginConfig::default();
|
2025-09-17 07:43:07 +09:00
|
|
|
|
config
|
|
|
|
|
|
.plugins
|
|
|
|
|
|
.insert("FileBox".to_string(), "filebox".to_string());
|
2025-08-17 22:52:17 +09:00
|
|
|
|
registry.apply_plugin_config(&config);
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-20 04:45:26 +09:00
|
|
|
|
// 4. プロバイダーがプラグインに切り替わっている
|
|
|
|
|
|
match registry.get_provider("FileBox").unwrap() {
|
|
|
|
|
|
BoxProvider::Plugin(name) => assert_eq!(name, "filebox"),
|
|
|
|
|
|
_ => panic!("Expected plugin provider after override"),
|
|
|
|
|
|
}
|
2025-08-17 22:52:17 +09:00
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-17 22:52:17 +09:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_multiple_plugin_types() {
|
|
|
|
|
|
let mut config = PluginConfig::default();
|
2025-09-17 07:43:07 +09:00
|
|
|
|
config
|
|
|
|
|
|
.plugins
|
|
|
|
|
|
.insert("FileBox".to_string(), "filebox".to_string());
|
|
|
|
|
|
config
|
|
|
|
|
|
.plugins
|
|
|
|
|
|
.insert("StringBox".to_string(), "custom_string".to_string());
|
|
|
|
|
|
config
|
|
|
|
|
|
.plugins
|
|
|
|
|
|
.insert("MathBox".to_string(), "advanced_math".to_string());
|
|
|
|
|
|
|
2025-08-17 22:52:17 +09:00
|
|
|
|
assert_eq!(config.plugins.len(), 3);
|
|
|
|
|
|
assert_eq!(config.plugins.get("FileBox"), Some(&"filebox".to_string()));
|
2025-09-17 07:43:07 +09:00
|
|
|
|
assert_eq!(
|
|
|
|
|
|
config.plugins.get("StringBox"),
|
|
|
|
|
|
Some(&"custom_string".to_string())
|
|
|
|
|
|
);
|
|
|
|
|
|
assert_eq!(
|
|
|
|
|
|
config.plugins.get("MathBox"),
|
|
|
|
|
|
Some(&"advanced_math".to_string())
|
|
|
|
|
|
);
|
2025-08-17 22:52:17 +09:00
|
|
|
|
}
|
2025-08-20 04:45:26 +09:00
|
|
|
|
}
|