changeset 228:7c21ca1482cb

Re #419: Remove assumptions of a file-based install * Update tests to use new "loadable object" and "loadable object source" wrappers
author IBBoard <dev@ibboard.co.uk>
date Sat, 07 Jul 2012 21:02:53 +0100
parents d8cd6b259a9f
children 6ec46f3db2d4
files API/AbstractWarFoundryLoaderTests.cs API/Factories/AbstractNativeWarFoundryFactoryTest.cs API/Factories/Xml/WarFoundryXmlFactoryTests.cs API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs API/Factories/Xml/WarFoundryXmlSystemFactoryTest.cs API/Loading/LoadableObjectSourceDirectoryTests.cs API/Loading/LoadableObjectSourceResourceSetTests.cs API/WarFoundryLoaderTest.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 9 files changed, 104 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/API/AbstractWarFoundryLoaderTests.cs	Mon Apr 16 20:45:45 2012 +0100
+++ b/API/AbstractWarFoundryLoaderTests.cs	Sat Jul 07 21:02:53 2012 +0100
@@ -4,6 +4,7 @@
 using System.Collections.Generic;
 using NUnit.Framework.SyntaxHelpers;
 using System.IO;
+using IBBoard.WarFoundry.API.Loading;
 
 namespace IBBoard.WarFoundry.API
 {
@@ -14,8 +15,8 @@
 		public void TestTriesToLoadFromSubdir()
 		{
 			MockWarFoundryLoader loader = new MockWarFoundryLoader();
-			loader.AddLoadDirectory(new DirectoryInfo("testdata/subdir-loading-test"));
-			List<FileLoadFailure> failures = loader.LoadFiles ();
+			loader.AddLoadSource(new LoadableObjectSourceDirectory("testdata/subdir-loading-test"));
+			List<FileLoadFailure> failures = loader.LoadFiles();
 			Assert.That(failures.Count, Is.EqualTo(2));
 		}
 	}
--- a/API/Factories/AbstractNativeWarFoundryFactoryTest.cs	Mon Apr 16 20:45:45 2012 +0100
+++ b/API/Factories/AbstractNativeWarFoundryFactoryTest.cs	Sat Jul 07 21:02:53 2012 +0100
@@ -9,6 +9,7 @@
 using System.IO;
 using IBBoard.WarFoundry.API.Objects;
 using System.Collections.Generic;
+using IBBoard.WarFoundry.API.Loading;
 
 namespace IBBoard.WarFoundry.API.Factories
 {
@@ -20,12 +21,12 @@
 		{
 			MockNativeWarFoundryFactory factory = new MockNativeWarFoundryFactory();
 			Stopwatch sw = Stopwatch.StartNew();
-			factory.CreateObjectsFromFile(new FileInfo("testdata/Test.race"));
+			factory.CreateObjectsFromFile(new LoadableFileObject("testdata/Test.race"));
 			sw.Stop();
 			long successElapsed = sw.ElapsedMilliseconds;
 			sw.Reset();
 			sw.Start();
-			factory.CreateObjectsFromFile(new FileInfo("testdata/NotARaceFile.txt"));
+			factory.CreateObjectsFromFile(new LoadableFileObject("testdata/NotARaceFile.txt"));
 			sw.Stop();
 			long failedElapsed = sw.ElapsedMilliseconds;
 			long timeRatio = failedElapsed / successElapsed;
@@ -39,7 +40,7 @@
 			//This will also be triggered by Bug94TestLoadingTimesForNonZipFiles, but this makes it separate and explicit
 			FileInfo nonRaceFile = new FileInfo("testdata/NotARaceFile.txt");
 			Assert.That(nonRaceFile.Exists, Is.True);
-			Assert.That(factory.CanHandleFileFormat(nonRaceFile), Is.False);
+			Assert.That(factory.CanHandleFileFormat(new LoadableFileObject(nonRaceFile)), Is.False);
 		}
 
 		[Test]
@@ -50,7 +51,7 @@
 			Assert.That(factory.GetGameSystemZipEntries(file), Has.Count(3));
 			Assert.That(factory.GetRaceZipEntries(file), Has.Count(3));
 			Assert.That(factory.GetArmyZipEntries(file), Has.Count(3));
-			ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(file);
+			ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new LoadableFileObject(file));
 			Assert.That(objs, Has.Count(0));
 		}
 	}
--- a/API/Factories/Xml/WarFoundryXmlFactoryTests.cs	Mon Apr 16 20:45:45 2012 +0100
+++ b/API/Factories/Xml/WarFoundryXmlFactoryTests.cs	Sat Jul 07 21:02:53 2012 +0100
@@ -4,6 +4,7 @@
 using System.Collections.Generic;
 using IBBoard.WarFoundry.API.Objects;
 using NUnit.Framework.SyntaxHelpers;
