changeset 203:2b27447ae74e

Re #352: Test/fix cyclic references in unit types * Add test case
author IBBoard <dev@ibboard.co.uk>
date Sat, 21 Jan 2012 21:01:02 +0000
parents 49e50238c380
children ea104de9189e
files API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs IBBoard.WarFoundry.API.Tests.csproj testdata/xml-race-factory/cyclic.racex
diffstat 3 files changed, 62 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Fri Dec 23 15:33:53 2011 +0000
+++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Sat Jan 21 21:01:02 2012 +0000
@@ -375,6 +375,15 @@
 			Assert.That(unitType.GetRequirements()[0], Is.InstanceOfType(typeof(UnitRequiresAtLeastNUnitsRequirement)));
 		}
 
+		[Test]
+		public void TestCyclicReferenceDoesNotCrash()
+		{
+			SetDefaultGameSystem();
+			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/xml-race-factory/cyclic.racex"));
+			UnitType unitType = race.GetUnitType("Empire1");
+			Assert.That(unitType.GetRequirements()[0], Is.InstanceOfType(typeof(UnitRequiresAtLeastNUnitsRequirement)));
+		}
+
 		private void TestFileValidationFailure(string filePath)
 		{
 			SetDefaultGameSystem();
--- a/IBBoard.WarFoundry.API.Tests.csproj	Fri Dec 23 15:33:53 2011 +0000
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Sat Jan 21 21:01:02 2012 +0000
@@ -314,6 +314,9 @@
     <None Include="testdata\multifile-zips\Test-OSX-style.system">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
+    <None Include="testdata\xml-race-factory\cyclic.racex">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <Reference Include="System" />
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/xml-race-factory/cyclic.racex	Sat Jan 21 21:01:02 2012 +0000
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<race xmlns="http://ibboard.co.uk/warfoundry/race" xmlns:cats="http://ibboard.co.uk/warfoundry/cats" xmlns:core="http://ibboard.co.uk/warfoundry/core" id="Empire" name="Empire" system="default">
+	<categories>
+		<cats:cat id="cat1" name="Characters" minPercentage="0" maxPercentage="50" />
+		<cats:cat id="cat2" name="Regiments" minPercentage="25" maxPercentage="100" />
+		<cats:cat id="cat3" name="War Machines" minPercentage="0" maxPercentage="25" />
+		<cats:cat id="cat4" name="Monsters" minPercentage="0" maxPercentage="25" />
+		<cats:cat id="cat5" name="Allies" minPercentage="0" maxPercentage="25" />
+	</categories>
+	<units>
+		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100">
+			<stats>
+				<stat name="M">4</stat>
+				<stat name="WS">6</stat>
+				<stat name="BS">6</stat>
+				<stat name="S">4</stat>
+				<stat name="T">4</stat>
+				<stat name="W">3</stat>
+				<stat name="I">6</stat>
+				<stat name="A">4</stat>
+				<stat name="Ld">9</stat>
+			</stats>
+			<requirements>
+				<!-- Unlimited generals, unless we have more than four minions -->
+				<requirement requirementName="RequiresNoMoreThanNUnits">
+					<data>Empire2:4</data>
+				</requirement>
+			</requirements>
+		</unit>
+		<unit id="Empire2" typeName="Minion" cat="cat1" points="0">
+			<stats>
+				<stat name="M">4</stat>
+				<stat name="WS">2</stat>
+				<stat name="BS">2</stat>
+				<stat name="S">2</stat>
+				<stat name="T">2</stat>
+				<stat name="W">1</stat>
+				<stat name="I">2</stat>
+				<stat name="A">1</stat>
+				<stat name="Ld">5</stat>
+			</stats>
+			<requirements>
+				<!-- Unlimited minions for one or more generals -->
+				<requirement requirementName="RequiresAtLeastNUnits">
+					<data>Empire1</data>
+				</requirement>
+			</requirements>
+		</unit>
+	</units>
+</race>
\ No newline at end of file