client handshake tests, errors
This commit is contained in:
parent
edba351335
commit
a8bd7d07df
@ -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)]
|
||||
|
@ -39,9 +39,12 @@ pub trait IpcConfig {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
UnkownSystemCall,
|
||||
ClientUnsupported,
|
||||
RemoteServiceUnsupported,
|
||||
HandshakeFailed,
|
||||
}
|
||||
|
||||
pub trait IpcInterface<T> where T: IpcConfig {
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user