1 use test_programs::p3::wasi::sockets::types::{ErrorCode, IpAddressFamily, UdpSocket}; 2 3 struct Component; 4 5 test_programs::p3::export!(Component); 6 7 // Receive requires the socket to be bound. test_udp_receive_without_bind_or_connect(family: IpAddressFamily)8async fn test_udp_receive_without_bind_or_connect(family: IpAddressFamily) { 9 let sock = UdpSocket::create(family).unwrap(); 10 11 assert!(matches!(sock.get_local_address(), Err(_))); 12 13 assert!(matches!(sock.receive().await, Err(ErrorCode::InvalidState))); 14 15 assert!(matches!(sock.get_local_address(), Err(_))); 16 assert!(matches!(sock.get_remote_address(), Err(_))); 17 } 18 19 impl test_programs::p3::exports::wasi::cli::run::Guest for Component { run() -> Result<(), ()>20 async fn run() -> Result<(), ()> { 21 test_udp_receive_without_bind_or_connect(IpAddressFamily::Ipv4).await; 22 test_udp_receive_without_bind_or_connect(IpAddressFamily::Ipv6).await; 23 24 Ok(()) 25 } 26 } 27 main()28fn main() {} 29