Skip to content

Commit 05ca989

Browse files
PiotrSikoraThomasdezeeuw
authored andcommitted
review: add tests.
Signed-off-by: Piotr Sikora <[email protected]>
1 parent 02968e9 commit 05ca989

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/socket.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,3 +1297,39 @@ fn header_included() {
12971297
let got = socket.header_included().expect("failed to get value");
12981298
assert_eq!(got, true, "set and get values differ");
12991299
}
1300+
1301+
#[test]
1302+
#[cfg(all(
1303+
feature = "all",
1304+
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
1305+
))]
1306+
fn original_dst() {
1307+
let socket = Socket::new(Domain::IPV4, Type::STREAM, None).unwrap();
1308+
match socket.original_dst() {
1309+
Ok(_) => panic!("original_dst on non-redirected socket should fail"),
1310+
Err(err) => assert_eq!(err.raw_os_error(), Some(libc::ENOENT)),
1311+
}
1312+
1313+
let socket = Socket::new(Domain::IPV6, Type::STREAM, None).unwrap();
1314+
match socket.original_dst() {
1315+
Ok(_) => panic!("original_dst on non-redirected socket should fail"),
1316+
Err(err) => assert_eq!(err.raw_os_error(), Some(libc::ENOENT)),
1317+
}
1318+
}
1319+
1320+
#[test]
1321+
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
1322+
fn original_dst_ipv6() {
1323+
let socket = Socket::new(Domain::IPV6, Type::STREAM, None).unwrap();
1324+
match socket.original_dst_ipv6() {
1325+
Ok(_) => panic!("original_dst_ipv6 on non-redirected socket should fail"),
1326+
Err(err) => assert_eq!(err.raw_os_error(), Some(libc::ENOENT)),
1327+
}
1328+
1329+
// Not supported on IPv4 socket.
1330+
let socket = Socket::new(Domain::IPV4, Type::STREAM, None).unwrap();
1331+
match socket.original_dst_ipv6() {
1332+
Ok(_) => panic!("original_dst_ipv6 on non-redirected socket should fail"),
1333+
Err(err) => assert_eq!(err.raw_os_error(), Some(libc::EOPNOTSUPP)),
1334+
}
1335+
}

0 commit comments

Comments
 (0)