Debian Codegraph @

src/stream/write/tests.rs

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 use std::io::{Cursor, Write};
2 use std::iter;
3
4 use crate::stream::decode_all;
5 use crate::stream::write::{Decoder, Encoder};
6
7 #[test]
8 fn test_cycle() {
9 let input = b"Abcdefghabcdefgh";
10
11 let buffer = Cursor::new(Vec::new());
12 let mut encoder = Encoder::new(buffer, 1).unwrap();
13 encoder.write_all(input).unwrap();
14 let encoded = encoder.finish().unwrap().into_inner();
15
16 // println!("Encoded: {:?}", encoded);
17
18 let buffer = Cursor::new(Vec::new());
19 let mut decoder = Decoder::new(buffer).unwrap();
20 decoder.write_all(&encoded).unwrap();
21 decoder.flush().unwrap();
22 let decoded = decoder.into_inner().into_inner();
23
24 assert_eq!(input, &decoded[..]);
25 }
26
•27 /*
28 /// Test that flush after a partial write works successfully without
29 /// corrupting the frame. This test is in this module because it checks
30 /// internal implementation details.
31 #[test]
32 fn test_partial_write_flush() {
33 let input = vec![b'b'; 128 * 1024];
34 let mut z = setup_partial_write(&input);
35
36 // flush shouldn't corrupt the stream
37 z.flush().unwrap();
38
39 let buf = z.finish().unwrap().into_inner();
40 assert_eq!(&decode_all(&buf[..]).unwrap(), &input);
41 }
42
43 /// Test that finish after a partial write works successfully without
44 /// corrupting the frame. This test is in this module because it checks
45 /// internal implementation details.
46 #[test]
47 fn test_partial_write_finish() {
48 let input = vec![b'b'; 128 * 1024];
49 let z = setup_partial_write(&input);
50
51 // finish shouldn't corrupt the stream
52 let buf = z.finish().unwrap().into_inner();
53 assert_eq!(&decode_all(&buf[..]).unwrap(), &input);
54 }
55
56 fn setup_partial_write(input_data: &[u8]) -> Encoder<PartialWrite<Vec<u8>>> {
57 let buf =
58 PartialWrite::new(Vec::new(), iter::repeat(PartialOp::Limited(1)));
59 let mut z = Encoder::new(buf, 1).unwrap();
60
61 // Fill in enough data to make sure the buffer gets written out.
62 z.write(input_data).unwrap();
63
64 {
65 let inner = &mut z.writer;
66 // At this point, the internal buffer in z should have some data.
67 assert_ne!(inner.offset(), inner.buffer().len());
68 }
69
70 z
•71 }*/