mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
bittorrent_udp: add quickcheck tests for request byte conversion
This commit is contained in:
parent
554895a9df
commit
02b63feef7
2 changed files with 49 additions and 0 deletions
|
|
@ -197,3 +197,45 @@ pub fn request_from_bytes(
|
||||||
_ => Err(RequestParseError::text(transaction_id, "Invalid action"))
|
_ => Err(RequestParseError::text(transaction_id, "Invalid action"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn same_after_conversion(request: Request) -> bool {
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
|
request_to_bytes(&mut buf, request.clone()).unwrap();
|
||||||
|
let r2 = request_from_bytes(&buf[..], ::std::u8::MAX).unwrap();
|
||||||
|
|
||||||
|
let success = request == r2;
|
||||||
|
|
||||||
|
if !success {
|
||||||
|
println!("before: {:#?}\nafter: {:#?}", request, r2);
|
||||||
|
}
|
||||||
|
|
||||||
|
success
|
||||||
|
}
|
||||||
|
|
||||||
|
#[quickcheck]
|
||||||
|
fn test_connect_request_convert_identity(
|
||||||
|
request: ConnectRequest
|
||||||
|
) -> bool {
|
||||||
|
same_after_conversion(request.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[quickcheck]
|
||||||
|
fn test_announce_request_convert_identity(
|
||||||
|
request: AnnounceRequest
|
||||||
|
) -> bool {
|
||||||
|
same_after_conversion(request.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[quickcheck]
|
||||||
|
fn test_scrape_request_convert_identity(
|
||||||
|
request: ScrapeRequest
|
||||||
|
) -> bool {
|
||||||
|
same_after_conversion(request.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,2 +1,9 @@
|
||||||
|
#[cfg(test)]
|
||||||
|
extern crate quickcheck;
|
||||||
|
#[cfg(test)]
|
||||||
|
#[macro_use(quickcheck)]
|
||||||
|
extern crate quickcheck_macros;
|
||||||
|
|
||||||
|
|
||||||
pub mod converters;
|
pub mod converters;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue