Пример #1
0
        public void EncodeData()
        {
            int[] arr = { 5, 6, 7, 8, 9 };
            TestObject pre = new TestObject('1', 2, 3, 4, 1.5f, "Hello, World!", arr);

            byte[] encoded = NetworkManager.Encode(pre);
            TestObject post = NetworkManager.Decode<TestObject>(encoded);

            Console.WriteLine(pre);
            Console.WriteLine(post);

            Assert.That(pre.Equals(post));
        }
Пример #2
0
        public void SendRecieveEncodedData()
        {
            netMan.Listen();
            int[]      intArr          = { 8, 9, 10 };
            TestObject serializableObj = new TestObject('1', 2, 3, 4, 4f, "seven", intArr);

            if (!netMan.Connect(NetworkManager.LocalIP))
            {
                Assert.Fail("Failed to connect to self");
            }

            byte[] data = NetworkManager.Encode(serializableObj);

            if (!netMan.Send(NetworkManager.LocalIP, data))
            {
                Assert.Fail("Failed to send data");
            }

            while (!obs.recieved)
            {
                ;
            }

            TestObject post = NetworkManager.Decode <TestObject>(obs.dataRecieved);

            for (int i = 0; i < data.Length && i < obs.dataRecieved.Length; ++i)
            {
                Console.WriteLine("pre: {0}", data[i]);
                Console.WriteLine("post: {0}", obs.dataRecieved[i]);
                Assert.That(data[i] == obs.dataRecieved[i], "Data not the same here {0}: pre: {0} post: {0}", i);
            }

            Console.WriteLine("Pre: {0}", serializableObj.ToString());
            Console.WriteLine("Post: {0}", post.ToString());

            Assert.That(post.Equals(serializableObj));
        }
Пример #3
0
        public bool Equals(TestObject obj)
        {
            if (this.array.Length != obj.array.Length)
                return false;

            for(int i = 0; i < this.array.Length; ++i)
            {
                if (this.array[i] != obj.array[i])
                    return false;
            }

            return (this.charfield == obj.charfield &&
                    this.shortfield == obj.shortfield &&
                    this.intfield == obj.intfield &&
                    this.longfield == obj.longfield &&
                    this.floatfield == obj.floatfield &&
                    this.stringfield == obj.stringfield);
        }
Пример #4
0
        public void SendRecieveEncodedData()
        {
            netMan.Listen();
            int[] intArr = { 8, 9, 10 };
            TestObject serializableObj = new TestObject('1', 2, 3, 4, 4f, "seven", intArr);

            if (!netMan.Connect(NetworkManager.LocalIP))
                Assert.Fail("Failed to connect to self");

            byte[] data = NetworkManager.Encode(serializableObj);

            if (!netMan.Send(NetworkManager.LocalIP, data))
                Assert.Fail("Failed to send data");

            while (!obs.recieved);

            TestObject post = NetworkManager.Decode<TestObject>(obs.dataRecieved);

            for (int i = 0; i < data.Length && i < obs.dataRecieved.Length; ++i)
            {
                Console.WriteLine("pre: {0}", data[i]);
                Console.WriteLine("post: {0}", obs.dataRecieved[i]);
                Assert.That(data[i] == obs.dataRecieved[i], "Data not the same here {0}: pre: {0} post: {0}", i);
            }

            Console.WriteLine("Pre: {0}", serializableObj.ToString());
            Console.WriteLine("Post: {0}", post.ToString());

            Assert.That(post.Equals(serializableObj));
        }