예제 #1
0
        public void StartAsync_SendHeaderError()
        {
            var str    = new std_msgs.String();
            var header = new
            {
                callerid = "test",
                topic    = "mytopic",
                md5sum   = str.Md5Sum,
                type     = str.MessageType
            };
            var stream = new MemoryStream();

            TcpRosHeaderSerializer.Serialize(stream, header);

            MTcpRosClient.AllInstances.ReceiveAsyncInt32  = (t1, t2) => Observable.Return(stream.ToArray());
            MTcpRosClient.AllInstances.SendAsyncByteArray = (t1, t2) => { throw new InvalidOperationException("Send Error"); };

            var sock  = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            var topic = new RosTopicClient <std_msgs.String>("mynode", "mytopic");

            var ex = AssertEx.Throws <AggregateException>(() => topic.StartAsync(sock).Wait());

            ex.InnerException.GetType().Is(typeof(InvalidOperationException));
            ex.InnerException.Message.Is("Send Error");
        }
예제 #2
0
        public void SendTaskAsync_Success()
        {
            var str    = new std_msgs.String();
            var header = new
            {
                callerid = "test",
                topic    = "mytopic",
                md5sum   = str.Md5Sum,
                type     = str.MessageType
            };
            var stream = new MemoryStream();

            TcpRosHeaderSerializer.Serialize(stream, header);

            MTcpRosClient.AllInstances.ReceiveAsyncInt32  = (t1, t2) => Observable.Return(stream.ToArray());
            MTcpRosClient.AllInstances.SendAsyncByteArray = (t1, t2) => Task.Factory.StartNew(() => t2.Length);

            var sock  = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            var topic = new RosTopicClient <std_msgs.String>("mynode", "mytopic");

            topic.StartAsync(sock).Wait();
            topic.SendAsync(new std_msgs.String()
            {
                data = "test"
            }).Result.Is(12);
        }
예제 #3
0
        public void StartAsync_ReceiveError()
        {
            MTcpRosClient.AllInstances.ReceiveAsyncInt32 = (t1, t2) => { throw new InvalidOperationException("Receive Error"); };

            var sock  = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            var topic = new RosTopicClient <std_msgs.String>("mynode", "mytopic");

            var ex = AssertEx.Throws <InvalidOperationException>(() => topic.StartAsync(sock).Wait());

            //ex.InnerException.GetType().Is(typeof(InvalidOperationException));
            ex.Message.Is("Receive Error");
        }
예제 #4
0
        public void StartAsync_ReceiveTimeoutError()
        {
            Ros.TopicTimeout = 100;

            MTcpRosClient.AllInstances.ReceiveAsyncInt32 = (t1, t2) =>
                                                           Observable.Return(new byte[0]).Delay(TimeSpan.FromSeconds(3));

            var sock  = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            var topic = new RosTopicClient <std_msgs.String>("mynode", "mytopic");

            var ex = AssertEx.Throws <AggregateException>(() => topic.StartAsync(sock).Wait());

            ex.InnerException.GetType().Is(typeof(TimeoutException));
        }
예제 #5
0
        public void StartAsync_ReceiveHeaderNotEnoughtMemberError()
        {
            var str    = new std_msgs.String();
            var header = new
            {
                callerid = "test",
                type     = str.MessageType
            };
            var stream = new MemoryStream();

            TcpRosHeaderSerializer.Serialize(stream, header);

            MTcpRosClient.AllInstances.ReceiveAsyncInt32 = (t1, t2) => Observable.Return(stream.ToArray());

            var sock  = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            var topic = new RosTopicClient <std_msgs.String>("mynode", "mytopic");

            var ex = AssertEx.Throws <AggregateException>(() => topic.StartAsync(sock).Wait());

            ex.InnerException.GetType().Is(typeof(RuntimeBinderException));
        }