Exemplo n.º 1
0
        public void CommandMessage()
        {
            // try setting value with constructor
            CommandMessage message = new CommandMessage
            {
                netId          = 42,
                componentIndex = 4,
                functionHash   = 0xABCDEF,
                payload        = new ArraySegment <byte>(new byte[] { 0x01, 0x02 })
            };

            byte[] arr = MessagePackingTest.PackToByteArray(message);

            // deserialize the same data - do we get the same result?
            CommandMessage fresh = MessagePackingTest.UnpackFromByteArray <CommandMessage>(arr);

            Assert.That(fresh.netId, Is.EqualTo(message.netId));
            Assert.That(fresh.componentIndex, Is.EqualTo(message.componentIndex));
            Assert.That(fresh.functionHash, Is.EqualTo(message.functionHash));
            Assert.That(fresh.payload.Count, Is.EqualTo(message.payload.Count));
            for (int i = 0; i < fresh.payload.Count; ++i)
            {
                Assert.That(fresh.payload.Array[fresh.payload.Offset + i],
                            Is.EqualTo(message.payload.Array[message.payload.Offset + i]));
            }
        }
        public void SendsData()
        {
            Message message = new Message
            {
                collection = new ClassWithNoConstructor[]
                {
                    new ClassWithNoConstructor {
                        a = 3
                    }, new ClassWithNoConstructor {
                        a = 4
                    }, new ClassWithNoConstructor {
                        a = 5
                    }
                }
            };

            byte[] data = MessagePackingTest.PackToByteArray(message);

            Message unpacked = MessagePackingTest.UnpackFromByteArray <Message>(data);

            ClassWithNoConstructor[] unpackedCollection = unpacked.collection;

            Assert.IsNotNull(unpackedCollection);
            Assert.IsNotEmpty(unpackedCollection);
            Assert.That(unpackedCollection[0].a, Is.EqualTo(new ClassWithNoConstructor {
                a = 3
            }.a));
            Assert.That(unpackedCollection[1].a, Is.EqualTo(new ClassWithNoConstructor {
                a = 4
            }.a));
            Assert.That(unpackedCollection[2].a, Is.EqualTo(new ClassWithNoConstructor {
                a = 5
            }.a));
        }
        public void SendsData()
        {
            Message message = new Message
            {
                collection = new FloatStringStruct[]
                {
                    new FloatStringStruct {
                        value = 3, anotherValue = "Some"
                    }, new FloatStringStruct {
                        value = 4, anotherValue = "String"
                    }, new FloatStringStruct {
                        value = 5, anotherValue = "Values"
                    }
                }
            };

            byte[] data = MessagePackingTest.PackToByteArray(message);

            Message unpacked = MessagePackingTest.UnpackFromByteArray <Message>(data);

            FloatStringStruct[] unpackedCollection = unpacked.collection;

            Assert.IsNotNull(unpackedCollection);
            Assert.IsNotEmpty(unpackedCollection);
            Assert.That(unpackedCollection[0], Is.EqualTo(new FloatStringStruct {
                value = 3, anotherValue = "Some"
            }));
            Assert.That(unpackedCollection[1], Is.EqualTo(new FloatStringStruct {
                value = 4, anotherValue = "String"
            }));
            Assert.That(unpackedCollection[2], Is.EqualTo(new FloatStringStruct {
                value = 5, anotherValue = "Values"
            }));
        }
        public void StructWithMethods()
        {
            byte[]      arr = MessagePackingTest.PackToByteArray(new TestMessage(1, "2", 3.3));
            TestMessage t   = MessagePackingTest.UnpackFromByteArray <TestMessage>(arr);

            Assert.AreEqual(1, t.IntValue);
        }
Exemplo n.º 5
0
        public void StructWithMethods()
        {
            byte[]      bytes   = MessagePackingTest.PackToByteArray(new TestMessage(1, "2", 3.3));
            TestMessage message = MessagePackingTest.UnpackFromByteArray <TestMessage>(bytes);

            Assert.AreEqual(1, message.IntValue);
        }
Exemplo n.º 6
0
        public void NotReadyMessage()
        {
            NotReadyMessage message = new NotReadyMessage();

            byte[] arr = MessagePackingTest.PackToByteArray(message);

            NotReadyMessage fresh = MessagePackingTest.UnpackFromByteArray <NotReadyMessage>(arr);

            Assert.That(fresh, Is.EqualTo(message));
        }
Exemplo n.º 7
0
        public void NetworkPingMessage()
        {
            NetworkPingMessage message = new NetworkPingMessage(DateTime.Now.ToOADate());

            byte[] arr = MessagePackingTest.PackToByteArray(message);

            NetworkPingMessage fresh = MessagePackingTest.UnpackFromByteArray <NetworkPingMessage>(arr);

            Assert.That(fresh, Is.EqualTo(message));
        }
