@@ -13,6 +13,8 @@ impl Writer for VecWriter {
13
13
}
14
14
}
15
15
16
+ // Tests a message that must survive roundtrip exactly, though may not empty the read buffer
17
+ // entirely
16
18
#[ macro_export]
17
19
macro_rules! test_msg {
18
20
( $MsgType: path, $data: ident) => {
@@ -31,6 +33,8 @@ macro_rules! test_msg {
31
33
}
32
34
}
33
35
36
+ // Tests a message that may lose data on roundtrip, but shoulnd't lose data compared to our
37
+ // re-serialization.
34
38
#[ macro_export]
35
39
macro_rules! test_msg_simple {
36
40
( $MsgType: path, $data: ident) => {
@@ -40,11 +44,18 @@ macro_rules! test_msg_simple {
40
44
if let Ok ( msg) = <$MsgType as Readable <:: std:: io:: Cursor <& [ u8 ] >>>:: read( & mut r) {
41
45
let mut w = VecWriter ( Vec :: new( ) ) ;
42
46
msg. write( & mut w) . unwrap( ) ;
47
+
48
+ let msg = <$MsgType as Readable <:: std:: io:: Cursor <& [ u8 ] >>>:: read( & mut :: std:: io:: Cursor :: new( & w. 0 ) ) . unwrap( ) ;
49
+ let mut w_two = VecWriter ( Vec :: new( ) ) ;
50
+ msg. write( & mut w_two) . unwrap( ) ;
51
+ assert_eq!( & w. 0 [ ..] , & w_two. 0 [ ..] ) ;
43
52
}
44
53
}
45
54
}
46
55
}
47
56
57
+ // Tests a message that must survive roundtrip exactly, and must exactly empty the read buffer and
58
+ // split it back out on re-serialization.
48
59
#[ macro_export]
49
60
macro_rules! test_msg_exact {
50
61
( $MsgType: path, $data: ident) => {
@@ -54,13 +65,14 @@ macro_rules! test_msg_exact {
54
65
if let Ok ( msg) = <$MsgType as Readable <:: std:: io:: Cursor <& [ u8 ] >>>:: read( & mut r) {
55
66
let mut w = VecWriter ( Vec :: new( ) ) ;
56
67
msg. write( & mut w) . unwrap( ) ;
57
-
58
68
assert_eq!( & r. into_inner( ) [ ..] , & w. 0 [ ..] ) ;
59
69
}
60
70
}
61
71
}
62
72
}
63
73
74
+ // Tests a message that must survive roundtrip exactly, modulo one "hole" which may be set to 0s on
75
+ // re-serialization.
64
76
#[ macro_export]
65
77
macro_rules! test_msg_hole {
66
78
( $MsgType: path, $data: ident, $hole: expr, $hole_len: expr) => {
0 commit comments