use juiz_core::prelude::*;
fn plugin_file() -> std::path::PathBuf {
let name = "destroy_check_container_cpp";
#[cfg(target_os = "macos")]
let file = format!("lib{name}.dylib");
#[cfg(target_os = "linux")]
let file = format!("lib{name}.so");
#[cfg(target_os = "windows")]
let file = format!("{name}.dll");
std::path::PathBuf::from("../target").join(file)
}
fn system_manifest() -> Value {
jvalue!({
"name": "cpp_container_destroy_test",
"plugins": {
"container_factories": {
"destroy_check_container_cpp": { "language": "c++", "path": "../target" }
}
},
"containers": [
{ "type_name": "destroy_check_container_cpp", "name": "c0" }
]
})
}
#[test]
fn cpp_container_is_deleted_when_destroyed() -> JuizResult<()> {
let _ = env_logger::try_init();
let lib = unsafe { libloading::Library::new(plugin_file())? };
let alive_count: libloading::Symbol<unsafe extern "C" fn() -> i64> =
unsafe { lib.get(b"destroy_check_container_cpp_alive_count")? };
let alive = || unsafe { alive_count() };
let initial = alive();
System::new(system_manifest())?
.setup()?
.run_and_do_once(|system| {
let mut cb = system.core_broker().lock_mut()?;
assert_eq!(alive(), initial + 1);
let created = cb.container_create(
&ContainerManifest::new("destroy_check_container_cpp").name("c1"),
CapsuleMap::new(),
)?;
assert_eq!(alive(), initial + 2);
cb.container_destroy(&created.identifier())?;
assert_eq!(alive(), initial + 1);
Ok(())
})?;
Ok(())
}