view API/Factories/AbstractNativeWarFoundryFactoryTest.cs @ 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 498396c77601
children e173c5512067
line wrap: on
line source

// This file (AbstractNativeWarFoundryFactoryTest.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 NUnit.Framework;
using IBBoard.WarFoundry.API.Factories.Mock;
using System.Diagnostics;
using NUnit.Framework.SyntaxHelpers;
using System.IO;
using IBBoard.WarFoundry.API.Objects;
using System.Collections.Generic;
using IBBoard.WarFoundry.API.Loading;

namespace IBBoard.WarFoundry.API.Factories
{
	[TestFixture]
	public class AbstractNativeWarFoundryFactoryTest
	{
		[Test]
		public void Bug94TestLoadingTimesForNonZipFiles()
		{
			MockNativeWarFoundryFactory factory = new MockNativeWarFoundryFactory();
			Stopwatch sw = Stopwatch.StartNew();
			factory.CreateObjectsFromFile(new LoadableFileObject("testdata/Test.race"));
			sw.Stop();
			long successElapsed = sw.ElapsedMilliseconds;
			sw.Reset();
			sw.Start();
			factory.CreateObjectsFromFile(new LoadableFileObject("testdata/NotARaceFile.txt"));
			sw.Stop();
			long failedElapsed = sw.ElapsedMilliseconds;
			long timeRatio = failedElapsed / successElapsed;
			Assert.That(timeRatio, Is.LessThan(10));
		}

		[Test]
		public void Bug358TestLoadingOfFailedFiles()
		{
			MockNativeWarFoundryFactory factory = new MockNativeWarFoundryFactory();
			//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(new LoadableFileObject(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(new LoadableFileObject(file));
			Assert.That(objs, Has.Count(0));
		}
	}
}