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 diff
     1.1 --- a/API/AbstractWarFoundryLoaderTests.cs	Mon Apr 16 20:45:45 2012 +0100
     1.2 +++ b/API/AbstractWarFoundryLoaderTests.cs	Sat Jul 07 21:02:53 2012 +0100
     1.3 @@ -4,6 +4,7 @@
     1.4  using System.Collections.Generic;
     1.5  using NUnit.Framework.SyntaxHelpers;
     1.6  using System.IO;
     1.7 +using IBBoard.WarFoundry.API.Loading;
     1.8  
     1.9  namespace IBBoard.WarFoundry.API
    1.10  {
    1.11 @@ -14,8 +15,8 @@
    1.12  		public void TestTriesToLoadFromSubdir()
    1.13  		{
    1.14  			MockWarFoundryLoader loader = new MockWarFoundryLoader();
    1.15 -			loader.AddLoadDirectory(new DirectoryInfo("testdata/subdir-loading-test"));
    1.16 -			List<FileLoadFailure> failures = loader.LoadFiles ();
    1.17 +			loader.AddLoadSource(new LoadableObjectSourceDirectory("testdata/subdir-loading-test"));
    1.18 +			List<FileLoadFailure> failures = loader.LoadFiles();
    1.19  			Assert.That(failures.Count, Is.EqualTo(2));
    1.20  		}
    1.21  	}
     2.1 --- a/API/Factories/AbstractNativeWarFoundryFactoryTest.cs	Mon Apr 16 20:45:45 2012 +0100
     2.2 +++ b/API/Factories/AbstractNativeWarFoundryFactoryTest.cs	Sat Jul 07 21:02:53 2012 +0100
     2.3 @@ -9,6 +9,7 @@
     2.4  using System.IO;
     2.5  using IBBoard.WarFoundry.API.Objects;
     2.6  using System.Collections.Generic;
     2.7 +using IBBoard.WarFoundry.API.Loading;
     2.8  
     2.9  namespace IBBoard.WarFoundry.API.Factories
    2.10  {
    2.11 @@ -20,12 +21,12 @@
    2.12  		{
    2.13  			MockNativeWarFoundryFactory factory = new MockNativeWarFoundryFactory();
    2.14  			Stopwatch sw = Stopwatch.StartNew();
    2.15 -			factory.CreateObjectsFromFile(new FileInfo("testdata/Test.race"));
    2.16 +			factory.CreateObjectsFromFile(new LoadableFileObject("testdata/Test.race"));
    2.17  			sw.Stop();
    2.18  			long successElapsed = sw.ElapsedMilliseconds;
    2.19  			sw.Reset();
    2.20  			sw.Start();
    2.21 -			factory.CreateObjectsFromFile(new FileInfo("testdata/NotARaceFile.txt"));
    2.22 +			factory.CreateObjectsFromFile(new LoadableFileObject("testdata/NotARaceFile.txt"));
    2.23  			sw.Stop();
    2.24  			long failedElapsed = sw.ElapsedMilliseconds;
    2.25  			long timeRatio = failedElapsed / successElapsed;
    2.26 @@ -39,7 +40,7 @@
    2.27  			//This will also be triggered by Bug94TestLoadingTimesForNonZipFiles, but this makes it separate and explicit
    2.28  			FileInfo nonRaceFile = new FileInfo("testdata/NotARaceFile.txt");
    2.29  			Assert.That(nonRaceFile.Exists, Is.True);
    2.30 -			Assert.That(factory.CanHandleFileFormat(nonRaceFile), Is.False);
    2.31 +			Assert.That(factory.CanHandleFileFormat(new LoadableFileObject(nonRaceFile)), Is.False);
    2.32  		}
    2.33  
    2.34  		[Test]
    2.35 @@ -50,7 +51,7 @@
    2.36  			Assert.That(factory.GetGameSystemZipEntries(file), Has.Count(3));
    2.37  			Assert.That(factory.GetRaceZipEntries(file), Has.Count(3));
    2.38  			Assert.That(factory.GetArmyZipEntries(file), Has.Count(3));
    2.39 -			ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(file);
    2.40 +			ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new LoadableFileObject(file));
    2.41  			Assert.That(objs, Has.Count(0));
    2.42  		}
    2.43  	}
     3.1 --- a/API/Factories/Xml/WarFoundryXmlFactoryTests.cs	Mon Apr 16 20:45:45 2012 +0100
     3.2 +++ b/API/Factories/Xml/WarFoundryXmlFactoryTests.cs	Sat Jul 07 21:02:53 2012 +0100
     3.3 @@ -4,6 +4,7 @@
     3.4  using System.Collections.Generic;
     3.5  using IBBoard.WarFoundry.API.Objects;
     3.6  using NUnit.Framework.SyntaxHelpers;
     3.7 +using IBBoard.WarFoundry.API.Loading;
     3.8  
     3.9  namespace IBBoard.WarFoundry.API.Factories.Xml
    3.10  {
    3.11 @@ -19,7 +20,7 @@
    3.12  			try
    3.13  			{
    3.14  				loader.RegisterFactory(factory);
    3.15 -				ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Test.system"));
    3.16 +				ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new LoadableFileObject("testdata/multifile-zips/Test.system"));
    3.17  				Assert.That(objs, Has.Count(2));
    3.18  				int raceCount = 0;
    3.19  				int systemCount = 0;
    3.20 @@ -30,7 +31,8 @@
    3.21  					{
    3.22  						raceCount++;
    3.23  					}
    3.24 -					else if (obj is GameSystem)
    3.25 +					else
    3.26 +					if (obj is GameSystem)
    3.27  					{
    3.28  						systemCount++;
    3.29  					}
    3.30 @@ -54,7 +56,7 @@
    3.31  			loader.RegisterFactory(factory);
    3.32  			try
    3.33  			{
    3.34 -				ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Test.race"));
    3.35 +				ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new LoadableFileObject("testdata/multifile-zips/Test.race"));
    3.36  				Assert.That(objs, Has.Count(2));
    3.37  				int raceCount = 0;
    3.38  				int systemCount = 0;
    3.39 @@ -65,7 +67,8 @@
    3.40  					{
    3.41  						raceCount++;
    3.42  					}
    3.43 -					else if (obj is GameSystem)
    3.44 +					else
    3.45 +					if (obj is GameSystem)
    3.46  					{
    3.47  						systemCount++;
    3.48  					}
    3.49 @@ -89,7 +92,7 @@
    3.50  			loader.RegisterFactory(factory);
    3.51  			try
    3.52  			{
    3.53 -				ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Multipack.system"));
    3.54 +				ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new LoadableFileObject("testdata/multifile-zips/Multipack.system"));
    3.55  				Assert.That(objs, Has.Count(4));
    3.56  				int raceCount = 0;
    3.57  				int systemCount = 0;
    3.58 @@ -100,7 +103,8 @@
    3.59  					{
    3.60  						raceCount++;
    3.61  					}
    3.62 -					else if (obj is GameSystem)
    3.63 +					else
    3.64 +					if (obj is GameSystem)
    3.65  					{
    3.66  						systemCount++;
    3.67  					}
     4.1 --- a/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Mon Apr 16 20:45:45 2012 +0100
     4.2 +++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Sat Jul 07 21:02:53 2012 +0100
     4.3 @@ -12,6 +12,7 @@
     4.4  using NUnit.Framework.SyntaxHelpers;
     4.5  using IBBoard.WarFoundry.API.Objects.Requirement;
     4.6  using IBBoard.WarFoundry.API.Factories.Requirement;
     4.7 +using IBBoard.WarFoundry.API.Loading;
     4.8  
     4.9  namespace IBBoard.WarFoundry.API.Factories.Xml
    4.10  {
    4.11 @@ -167,7 +168,7 @@
    4.12  		[ExpectedException(typeof(InvalidFileException), ExpectedMessage="Referenced game system, 'nonexistant-system', did not exist")]
    4.13  		public void TestCompleteLoadingOnRaceWithMissingGameSystemErrors()
    4.14  		{
    4.15 -			ICollection<IWarFoundryObject> objs = WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(new FileInfo("testdata/race-with-non-existant-game-system.race"));
    4.16 +			ICollection<IWarFoundryObject> objs = WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(new LoadableFileObject(new FileInfo("testdata/race-with-non-existant-game-system.race")));
    4.17  			Assert.AreEqual(1, objs.Count);
    4.18  			IEnumerator<IWarFoundryObject> enumerator = objs.GetEnumerator();
    4.19  			enumerator.Reset();
     5.1 --- a/API/Factories/Xml/WarFoundryXmlSystemFactoryTest.cs	Mon Apr 16 20:45:45 2012 +0100
     5.2 +++ b/API/Factories/Xml/WarFoundryXmlSystemFactoryTest.cs	Sat Jul 07 21:02:53 2012 +0100
     5.3 @@ -9,6 +9,7 @@
     5.4  using NUnit.Framework.SyntaxHelpers;
     5.5  using IBBoard.IO;
     5.6  using System.Xml.Schema;
     5.7 +using IBBoard.WarFoundry.API.Loading;
     5.8  
     5.9  namespace IBBoard.WarFoundry.API.Factories.Xml
    5.10  {
    5.11 @@ -18,7 +19,7 @@
    5.12  		[Test()]
    5.13  		public void TestBug311InvalidVersionToExtract788()
    5.14  		{
    5.15 -			FileInfo repackFile = new FileInfo("testdata/zip-format/Repack.system");
    5.16 +			ILoadableObject repackFile = new LoadableFileObject("testdata/zip-format/Repack.system");
    5.17  			Assert.That(WarFoundryXmlFactory.GetFactory().CanHandleFileAsGameSystem(repackFile), Is.True);
    5.18  			Assert.That(WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(repackFile), Has.Count(1));
    5.19  		}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/API/Loading/LoadableObjectSourceDirectoryTests.cs	Sat Jul 07 21:02:53 2012 +0100
     6.3 @@ -0,0 +1,28 @@
     6.4 +// This file (LoadableObjectSourceDirectoryTests.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2012 IBBoard
     6.5 +//
     6.6 +// 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.
     6.7 +using System;
     6.8 +using IBBoard.NUnit;
     6.9 +using System.Reflection;
    6.10 +
    6.11 +namespace IBBoard.WarFoundry.API.Loading
    6.12 +{
    6.13 +	public class LoadableObjectSourceDirectoryTests : AbstractEqualityTest<LoadableObjectSourceDirectory>
    6.14 +	{
    6.15 +		public override LoadableObjectSourceDirectory GetObject()
    6.16 +		{
    6.17 +			return new LoadableObjectSourceDirectory("test");
    6.18 +		}
    6.19 +
    6.20 +		public override LoadableObjectSourceDirectory GetSameObject()
    6.21 +		{
    6.22 +			return new LoadableObjectSourceDirectory("test");
    6.23 +		}
    6.24 +
    6.25 +		public override LoadableObjectSourceDirectory GetDifferentObject()
    6.26 +		{
    6.27 +			return new LoadableObjectSourceDirectory("otherdir");
    6.28 +		}
    6.29 +	}
    6.30 +}
    6.31 +
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/API/Loading/LoadableObjectSourceResourceSetTests.cs	Sat Jul 07 21:02:53 2012 +0100
     7.3 @@ -0,0 +1,43 @@
     7.4 +// This file (LoadableObjectSourceResourceSetTests.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2012 IBBoard
     7.5 +//
     7.6 +// 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.
     7.7 +using System;
     7.8 +using IBBoard.NUnit;
     7.9 +using System.Reflection;
    7.10 +
    7.11 +namespace IBBoard.WarFoundry.API.Loading
    7.12 +{
    7.13 +	public class LoadableObjectSourceResourceSetTests : AbstractEqualityTest<LoadableObjectSourceResourceSet>
    7.14 +	{
    7.15 +		public override LoadableObjectSourceResourceSet GetObject()
    7.16 +		{
    7.17 +			return new LoadableObjectSourceResourceSet(Assembly.GetExecutingAssembly(), "test");
    7.18 +		}
    7.19 +
    7.20 +		public override LoadableObjectSourceResourceSet GetSameObject()
    7.21 +		{
    7.22 +			return new LoadableObjectSourceResourceSet(Assembly.GetExecutingAssembly(), "test");
    7.23 +		}
    7.24 +
    7.25 +		public override LoadableObjectSourceResourceSet GetDifferentObject()
    7.26 +		{
    7.27 +			return new LoadableObjectSourceResourceSet(typeof(Does).Assembly, "othertest");
    7.28 +		}
    7.29 +
    7.30 +		public LoadableObjectSourceResourceSet GetOtherDifferentAssemblyObject()
    7.31 +		{
    7.32 +			return new LoadableObjectSourceResourceSet(typeof(Does).Assembly, "test");
    7.33 +		}
    7.34 +		
    7.35 +		public LoadableObjectSourceResourceSet GetOtherDifferentIDListObject()
    7.36 +		{
    7.37 +			return new LoadableObjectSourceResourceSet(Assembly.GetExecutingAssembly(), "test", "othertest");
    7.38 +		}
    7.39 +		
    7.40 +		public LoadableObjectSourceResourceSet GetOtherDifferentAssemblyAndIDsObject()
    7.41 +		{
    7.42 +			return new LoadableObjectSourceResourceSet(typeof(Does).Assembly, "othertest");
    7.43 +		}
    7.44 +	}
    7.45 +}
    7.46 +
     8.1 --- a/API/WarFoundryLoaderTest.cs	Mon Apr 16 20:45:45 2012 +0100
     8.2 +++ b/API/WarFoundryLoaderTest.cs	Sat Jul 07 21:02:53 2012 +0100
     8.3 @@ -12,6 +12,7 @@
     8.4  using IBBoard.WarFoundry.API.Factories.Xml;
     8.5  using IBBoard.WarFoundry.API.Factories.Requirement;
     8.6  using IBBoard.WarFoundry.API.Objects.Requirement;
     8.7 +using IBBoard.WarFoundry.API.Loading;
     8.8  
     8.9  namespace IBBoard.WarFoundry.API.Factories
    8.10  {
    8.11 @@ -32,10 +33,11 @@
    8.12  			AbstractWarFoundryLoader loader = WarFoundryLoader.GetDefault();
    8.13  			DirectoryInfo dir = new DirectoryInfo("testdata");
    8.14  			loader.RegisterFactory(GetSystemFactory());
    8.15 -			loader.AddLoadDirectory(dir);
    8.16 +			ILoadableObjectSource loadSource = new LoadableObjectSourceDirectory(dir);
    8.17 +			loader.AddLoadSource(loadSource);
    8.18  			loader.LoadFiles();
    8.19  			Assert.Greater(loader.GetGameSystems().Length, 0);
    8.20 -			loader.RemoveLoadDirectory(dir);
    8.21 +			loader.RemoveLoadSource(loadSource);
    8.22  			loader.UnregisterFactory(GetSystemFactory());
    8.23  		}
    8.24  		
     9.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Mon Apr 16 20:45:45 2012 +0100
     9.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Sat Jul 07 21:02:53 2012 +0100
     9.3 @@ -33,9 +33,9 @@
     9.4      <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
     9.5    </PropertyGroup>
     9.6    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     9.7 -    <DebugSymbols>true</DebugSymbols>
     9.8 +    <DebugSymbols>True</DebugSymbols>
     9.9      <DebugType>full</DebugType>
    9.10 -    <Optimize>false</Optimize>
    9.11 +    <Optimize>False</Optimize>
    9.12      <OutputPath>bin\Debug\</OutputPath>
    9.13      <DefineConstants>DEBUG;TRACE</DefineConstants>
    9.14      <ErrorReport>prompt</ErrorReport>
    9.15 @@ -43,7 +43,7 @@
    9.16    </PropertyGroup>
    9.17    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    9.18      <DebugType>pdbonly</DebugType>
    9.19 -    <Optimize>true</Optimize>
    9.20 +    <Optimize>True</Optimize>
    9.21      <OutputPath>bin\Release\</OutputPath>
    9.22      <DefineConstants>TRACE</DefineConstants>
    9.23      <ErrorReport>prompt</ErrorReport>
    9.24 @@ -124,6 +124,8 @@
    9.25      <Compile Include="API\Objects\Mock\MockContainedUnitType.cs" />
    9.26      <Compile Include="API\Objects\ArmyCategoryTests.cs" />
    9.27      <Compile Include="API\Commands\RemoveUnitCommandTest.cs" />
    9.28 +    <Compile Include="API\Loading\LoadableObjectSourceResourceSetTests.cs" />
    9.29 +    <Compile Include="API\Loading\LoadableObjectSourceDirectoryTests.cs" />
    9.30    </ItemGroup>
    9.31    <ItemGroup>
    9.32      <None Include="app.config" />
    9.33 @@ -297,7 +299,7 @@
    9.34        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    9.35      </None>
    9.36      <None Include="testdata\points-strings\names.systemx">
    9.37 -      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
    9.38 +      <Gettext-ScanForTranslations>False</Gettext-ScanForTranslations>
    9.39        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    9.40      </None>
    9.41      <None Include="testdata\multifile-zips\Multipack.system">
    9.42 @@ -404,6 +406,7 @@
    9.43    </ItemGroup>
    9.44    <ItemGroup>
    9.45      <Folder Include="API\Savers\Xml\" />
    9.46 +    <Folder Include="API\Loading\" />
    9.47    </ItemGroup>
    9.48    <ItemGroup>
    9.49      <Content Include="testdata\xml_output.xml">