changeset 54:084049c8dff4

Re #279: Create composite limit * Add first tests for limit parser - composites are parsed, but children aren't picked up by XPath query yet
author IBBoard <dev@ibboard.co.uk>
date Sat, 05 Jun 2010 15:37:03 +0000
parents f6bbd77b5473
children 7f9e1fef069e
files API/Factories/Xml/WarFoundryXmlLimitParserTest.cs IBBoard.WarFoundry.API.Tests.csproj testdata/limits/absolute-limit.xml testdata/limits/composite-limit.xml
diffstat 4 files changed, 81 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Factories/Xml/WarFoundryXmlLimitParserTest.cs	Sat Jun 05 15:37:03 2010 +0000
@@ -0,0 +1,42 @@
+//  This file (WarFoundryXmlLimitParserTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2010 IBBoard
+// 
+//  // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System.IO;
+using System.Xml;
+using NUnit.Framework;
+using IBBoard.Limits;
+using NUnit.Framework.SyntaxHelpers;
+namespace IBBoard.WarFoundry.API.Factories.Xml
+{
+	[TestFixture()]
+	public class WarFoundryXmlLimitParserTest
+	{
+		[Test()]
+		public void TestCompositeLimit()
+		{
+			XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/composite-limit.xml"));
+			XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(document, "//race:maxLimit/*");
+			WarFoundryXmlLimitParser parser = new WarFoundryXmlLimitParser();
+			ILimit limit = parser.GetLimitFromElement(limitElem);
+			Assert.That(limit, Is.InstanceOfType(typeof(CompositeMaximumLimit)));
+			Assert.That(limit.GetLimit(1), Is.EqualTo(5));
+			Assert.That(limit.GetLimit(5), Is.EqualTo(5));
+			Assert.That(limit.GetLimit(10), Is.EqualTo(10));
+			Assert.That(limit.GetLimit(20), Is.EqualTo(10));
+		}
+		
+		[Test()]
+		public void TestAbsoluteLimit()
+		{
+			XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/absolute-limit.xml"));
+			XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(document, "//race:maxLimit/*");
+			WarFoundryXmlLimitParser parser = new WarFoundryXmlLimitParser();
+			ILimit limit = parser.GetLimitFromElement(limitElem);
+			Assert.That(limit, Is.InstanceOfType(typeof(AbsoluteNumericLimit)));
+			Assert.That(limit.GetLimit(1), Is.EqualTo(5));
+			Assert.That(limit.GetLimit(5), Is.EqualTo(5));
+			Assert.That(limit.GetLimit(10), Is.EqualTo(5));
+		}
+	}
+}
+
--- a/IBBoard.WarFoundry.API.Tests.csproj	Sat Jun 05 14:45:28 2010 +0000
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Sat Jun 05 15:37:03 2010 +0000
@@ -63,6 +63,7 @@
     <Compile Include="API\Objects\UnitTypeTest.cs" />
     <Compile Include="API\Factories\Xml\WarFoundryXmlArmyParserTest.cs" />
     <Compile Include="API\FixedObjectWarFoundryLoader.cs" />
+    <Compile Include="API\Factories\Xml\WarFoundryXmlLimitParserTest.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="testdata\Test.race">
@@ -133,6 +134,12 @@
     <None Include="testdata\unit-in-specified-main-category.armyx">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
+    <None Include="testdata\limits\composite-limit.xml">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="testdata\limits\absolute-limit.xml">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <Reference Include="ICSharpCode.SharpZipLib, Version=0.85.5.452, Culture=neutral, PublicKeyToken=1b03e6acf1164f73">
@@ -160,6 +167,7 @@
     <Folder Include="API\Factories\Mock\" />
     <Folder Include="API\Util\" />
     <Folder Include="API\Factories\Xml\" />
+    <Folder Include="testdata\limits\" />
   </ItemGroup>
   <ProjectExtensions>
     <MonoDevelop>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/limits/absolute-limit.xml	Sat Jun 05 15:37:03 2010 +0000
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<race xmlns="http://ibboard.co.uk/warfoundry/race" xmlns:core="http://ibboard.co.uk/warfoundry/core" id="EmpireAlt" name="Empire (Extended)" system="default" lang="en">
+	<units>
+		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1">
+			<equipmentSlots>
+				<equipmentSlot name="slot">
+					<maxLimit>
+						<absoluteLimit limit="5"/>
+					</maxLimit>
+				</equipmentSlot>
+			</equipmentSlots>
+		</unit>
+	</units>
+</race>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/limits/composite-limit.xml	Sat Jun 05 15:37:03 2010 +0000
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<race xmlns="http://ibboard.co.uk/warfoundry/race" xmlns:core="http://ibboard.co.uk/warfoundry/core" id="EmpireAlt" name="Empire (Extended)" system="default" lang="en">
+	<units>
+		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1">
+			<equipmentSlots>
+				<equipmentSlot name="slot">
+					<maxLimit>
+						<compositeMaxLimit>
+							<sizeConstrainedLimit limit="10"/>
+							<absoluteLimit limit="5"/>
+						</compositeMaxLimit>
+					</maxLimit>
+				</equipmentSlot>
+			</equipmentSlots>
+		</unit>
+	</units>
+</race>
\ No newline at end of file