Exemplo n.º 8
0
        public void ObjectSpawnStartedMessage()
        {
            ObjectSpawnStartedMessage message = new ObjectSpawnStartedMessage();

            byte[] arr = MessagePackingTest.PackToByteArray(message);

            ObjectSpawnStartedMessage fresh = MessagePackingTest.UnpackFromByteArray <ObjectSpawnStartedMessage>(arr);

            Assert.That(fresh, Is.EqualTo(message));
        }
Exemplo n.º 9
0
        public void NetworkPingMessage()
        {
            // try setting value with constructor
            NetworkPingMessage message = new NetworkPingMessage(DateTime.Now.ToOADate());

            byte[]             arr   = MessagePackingTest.PackToByteArray(message);
            NetworkPingMessage fresh = MessagePackingTest.UnpackFromByteArray <NetworkPingMessage>(arr);

            Assert.That(fresh.clientTime, Is.EqualTo(message.clientTime));
        }
Exemplo n.º 10
0
        public void NotReadyMessage()
        {
            // try setting value with constructor
            NotReadyMessage message = new NotReadyMessage();

            byte[] arr = MessagePackingTest.PackToByteArray(message);
            Assert.DoesNotThrow(() =>
            {
                NotReadyMessage fresh = MessagePackingTest.UnpackFromByteArray <NotReadyMessage>(arr);
            });
        }
        public void StructWithEmptyMethods()
        {
            byte[] arr = MessagePackingTest.PackToByteArray(new StructWithEmptyMethodMessage {
                IntValue = 1, StringValue = "2", DoubleValue = 3.3
            });
            StructWithEmptyMethodMessage t = MessagePackingTest.UnpackFromByteArray <StructWithEmptyMethodMessage>(arr);

            Assert.AreEqual(1, t.IntValue);
            Assert.AreEqual("2", t.StringValue);
            Assert.AreEqual(3.3, t.DoubleValue);
        }
Exemplo n.º 12
0
        public void ObjectSpawnStartedMessage()
        {
            // try setting value with constructor
            ObjectSpawnStartedMessage message = new ObjectSpawnStartedMessage();

            byte[] arr = MessagePackingTest.PackToByteArray(message);
            Assert.DoesNotThrow(() =>
            {
                ObjectSpawnStartedMessage fresh = MessagePackingTest.UnpackFromByteArray <ObjectSpawnStartedMessage>(arr);
            });
        }
Exemplo n.º 13
0
        public void StructWithEmptyMethods()
        {
            byte[] bytes = MessagePackingTest.PackToByteArray(new StructWithEmptyMethodMessage {
                IntValue = 1, StringValue = "2", DoubleValue = 3.3
            });
            StructWithEmptyMethodMessage message = MessagePackingTest.UnpackFromByteArray <StructWithEmptyMethodMessage>(bytes);

            Assert.AreEqual(1, message.IntValue);
            Assert.AreEqual("2", message.StringValue);
            Assert.AreEqual(3.3, message.DoubleValue);
        }
Exemplo n.º 14
0
    public void MethodsWithTwoArgs()
    {
        const int           value      = 10;
        TwoArgMethodMessage intMessage = new TwoArgMethodMessage
        {
            someValue = value
        };

        byte[] data = MessagePackingTest.PackToByteArray(intMessage);
        TwoArgMethodMessage unpacked = MessagePackingTest.UnpackFromByteArray <TwoArgMethodMessage>(data);

        Assert.That(unpacked.someValue, Is.EqualTo(value));
    }
Exemplo n.º 15
0
        public void ObjectHideMessage()
        {
            // try setting value with constructor
            ObjectHideMessage message = new ObjectHideMessage {
                netId = 42
            };

            byte[] arr = MessagePackingTest.PackToByteArray(message);

            ObjectHideMessage fresh = MessagePackingTest.UnpackFromByteArray <ObjectHideMessage>(arr);

            Assert.That(fresh, Is.EqualTo(message));
        }
        public void SendsNull()
        {
            Message message = new Message
            {
                collection = default
            };

            byte[] data = MessagePackingTest.PackToByteArray(message);

            Message            unpacked           = MessagePackingTest.UnpackFromByteArray <Message>(data);
            ArraySegment <int> unpackedCollection = unpacked.collection;

            Assert.That(unpackedCollection.Array, Is.Null.Or.Empty);
        }
        public void SendsNull()
        {
            Message message = new Message
            {
                collection = default
            };

            byte[] data = MessagePackingTest.PackToByteArray(message);

            Message unpacked = MessagePackingTest.UnpackFromByteArray <Message>(data);

            ClassWithNoConstructor[] unpackedCollection = unpacked.collection;

            Assert.That(unpackedCollection, Is.Null.Or.Empty);
        }
        public void SendsEmpty()
        {
            Message message = new Message
            {
                collection = new int[] {}
            };

            byte[] data = MessagePackingTest.PackToByteArray(message);

            Message unpacked = MessagePackingTest.UnpackFromByteArray <Message>(data);

            int[] unpackedCollection = unpacked.collection;

            Assert.IsNotNull(unpackedCollection);
            Assert.IsEmpty(unpackedCollection);
        }
