1 use futures::Future;
2 use partial_io::{GenWouldBlock, PartialAsyncRead, PartialWithErrors};
3 use quickcheck::quickcheck;
4 use std::io::{self, Cursor};
5 use tokio_io::{AsyncRead, AsyncWrite};
6 
7 #[test]
test_async_read()8 fn test_async_read() {
9     use crate::stream::encode_all;
10 
11     let source = "abc".repeat(1024 * 10).into_bytes();
12     let encoded = encode_all(&source[..], 1).unwrap();
13     let writer =
14         test_async_read_worker(&encoded[..], Cursor::new(Vec::new())).unwrap();
15     let output = writer.into_inner();
16     assert_eq!(source, output);
17 }
18 
19 #[test]
test_async_read_partial()20 fn test_async_read_partial() {
21     quickcheck(test as fn(_) -> _);
22 
23     // This used to test for Interrupted errors as well.
24     // But right now a solution to silently ignore Interrupted error
25     // would not compile.
26     // Plus, it's still not clear it's a good idea.
27     fn test(encode_ops: PartialWithErrors<GenWouldBlock>) {
28         use crate::stream::encode_all;
29 
30         let source = "abc".repeat(1024 * 10).into_bytes();
31         let encoded = encode_all(&source[..], 1).unwrap();
32         let reader = PartialAsyncRead::new(&encoded[..], encode_ops);
33         let writer =
34             test_async_read_worker(reader, Cursor::new(Vec::new())).unwrap();
35         let output = writer.into_inner();
36         assert_eq!(source, output);
37     }
38 }
39 
test_async_read_worker<R: AsyncRead, W: AsyncWrite>( r: R, w: W, ) -> io::Result<W>40 fn test_async_read_worker<R: AsyncRead, W: AsyncWrite>(
41     r: R,
42     w: W,
43 ) -> io::Result<W> {
44     use super::Decoder;
45 
46     let decoder = Decoder::new(r).unwrap();
47     let (_, _, w) = tokio_io::io::copy(decoder, w).wait()?;
48     Ok(w)
49 }
50