예제 #1
0
    public void GamestatePacketSerializeTestB()
    {
        GamestatePacket gamestatePacket = new GamestatePacket();

        gamestatePacket.revisionNumber = 5899;
        gamestatePacket.revisionActor  = 0xF7;
        gamestatePacket.id             = 12;
        gamestatePacket.hasName        = false;
        gamestatePacket.name           = "AAAAABBB";

        gamestatePacket.hasShortValues[0] = false;
        gamestatePacket.hasShortValues[1] = true;
        gamestatePacket.shortValues.Add(6);
        gamestatePacket.hasShortValues[2] = true;
        gamestatePacket.shortValues.Add(1359);
        gamestatePacket.hasShortValues[3] = true;
        gamestatePacket.shortValues.Add(13590);
        gamestatePacket.hasShortValues[4] = false;
        gamestatePacket.hasShortValues[5] = true;
        gamestatePacket.shortValues.Add(-13590);
        gamestatePacket.hasShortValues[6] = false;
        gamestatePacket.hasShortValues[7] = true;
        gamestatePacket.shortValues.Add(67);
        gamestatePacket.hasShortValues[8]  = false;
        gamestatePacket.hasShortValues[9]  = false;
        gamestatePacket.hasShortValues[10] = false;
        gamestatePacket.hasShortValues[11] = false;
        gamestatePacket.hasShortValues[12] = false;
        gamestatePacket.hasShortValues[13] = false;
        gamestatePacket.hasShortValues[14] = true;
        gamestatePacket.shortValues.Add(0);
        gamestatePacket.hasShortValues[15] = false;

        gamestatePacket.boolValues[0]  = false;
        gamestatePacket.boolValues[1]  = true;
        gamestatePacket.boolValues[2]  = true;
        gamestatePacket.boolValues[3]  = true;
        gamestatePacket.boolValues[4]  = false;
        gamestatePacket.boolValues[5]  = true;
        gamestatePacket.boolValues[6]  = false;
        gamestatePacket.boolValues[7]  = true;
        gamestatePacket.boolValues[8]  = false;
        gamestatePacket.boolValues[9]  = false;
        gamestatePacket.boolValues[10] = true;
        gamestatePacket.boolValues[11] = true;
        gamestatePacket.boolValues[12] = false;
        gamestatePacket.boolValues[13] = false;
        gamestatePacket.boolValues[14] = true;

        byte[] serializedPacket = GamestatePacket.Serialize(gamestatePacket);

        Assert.That(serializedPacket, Is.Not.Null);
        Assert.That(serializedPacket, Is.Not.Empty);

        GamestatePacket newPacket = GamestatePacket.Deserialize(serializedPacket) as GamestatePacket;

        Assert.That(newPacket, Is.Not.Null);

        GamestateAssertionUnit.AssertPacketEquality(gamestatePacket, newPacket);
    }
예제 #2
0
    public void GamestateApplyMultiplePlayerPacketsTest()
    {
        short actorNumber = 1;
        GamestateCommitTestHelper <PlayerEntry> testHelper = new GamestateCommitTestHelper <PlayerEntry>(actorNumber);
        GamestateTable <PlayerEntry>            players    = testHelper.TestTable(GamestateTracker.Table.Players);
        GamestateRandomTestingUnit generator = new GamestateRandomTestingUnit(8);

        for (short i = 0; i < 100; i++)
        {
            PlayerEntry playerEntry = players.Create(i);
            generator.RandomisePlayerEntry(playerEntry);
            playerEntry.Commit();

            GamestatePacket packet = testHelper.commitedPackets[0];
            testHelper.Apply(packet);

            playerEntry = players.Get(i);
            GamestateAssertionUnit.AssertPacketApplied(playerEntry, packet);

            generator.RandomisePlayerEntry(playerEntry);
            playerEntry.Commit();

            packet = testHelper.commitedPackets[1];
            testHelper.Apply(packet);

            playerEntry = players.Get(i);
            GamestateAssertionUnit.AssertPacketApplied(playerEntry, packet);
            playerEntry.Release();

            testHelper.commitedPackets.Clear();
        }
    }
