public void StartAsync_ReceiveHeaderMismatch() { var str = new std_msgs.String(); var header = new { callerid = "test", topic = "mytopic", md5sum = "aaaaaaaaaaaaa", type = str.MessageType }; var stream = new MemoryStream(); TcpRosHeaderSerializer.Serialize(stream, header); MTcpRosClient.AllInstances.ConnectAsyncStringInt32 = (t1, t2, t3) => Task.Factory.StartNew(() => { }); MTcpRosClient.AllInstances.ReceiveAsyncInt32 = (t1, t2) => Observable.Return(stream.ToArray()); MTcpRosClient.AllInstances.SendAsyncByteArray = (t1, t2) => Task <int> .Factory.StartNew(() => t2.Length); var server = new RosTopicServer <std_msgs.String>("mynode", "mytopic", new Uri("http://localhost")); var task = server.StartAsync(new TopicParam() { HostName = "test", PortNumber = 1234, ProtocolName = "TCPROS" }); var ex = AssertEx.Throws <AggregateException>(() => task.Wait()); ex.InnerException.GetType().Is(typeof(RosTopicException)); ex.InnerException.Message.Is("MD5Sum mismatch error"); }
public void StartAsync_ReceiveHeaderMismatch() { var str = new std_msgs.String(); var header = new { callerid = "test", topic = "mytopic", md5sum = "aaaaaaaaaaaaa", type = str.MessageType }; var stream = new MemoryStream(); TcpRosHeaderSerializer.Serialize(stream, header); MTcpRosClient.AllInstances.ConnectAsyncStringInt32 = (t1, t2, t3) => Task.Factory.StartNew(() => { }); MTcpRosClient.AllInstances.ReceiveAsyncInt32 = (t1, t2) => Observable.Return(stream.ToArray()); MTcpRosClient.AllInstances.SendAsyncByteArray = (t1, t2) => Task<int>.Factory.StartNew(() => t2.Length); var server = new RosTopicServer<std_msgs.String>("mynode", "mytopic", new Uri("http://localhost")); var task = server.StartAsync(new TopicParam() { HostName = "test", PortNumber = 1234, ProtocolName = "TCPROS" }); var ex = AssertEx.Throws<AggregateException>(() => task.Wait()); ex.InnerException.GetType().Is(typeof(RosTopicException)); ex.InnerException.Message.Is("MD5Sum mismatch error"); }
public void StartAsync_ConnectionError() { var server = new RosTopicServer<std_msgs.String>("mynode", "mytopic", new Uri("http://localhost")); var task = server.StartAsync(new TopicParam() {HostName = "test", PortNumber = 1234, ProtocolName = "TCPROS"}); var ex = AssertEx.Throws<AggregateException>(() => task.Wait()); ex.InnerException.GetType().Is(typeof (SocketException)); }
public void StartAsync_Success() { var str = new std_msgs.String() { data = "test message" }; var header = new { callerid = "test", topic = "mytopic", md5sum = str.Md5Sum, type = str.MessageType }; var headerStream = new MemoryStream(); TcpRosHeaderSerializer.Serialize(headerStream, header); var dataStream = new MemoryStream(); var bw = new BinaryWriter(dataStream); bw.Write(str.SerializeLength); str.Serialize(bw); MTcpRosClient.AllInstances.ConnectAsyncStringInt32 = (t1, t2, t3) => Task.Factory.StartNew(() => { }); // 1.Receive Header, 2.Receive Data(std_msgs.String) int count = 0; MTcpRosClient.AllInstances.ReceiveAsyncInt32 = (t1, t2) => { if (count == 0) { count++; return(Observable.Return(headerStream.ToArray())); } else { return(Observable.Return(dataStream.ToArray())); } }; MTcpRosClient.AllInstances.SendAsyncByteArray = (t1, t2) => Task <int> .Factory.StartNew(() => t2.Length); var server = new RosTopicServer <std_msgs.String>("mynode", "mytopic", new Uri("http://localhost")); var task = server.StartAsync(new TopicParam() { HostName = "test", PortNumber = 1234, ProtocolName = "TCPROS" }); var subscriber = task.Result; var rec = subscriber.Timeout(TimeSpan.FromSeconds(3)).First(); rec.data.Is("test message"); }
public void StartAsync_ConnectionError() { var server = new RosTopicServer <std_msgs.String>("mynode", "mytopic", new Uri("http://localhost")); var task = server.StartAsync(new TopicParam() { HostName = "test", PortNumber = 1234, ProtocolName = "TCPROS" }); var ex = AssertEx.Throws <AggregateException>(() => task.Wait()); ex.InnerException.GetType().Is(typeof(SocketException)); }
public void StartAsync_HeaderDeserializeError() { MTcpRosClient.AllInstances.ConnectAsyncStringInt32 = (t1, t2, t3) => Task.Factory.StartNew(() => { }); MTcpRosClient.AllInstances.ReceiveAsyncInt32 = (t1, t2) => Observable.Return(new byte[0]); MTcpRosClient.AllInstances.SendAsyncByteArray = (t1, t2) => Task<int>.Factory.StartNew(() => t2.Length); var server = new RosTopicServer<std_msgs.String>("mynode", "mytopic", new Uri("http://localhost")); var task = server.StartAsync(new TopicParam() { HostName = "test", PortNumber = 1234, ProtocolName = "TCPROS" }); var ex = AssertEx.Throws<AggregateException>(() => task.Wait()); ex.InnerException.GetType().Is(typeof(RosTopicException)); ex.InnerException.Message.Is("Stream length is too short"); }
public void StartAsync_SendAsyncError() { MTcpRosClient.AllInstances.ConnectAsyncStringInt32 = (t1, t2, t3) => Task.Factory.StartNew(() => { }); MTcpRosClient.AllInstances.ReceiveAsyncInt32 = (t1, t2) => Observable.Return(new byte[0]); var server = new RosTopicServer <std_msgs.String>("mynode", "mytopic", new Uri("http://localhost")); var task = server.StartAsync(new TopicParam() { HostName = "test", PortNumber = 1234, ProtocolName = "TCPROS" }); var ex = AssertEx.Throws <AggregateException>(() => task.Wait()); ex.InnerException.GetType().Is(typeof(ArgumentException)); }
public void StartAsync_ReceiveHeaderTimeoutError() { Ros.TopicTimeout = 100; MTcpRosClient.AllInstances.ConnectAsyncStringInt32 = (t1, t2, t3) => Task.Factory.StartNew(() => { }); MTcpRosClient.AllInstances.ReceiveAsyncInt32 = (t1, t2) => Observable.Return(new byte[0]).Delay(TimeSpan.FromSeconds(3)); MTcpRosClient.AllInstances.SendAsyncByteArray = (t1, t2) => Task <int> .Factory.StartNew(() => t2.Length); var server = new RosTopicServer <std_msgs.String>("mynode", "mytopic", new Uri("http://localhost")); var task = server.StartAsync(new TopicParam() { HostName = "test", PortNumber = 1234, ProtocolName = "TCPROS" }); var ex = AssertEx.Throws <AggregateException>(() => task.Wait()); ex.InnerException.GetType().Is(typeof(TimeoutException)); }
public void StartAsync_ReceiveHeaderTimeoutError() { Ros.TopicTimeout = 100; MTcpRosClient.AllInstances.ConnectAsyncStringInt32 = (t1, t2, t3) => Task.Factory.StartNew(() => { }); MTcpRosClient.AllInstances.ReceiveAsyncInt32 = (t1, t2) => Observable.Return(new byte[0]).Delay(TimeSpan.FromSeconds(3)); MTcpRosClient.AllInstances.SendAsyncByteArray = (t1, t2) => Task<int>.Factory.StartNew(() => t2.Length); var server = new RosTopicServer<std_msgs.String>("mynode", "mytopic", new Uri("http://localhost")); var task = server.StartAsync(new TopicParam() {HostName = "test", PortNumber = 1234, ProtocolName = "TCPROS"}); var ex = AssertEx.Throws<AggregateException>(() => task.Wait()); ex.InnerException.GetType().Is(typeof (TimeoutException)); }
public void StartAsync_Success() { var str = new std_msgs.String(){data = "test message"}; var header = new { callerid = "test", topic = "mytopic", md5sum = str.Md5Sum, type = str.MessageType }; var headerStream = new MemoryStream(); TcpRosHeaderSerializer.Serialize(headerStream, header); var dataStream = new MemoryStream(); var bw = new BinaryWriter(dataStream); bw.Write(str.SerializeLength); str.Serialize(bw); MTcpRosClient.AllInstances.ConnectAsyncStringInt32 = (t1, t2, t3) => Task.Factory.StartNew(() => { }); // 1.Receive Header, 2.Receive Data(std_msgs.String) int count = 0; MTcpRosClient.AllInstances.ReceiveAsyncInt32 = (t1, t2) => { if(count == 0) { count++; return Observable.Return(headerStream.ToArray()); } else { return Observable.Return(dataStream.ToArray()); } }; MTcpRosClient.AllInstances.SendAsyncByteArray = (t1, t2) => Task<int>.Factory.StartNew(() => t2.Length); var server = new RosTopicServer<std_msgs.String>("mynode", "mytopic", new Uri("http://localhost")); var task = server.StartAsync(new TopicParam() { HostName = "test", PortNumber = 1234, ProtocolName = "TCPROS" }); var subscriber = task.Result; var rec = subscriber.Timeout(TimeSpan.FromSeconds(3)).First(); rec.data.Is("test message"); }