예제 #1
0
        public async void CommunicationDeviceSerializerBatchTest()
        {
            Regulus.Serialization.ISerializer serializer = new Regulus.Serialization.Dynamic.Serializer();
            Stream      cd   = new Regulus.Remote.Standalone.Stream();
            IStreamable peer = cd;

            byte[] buf = serializer.ServerToClient(ServerToClientOpCode.LoadSoul, new Regulus.Remote.PackageLoadSoul()
            {
                EntityId = 1, ReturnType = false, TypeId = 1
            });

            await cd.Push(buf, 0, 1);

            await cd.Push(buf, 1, buf.Length - 1);

            byte[] recvBuf = new byte[buf.Length];
            await peer.Receive(recvBuf, 0, recvBuf.Length);

            await peer.Receive(recvBuf, 1, recvBuf.Length - 1);

            ResponsePackage responsePkg = serializer.Deserialize(recvBuf) as ResponsePackage;
            PackageLoadSoul lordsoulPkg = serializer.Deserialize(responsePkg.Data) as PackageLoadSoul;

            Assert.Equal(ServerToClientOpCode.LoadSoul, responsePkg.Code);
            Assert.Equal(1, lordsoulPkg.EntityId);
            Assert.False(lordsoulPkg.ReturnType);
            Assert.Equal(1, lordsoulPkg.TypeId);
        }
예제 #2
0
        public void ServiceTest()
        {
            Stream      serverPeerStream = new Regulus.Remote.Standalone.Stream();
            IStreamable serverStream     = serverPeerStream;
            IStreamable clientStream     = new ReverseStream(serverPeerStream);

            IBinderProvider entry = NSubstitute.Substitute.For <IBinderProvider>();
            IGpiA           gpia  = new SoulGpiA();

            entry.AssignBinder(NSubstitute.Arg.Do <IBinder>(binder => binder.Bind <IGpiA>(gpia)), NSubstitute.Arg.Any <object>());

            Serialization.ISerializer serializer = new Regulus.Serialization.Dynamic.Serializer();
            IProtocol protocol = ProtocolHelper.CreateProtocol(serializer);

            Soul.IService service   = new Regulus.Remote.Soul.Service(entry, protocol);
            IAgent        agent     = new Regulus.Remote.Ghost.Agent(protocol) as Ghost.IAgent;
            IGpiA         ghostGpia = null;


            service.Join(serverStream);
            agent.Start(clientStream);
            agent.QueryNotifier <IGpiA>().Supply += gpi => ghostGpia = gpi;

            while (ghostGpia == null)
            {
                agent.Update();
            }

            agent.Stop();
            service.Leave(serverStream);

            IDisposable disposable = service;

            disposable.Dispose();
        }
예제 #3
0
        public void AgentSupplyGpiTest()
        {
            IGpiA retGpiA = null;

            Regulus.Serialization.ISerializer serializer = new Regulus.Serialization.Dynamic.Serializer();
            IProtocol protocol = ProtocolHelper.CreateProtocol(serializer);

            Stream cdClient = new Regulus.Remote.Standalone.Stream();

            Network.IStreamable             peerClient = cdClient;
            PackageWriter <ResponsePackage> writer     = new PackageWriter <ResponsePackage>(serializer);

            writer.Start(new ReverseStream(cdClient));

            Ghost.IAgent agent = new Regulus.Remote.Ghost.Agent(protocol) as Ghost.IAgent;
            agent.QueryNotifier <IGpiA>().Supply += gpi => retGpiA = gpi;
            agent.Start(peerClient);

            writer.ServerToClient(serializer, ServerToClientOpCode.LoadSoul, new Regulus.Remote.PackageLoadSoul()
            {
                EntityId = 1, ReturnType = false, TypeId = 1
            });
            writer.ServerToClient(serializer, ServerToClientOpCode.LoadSoulCompile, new Regulus.Remote.PackageLoadSoulCompile()
            {
                EntityId = 1, TypeId = 1, ReturnId = 0, PassageId = 0
            });
            while (retGpiA == null)
            {
                agent.Update();
            }
            agent.Stop();
            writer.Stop();
            Assert.AreNotEqual(null, retGpiA);
        }
예제 #4
0
        public void CommunicationDevicePushTest()
        {
            byte[] sendBuf = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            byte[] recvBuf = new byte[10];

            Stream      cd   = new Regulus.Remote.Standalone.Stream();
            IStreamable peer = cd as IStreamable;

            cd.Push(sendBuf, 0, sendBuf.Length);
            System.Threading.Tasks.Task <int> receiveResult1 = peer.Receive(recvBuf, 0, 4);
            System.Threading.Tasks.Task <int> receiveResult2 = peer.Receive(recvBuf, 4, 6);

            int receiveCount1 = receiveResult1.GetAwaiter().GetResult();
            int receiveCount2 = receiveResult2.GetAwaiter().GetResult();

            Assert.AreEqual(4, receiveCount1);
            Assert.AreEqual(6, receiveCount2);
        }
