diff options
Diffstat (limited to 'vendor/weezl/tests')
-rw-r--r-- | vendor/weezl/tests/async.rs | 48 | ||||
-rw-r--r-- | vendor/weezl/tests/implicit_reset.rs | 21 | ||||
-rw-r--r-- | vendor/weezl/tests/roundtrip.rs | 66 | ||||
-rw-r--r-- | vendor/weezl/tests/roundtrip_vec.rs | 65 |
4 files changed, 0 insertions, 200 deletions
diff --git a/vendor/weezl/tests/async.rs b/vendor/weezl/tests/async.rs deleted file mode 100644 index 5df95b0..0000000 --- a/vendor/weezl/tests/async.rs +++ /dev/null @@ -1,48 +0,0 @@ -use std::{env, fs}; -use tokio::io::BufReader; -use tokio::net::{TcpListener, TcpStream}; -use tokio_util::compat::TokioAsyncReadCompatExt as _; -use weezl::{decode, encode, BitOrder}; - -async fn pair() -> (TcpStream, TcpStream) { - let listener = TcpListener::bind("localhost:0") - .await - .expect("No loop tcp for testing"); - let addr = listener.local_addr().expect("No address for listener"); - - let connect = TcpStream::connect(addr); - let accept = listener.accept(); - - let (a, (b, _)) = tokio::try_join!(connect, accept).expect("Can connect"); - (a, b) -} - -async fn assert_send_through(data: &[u8], send: &mut TcpStream, recv: &mut TcpStream) { - let mut send = send.compat(); - let mut recv = BufReader::new(recv).compat(); - - let mut encoder = encode::Encoder::new(BitOrder::Lsb, 8); - let encode = encoder.into_async(&mut send).encode_all(data); - - let mut recv_buffer = vec![]; - let mut decoder = decode::Decoder::new(BitOrder::Lsb, 8); - let decode = decoder.into_async(&mut recv_buffer).decode_all(&mut recv); - - let (encode, decode) = tokio::join!(encode, decode); - encode.status.expect("Could send/encoded data"); - decode.status.expect("Could recv/decode data"); - - assert_eq!(recv_buffer, data); -} - -#[test] -fn with_streams() { - let file = env::args().next().unwrap(); - let data = fs::read(file).unwrap(); - - let rt = tokio::runtime::Runtime::new().expect("runtime"); - let _enter = rt.enter(); - - let (mut send, mut recv) = rt.block_on(pair()); - rt.block_on(assert_send_through(&data, &mut send, &mut recv)); -} diff --git a/vendor/weezl/tests/implicit_reset.rs b/vendor/weezl/tests/implicit_reset.rs deleted file mode 100644 index 69dd8a8..0000000 --- a/vendor/weezl/tests/implicit_reset.rs +++ /dev/null @@ -1,21 +0,0 @@ -use std::{env, fs}; -use weezl::{decode, encode, BitOrder}; - -#[test] -fn read_from_mangled() { - let file = env::args().next().unwrap(); - let data = fs::read(file).unwrap(); - - // For simplicity, encode 7-bit data. - let data: Vec<_> = data.iter().copied().map(|b| b & 0x7f).collect(); - - let mut encoder = encode::Encoder::new(BitOrder::Lsb, 7); - let mut buffer = Vec::with_capacity(2 * data.len() + 40); - let _ = encoder.into_stream(&mut buffer).encode_all(&*data); - - let mut decoder = decode::Decoder::new(BitOrder::Lsb, 7); - let mut compare = vec![]; - let result = decoder.into_stream(&mut compare).decode_all(&buffer[1..]); - assert!(result.status.is_ok(), "{:?}", result.status); - assert!(data == &*compare, "{:?}\n{:?}", data, compare); -} diff --git a/vendor/weezl/tests/roundtrip.rs b/vendor/weezl/tests/roundtrip.rs deleted file mode 100644 index f124fae..0000000 --- a/vendor/weezl/tests/roundtrip.rs +++ /dev/null @@ -1,66 +0,0 @@ -use std::{env, fs}; -use weezl::{decode, encode, BitOrder}; - -#[derive(Clone, Copy, Debug)] -enum Flavor { - Gif, - Tiff, -} - -#[test] -fn roundtrip_all() { - let file = env::args().next().unwrap(); - let data = fs::read(file).unwrap(); - - for &flavor in &[Flavor::Gif, Flavor::Tiff] { - for &bit_order in &[BitOrder::Lsb, BitOrder::Msb] { - for bit_width in 2..8 { - let data: Vec<_> = data - .iter() - .copied() - .map(|b| b & ((1 << bit_width) - 1)) - .collect(); - - println!("Roundtrip test {:?} {:?} {}", flavor, bit_order, bit_width); - assert_roundtrips(&*data, flavor, bit_width, bit_order); - } - } - } -} - -fn assert_roundtrips(data: &[u8], flavor: Flavor, bit_width: u8, bit_order: BitOrder) { - let (c, d): ( - fn(BitOrder, u8) -> encode::Encoder, - fn(BitOrder, u8) -> decode::Decoder, - ) = match flavor { - Flavor::Gif => (encode::Encoder::new, decode::Decoder::new), - Flavor::Tiff => ( - encode::Encoder::with_tiff_size_switch, - decode::Decoder::with_tiff_size_switch, - ), - }; - let mut encoder = c(bit_order, bit_width); - let mut buffer = Vec::with_capacity(2 * data.len() + 40); - let _ = encoder.into_stream(&mut buffer).encode_all(data); - - let mut decoder = d(bit_order, bit_width); - let mut compare = vec![]; - let result = decoder - .into_stream(&mut compare) - .decode_all(buffer.as_slice()); - assert!( - result.status.is_ok(), - "{:?}, {}, {:?}", - bit_order, - bit_width, - result.status - ); - assert!( - data == &*compare, - "{:?}, {}\n{:?}\n{:?}", - bit_order, - bit_width, - data, - compare - ); -} diff --git a/vendor/weezl/tests/roundtrip_vec.rs b/vendor/weezl/tests/roundtrip_vec.rs deleted file mode 100644 index d8bfd84..0000000 --- a/vendor/weezl/tests/roundtrip_vec.rs +++ /dev/null @@ -1,65 +0,0 @@ -use std::{env, fs}; -use weezl::{decode, encode, BitOrder}; - -#[derive(Clone, Copy, Debug)] -enum Flavor { - Gif, - Tiff, -} - -#[test] -fn roundtrip_all() { - let file = env::args().next().unwrap(); - let data = fs::read(file).unwrap(); - - for &flavor in &[Flavor::Gif, Flavor::Tiff] { - for &bit_order in &[BitOrder::Lsb, BitOrder::Msb] { - for bit_width in 2..8 { - let data: Vec<_> = data - .iter() - .copied() - .map(|b| b & ((1 << bit_width) - 1)) - .collect(); - - println!("Roundtrip test {:?} {:?} {}", flavor, bit_order, bit_width); - assert_roundtrips(&*data, flavor, bit_width, bit_order); - } - } - } -} - -fn assert_roundtrips(data: &[u8], flavor: Flavor, bit_width: u8, bit_order: BitOrder) { - let (c, d): ( - fn(BitOrder, u8) -> encode::Encoder, - fn(BitOrder, u8) -> decode::Decoder, - ) = match flavor { - Flavor::Gif => (encode::Encoder::new, decode::Decoder::new), - Flavor::Tiff => ( - encode::Encoder::with_tiff_size_switch, - decode::Decoder::with_tiff_size_switch, - ), - }; - let mut encoder = c(bit_order, bit_width); - let mut buffer = Vec::with_capacity(2 * data.len() + 40); - - let _ = encoder.into_vec(&mut buffer).encode_all(data); - - let mut decoder = d(bit_order, bit_width); - let mut compare = vec![]; - let result = decoder.into_vec(&mut compare).decode_all(buffer.as_slice()); - assert!( - result.status.is_ok(), - "{:?}, {}, {:?}", - bit_order, - bit_width, - result.status - ); - assert!( - data == &*compare, - "{:?}, {}\n{:?}\n{:?}", - bit_order, - bit_width, - data, - compare - ); -} |