client handshake tests, errors

This commit is contained in:
NikVolf 2016-04-12 07:13:31 +03:00
parent edba351335
commit a8bd7d07df
3 changed files with 23 additions and 6 deletions

View File

@ -512,7 +512,7 @@ fn push_client_implementation(
} }
} }
pub fn handshake(&self) -> bool { pub fn handshake(&self) -> Result<(), ::ipc::Error> {
let payload = BinHandshake { let payload = BinHandshake {
protocol_version: $item_ident::protocol_version().to_string(), protocol_version: $item_ident::protocol_version().to_string(),
api_version: $item_ident::api_version().to_string(), api_version: $item_ident::api_version().to_string(),
@ -527,10 +527,13 @@ fn push_client_implementation(
&mut socket); &mut socket);
let mut result = vec![0u8; 1]; let mut result = vec![0u8; 1];
if socket.read(&mut result).unwrap() == 1 { if try!(socket.read(&mut result).map_err(|_| ::ipc::Error::HandshakeFailed)) == 1 {
result[0] == 1 match result[0] {
1 => Ok(()),
_ => Err(::ipc::Error::RemoteServiceUnsupported),
}
} }
else { false } else { Err(::ipc::Error::HandshakeFailed) }
} }
#[cfg(test)] #[cfg(test)]

View File

@ -39,9 +39,12 @@ pub trait IpcConfig {
} }
} }
#[derive(Debug)]
pub enum Error { pub enum Error {
UnkownSystemCall, UnkownSystemCall,
ClientUnsupported, ClientUnsupported,
RemoteServiceUnsupported,
HandshakeFailed,
} }
pub trait IpcInterface<T> where T: IpcConfig { pub trait IpcInterface<T> where T: IpcConfig {

View File

@ -60,7 +60,7 @@ mod tests {
#[test] #[test]
fn call_service_proxy() { fn call_service_client() {
let mut socket = TestSocket::new(); let mut socket = TestSocket::new();
socket.read_buffer = vec![0, 0, 0, 10]; socket.read_buffer = vec![0, 0, 0, 10];
let service_client = ServiceClient::new(socket); let service_client = ServiceClient::new(socket);
@ -72,7 +72,7 @@ mod tests {
} }
#[test] #[test]
fn call_service_proxy_optional() { fn call_service_client_optional() {
let mut socket = TestSocket::new(); let mut socket = TestSocket::new();
socket.read_buffer = vec![0, 0, 0, 10]; socket.read_buffer = vec![0, 0, 0, 10];
let service_client = ServiceClient::new(socket); let service_client = ServiceClient::new(socket);
@ -90,4 +90,15 @@ mod tests {
let ver = Service::api_version(); let ver = Service::api_version();
assert_eq!(ver, Version::parse("1.0.0").unwrap()); 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());
}
} }