예제 #5
0
        public async System.Threading.Tasks.Task CommunicationDevicePushTest()
        {
            byte[] sendBuf = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            byte[] recvBuf = new byte[10];

            Stream      cd   = new Regulus.Remote.Standalone.Stream();
            IStreamable peer = cd as IStreamable;
            await cd.Push(sendBuf, 0, sendBuf.Length);


            int receiveCount1 = await peer.Receive(recvBuf, 0, 4);

            int receiveCount2 = await peer.Receive(recvBuf, 4, 5);

            int receiveCount3 = await peer.Receive(recvBuf, 9, 2);

            Assert.Equal(4, receiveCount1);
            Assert.Equal(5, receiveCount2);
            Assert.Equal(1, receiveCount3);
        }
예제 #6
0
        public async void CommunicationDevicePopTest()
        {
            byte[] sendBuf = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            byte[] recvBuf = new byte[10];

            Stream      cd   = new Regulus.Remote.Standalone.Stream();
            IStreamable peer = cd as IStreamable;

            var result1     = peer.Send(sendBuf, 0, 4);
            int sendResult1 = await result1;

            var result2     = peer.Send(sendBuf, 4, 6);
            int sendResult2 = await result2;


            var streamTask1 = cd.Pop(recvBuf, 0, 3);
            int stream1     = await streamTask1;

            var streamTask2 = cd.Pop(recvBuf, stream1, recvBuf.Length - stream1);
            int stream2     = await streamTask2;

            var streamTask3 = cd.Pop(recvBuf, stream1 + stream2, recvBuf.Length - (stream1 + stream2));
            int stream3     = await streamTask3;



            Assert.Equal(10, stream3 + stream2 + stream1);
            Assert.Equal((byte)0, recvBuf[0]);
            Assert.Equal((byte)1, recvBuf[1]);
            Assert.Equal((byte)2, recvBuf[2]);
            Assert.Equal((byte)3, recvBuf[3]);
            Assert.Equal((byte)4, recvBuf[4]);
            Assert.Equal((byte)5, recvBuf[5]);
            Assert.Equal((byte)6, recvBuf[6]);
            Assert.Equal((byte)7, recvBuf[7]);
            Assert.Equal((byte)8, recvBuf[8]);
            Assert.Equal((byte)9, recvBuf[9]);
        }
예제 #7
0
        public void CommunicationDevicePopTest()
        {
            byte[] sendBuf = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            byte[] recvBuf = new byte[10];

            Stream      cd   = new Regulus.Remote.Standalone.Stream();
            IStreamable peer = cd as IStreamable;

            System.Threading.Tasks.Task <int> result1 = peer.Send(sendBuf, 0, 4);
            int sendResult1 = result1.GetAwaiter().GetResult();

            System.Threading.Tasks.Task <int> result2 = peer.Send(sendBuf, 4, 6);
            int sendResult2 = result2.GetAwaiter().GetResult();


            System.Threading.Tasks.Task <int> streamTask1 = cd.Pop(recvBuf, 0, 3);
            int stream1 = streamTask1.GetAwaiter().GetResult();

            System.Threading.Tasks.Task <int> streamTask2 = cd.Pop(recvBuf, stream1, recvBuf.Length - stream1);
            int stream2 = streamTask2.GetAwaiter().GetResult();

            System.Threading.Tasks.Task <int> streamTask3 = cd.Pop(recvBuf, stream1 + stream2, recvBuf.Length - (stream1 + stream2));
            int stream3 = streamTask3.GetAwaiter().GetResult();



            Assert.AreEqual(10, stream3 + stream2 + stream1);
            Assert.AreEqual((byte)0, recvBuf[0]);
            Assert.AreEqual((byte)1, recvBuf[1]);
            Assert.AreEqual((byte)2, recvBuf[2]);
            Assert.AreEqual((byte)3, recvBuf[3]);
            Assert.AreEqual((byte)4, recvBuf[4]);
            Assert.AreEqual((byte)5, recvBuf[5]);
            Assert.AreEqual((byte)6, recvBuf[6]);
            Assert.AreEqual((byte)7, recvBuf[7]);
            Assert.AreEqual((byte)8, recvBuf[8]);
            Assert.AreEqual((byte)9, recvBuf[9]);
        }