Exemplo n.º 19
0
        public void SpawnMessage()
        {
            DoTest(0);
            DoTest(42);

            void DoTest(ulong testSceneId)
            {
                // try setting value with constructor
                SpawnMessage message = new SpawnMessage
                {
                    netId         = 42,
                    isLocalPlayer = true,
                    isOwner       = true,
                    sceneId       = testSceneId,
                    assetId       = Guid.NewGuid(),
                    position      = UnityEngine.Vector3.one,
                    rotation      = UnityEngine.Quaternion.identity,
                    scale         = UnityEngine.Vector3.one,
                    payload       = new ArraySegment <byte>(new byte[] { 0x01, 0x02 })
                };

                byte[]       arr   = MessagePackingTest.PackToByteArray(message);
                SpawnMessage fresh = MessagePackingTest.UnpackFromByteArray <SpawnMessage>(arr);

                Assert.That(fresh.netId, Is.EqualTo(message.netId));
                Assert.That(fresh.isLocalPlayer, Is.EqualTo(message.isLocalPlayer));
                Assert.That(fresh.isOwner, Is.EqualTo(message.isOwner));
                Assert.That(fresh.sceneId, Is.EqualTo(message.sceneId));
                if (fresh.sceneId == 0)
                {
                    Assert.That(fresh.assetId, Is.EqualTo(message.assetId));
                }
                Assert.That(fresh.position, Is.EqualTo(message.position));
                Assert.That(fresh.rotation, Is.EqualTo(message.rotation));
                Assert.That(fresh.scale, Is.EqualTo(message.scale));
                Assert.That(fresh.payload.Count, Is.EqualTo(message.payload.Count));
                for (int i = 0; i < fresh.payload.Count; ++i)
                {
                    Assert.That(fresh.payload.Array[fresh.payload.Offset + i],
                                Is.EqualTo(message.payload.Array[message.payload.Offset + i]));
                }
            }
        }
Exemplo n.º 20
0
        public void UpdateVarsMessage()
        {
            // try setting value with constructor
            UpdateVarsMessage message = new UpdateVarsMessage
            {
                netId   = 42,
                payload = new ArraySegment <byte>(new byte[] { 0x01, 0x02 })
            };

            byte[]            arr   = MessagePackingTest.PackToByteArray(message);
            UpdateVarsMessage fresh = MessagePackingTest.UnpackFromByteArray <UpdateVarsMessage>(arr);

            Assert.That(fresh.netId, Is.EqualTo(message.netId));
            Assert.That(fresh.payload.Count, Is.EqualTo(message.payload.Count));
            for (int i = 0; i < fresh.payload.Count; ++i)
            {
                Assert.That(fresh.payload.Array[fresh.payload.Offset + i],
                            Is.EqualTo(message.payload.Array[message.payload.Offset + i]));
            }
        }
        public void SendsData()
        {
            Message message = new Message
            {
                collection = new int[]
                {
                    3, 4, 5
                }
            };

            byte[] data = MessagePackingTest.PackToByteArray(message);

            Message unpacked = MessagePackingTest.UnpackFromByteArray <Message>(data);

            int[] unpackedCollection = unpacked.collection;

            Assert.IsNotNull(unpackedCollection);
            Assert.IsNotEmpty(unpackedCollection);
            Assert.That(unpackedCollection[0], Is.EqualTo(3));
            Assert.That(unpackedCollection[1], Is.EqualTo(4));
            Assert.That(unpackedCollection[2], Is.EqualTo(5));
        }
        public void SendsData()
        {
            Message message = new Message
            {
                collection = new Vector3[]
                {
                    new Vector3(1, 2, 3), new Vector3(4, 5, 6), new Vector3(7, 8, 9)
                }
            };

            byte[] data = MessagePackingTest.PackToByteArray(message);

            Message unpacked = MessagePackingTest.UnpackFromByteArray <Message>(data);

            Vector3[] unpackedCollection = unpacked.collection;

            Assert.IsNotNull(unpackedCollection);
            Assert.IsNotEmpty(unpackedCollection);
            Assert.That(unpackedCollection[0], Is.EqualTo(new Vector3(1, 2, 3)));
            Assert.That(unpackedCollection[1], Is.EqualTo(new Vector3(4, 5, 6)));
            Assert.That(unpackedCollection[2], Is.EqualTo(new Vector3(7, 8, 9)));
        }
        public void SendsData()
        {
            Message message = new Message
            {
                collection = new string[]
                {
                    "Some", "String", "Value"
                }
            };

            byte[] data = MessagePackingTest.PackToByteArray(message);

            Message unpacked = MessagePackingTest.UnpackFromByteArray <Message>(data);

            string[] unpackedCollection = unpacked.collection;

            Assert.IsNotNull(unpackedCollection);
            Assert.IsNotEmpty(unpackedCollection);
            Assert.That(unpackedCollection[0], Is.EqualTo("Some"));
            Assert.That(unpackedCollection[1], Is.EqualTo("String"));
            Assert.That(unpackedCollection[2], Is.EqualTo("Value"));
        }