changeset 196:498396c77601

Re #380: WarFoundry chokes on zips written by Mac OS X * Add test to check that entries are found but skipped for loading * Add mock file that extends the standard XML factory to give us public access to protected methods
author IBBoard <dev@ibboard.co.uk>
date Sun, 04 Dec 2011 20:52:24 +0000
parents 8e95ccb8e9d5
children aa921248ffbf
files API/Factories/AbstractNativeWarFoundryFactoryTest.cs API/Factories/Mock/FileSearchingWarFoundryFactory.cs IBBoard.WarFoundry.API.Tests.csproj testdata/multifile-zips/Test-OSX-style.system
diffstat 4 files changed, 57 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/API/Factories/AbstractNativeWarFoundryFactoryTest.cs	Sat Dec 03 20:09:25 2011 +0000
+++ b/API/Factories/AbstractNativeWarFoundryFactoryTest.cs	Sun Dec 04 20:52:24 2011 +0000
@@ -7,6 +7,8 @@
 using System.Diagnostics;
 using NUnit.Framework.SyntaxHelpers;
 using System.IO;
+using IBBoard.WarFoundry.API.Objects;
+using System.Collections.Generic;
 
 namespace IBBoard.WarFoundry.API.Factories
 {
@@ -39,6 +41,18 @@
 			Assert.That(nonRaceFile.Exists, Is.True);
 			Assert.That(factory.CanHandleFileFormat(nonRaceFile), Is.False);
 		}
+
+		[Test]
+		public void Bug380TestLoadingOfOSXesqueFile()
+		{
+			FileSearchingWarFoundryFactory factory = new FileSearchingWarFoundryFactory();
+			FileInfo file = new FileInfo("testdata/multifile-zips/Test-OSX-style.system");
+			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);
+			Assert.That(objs, Has.Count(0));
+		}
 	}
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Factories/Mock/FileSearchingWarFoundryFactory.cs	Sun Dec 04 20:52:24 2011 +0000
@@ -0,0 +1,39 @@
+// This file (FileSearchingWarFoundryFactory.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 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 System.Collections.Generic;
+using ICSharpCode.SharpZipLib.Zip;
+using IBBoard.WarFoundry.API.Factories.Xml;
+using System.IO;
+using IBBoard.WarFoundry.API.Objects;
+
+namespace IBBoard.WarFoundry.API.Factories.Mock
+{
+	public class FileSearchingWarFoundryFactory : WarFoundryXmlFactory
+	{
+		public FileSearchingWarFoundryFactory()
+		{
+			//Do nothing special
+		}
+
+		public ICollection<ZipEntry> GetGameSystemZipEntries(FileInfo file)
+		{
+			ZipFile zip = new ZipFile(file.FullName);
+			return GetGameSystemZipEntries(zip);
+		}
+
+		public ICollection<ZipEntry> GetRaceZipEntries(FileInfo file)
+		{
+			ZipFile zip = new ZipFile(file.FullName);
+			return GetRaceZipEntries(zip);
+		}
+
+		public ICollection<ZipEntry> GetArmyZipEntries(FileInfo file)
+		{
+			ZipFile zip = new ZipFile(file.FullName);
+			return GetArmyZipEntries(zip);
+		}
+	}
+}
+
--- a/IBBoard.WarFoundry.API.Tests.csproj	Sat Dec 03 20:09:25 2011 +0000
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Sun Dec 04 20:52:24 2011 +0000
@@ -115,6 +115,7 @@
     <Compile Include="API\Factories\Requirement\UnitRequiresNoMoreThanNOfUnitTypeRequirementFactoryTest.cs" />
     <Compile Include="API\Objects\Requirement\RequiresNUnitsForMUnitsRequirementTest.cs" />
     <Compile Include="API\Factories\Requirement\UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs" />
+    <Compile Include="API\Factories\Mock\FileSearchingWarFoundryFactory.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
@@ -310,6 +311,9 @@
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </Content>
     <None Include="libs\xmlunit.dll" />
+    <None Include="testdata\multifile-zips\Test-OSX-style.system">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <Reference Include="System" />
Binary file testdata/multifile-zips/Test-OSX-style.system has changed