#[cfg(test)]
mod tests {
use std::collections::BTreeMap;
use serde_cbor::Value;
#[test]
fn test_channel_api_signatures_compile() {
let channel_id: u16 = 42;
let read_cap: BTreeMap<Value, Value> = BTreeMap::new();
let write_cap: BTreeMap<Value, Value> = BTreeMap::new();
let message_box_index: BTreeMap<Value, Value> = BTreeMap::new();
let payload: Vec<u8> = vec![1, 2, 3];
let _create_write_result: (u16, BTreeMap<Value, Value>, BTreeMap<Value, Value>, BTreeMap<Value, Value>) =
(channel_id, read_cap.clone(), write_cap.clone(), message_box_index.clone());
let _create_result: (u16, BTreeMap<Value, Value>) = (channel_id, read_cap.clone());
let _create_read_result: (u16, BTreeMap<Value, Value>) = (channel_id, message_box_index.clone());
let _write_result: (Vec<u8>, BTreeMap<Value, Value>) = (payload.clone(), message_box_index.clone());
let reply_index: Option<u8> = Some(0);
let _read_result: (Vec<u8>, BTreeMap<Value, Value>, Option<u8>) = (payload, message_box_index, reply_index);
let _close_result: () = ();
let _copy_result: () = ();
assert_eq!(std::mem::size_of::<u16>(), 2);
assert!(channel_id <= u16::MAX);
println!("All channel API type signatures are correct!");
}
#[test]
fn test_channel_id_conversion() {
let channel_id: u16 = 12345;
let cbor_value = Value::Integer(channel_id.into());
if let Value::Integer(i) = cbor_value {
let converted_back = i as u16;
assert_eq!(converted_back, channel_id);
} else {
panic!("CBOR conversion failed");
}
}
}