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); }
public void TestInherit() { Serializer ser = new Regulus.Serialization.Dynamic.Serializer(); TestGrandson test = new TestGrandson(); test.Data = 100; TestChild testChild = test as TestChild; testChild.Data = 1; TestParent testParent = test as TestParent; testParent.Data = 33; byte[] buf = ser.ObjectToBuffer(test); TestGrandson val = (TestGrandson)ser.BufferToObject(buf); TestParent valParent = val as TestParent; TestChild child = val as TestChild; Assert.AreEqual(100, val.Data); Assert.AreEqual(1, child.Data); Assert.AreEqual(33, valParent.Data); }
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(); }
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); }
public void TestSerializerInt() { Serializer ser = new Regulus.Serialization.Dynamic.Serializer(); byte[] buf = ser.ObjectToBuffer(12345); int val = (int)ser.BufferToObject(buf); Assert.AreEqual(12345, val); }
public void TestSerializerNull() { Serializer ser = new Regulus.Serialization.Dynamic.Serializer(); byte[] buf = ser.ObjectToBuffer(null); object val = ser.BufferToObject(buf); Assert.AreEqual(null, val); }
public void TestSerializerString() { Serializer ser = new Regulus.Serialization.Dynamic.Serializer(); byte[] buf = ser.ObjectToBuffer("12345"); string val = (string)ser.BufferToObject(buf); Assert.AreEqual("12345", val); }
public void TestSerializerStringArray() { Serializer ser = new Regulus.Serialization.Dynamic.Serializer(); byte[] buf = ser.ObjectToBuffer(new[] { "1", "2", "3", "4", "5" }); string[] val = (string[])ser.BufferToObject(buf); Assert.AreEqual("1", val[0]); Assert.AreEqual("2", val[1]); Assert.AreEqual("3", val[2]); Assert.AreEqual("4", val[3]); Assert.AreEqual("5", val[4]); }
public void TestSerializerArray() { Serializer ser = new Regulus.Serialization.Dynamic.Serializer(); byte[] buf = ser.ObjectToBuffer(new[] { 1, 2, 3, 4, 5 }); int[] val = (int[])ser.BufferToObject(buf); Assert.AreEqual(1, val[0]); Assert.AreEqual(2, val[1]); Assert.AreEqual(3, val[2]); Assert.AreEqual(4, val[3]); Assert.AreEqual(5, val[4]); }
public void Test() { IBinderProvider entry = NSubstitute.Substitute.For <IBinderProvider>(); IGpiA gpia = new SoulGpiA(); bool bind = false; entry.AssignBinder(NSubstitute.Arg.Do <IBinder>(binder => { bind = true; binder.Bind <IGpiA>(gpia); }), NSubstitute.Arg.Any <object>()); Serialization.ISerializer serializer = new Regulus.Serialization.Dynamic.Serializer(); IProtocol protocol = ProtocolHelper.CreateProtocol(serializer); _TestService(entry, ref bind, protocol); }
public void TestClassPolytype1() { TestGrandson g = new TestGrandson(); g.Data = 100; TestPoly test = new TestPoly(); test.Parent = g; Serializer serializer = new Regulus.Serialization.Dynamic.Serializer(new CustomFinder((name) => Type.GetType(name))); byte[] buf = serializer.ObjectToBuffer(test); TestPoly val = (TestPoly)serializer.BufferToObject(buf); TestGrandson valChild = val.Parent as TestGrandson; Assert.AreEqual(100, valChild.Data); }
public void TestArray1() { TestGrandson test = new TestGrandson(); test.Data = 100; TestChild testChild = test as TestChild; testChild.Data = 1; TestParent testParent = test as TestParent; testParent.Data = 33; Serializer serializer = new Regulus.Serialization.Dynamic.Serializer(new CustomFinder((name) => Type.GetType(name))); byte[] buf = serializer.ObjectToBuffer(new TestParent[] { test, testChild, testParent }); TestParent[] val = (TestParent[])serializer.BufferToObject(buf); Assert.AreEqual(100, (val[0] as TestGrandson).Data); Assert.AreEqual(1, (val[1] as TestChild).Data); Assert.AreEqual(33, (val[2] as TestParent).Data); }