use pmpx_plugin::abi::{self, PmpxStr};
use pmpx_plugin::Verb;
use crate::support::{call_command, entry};
#[test]
fn unsupported_verb_has_its_own_code() {
let code = call_command("/proj", &[], Some(Verb::Exec), &[]).unwrap_err();
assert_eq!(code, abi::PMPX_ERR_UNSUPPORTED_VERB);
let other = call_command("/proj", &[], Some(Verb::Build), &[]).unwrap_err();
assert_eq!(other, abi::PMPX_ERR_INTERNAL);
}
#[test]
fn an_unknown_verb_number_is_rejected() {
let code = call_command("/proj", &[], None, &[]).unwrap_err();
assert_eq!(code, abi::PMPX_ERR_INVALID_ARGS);
}
#[test]
fn a_null_out_pointer_is_rejected() {
let e = entry();
let root = PmpxStr {
ptr: "/proj".as_ptr(),
len: 5,
};
let empty: Vec<PmpxStr> = Vec::new();
let code = unsafe {
(e.command)(
root,
empty.as_ptr(),
0,
Verb::Install.to_abi(),
empty.as_ptr(),
0,
std::ptr::null_mut(),
)
};
assert_eq!(code, abi::PMPX_ERR_INVALID_ARGS);
}
#[test]
fn a_panicking_plugin_does_not_take_the_host_down() {
let code = call_command("/proj", &[], Some(Verb::Install), &["panic"]).unwrap_err();
assert_eq!(code, abi::PMPX_ERR_INTERNAL);
}