use labstream_net::{resolve, Outlet, StreamInfo};
use labstream_wire::Format;
use std::time::Duration;
#[test]
#[cfg_attr(
target_os = "macos",
ignore = "open on macOS: read docs/conformance.md"
)]
fn both_outlets_hold_the_multicast_port() {
let mut a = StreamInfo::new("TwoA", "EEG", 2, Format::Float32, 100.0);
a.source_id = "two_a".into();
let mut b = StreamInfo::new("TwoB", "Markers", 1, Format::String, 0.0);
b.source_id = "two_b".into();
let first = Outlet::new(a).expect("the first outlet");
let second = Outlet::new(b).expect("the second outlet");
assert!(
first.holds_multicast_port(),
"the first outlet must hold the port"
);
assert!(
second.holds_multicast_port(),
"the second outlet must hold the port as well, or another machine sees only one stream"
);
assert_ne!(first.info().v4data_port, second.info().v4data_port);
}
#[test]
fn a_resolver_finds_both_streams() {
let mut a = StreamInfo::new("BothA", "EEG", 2, Format::Float32, 100.0);
a.source_id = "both_a".into();
let mut b = StreamInfo::new("BothB", "Markers", 1, Format::String, 0.0);
b.source_id = "both_b".into();
let _first = Outlet::new(a).expect("the first outlet");
let _second = Outlet::new(b).expect("the second outlet");
std::thread::sleep(Duration::from_millis(300));
let found = resolve("session_id='default'", 2, Duration::from_secs(5)).expect("a resolve");
let names: Vec<&str> = found.iter().map(|i| i.name.as_str()).collect();
assert!(names.contains(&"BothA"), "got {names:?}");
assert!(names.contains(&"BothB"), "got {names:?}");
}