From 0c42126b8f0e86928265503864d213c4f40faacc Mon Sep 17 00:00:00 2001 From: NikVolf Date: Tue, 12 Apr 2016 07:13:31 +0300 Subject: [PATCH] client handshake tests, errors --- ipc/codegen/src/codegen.rs | 11 +++++++---- ipc/rpc/src/interface.rs | 3 +++ ipc/tests/examples.rs | 15 +++++++++++++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/ipc/codegen/src/codegen.rs b/ipc/codegen/src/codegen.rs index 1be753103..7341cc220 100644 --- a/ipc/codegen/src/codegen.rs +++ b/ipc/codegen/src/codegen.rs @@ -512,7 +512,7 @@ fn push_client_implementation( } } - pub fn handshake(&self) -> bool { + pub fn handshake(&self) -> Result<(), ::ipc::Error> { let payload = BinHandshake { protocol_version: $item_ident::protocol_version().to_string(), api_version: $item_ident::api_version().to_string(), @@ -527,10 +527,13 @@ fn push_client_implementation( &mut socket); let mut result = vec![0u8; 1]; - if socket.read(&mut result).unwrap() == 1 { - result[0] == 1 + if try!(socket.read(&mut result).map_err(|_| ::ipc::Error::HandshakeFailed)) == 1 { + match result[0] { + 1 => Ok(()), + _ => Err(::ipc::Error::RemoteServiceUnsupported), + } } - else { false } + else { Err(::ipc::Error::HandshakeFailed) } } #[cfg(test)] diff --git a/ipc/rpc/src/interface.rs b/ipc/rpc/src/interface.rs index 5b5a30b27..a4e2b3c05 100644 --- a/ipc/rpc/src/interface.rs +++ b/ipc/rpc/src/interface.rs @@ -39,9 +39,12 @@ pub trait IpcConfig { } } +#[derive(Debug)] pub enum Error { UnkownSystemCall, ClientUnsupported, + RemoteServiceUnsupported, + HandshakeFailed, } pub trait IpcInterface where T: IpcConfig { diff --git a/ipc/tests/examples.rs b/ipc/tests/examples.rs index 9a5158830..931021d73 100644 --- a/ipc/tests/examples.rs +++ b/ipc/tests/examples.rs @@ -60,7 +60,7 @@ mod tests { #[test] - fn call_service_proxy() { + fn call_service_client() { let mut socket = TestSocket::new(); socket.read_buffer = vec![0, 0, 0, 10]; let service_client = ServiceClient::new(socket); @@ -72,7 +72,7 @@ mod tests { } #[test] - fn call_service_proxy_optional() { + fn call_service_client_optional() { let mut socket = TestSocket::new(); socket.read_buffer = vec![0, 0, 0, 10]; let service_client = ServiceClient::new(socket); @@ -90,4 +90,15 @@ mod tests { let ver = Service::api_version(); assert_eq!(ver, Version::parse("1.0.0").unwrap()); } + + #[test] + fn call_service_client_handshake() { + let mut socket = TestSocket::new(); + socket.read_buffer = vec![1]; + let service_client = ServiceClient::new(socket); + + let result = service_client.handshake(); + + assert!(result.is_ok()); + } }