예제 #3
0
    public void GamestateApplyTeamPacketErrorCallbackTest()
    {
        short actorNumber = 1;
        GamestateCommitTestHelper <TeamEntry> testHelper = new GamestateCommitTestHelper <TeamEntry>(actorNumber);
        GamestateTable <TeamEntry>            teams      = testHelper.TestTable(GamestateTracker.Table.Teams);
        GamestateRandomTestingUnit            generator  = new GamestateRandomTestingUnit(777);

        for (short i = 0; i < 100; i++)
        {
            TeamEntry teamEntry = teams.Create(i);
            generator.RandomiseTeamEntry(teamEntry);

            GamestatePacket packet = GamestatePacketManager.GetPacket();

            bool errorCallbackCalled = false;

            teamEntry.Commit((TeamEntry entry, bool succeeded) => {
                Assert.That(succeeded, Is.EqualTo(true));
                GamestateAssertionUnit.AssertPacketApplied(entry, packet);
                entry.Release();
                errorCallbackCalled = true;
            });

            packet = testHelper.commitedPackets[0];
            testHelper.Apply(packet);

            Assert.That(errorCallbackCalled, Is.EqualTo(true));

            testHelper.commitedPackets.Clear();
        }
    }
예제 #4
0
    public void GamestateApplyPlayerPacketListenerTest()
    {
        short actorNumber = 1;
        GamestateCommitTestHelper <PlayerEntry> testHelper = new GamestateCommitTestHelper <PlayerEntry>(actorNumber);
        GamestateTable <PlayerEntry>            players    = testHelper.TestTable(GamestateTracker.Table.Players);
        GamestateRandomTestingUnit generator = new GamestateRandomTestingUnit(12);

        for (short i = 0; i < 100; i++)
        {
            PlayerEntry playerEntry = players.Create(i);
            generator.RandomisePlayerEntry(playerEntry);

            GamestatePacket packet = GamestatePacketManager.GetPacket();

            bool listenerACalled = false;
            bool listenerBCalled = false;
            bool listenerCCalled = false;

            playerEntry.AddListener((PlayerEntry entry) => {
                GamestateAssertionUnit.AssertPacketApplied(entry, packet);
                entry.Release();
                listenerACalled = true;
            });

            playerEntry.AddListener((PlayerEntry entry) => {
                GamestateAssertionUnit.AssertPacketApplied(entry, packet);
                entry.Release();
                listenerBCalled = true;
            });

            playerEntry.AddListener((PlayerEntry entry) => {
                GamestateAssertionUnit.AssertPacketApplied(entry, packet);
                entry.Release();
                listenerCCalled = true;
            });

            playerEntry.Commit();

            packet = testHelper.commitedPackets[0];
            testHelper.Apply(packet);

            Assert.That(listenerACalled, Is.EqualTo(true));
            Assert.That(listenerBCalled, Is.EqualTo(true));
            Assert.That(listenerCCalled, Is.EqualTo(true));

            testHelper.commitedPackets.Clear();
        }
    }
예제 #5
0
    public void GamestateApplyPlayerPacketMultipleErrorCallbacksTest()
    {
        short actorNumber = 1;
        GamestateCommitTestHelper <PlayerEntry> testHelper = new GamestateCommitTestHelper <PlayerEntry>(actorNumber);
        GamestateTable <PlayerEntry>            players    = testHelper.TestTable(GamestateTracker.Table.Players);
        GamestateRandomTestingUnit generator = new GamestateRandomTestingUnit(23);

        for (short i = 0; i < 100; i++)
        {
            PlayerEntry playerEntry = players.Create(i);
            generator.RandomisePlayerEntry(playerEntry);

            GamestatePacket packet = GamestatePacketManager.GetPacket();

            bool errorCallbackACalled = false;
            bool errorCallbackBCalled = false;

            playerEntry.Commit((PlayerEntry entry, bool succeeded) => {
                Assert.That(succeeded, Is.EqualTo(true));
                GamestateAssertionUnit.AssertPacketApplied(entry, packet);
                entry.Release();
                errorCallbackACalled = true;
            });

            playerEntry = players.Get(i);

            playerEntry.Commit((PlayerEntry entry, bool succeeded) => {
                Assert.That(succeeded, Is.EqualTo(false));
                GamestateAssertionUnit.AssertPacketApplied(entry, packet);
                entry.Release();
                errorCallbackBCalled = true;
            });

            packet = testHelper.commitedPackets[0];
            testHelper.Apply(packet);

            Assert.That(errorCallbackACalled, Is.EqualTo(true));
            Assert.That(errorCallbackBCalled, Is.EqualTo(true));

            testHelper.commitedPackets.Clear();
        }
    }
