1
1
use super :: * ;
2
2
use bytes:: { Bytes , BytesMut } ;
3
- use std:: collections:: HashMap ;
3
+ // use std::collections::HashMap;
4
4
5
5
#[ test]
6
6
fn test_basic ( ) -> Result < ( ) > {
@@ -53,8 +53,8 @@ fn test_basic() -> Result<()> {
53
53
"wrong computed marshal size"
54
54
) ;
55
55
56
- let mut raw = BytesMut :: new ( ) ;
57
- let n = packet . marshal_to ( & mut raw ) ? ;
56
+ let raw = packet . marshal ( ) ? ;
57
+ let n = raw . len ( ) ;
58
58
assert_eq ! ( n, raw_pkt. len( ) , "wrong marshal size" ) ;
59
59
60
60
assert_eq ! (
@@ -115,6 +115,9 @@ fn test_extension() -> Result<()> {
115
115
result. is_err( ) ,
116
116
"Marshal did not error on packet with invalid extension length"
117
117
) ;
118
+ if let Err ( err) = result {
119
+ assert ! ( Error :: ErrBufferTooSmall . equal( & err) ) ;
120
+ }
118
121
119
122
Ok ( ( ) )
120
123
}
@@ -158,12 +161,8 @@ fn test_packet_marshal_unmarshal() -> Result<()> {
158
161
payload : Bytes :: from_static ( & [ 0xFFu8 ; 15 ] ) ,
159
162
..Default :: default ( )
160
163
} ;
161
- let mut raw = BytesMut :: new ( ) ;
162
- let _ = pkt. marshal_to ( & mut raw) ?;
163
-
164
- let raw = raw. freeze ( ) ;
165
- let buf = & mut raw. clone ( ) ;
166
- let p = Packet :: unmarshal ( buf) ?;
164
+ let mut raw = pkt. marshal ( ) ?;
165
+ let p = Packet :: unmarshal ( & mut raw) ?;
167
166
168
167
assert_eq ! ( pkt, p) ;
169
168
@@ -199,8 +198,7 @@ fn test_rfc8285_one_byte_extension() -> Result<()> {
199
198
payload : raw_pkt. slice ( 20 ..) ,
200
199
} ;
201
200
202
- let mut dst = BytesMut :: new ( ) ;
203
- let _ = p. marshal_to ( & mut dst) ?;
201
+ let dst = p. marshal ( ) ?;
204
202
assert_eq ! ( dst, raw_pkt) ;
205
203
206
204
Ok ( ( ) )
@@ -266,8 +264,7 @@ fn test_rfc8285_one_byte_two_extension_of_two_bytes() -> Result<()> {
266
264
payload : raw_pkt. slice ( 20 ..) ,
267
265
} ;
268
266
269
- let mut dst = BytesMut :: new ( ) ;
270
- let _ = p. marshal_to ( & mut dst) ?;
267
+ let dst = p. marshal ( ) ?;
271
268
assert_eq ! ( dst, raw_pkt) ;
272
269
273
270
Ok ( ( ) )
@@ -329,7 +326,7 @@ fn test_rfc8285_one_byte_multiple_extensions_with_padding() -> Result<()> {
329
326
0x98 , 0x36 , 0xbe , 0x88 , 0x9e ,
330
327
] ;
331
328
332
- let checker = |name : & str , buf : & mut [ u8 ] , p : & mut Packet | -> Result < ( ) > {
329
+ let checker = |name : & str , buf : & mut [ u8 ] , p : & Packet | -> Result < ( ) > {
333
330
let size = p. marshal_to ( buf) ?;
334
331
335
332
assert_eq ! (
@@ -342,8 +339,16 @@ fn test_rfc8285_one_byte_multiple_extensions_with_padding() -> Result<()> {
342
339
Ok ( ( ) )
343
340
} ;
344
341
345
- checker ( "CleanBuffer" , & mut dst_buf[ 0 ] , & mut p) ?;
346
- checker ( "DirtyBuffer" , & mut dst_buf[ 1 ] , & mut p)
342
+ checker ( "CleanBuffer" , & mut dst_buf[ 0 ] , & packet) ?;
343
+ checker ( "DirtyBuffer" , & mut dst_buf[ 1 ] , & packet) ?;
344
+
345
+ let result = packet. marshal_to ( & mut dst_buf[ 2 ] ) ;
346
+ assert ! ( result. is_err( ) ) ;
347
+ if let Err ( err) = result {
348
+ assert ! ( Error :: ErrBufferTooSmall . equal( & err) ) ;
349
+ }
350
+
351
+ Ok ( ( ) )
347
352
}
348
353
349
354
/*
0 commit comments