summaryrefslogtreecommitdiff
path: root/test/sys/test_socket.rs
diff options
context:
space:
mode:
Diffstat (limited to 'test/sys/test_socket.rs')
-rw-r--r--test/sys/test_socket.rs20
1 files changed, 15 insertions, 5 deletions
diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs
index 8451853f..4662b7e8 100644
--- a/test/sys/test_socket.rs
+++ b/test/sys/test_socket.rs
@@ -1,29 +1,39 @@
-use nix::sys::socket::{AsSockAddr, SockAddr};
+use nix::sys::socket::{SockAddr, ToSockAddr, FromSockAddr};
use std::{mem, net};
use std::num::Int;
-use std::path::Path;
+use std::path::{Path, PathBuf};
use std::str::FromStr;
#[test]
pub fn test_inetv4_addr_to_sock_addr() {
- let std: net::SocketAddr = FromStr::from_str("127.0.0.1:3000").unwrap();
+ let actual: net::SocketAddr = FromStr::from_str("127.0.0.1:3000").unwrap();
+ let addr = actual.to_sock_addr().unwrap();
- match std.as_sock_addr().unwrap() {
+ match addr {
SockAddr::SockIpV4(addr) => {
assert_eq!(addr.sin_addr.s_addr, Int::from_be(2130706433));
assert_eq!(addr.sin_port, 3000);
}
_ => panic!("nope"),
}
+
+ let inet = FromSockAddr::from_sock_addr(&addr).unwrap();
+ assert_eq!(actual, inet);
}
#[test]
pub fn test_path_to_sock_addr() {
- match Path::new("/foo/bar").as_sock_addr().unwrap() {
+ let actual = Path::new("/foo/bar");
+ let addr = actual.to_sock_addr().unwrap();
+
+ match addr {
SockAddr::SockUnix(addr) => {
let expect: &'static [i8] = unsafe { mem::transmute(b"/foo/bar") };
assert_eq!(&addr.sun_path[..8], expect);
}
_ => panic!("nope"),
}
+
+ let path: PathBuf = FromSockAddr::from_sock_addr(&addr).unwrap();
+ assert_eq!(actual, &*path);
}