]> git.proxmox.com Git - rustc.git/blame - vendor/socket2/src/tests.rs
New upstream version 1.52.1+dfsg1
[rustc.git] / vendor / socket2 / src / tests.rs
CommitLineData
ba9703b0
XL
1use std::io::Write;
2use std::str;
3
4use crate::{Domain, Protocol, Type};
5
6#[test]
7fn domain_fmt_debug() {
8 let tests = &[
9 (Domain::ipv4(), "AF_INET"),
10 (Domain::ipv6(), "AF_INET6"),
11 #[cfg(unix)]
12 (Domain::unix(), "AF_UNIX"),
13 (0.into(), "AF_UNSPEC"),
14 (500.into(), "500"),
15 ];
16
17 let mut buf = Vec::new();
18 for (input, want) in tests {
19 buf.clear();
20 write!(buf, "{:?}", input).unwrap();
21 let got = str::from_utf8(&buf).unwrap();
22 assert_eq!(got, *want);
23 }
24}
25
26#[test]
27fn type_fmt_debug() {
28 let tests = &[
29 (Type::stream(), "SOCK_STREAM"),
30 (Type::dgram(), "SOCK_DGRAM"),
31 (Type::seqpacket(), "SOCK_SEQPACKET"),
32 (Type::raw(), "SOCK_RAW"),
33 (500.into(), "500"),
34 ];
35
36 let mut buf = Vec::new();
37 for (input, want) in tests {
38 buf.clear();
39 write!(buf, "{:?}", input).unwrap();
40 let got = str::from_utf8(&buf).unwrap();
41 assert_eq!(got, *want);
42 }
43}
44
45#[test]
46fn protocol_fmt_debug() {
47 let tests = &[
48 (Protocol::icmpv4(), "IPPROTO_ICMP"),
49 (Protocol::icmpv6(), "IPPROTO_ICMPV6"),
50 (Protocol::tcp(), "IPPROTO_TCP"),
51 (Protocol::udp(), "IPPROTO_UDP"),
52 (500.into(), "500"),
53 ];
54
55 let mut buf = Vec::new();
56 for (input, want) in tests {
57 buf.clear();
58 write!(buf, "{:?}", input).unwrap();
59 let got = str::from_utf8(&buf).unwrap();
60 assert_eq!(got, *want);
61 }
62}