#![allow(unexpected_cfgs)]
use fidius_host::{CallError, PluginHandle};
#[fidius_macro::plugin_interface(version = 1, buffer = PluginAllocated, crate = "fidius_core")]
pub trait Api: Send + Sync {
fn base(&self) -> String;
}
pub struct Plugin;
#[fidius_macro::plugin_impl(Api, crate = "fidius_core")]
impl Api for Plugin {
fn base(&self) -> String {
"base".into()
}
}
fidius_core::fidius_plugin_registry!();
#[test]
fn calling_a_method_the_plugin_lacks_is_a_clean_error_not_a_segfault() {
let desc = PluginHandle::find_in_process_descriptor("Plugin").unwrap();
let handle = PluginHandle::from_descriptor(desc).unwrap();
let b: String = handle.call_method(0, &()).expect("base");
assert_eq!(b, "base");
let unary: Result<String, CallError> = handle.call_method(1, &());
assert!(
matches!(
unary,
Err(CallError::InvalidMethodIndex { index: 1, count: 1 })
),
"expected InvalidMethodIndex, got {unary:?}"
);
let raw = handle.call_method_raw(7, b"x");
assert!(
matches!(raw, Err(CallError::InvalidMethodIndex { .. })),
"raw out-of-range must be a clean error, got {raw:?}"
);
}