+using IBBoard.WarFoundry.API.Loading;
 
 namespace IBBoard.WarFoundry.API.Factories.Xml
 {
@@ -19,7 +20,7 @@
 			try
 			{
 				loader.RegisterFactory(factory);
-				ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Test.system"));
+				ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new LoadableFileObject("testdata/multifile-zips/Test.system"));
 				Assert.That(objs, Has.Count(2));
 				int raceCount = 0;
 				int systemCount = 0;
@@ -30,7 +31,8 @@
 					{
 						raceCount++;
 					}
-					else if (obj is GameSystem)
+					else
+					if (obj is GameSystem)
 					{
 						systemCount++;
 					}
@@ -54,7 +56,7 @@
 			loader.RegisterFactory(factory);
 			try
 			{
-				ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Test.race"));
+				ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new LoadableFileObject("testdata/multifile-zips/Test.race"));
 				Assert.That(objs, Has.Count(2));
 				int raceCount = 0;
 				int systemCount = 0;
@@ -65,7 +67,8 @@
 					{
 						raceCount++;
 					}
-					else if (obj is GameSystem)
+					else
+					if (obj is GameSystem)
 					{
 						systemCount++;
 					}
@@ -89,7 +92,7 @@
 			loader.RegisterFactory(factory);
 			try
 			{
-				ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Multipack.system"));
+				ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new LoadableFileObject("testdata/multifile-zips/Multipack.system"));
 				Assert.That(objs, Has.Count(4));
 				int raceCount = 0;
 				int systemCount = 0;
@@ -100,7 +103,8 @@
 					{
 						raceCount++;
 					}
-					else if (obj is GameSystem)
+					else
+					if (obj is GameSystem)
 					{
 						systemCount++;
 					}
--- a/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Mon Apr 16 20:45:45 2012 +0100
+++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Sat Jul 07 21:02:53 2012 +0100
@@ -12,6 +12,7 @@
 using NUnit.Framework.SyntaxHelpers;
 using IBBoard.WarFoundry.API.Objects.Requirement;
 using IBBoard.WarFoundry.API.Factories.Requirement;
+using IBBoard.WarFoundry.API.Loading;
 
 namespace IBBoard.WarFoundry.API.Factories.Xml
 {
@@ -167,7 +168,7 @@
 		[ExpectedException(typeof(InvalidFileException), ExpectedMessage="Referenced game system, 'nonexistant-system', did not exist")]
 		public void TestCompleteLoadingOnRaceWithMissingGameSystemErrors()
 		{
-			ICollection<IWarFoundryObject> objs = WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(new FileInfo("testdata/race-with-non-existant-game-system.race"));
+			ICollection<IWarFoundryObject> objs = WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(new LoadableFileObject(new FileInfo("testdata/race-with-non-existant-game-system.race")));
 			Assert.AreEqual(1, objs.Count);
 			IEnumerator<IWarFoundryObject> enumerator = objs.GetEnumerator();
 			enumerator.Reset();
--- a/API/Factories/Xml/WarFoundryXmlSystemFactoryTest.cs	Mon Apr 16 20:45:45 2012 +0100
+++ b/API/Factories/Xml/WarFoundryXmlSystemFactoryTest.cs	Sat Jul 07 21:02:53 2012 +0100
@@ -9,6 +9,7 @@
 using NUnit.Framework.SyntaxHelpers;
 using IBBoard.IO;
 using System.Xml.Schema;
+using IBBoard.WarFoundry.API.Loading;
 
 namespace IBBoard.WarFoundry.API.Factories.Xml
 {
@@ -18,7 +19,7 @@
 		[Test()]
 		public void TestBug311InvalidVersionToExtract788()
 		{
-			FileInfo repackFile = new FileInfo("testdata/zip-format/Repack.system");
+			ILoadableObject repackFile = new LoadableFileObject("testdata/zip-format/Repack.system");
 			Assert.That(WarFoundryXmlFactory.GetFactory().CanHandleFileAsGameSystem(repackFile), Is.True);
 			Assert.That(WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(repackFile), Has.Count(1));
 		}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Loading/LoadableObjectSourceDirectoryTests.cs	Sat Jul 07 21:02:53 2012 +0100
@@ -0,0 +1,28 @@
+// This file (LoadableObjectSourceDirectoryTests.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2012 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;
+using IBBoard.NUnit;
+using System.Reflection;
+
+namespace IBBoard.WarFoundry.API.Loading
+{
+	public class LoadableObjectSourceDirectoryTests : AbstractEqualityTest<LoadableObjectSourceDirectory>
+	{
+		public override LoadableObjectSourceDirectory GetObject()
+		{
+			return new LoadableObjectSourceDirectory("test");
+		}
+
+		public override LoadableObjectSourceDirectory GetSameObject()
+		{
+			return new LoadableObjectSourceDirectory("test");
+		}
+
+		public override LoadableObjectSourceDirectory GetDifferentObject()
+		{
+			return new LoadableObjectSourceDirectory("otherdir");
+		}
+	}
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Loading/LoadableObjectSourceResourceSetTests.cs	Sat Jul 07 21:02:53 2012 +0100
@@ -0,0 +1,43 @@
+// This file (LoadableObjectSourceResourceSetTests.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2012 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;
+using IBBoard.NUnit;
+using System.Reflection;
+
+namespace IBBoard.WarFoundry.API.Loading
+{
+	public class LoadableObjectSourceResourceSetTests : AbstractEqualityTest<LoadableObjectSourceResourceSet>
+	{
+		public override LoadableObjectSourceResourceSet GetObject()
+		{
+			return new LoadableObjectSourceResourceSet(Assembly.GetExecutingAssembly(), "test");
+		}
+
+		public override LoadableObjectSourceResourceSet GetSameObject()
+		{
+			return new LoadableObjectSourceResourceSet(Assembly.GetExecutingAssembly(), "test");
+		}
+
+		public override LoadableObjectSourceResourceSet GetDifferentObject()
+		{
+			return new LoadableObjectSourceResourceSet(typeof(Does).Assembly, "othertest");
+		}
+
+		public LoadableObjectSourceResourceSet GetOtherDifferentAssemblyObject()
+		{
+			return new LoadableObjectSourceResourceSet(typeof(Does).Assembly, "test");
+		}
+		
+		public LoadableObjectSourceResourceSet GetOtherDifferentIDListObject()
+		{
+			return new LoadableObjectSourceResourceSet(Assembly.GetExecutingAssembly(), "test", "othertest");
+		}
+		
+		public LoadableObjectSourceResourceSet GetOtherDifferentAssemblyAndIDsObject()
+		{
+			return new LoadableObjectSourceResourceSet(typeof(Does).Assembly, "othertest");
+		}
+	}
+}
+
--- a/API/WarFoundryLoaderTest.cs	Mon Apr 16 20:45:45 2012 +0100
+++ b/API/WarFoundryLoaderTest.cs	Sat Jul 07 21:02:53 2012 +0100
@@ -12,6 +12,7 @@
 using IBBoard.WarFoundry.API.Factories.Xml;
 using IBBoard.WarFoundry.API.Factories.Requirement;
 using IBBoard.WarFoundry.API.Objects.Requirement;
+using IBBoard.WarFoundry.API.Loading;
 
 namespace IBBoard.WarFoundry.API.Factories
 {
@@ -32,10 +33,11 @@
 			AbstractWarFoundryLoader loader = WarFoundryLoader.GetDefault();
 			DirectoryInfo dir = new DirectoryInfo("testdata");
 			loader.RegisterFactory(GetSystemFactory());
-			loader.AddLoadDirectory(dir);
+			ILoadableObjectSource loadSource = new LoadableObjectSourceDirectory(dir);
+			loader.AddLoadSource(loadSource);
 			loader.LoadFiles();
 			Assert.Greater(loader.GetGameSystems().Length, 0);
-			loader.RemoveLoadDirectory(dir);
+			loader.RemoveLoadSource(loadSource);
 			loader.UnregisterFactory(GetSystemFactory());
 		}
 		
--- a/IBBoard.WarFoundry.API.Tests.csproj	Mon Apr 16 20:45:45 2012 +0100
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Sat Jul 07 21:02:53 2012 +0100
@@ -33,9 +33,9 @@
     <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
-    <DebugSymbols>true</DebugSymbols>
+    <DebugSymbols>True</DebugSymbols>
     <DebugType>full</DebugType>
-    <Optimize>false</Optimize>
+    <Optimize>False</Optimize>
     <OutputPath>bin\Debug\</OutputPath>
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
@@ -43,7 +43,7 @@
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <DebugType>pdbonly</DebugType>
-    <Optimize>true</Optimize>
+    <Optimize>True</Optimize>
     <OutputPath>bin\Release\</OutputPath>
     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
@@ -124,6 +124,8 @@
     <Compile Include="API\Objects\Mock\MockContainedUnitType.cs" />
     <Compile Include="API\Objects\ArmyCategoryTests.cs" />
     <Compile Include="API\Commands\RemoveUnitCommandTest.cs" />
+    <Compile Include="API\Loading\LoadableObjectSourceResourceSetTests.cs" />
+    <Compile Include="API\Loading\LoadableObjectSourceDirectoryTests.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
@@ -297,7 +299,7 @@
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
     <None Include="testdata\points-strings\names.systemx">
-      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
+      <Gettext-ScanForTranslations>False</Gettext-ScanForTranslations>
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
     <None Include="testdata\multifile-zips\Multipack.system">
@@ -404,6 +406,7 @@
   </ItemGroup>
   <ItemGroup>
     <Folder Include="API\Savers\Xml\" />
+    <Folder Include="API\Loading\" />
   </ItemGroup>
   <ItemGroup>
     <Content Include="testdata\xml_output.xml">