vpncloud/src/tests/helper.rs

68 lines
2.1 KiB
Rust
Raw Normal View History

2019-02-26 17:36:54 +00:00
macro_rules! assert_clean {
($($node: expr),*) => {
$(
assert_eq!($node.socket4().pop_outbound().map(|(addr, mut msg)| (addr, $node.decode_message(&mut msg).unwrap().without_data())), None);
assert_eq!($node.socket6().pop_outbound().map(|(addr, mut msg)| (addr, $node.decode_message(&mut msg).unwrap().without_data())), None);
assert_eq!($node.device().pop_outbound(), None);
)*
};
}
macro_rules! assert_message4 {
($from: expr, $from_addr: expr, $to: expr, $to_addr: expr, $message: expr) => {
let (addr, mut data) = msg4_get(&mut $from);
assert_eq!($to_addr, addr);
{
2019-03-03 13:56:59 +00:00
let message = $from.decode_message(&mut data).unwrap();
2019-02-26 17:36:54 +00:00
assert_eq!($message, message.without_data());
}
msg4_put(&mut $to, $from_addr, data);
};
}
2019-03-02 11:23:12 +00:00
#[allow(unused_macros)]
2019-02-26 17:36:54 +00:00
macro_rules! assert_message6 {
($from: expr, $from_addr: expr, $to: expr, $to_addr: expr, $message: expr) => {
let (addr, mut data) = msg6_get(&mut $from);
assert_eq!($to_addr, addr);
{
2019-03-03 13:56:59 +00:00
let message = $from.decode_message(&mut data).unwrap();
2019-02-26 17:36:54 +00:00
assert_eq!($message, message.without_data());
}
msg6_put(&mut $to, $from_addr, data);
};
}
macro_rules! simulate {
($($node: expr => $addr: expr),*) => {
simulate(&mut [$((&mut $node, $addr)),*]);
};
}
2019-12-04 12:09:20 +00:00
macro_rules! simulate_time {
($time:expr, $($node: expr => $addr: expr),*) => {
for _ in 0..$time {
use crate::util::{MockTimeSource, TimeSource};
MockTimeSource::set_time(MockTimeSource::now()+1);
$(
$node.trigger_housekeep();
)*
simulate(&mut [$((&mut $node, $addr)),*]);
}
};
}
2019-02-26 17:36:54 +00:00
macro_rules! assert_connected {
($($node:expr),*) => {
for node1 in [$(&$node),*].iter() {
for node2 in [$(&$node),*].iter() {
if node1.node_id() == node2.node_id() {
continue
}
assert!(node1.peers().contains_node(&node2.node_id()));
}
}
};
2019-12-04 08:32:35 +00:00
}