Skip to content

Commit 9dcfd9f

Browse files
committed
std::net: tests for Ipv4addr::is_benchmarking()
also add test to Ipaddr, making sure that these addresses are not global.
1 parent 40d0127 commit 9dcfd9f

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

src/libstd/net/ip.rs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,6 +2023,9 @@ mod tests {
20232023
check!("224.0.0.0", global|multicast);
20242024
check!("239.255.255.255", global|multicast);
20252025
check!("255.255.255.255");
2026+
check!("198.18.0.0");
2027+
check!("198.18.54.2");
2028+
check!("198.19.255.255");
20262029

20272030
check!("::", unspec);
20282031
check!("::1", loopback);
@@ -2058,14 +2061,15 @@ mod tests {
20582061
};
20592062

20602063
($s:expr, $mask:expr) => {{
2061-
let unspec: u8 = 1 << 0;
2062-
let loopback: u8 = 1 << 1;
2063-
let private: u8 = 1 << 2;
2064-
let link_local: u8 = 1 << 3;
2065-
let global: u8 = 1 << 4;
2066-
let multicast: u8 = 1 << 5;
2067-
let broadcast: u8 = 1 << 6;
2068-
let documentation: u8 = 1 << 7;
2064+
let unspec: u16 = 1 << 0;
2065+
let loopback: u16 = 1 << 1;
2066+
let private: u16 = 1 << 2;
2067+
let link_local: u16 = 1 << 3;
2068+
let global: u16 = 1 << 4;
2069+
let multicast: u16 = 1 << 5;
2070+
let broadcast: u16 = 1 << 6;
2071+
let documentation: u16 = 1 << 7;
2072+
let benchmarking: u16 = 1 << 8;
20692073

20702074
if ($mask & unspec) == unspec {
20712075
assert!(ip!($s).is_unspecified());
@@ -2114,17 +2118,24 @@ mod tests {
21142118
} else {
21152119
assert!(!ip!($s).is_documentation());
21162120
}
2121+
2122+
if ($mask & benchmarking) == benchmarking {
2123+
assert!(ip!($s).is_benchmarking());
2124+
} else {
2125+
assert!(!ip!($s).is_benchmarking());
2126+
}
21172127
}}
21182128
}
21192129

2120-
let unspec: u8 = 1 << 0;
2121-
let loopback: u8 = 1 << 1;
2122-
let private: u8 = 1 << 2;
2123-
let link_local: u8 = 1 << 3;
2124-
let global: u8 = 1 << 4;
2125-
let multicast: u8 = 1 << 5;
2126-
let broadcast: u8 = 1 << 6;
2127-
let documentation: u8 = 1 << 7;
2130+
let unspec: u16 = 1 << 0;
2131+
let loopback: u16 = 1 << 1;
2132+
let private: u16 = 1 << 2;
2133+
let link_local: u16 = 1 << 3;
2134+
let global: u16 = 1 << 4;
2135+
let multicast: u16 = 1 << 5;
2136+
let broadcast: u16 = 1 << 6;
2137+
let documentation: u16 = 1 << 7;
2138+
let benchmarking: u16 = 1 << 8;
21282139

21292140
check!("0.0.0.0", unspec);
21302141
check!("0.0.0.1");
@@ -2142,6 +2153,9 @@ mod tests {
21422153
check!("224.0.0.0", global|multicast);
21432154
check!("239.255.255.255", global|multicast);
21442155
check!("255.255.255.255", broadcast);
2156+
check!("198.18.0.0", benchmarking);
2157+
check!("198.18.54.2", benchmarking);
2158+
check!("198.19.255.255", benchmarking);
21452159
}
21462160

21472161
#[test]

0 commit comments

Comments
 (0)