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); }
public GamestatePacket GetRandomPacket() { Random.state = currentState; GamestatePacket packet = GamestatePacketManager.GetPacket(); packet.packetType = (GamestatePacket.PacketType)Random.Range(0, 4); packet.table = (GamestateTracker.Table)Random.Range(0, 3); packet.revisionNumber = (uint)Random.Range(int.MinValue, int.MaxValue); packet.revisionActor = (byte)Random.Range(byte.MinValue, byte.MaxValue + 1); packet.id = (short)Random.Range(short.MinValue, short.MaxValue + 1); packet.hasName = Random.Range(0, 2) == 1; packet.name = GetRandomUTF8String(); for (int i = 0; i < GamestatePacket.maxShorts; i++) { packet.hasShortValues[i] = Random.Range(0, 2) == 1; if (packet.hasShortValues[i]) { packet.shortValues.Add((short)Random.Range(short.MinValue, short.MaxValue + 1)); } } for (int i = 0; i < GamestatePacket.maxBools; i++) { packet.boolValues[i] = Random.Range(0, 2) == 1; } currentState = Random.state; return(packet); }
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(); } }
public static void AssertPacketApplied(TeamEntry entry, GamestatePacket packet) { if (packet.hasName) { Assert.That(entry.name, Is.EqualTo(packet.name)); } int i = 0; if (packet.hasShortValues[(int)TeamEntry.ShortFields.Kills]) { Assert.That(entry.kills, Is.EqualTo(packet.shortValues[i])); i++; } if (packet.hasShortValues[(int)TeamEntry.ShortFields.Deaths]) { Assert.That(entry.deaths, Is.EqualTo(packet.shortValues[i])); i++; } if (packet.hasShortValues[(int)TeamEntry.ShortFields.Assists]) { Assert.That(entry.assists, Is.EqualTo(packet.shortValues[i])); i++; } if (packet.hasShortValues[(int)TeamEntry.ShortFields.Checkpoint]) { Assert.That(entry.checkpoint, Is.EqualTo(packet.shortValues[i])); i++; } Assert.That(entry.isDead, Is.EqualTo(packet.boolValues[(int)TeamEntry.BoolFields.IsDead])); }
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(); } }
public static void AssertPacketEquality(GamestatePacket a, GamestatePacket b) { Assert.That(b.packetType, Is.EqualTo(a.packetType)); Assert.That(b.table, Is.EqualTo(a.table)); Assert.That(b.id, Is.EqualTo(a.id)); if (a.packetType != GamestatePacket.PacketType.Delete) { if (a.packetType != GamestatePacket.PacketType.Increment) { Assert.That(b.revisionNumber, Is.EqualTo(a.revisionNumber)); } Assert.That(b.revisionActor, Is.EqualTo(a.revisionActor)); if (a.packetType != GamestatePacket.PacketType.Increment) { Assert.That(b.hasName, Is.EqualTo(a.hasName)); if (a.hasName) { Assert.That(b.name, Is.EqualTo(a.name)); } } Assert.That(b.boolValues, Is.EquivalentTo(a.boolValues)); Assert.That(b.hasShortValues, Is.EquivalentTo(a.hasShortValues)); Assert.That(b.shortValues, Is.EquivalentTo(a.shortValues)); } }
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 static void AssertPacketApplied(GlobalsEntry entry, GamestatePacket packet) { if (packet.hasName) { Assert.That(entry.name, Is.EqualTo(packet.name)); } int i = 0; if (packet.hasShortValues[(int)GlobalsEntry.ShortFields.TimeLimit]) { Assert.That(entry.timeLimit, Is.EqualTo(packet.shortValues[i])); i++; } }
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)); }
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)); }
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(); } }
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); } }
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(); } }
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(); } }
public static void AssertPacketApplied(PlayerEntry entry, GamestatePacket packet) { if (packet.hasName) { Assert.That(entry.name, Is.EqualTo(packet.name)); } int i = 0; if (packet.hasShortValues[(int)PlayerEntry.ShortFields.ActorNumber]) { Assert.That(entry.actorNumber, Is.EqualTo(packet.shortValues[i])); i++; } if (packet.hasShortValues[(int)PlayerEntry.ShortFields.Role]) { Assert.That(entry.role, Is.EqualTo(packet.shortValues[i])); i++; } if (packet.hasShortValues[(int)PlayerEntry.ShortFields.Character]) { Assert.That(entry.character, Is.EqualTo(packet.shortValues[i])); i++; } if (packet.hasShortValues[(int)PlayerEntry.ShortFields.TeamId]) { Assert.That(entry.teamId, Is.EqualTo(packet.shortValues[i])); i++; } Assert.That(entry.isBot, Is.EqualTo(packet.boolValues[(int)PlayerEntry.BoolFields.IsBot])); Assert.That(entry.ready, Is.EqualTo(packet.boolValues[(int)PlayerEntry.BoolFields.Ready])); }