mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 18:55:32 +00:00
bittorrent_udp: simplify quickcheck test syntax, keeping functionality
This commit is contained in:
parent
02b63feef7
commit
c45fa80391
1 changed files with 28 additions and 33 deletions
|
|
@ -178,11 +178,12 @@ pub fn response_from_bytes(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use quickcheck::{TestResult, quickcheck};
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
fn same_after_conversion(response: Response, ip_version: IpVersion) -> bool {
|
fn same_after_conversion(
|
||||||
|
response: Response,
|
||||||
|
ip_version: IpVersion
|
||||||
|
) -> bool {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
response_to_bytes(&mut buf, response.clone(), ip_version);
|
response_to_bytes(&mut buf, response.clone(), ip_version);
|
||||||
|
|
@ -197,18 +198,17 @@ mod tests {
|
||||||
success
|
success
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[quickcheck]
|
||||||
fn test_convert_identity_connect_response(){
|
fn test_connect_response_convert_identity(
|
||||||
fn prop(response: ConnectResponse) -> TestResult {
|
response: ConnectResponse
|
||||||
TestResult::from_bool(same_after_conversion(response.into(), IpVersion::IPv4))
|
) -> bool {
|
||||||
|
same_after_conversion(response.into(), IpVersion::IPv4)
|
||||||
}
|
}
|
||||||
|
|
||||||
quickcheck(prop as fn(ConnectResponse) -> TestResult);
|
#[quickcheck]
|
||||||
}
|
fn test_announce_response_convert_identity(
|
||||||
|
data: (AnnounceResponse, IpVersion)
|
||||||
#[test]
|
) -> bool {
|
||||||
fn test_convert_identity_announce_response(){
|
|
||||||
fn prop(data: (AnnounceResponse, IpVersion)) -> TestResult {
|
|
||||||
let mut r = data.0;
|
let mut r = data.0;
|
||||||
|
|
||||||
if data.1 == IpVersion::IPv4 {
|
if data.1 == IpVersion::IPv4 {
|
||||||
|
|
@ -217,18 +217,13 @@ mod tests {
|
||||||
r.peers.retain(|peer| peer.ip_address.is_ipv6());
|
r.peers.retain(|peer| peer.ip_address.is_ipv6());
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResult::from_bool(same_after_conversion(r.into(), data.1))
|
same_after_conversion(r.into(), data.1)
|
||||||
}
|
}
|
||||||
|
|
||||||
quickcheck(prop as fn((AnnounceResponse, IpVersion)) -> TestResult);
|
#[quickcheck]
|
||||||
}
|
fn test_scrape_response_convert_identity(
|
||||||
|
response: ScrapeResponse
|
||||||
#[test]
|
) -> bool {
|
||||||
fn test_convert_identity_scrape_response(){
|
same_after_conversion(response.into(), IpVersion::IPv4)
|
||||||
fn prop(response: ScrapeResponse) -> TestResult {
|
|
||||||
TestResult::from_bool(same_after_conversion(response.into(), IpVersion::IPv4))
|
|
||||||
}
|
|
||||||
|
|
||||||
quickcheck(prop as fn(ScrapeResponse) -> TestResult);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue