public void ListBubblesResponseEncoding() { ListBubblesResponse originalMessage = new ListBubblesResponse(); { BubbleFragment bubbleEntry = new BubbleFragment(); bubbleEntry.BubbleId = Guid.NewGuid(); bubbleEntry.BubbleName = "TestBubble1"; bubbleEntry.BubbleAssetCacheUrl = "TestCloudUrl"; bubbleEntry.BubbleAddress = "TestBubbleAddress"; bubbleEntry.BubblePort = 1; bubbleEntry.BubbleCenter.X = 2; bubbleEntry.BubbleCenter.Y = 3; bubbleEntry.BubbleCenter.Z = 4; bubbleEntry.BubbleRange = 5; bubbleEntry.BubblePerceptionRange = 6; bubbleEntry.BubbleRealTime = 7; originalMessage.AddBubbleFragment(bubbleEntry); } { BubbleFragment bubbleEntry = new BubbleFragment(); bubbleEntry.BubbleId = Guid.NewGuid(); bubbleEntry.BubbleName = "TestBubble2"; bubbleEntry.BubbleAssetCacheUrl = "TestCloudUrl"; bubbleEntry.BubbleAddress = "TestBubbleAddress"; bubbleEntry.BubblePort = 1; bubbleEntry.BubbleCenter.X = 2; bubbleEntry.BubbleCenter.Y = 3; bubbleEntry.BubbleCenter.Z = 4; bubbleEntry.BubbleRange = 5; bubbleEntry.BubblePerceptionRange = 6; bubbleEntry.BubbleRealTime = 7; originalMessage.AddBubbleFragment(bubbleEntry); } { BubbleFragment bubbleEntry = new BubbleFragment(); bubbleEntry.BubbleId = Guid.NewGuid(); bubbleEntry.BubbleName = "TestBubble3"; bubbleEntry.BubbleAssetCacheUrl = "TestCloudUrl"; bubbleEntry.BubbleAddress = "TestBubbleAddress"; bubbleEntry.BubblePort = 1; bubbleEntry.BubbleCenter.X = 2; bubbleEntry.BubbleCenter.Y = 3; bubbleEntry.BubbleCenter.Z = 4; bubbleEntry.BubbleRange = 5; bubbleEntry.BubblePerceptionRange = 6; bubbleEntry.BubbleRealTime = 7; originalMessage.AddBubbleFragment(bubbleEntry); } { BubbleFragment bubbleEntry = new BubbleFragment(); bubbleEntry.BubbleId = Guid.NewGuid(); bubbleEntry.BubbleName = "TestBubble4"; bubbleEntry.BubbleAssetCacheUrl = "TestCloudUrl"; bubbleEntry.BubbleAddress = "TestBubbleAddress"; bubbleEntry.BubblePort = 1; bubbleEntry.BubbleCenter.X = 2; bubbleEntry.BubbleCenter.Y = 3; bubbleEntry.BubbleCenter.Z = 4; bubbleEntry.BubbleRange = 5; bubbleEntry.BubblePerceptionRange = 6; bubbleEntry.BubbleRealTime = 7; originalMessage.AddBubbleFragment(bubbleEntry); } byte[] encodedBytes = new byte[MxpConstants.MaxPacketSize]; Assert.AreEqual(originalMessage.FrameCount, 4); Assert.AreEqual(originalMessage.FrameDataSize(0), 255); Assert.AreEqual(originalMessage.FrameDataSize(1), 255); Assert.AreEqual(originalMessage.FrameDataSize(2), 255); Assert.AreEqual(originalMessage.FrameDataSize(3), 255); int currentIndex = originalMessage.EncodeFrameData(0, encodedBytes, 0); currentIndex = originalMessage.EncodeFrameData(1, encodedBytes, currentIndex); currentIndex = originalMessage.EncodeFrameData(2, encodedBytes, currentIndex); currentIndex = originalMessage.EncodeFrameData(3, encodedBytes, currentIndex); ListBubblesResponse decodedMessage = new ListBubblesResponse(); int currentDecodeIndex = decodedMessage.DecodeFrameData(0, encodedBytes, 0, originalMessage.FrameDataSize(0)); currentDecodeIndex = decodedMessage.DecodeFrameData(1, encodedBytes, currentDecodeIndex, originalMessage.FrameDataSize(1)); currentDecodeIndex = decodedMessage.DecodeFrameData(2, encodedBytes, currentDecodeIndex, originalMessage.FrameDataSize(2)); currentDecodeIndex = decodedMessage.DecodeFrameData(3, encodedBytes, currentDecodeIndex, originalMessage.FrameDataSize(3)); decodedMessage.MessageId = originalMessage.MessageId; String originalMessageString = originalMessage.ToString(); String decodedMessageString = decodedMessage.ToString(); Assert.AreEqual(originalMessageString, decodedMessageString); Assert.AreEqual(originalMessage.BubbleFragments.Count, decodedMessage.BubbleFragments.Count); for (int i = 0; i < originalMessage.BubbleFragments.Count; i++) { Assert.AreEqual(originalMessage.BubbleFragments[i].BubbleId, decodedMessage.BubbleFragments[i].BubbleId); Assert.AreEqual(originalMessage.BubbleFragments[i].BubbleName, decodedMessage.BubbleFragments[i].BubbleName); } }
public void PacketEncodingMultiFrame() { ListBubblesResponse originalMessage = new ListBubblesResponse(); { BubbleFragment bubbleEntry = new BubbleFragment(); bubbleEntry.BubbleId = Guid.NewGuid(); bubbleEntry.BubbleName = "TestBubble1"; bubbleEntry.BubbleAssetCacheUrl = "TestCloudUrl"; bubbleEntry.BubbleAddress = "TestBubbleAddress"; bubbleEntry.BubblePort = 1; bubbleEntry.BubbleCenter.X = 2; bubbleEntry.BubbleCenter.Y = 3; bubbleEntry.BubbleCenter.Z = 4; bubbleEntry.BubbleRange = 5; bubbleEntry.BubblePerceptionRange = 6; bubbleEntry.BubbleRealTime = 7; originalMessage.AddBubbleFragment(bubbleEntry); } { BubbleFragment bubbleEntry = new BubbleFragment(); bubbleEntry.BubbleId = Guid.NewGuid(); bubbleEntry.BubbleName = "TestBubble2"; bubbleEntry.BubbleAssetCacheUrl = "TestCloudUrl"; bubbleEntry.BubbleAddress = "TestBubbleAddress"; bubbleEntry.BubblePort = 1; bubbleEntry.BubbleCenter.X = 2; bubbleEntry.BubbleCenter.Y = 3; bubbleEntry.BubbleCenter.Z = 4; bubbleEntry.BubbleRange = 5; bubbleEntry.BubblePerceptionRange = 6; bubbleEntry.BubbleRealTime = 7; originalMessage.AddBubbleFragment(bubbleEntry); } { BubbleFragment bubbleEntry = new BubbleFragment(); bubbleEntry.BubbleId = Guid.NewGuid(); bubbleEntry.BubbleName = "TestBubble3"; bubbleEntry.BubbleAssetCacheUrl = "TestCloudUrl"; bubbleEntry.BubbleAddress = "TestBubbleAddress"; bubbleEntry.BubblePort = 1; bubbleEntry.BubbleCenter.X = 2; bubbleEntry.BubbleCenter.Y = 3; bubbleEntry.BubbleCenter.Z = 4; bubbleEntry.BubbleRange = 5; bubbleEntry.BubblePerceptionRange = 6; bubbleEntry.BubbleRealTime = 7; originalMessage.AddBubbleFragment(bubbleEntry); } { BubbleFragment bubbleEntry = new BubbleFragment(); bubbleEntry.BubbleId = Guid.NewGuid(); bubbleEntry.BubbleName = "TestBubble4"; bubbleEntry.BubbleAssetCacheUrl = "TestCloudUrl"; bubbleEntry.BubbleAddress = "TestBubbleAddress"; bubbleEntry.BubblePort = 1; bubbleEntry.BubbleCenter.X = 2; bubbleEntry.BubbleCenter.Y = 3; bubbleEntry.BubbleCenter.Z = 4; bubbleEntry.BubbleRange = 5; bubbleEntry.BubblePerceptionRange = 6; bubbleEntry.BubbleRealTime = 7; originalMessage.AddBubbleFragment(bubbleEntry); } { BubbleFragment bubbleEntry = new BubbleFragment(); bubbleEntry.BubbleId = Guid.NewGuid(); bubbleEntry.BubbleName = "TestBubble5"; bubbleEntry.BubbleAssetCacheUrl = "TestCloudUrl"; bubbleEntry.BubbleAddress = "TestBubbleAddress"; bubbleEntry.BubblePort = 1; bubbleEntry.BubbleCenter.X = 2; bubbleEntry.BubbleCenter.Y = 3; bubbleEntry.BubbleCenter.Z = 4; bubbleEntry.BubbleRange = 5; bubbleEntry.BubblePerceptionRange = 6; bubbleEntry.BubbleRealTime = 7; originalMessage.AddBubbleFragment(bubbleEntry); } Packet originalPacket = new Packet(); originalPacket.SessionId = 1; originalPacket.PacketId = 2; originalPacket.FirstSendTime = 3; originalPacket.ResendCount = 4; originalPacket.Quaranteed = true; Session senderSession = new Session(); senderSession.Send(originalMessage); PacketEncoder.EncodePacketHeader(originalPacket); bool packetQuaranteed = false; PacketEncoder.EncodePacketData(senderSession, originalPacket, ref packetQuaranteed); Assert.IsTrue(packetQuaranteed); Session receiverSession = new Session(); Packet receivedPacket = new Packet(); receivedPacket.PacketLength = originalPacket.PacketLength; receivedPacket.PacketBytes = originalPacket.PacketBytes; PacketEncoder.DecodePacketHeader(receivedPacket); packetQuaranteed = false; PacketEncoder.DecodePacketData(receiverSession, receivedPacket, ref packetQuaranteed); Assert.IsTrue(packetQuaranteed); Message decodedMessage = receiverSession.Receive(); Assert.IsNotNull(decodedMessage); Assert.AreEqual(0, senderSession.GetOutboundMessageCount()); Assert.AreEqual(0, senderSession.GetPartiallySentMessageCount()); Assert.AreEqual(0, senderSession.AvailableMessages); Assert.AreEqual(0, senderSession.GetPartiallyReceivedMessageCount()); Assert.AreEqual(0, receiverSession.GetOutboundMessageCount()); Assert.AreEqual(0, receiverSession.GetPartiallySentMessageCount()); Assert.AreEqual(0, receiverSession.AvailableMessages); Assert.AreEqual(0, receiverSession.GetPartiallyReceivedMessageCount()); decodedMessage.MessageId = originalMessage.MessageId; String originalMessageString = originalMessage.ToString(); String decodedMessageString = decodedMessage.ToString(); Assert.AreEqual(originalMessageString, decodedMessageString); String originalPacketString = originalPacket.ToString(); String receivedPacketString = receivedPacket.ToString(); Assert.AreEqual(originalPacketString, receivedPacketString); }
public void ListBubblesResponseClear() { ListBubblesResponse originalMessage = new ListBubblesResponse(); { BubbleFragment bubbleEntry = new BubbleFragment(); bubbleEntry.BubbleId = Guid.NewGuid(); bubbleEntry.BubbleName = "TestBubble1"; bubbleEntry.BubbleAssetCacheUrl = "TestCloudUrl"; bubbleEntry.BubbleAddress = "TestBubbleAddress"; bubbleEntry.BubblePort = 1; bubbleEntry.BubbleCenter.X = 2; bubbleEntry.BubbleCenter.Y = 3; bubbleEntry.BubbleCenter.Z = 4; bubbleEntry.BubbleRange = 5; bubbleEntry.BubblePerceptionRange = 6; bubbleEntry.BubbleRealTime = 7; originalMessage.AddBubbleFragment(bubbleEntry); } { BubbleFragment bubbleEntry = new BubbleFragment(); bubbleEntry.BubbleId = Guid.NewGuid(); bubbleEntry.BubbleName = "TestBubble2"; bubbleEntry.BubbleAssetCacheUrl = "TestCloudUrl"; bubbleEntry.BubbleAddress = "TestBubbleAddress"; bubbleEntry.BubblePort = 1; bubbleEntry.BubbleCenter.X = 2; bubbleEntry.BubbleCenter.Y = 3; bubbleEntry.BubbleCenter.Z = 4; bubbleEntry.BubbleRange = 5; bubbleEntry.BubblePerceptionRange = 6; bubbleEntry.BubbleRealTime = 7; originalMessage.AddBubbleFragment(bubbleEntry); } { BubbleFragment bubbleEntry = new BubbleFragment(); bubbleEntry.BubbleId = Guid.NewGuid(); bubbleEntry.BubbleName = "TestBubble3"; bubbleEntry.BubbleAssetCacheUrl = "TestCloudUrl"; bubbleEntry.BubbleAddress = "TestBubbleAddress"; bubbleEntry.BubblePort = 1; bubbleEntry.BubbleCenter.X = 2; bubbleEntry.BubbleCenter.Y = 3; bubbleEntry.BubbleCenter.Z = 4; bubbleEntry.BubbleRange = 5; bubbleEntry.BubblePerceptionRange = 6; bubbleEntry.BubbleRealTime = 7; originalMessage.AddBubbleFragment(bubbleEntry); } { BubbleFragment bubbleEntry = new BubbleFragment(); bubbleEntry.BubbleId = Guid.NewGuid(); bubbleEntry.BubbleName = "TestBubble4"; bubbleEntry.BubbleAssetCacheUrl = "TestCloudUrl"; bubbleEntry.BubbleAddress = "TestBubbleAddress"; bubbleEntry.BubblePort = 1; bubbleEntry.BubbleCenter.X = 2; bubbleEntry.BubbleCenter.Y = 3; bubbleEntry.BubbleCenter.Z = 4; bubbleEntry.BubbleRange = 5; bubbleEntry.BubblePerceptionRange = 6; bubbleEntry.BubbleRealTime = 7; originalMessage.AddBubbleFragment(bubbleEntry); } { BubbleFragment bubbleEntry = new BubbleFragment(); bubbleEntry.BubbleId = Guid.NewGuid(); bubbleEntry.BubbleName = "TestBubble5"; bubbleEntry.BubbleAssetCacheUrl = "TestCloudUrl"; bubbleEntry.BubbleAddress = "TestBubbleAddress"; bubbleEntry.BubblePort = 1; bubbleEntry.BubbleCenter.X = 2; bubbleEntry.BubbleCenter.Y = 3; bubbleEntry.BubbleCenter.Z = 4; bubbleEntry.BubbleRange = 5; bubbleEntry.BubblePerceptionRange = 6; bubbleEntry.BubbleRealTime = 7; originalMessage.AddBubbleFragment(bubbleEntry); } originalMessage.Clear(); ListBubblesResponse emptyMessage = new ListBubblesResponse(); emptyMessage.MessageId = originalMessage.MessageId; Assert.AreEqual(originalMessage.ToString(), emptyMessage.ToString()); }