Ejemplo n.º 1
0
        public void TestToxLossyPacket()
        {
            int receivedPackets = 0;

            byte[] data = new byte[ToxConstants.MaxCustomPacketSize];
            new Random().NextBytes(data);
            data[0] = 210;

            _tox2.OnFriendLossyPacketReceived += (sender, args) =>
            {
                if (args.Data.Length != data.Length || data[0] != args.Data[0])
                {
                    Assert.Fail("Packet doesn't have the same length/identifier");
                }
                else if (!data.SequenceEqual(args.Data))
                {
                    Assert.Fail("Packet contents don't match");
                }

                receivedPackets++;
            };

            var  error  = ToxErrorFriendCustomPacket.Ok;
            bool result = _tox1.FriendSendLossyPacket(0, data, out error);

            if (!result || error != ToxErrorFriendCustomPacket.Ok)
            {
                Assert.Fail("Failed to send lossy packet to friend, error: {0}, result: {1}", error, result);
            }

            while (receivedPackets != 1)
            {
                DoIterate();
            }
        }