little test

This commit is contained in:
NikVolf 2016-04-13 13:46:49 +03:00
parent 987b84c530
commit 08874e8483
2 changed files with 23 additions and 3 deletions

View File

@ -101,4 +101,24 @@ mod tests {
assert!(result.is_ok());
}
#[test]
fn can_use_custom_params() {
let mut socket = TestSocket::new();
socket.read_buffer = vec![1];
let service_client = ServiceClient::init(socket);
let result = service_client.push_custom(CustomData { a: 3, b: 11});
assert_eq!(vec![
// message num..
0, 18,
// payload length
0, 0, 0, 0, 0, 0, 0, 16,
// structure raw bytes (bigendians :( )
3, 0, 0, 0, 0, 0, 0, 0,
11, 0, 0, 0, 0, 0, 0, 0],
service_client.socket().borrow().write_buffer.clone());
assert_eq!(true, result);
}
}

View File

@ -26,8 +26,8 @@ pub struct Service {
}
pub struct CustomData {
a: usize,
b: usize,
pub a: usize,
pub b: usize,
}
impl FromRawBytes for CustomData {
@ -46,7 +46,7 @@ impl BytesConvertable for CustomData {
unsafe {
::std::slice::from_raw_parts(
ptr,
::std::mem::size_of::<i64>()
::std::mem::size_of::<CustomData>()
)
}
}