From 2ca9c46b4b93d3707794dd3d14699c8332e68379 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Thu, 5 Sep 2019 23:56:31 +0100 Subject: [PATCH] Add tests for UnixDatagram from_raw_fd/into_raw_fd --- tests/uds.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/uds.rs b/tests/uds.rs index 9dbda87..e160ad7 100644 --- a/tests/uds.rs +++ b/tests/uds.rs @@ -22,3 +22,21 @@ fn send_recv() -> io::Result<()> { Ok(()) }) } + +#[test] +fn into_raw_fd() -> io::Result<()> { + use async_std::os::unix::io::{FromRawFd, IntoRawFd}; + task::block_on(async { + let (socket1, socket2) = UnixDatagram::pair().unwrap(); + socket1.send(JULIUS_CAESAR).await?; + + let mut buf = vec![0; 1024]; + + let socket2 = unsafe { UnixDatagram::from_raw_fd(socket2.into_raw_fd()) }; + let n = socket2.recv(&mut buf).await?; + assert_eq!(&buf[..n], JULIUS_CAESAR); + + Ok(()) + }) + +}