Add tests to verify sync hashing mechanism.

This commit is contained in:
RoosterDragon
2015-07-31 22:11:14 +01:00
parent cfd2f265d5
commit 9f32eb76cd
2 changed files with 79 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
#region Copyright & License Information
/*
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using NUnit.Framework;
using OpenRA.Traits;
namespace OpenRA.Test
{
[TestFixture]
class SyncTest
{
class Complex : ISync
{
[Sync]
public bool Bool = true;
[Sync]
public int Int = -123456789;
[Sync]
public int2 Int2 = new int2(123, -456);
[Sync]
public CPos CPos = new CPos(123, -456);
[Sync]
public CVec CVec = new CVec(123, -456);
[Sync]
public WDist WDist = new WDist(123);
[Sync]
public WPos WPos = new WPos(123, -456, int.MaxValue);
[Sync]
public WVec WVec = new WVec(123, -456, int.MaxValue);
[Sync]
public WAngle WAngle = new WAngle(123);
[Sync]
public WRot WRot = new WRot(new WAngle(123), new WAngle(-456), new WAngle(int.MaxValue));
[Sync]
public Target Target = Target.FromPos(new WPos(123, -456, int.MaxValue));
}
[TestCase(TestName = "Sync hashing has not accidentally changed")]
public void ComplexHash()
{
// If you have intentionally changed the values used for sync hashing, just update the expected value.
Assert.AreEqual(-2024026914, Sync.CalculateSyncHash(new Complex()));
}
class Flat : ISync
{
[Sync]
int a = 123456789;
[Sync]
bool b = true;
}
class Base : ISync
{
[Sync]
bool b = true;
}
class Derived : Base
{
[Sync]
int a = 123456789;
}
[TestCase(TestName = "All sync members in inheritance hierarchy are hashed")]
public void DerivedHash()
{
Assert.AreEqual(Sync.CalculateSyncHash(new Flat()), Sync.CalculateSyncHash(new Derived()));
}
}
}

View File

@@ -49,6 +49,7 @@
<Compile Include="OpenRA.Game\ActorInfoTest.cs" /> <Compile Include="OpenRA.Game\ActorInfoTest.cs" />
<Compile Include="OpenRA.Game\OrderTest.cs" /> <Compile Include="OpenRA.Game\OrderTest.cs" />
<Compile Include="OpenRA.Game\PlatformTest.cs" /> <Compile Include="OpenRA.Game\PlatformTest.cs" />
<Compile Include="OpenRA.Game\SyncTest.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj"> <ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">