aquatic http protocol: add quickcheck test for urlencode/decode 20 bytes

This commit is contained in:
Joakim Frostegård 2020-07-21 00:36:34 +02:00
parent 909f0edce9
commit 597a2a83d1

View file

@ -146,6 +146,8 @@ pub fn serialize_response_peers_ipv6<S>(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use quickcheck_macros::*;
use super::*; use super::*;
#[test] #[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] #[test]
fn test_urldecode(){ fn test_urldecode(){
assert_eq!(urldecode("").unwrap(), "".to_string()); assert_eq!(urldecode("").unwrap(), "".to_string());