From 597a2a83d18364c0e4225210e9c73a1988432dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Tue, 21 Jul 2020 00:36:34 +0200 Subject: [PATCH] aquatic http protocol: add quickcheck test for urlencode/decode 20 bytes --- aquatic_http_protocol/src/utils.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/aquatic_http_protocol/src/utils.rs b/aquatic_http_protocol/src/utils.rs index daf5a32..1ac1b76 100644 --- a/aquatic_http_protocol/src/utils.rs +++ b/aquatic_http_protocol/src/utils.rs @@ -146,6 +146,8 @@ pub fn serialize_response_peers_ipv6( #[cfg(test)] mod tests { + use quickcheck_macros::*; + use super::*; #[test] @@ -176,6 +178,34 @@ mod tests { } } + #[quickcheck] + fn test_urlencode_urldecode_20_bytes( + a: u8, + b: u8, + c: u8, + d: u8, + e: u8, + f: u8, + g: u8, + h: u8, + ) -> bool { + let input: [u8; 20] = [ + a, b, c, d, e, f, g, h, b, c, d, a, e, f, g, h, a, b, d, c + ]; + + let mut output = Vec::new(); + + urlencode_20_bytes(input, &mut output); + + let s = ::std::str::from_utf8(&output).unwrap(); + + let decoded = urldecode_20_bytes(s).unwrap(); + + assert_eq!(input, decoded); + + input == decoded + } + #[test] fn test_urldecode(){ assert_eq!(urldecode("").unwrap(), "".to_string());