Exemple #1
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();
        }
    }
Exemple #2
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();
        }
    }
Exemple #3
0
    public void GamestateApplyPlayerPacketListenerDeletionTest()
    {
        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;
            bool listenerDCalled = false;

            int a = playerEntry.AddListener((PlayerEntry entry) => {
                entry.Release();
                listenerACalled = true;
            });

            int b = playerEntry.AddListener((PlayerEntry entry) => {
                entry.Release();
                listenerBCalled = true;
            });

            int c = playerEntry.AddListener((PlayerEntry entry) => {
                entry.Release();
                listenerCCalled = true;
            });

            playerEntry.RemoveListener(b);

            int d = playerEntry.AddListener((PlayerEntry entry) => {
                entry.Release();
                listenerDCalled = true;
            });

            playerEntry.RemoveListener(c);


            playerEntry.Commit();

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

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

            testHelper.commitedPackets.Clear();
        }
    }
    public void GamestateCreateTeamTest()
    {
        short id = -100;
        GamestateCommitTestHelper <TeamEntry> testHelper = new GamestateCommitTestHelper <TeamEntry>(1);
        GamestateTable <TeamEntry>            teams      = testHelper.TestTable(GamestateTracker.Table.Teams);

        TeamEntry teamEntry = teams.Create(id);

        Assert.That(teamEntry, Is.Not.Null);
        Assert.That(teamEntry.id, Is.EqualTo(id));

        teamEntry.Commit();

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

        Assert.That(teams.Get(id), Is.Not.Null);
    }
    public void GamestateCreatePlayerTest()
    {
        short id = 7;
        GamestateCommitTestHelper <PlayerEntry> testHelper = new GamestateCommitTestHelper <PlayerEntry>(1);
        GamestateTable <PlayerEntry>            players    = testHelper.TestTable(GamestateTracker.Table.Players);

        PlayerEntry playerEntry = players.Create(id);

        Assert.That(playerEntry, Is.Not.Null);
        Assert.That(playerEntry.id, Is.EqualTo(id));

        playerEntry.Commit();

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

        Assert.That(players.Get(id), Is.Not.Null);
    }
Exemple #6
0
    public void GamestateCommitTeamTest()
    {
        short actorNumber = 17;
        short entryId     = -100;
        GamestateCommitTestHelper <TeamEntry> testHelper = new GamestateCommitTestHelper <TeamEntry>(actorNumber);
        GamestateTable <TeamEntry>            teams      = testHelper.TestTable(GamestateTracker.Table.Teams);

        TeamEntry teamEntry = teams.Create(entryId);

        Assert.That(teamEntry, Is.Not.Null);
        Assert.That(teamEntry.id, Is.EqualTo(entryId));

        teamEntry.name       = "xrtycuhEEEEE";
        teamEntry.isDead     = true;
        teamEntry.kills      = 67;
        teamEntry.deaths     = 222;
        teamEntry.assists    = 0;
        teamEntry.checkpoint = -9;

        teamEntry.Commit();

        Assert.That(testHelper.commitedPackets.Count, Is.EqualTo(1));

        GamestatePacket packet = testHelper.commitedPackets[0];

        Assert.That(packet.revisionNumber, Is.EqualTo(1));
        Assert.That(packet.revisionActor, Is.EqualTo(actorNumber));

        Assert.That(packet.id, Is.EqualTo(entryId));

        Assert.That(packet.hasName, Is.EqualTo(true));
        Assert.That(packet.name, Is.EqualTo("xrtycuhEEEEE"));

        bool[] hasShortValues = new bool[GamestatePacket.maxShorts];
        hasShortValues[(int)TeamEntry.ShortFields.Kills]      = true;
        hasShortValues[(int)TeamEntry.ShortFields.Deaths]     = true;
        hasShortValues[(int)TeamEntry.ShortFields.Assists]    = true;
        hasShortValues[(int)TeamEntry.ShortFields.Checkpoint] = true;
        Assert.That(packet.hasShortValues, Is.EquivalentTo(hasShortValues));
        Assert.That(packet.shortValues, Is.EquivalentTo(new short[] { 67, 222, 0, -9 }));

        bool[] boolValues = new bool[GamestatePacket.maxBools];
        boolValues[0] = true;
        Assert.That(packet.boolValues, Is.EquivalentTo(boolValues));
    }
Exemple #7
0
    public void GamestateCommitPlayerTest()
    {
        short actorNumber = 1;
        short entryId     = 2;
        GamestateCommitTestHelper <PlayerEntry> testHelper = new GamestateCommitTestHelper <PlayerEntry>(actorNumber);
        GamestateTable <PlayerEntry>            players    = testHelper.TestTable(GamestateTracker.Table.Players);

        PlayerEntry playerEntry = players.Create(entryId);

        playerEntry.name        = "AAA";
        playerEntry.isBot       = false;
        playerEntry.ready       = true;
        playerEntry.actorNumber = actorNumber;
        playerEntry.role        = 5;
        playerEntry.character   = 2;
        playerEntry.teamId      = 9;

        playerEntry.Commit();

        Assert.That(testHelper.commitedPackets.Count, Is.EqualTo(1));

        GamestatePacket packet = testHelper.commitedPackets[0];

        Assert.That(packet.revisionNumber, Is.EqualTo(1));
        Assert.That(packet.revisionActor, Is.EqualTo(actorNumber));

        Assert.That(packet.id, Is.EqualTo(entryId));

        Assert.That(packet.hasName, Is.EqualTo(true));
        Assert.That(packet.name, Is.EqualTo("AAA"));

        bool[] hasShortValues = new bool[GamestatePacket.maxShorts];
        hasShortValues[(int)PlayerEntry.ShortFields.ActorNumber] = true;
        hasShortValues[(int)PlayerEntry.ShortFields.Role]        = true;
        hasShortValues[(int)PlayerEntry.ShortFields.Character]   = true;
        hasShortValues[(int)PlayerEntry.ShortFields.TeamId]      = true;
        Assert.That(packet.hasShortValues, Is.EquivalentTo(hasShortValues));
        Assert.That(packet.shortValues, Is.EquivalentTo(new short[] { actorNumber, 5, 2, 9 }));

        bool[] boolValues = new bool[GamestatePacket.maxBools];
        boolValues[0] = false;
        boolValues[1] = true;
        Assert.That(packet.boolValues, Is.EquivalentTo(boolValues));
    }
Exemple #8
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();
        }
    }
Exemple #9
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();
        }
    }
Exemple #10
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();
        }
    }