예제 #6
0
    public void GamestatePacketSerializeTestC()
    {
        GamestateRandomTestingUnit generator = new GamestateRandomTestingUnit(5);

        for (int i = 0; i < 100; i++)
        {
            GamestatePacket gamestatePacket = generator.GetRandomPacket();

            byte[] serializedPacket = GamestatePacket.Serialize(gamestatePacket);

            Assert.That(serializedPacket, Is.Not.Null);
            Assert.That(serializedPacket, Is.Not.Empty);

            GamestatePacket newPacket = GamestatePacket.Deserialize(serializedPacket) as GamestatePacket;

            Assert.That(newPacket, Is.Not.Null);

            GamestateAssertionUnit.AssertPacketEquality(gamestatePacket, newPacket);
        }
    }
예제 #7
0
    public void GamestateAttemptApplyPlayerPacketTest()
    {
        byte actorNumber = 1;
        GamestateCommitTestHelper <PlayerEntry> testHelper = new GamestateCommitTestHelper <PlayerEntry>(actorNumber);
        GamestateTable <PlayerEntry>            players    = testHelper.TestTable(GamestateTracker.Table.Players);
        GamestateRandomTestingUnit generator = new GamestateRandomTestingUnit(902);

        for (short i = 0; i < 100; i++)
        {
            PlayerEntry playerEntry = players.Create(i);
            generator.RandomisePlayerEntry(playerEntry);
            playerEntry.Commit();

            GamestatePacket packetA  = testHelper.commitedPackets[0];
            bool            attemptA = testHelper.AttemptApply(packetA);

            GamestatePacket packetB = generator.GetRandomPacket();
            packetB.id             = i;
            packetB.packetType     = GamestatePacket.PacketType.Update;
            packetB.revisionNumber = packetA.revisionNumber;
            bool attemptB = testHelper.AttemptApply(packetB);

            GamestatePacket packetC = generator.GetRandomPacket();
            packetC.id             = i;
            packetC.packetType     = GamestatePacket.PacketType.Update;
            packetC.revisionNumber = packetA.revisionNumber;
            bool attemptC = testHelper.AttemptApply(packetC);

            Assert.That(attemptA, Is.EqualTo(true));
            Assert.That(attemptB, Is.EqualTo(false));
            Assert.That(attemptC, Is.EqualTo(false));

            playerEntry = players.Get(i);
            GamestateAssertionUnit.AssertPacketApplied(playerEntry, packetA);
            playerEntry.Release();

            testHelper.commitedPackets.Clear();
        }
    }
예제 #8
0
    public void GamestateApplyTeamPacketTest()
    {
        short actorNumber = 17;
        GamestateCommitTestHelper <TeamEntry> testHelper = new GamestateCommitTestHelper <TeamEntry>(actorNumber);
        GamestateTable <TeamEntry>            teams      = testHelper.TestTable(GamestateTracker.Table.Teams);
        GamestateRandomTestingUnit            generator  = new GamestateRandomTestingUnit(82);

        for (short i = 0; i < 100; i++)
        {
            TeamEntry teamEntry = teams.Create(i);
            generator.RandomiseTeamEntry(teamEntry);
            teamEntry.Commit();

            GamestatePacket packet = testHelper.commitedPackets[0];
            testHelper.Apply(packet);

            teamEntry = teams.Get(i);
            GamestateAssertionUnit.AssertPacketApplied(teamEntry, packet);
            teamEntry.Release();

            testHelper.commitedPackets.Clear();
        }
    }