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
line source
1 // This file (AbstractNativeWarFoundryFactoryTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard
2 //
3 // 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.
4 using System;
5 using NUnit.Framework;
6 using IBBoard.WarFoundry.API.Factories.Mock;
7 using System.Diagnostics;
8 using NUnit.Framework.SyntaxHelpers;
9 using System.IO;
10 using IBBoard.WarFoundry.API.Objects;
11 using System.Collections.Generic;
12 using IBBoard.WarFoundry.API.Loading;
14 namespace IBBoard.WarFoundry.API.Factories
15 {
16 [TestFixture]
17 public class AbstractNativeWarFoundryFactoryTest
18 {
19 [Test]
20 public void Bug94TestLoadingTimesForNonZipFiles()
21 {
22 MockNativeWarFoundryFactory factory = new MockNativeWarFoundryFactory();
23 Stopwatch sw = Stopwatch.StartNew();
24 factory.CreateObjectsFromFile(new LoadableFileObject("testdata/Test.race"));
25 sw.Stop();
26 long successElapsed = sw.ElapsedMilliseconds;
27 sw.Reset();
28 sw.Start();
29 factory.CreateObjectsFromFile(new LoadableFileObject("testdata/NotARaceFile.txt"));
30 sw.Stop();
31 long failedElapsed = sw.ElapsedMilliseconds;
32 long timeRatio = failedElapsed / successElapsed;
33 Assert.That(timeRatio, Is.LessThan(10));
34 }
36 [Test]
37 public void Bug358TestLoadingOfFailedFiles()
38 {
39 MockNativeWarFoundryFactory factory = new MockNativeWarFoundryFactory();
40 //This will also be triggered by Bug94TestLoadingTimesForNonZipFiles, but this makes it separate and explicit
41 FileInfo nonRaceFile = new FileInfo("testdata/NotARaceFile.txt");
42 Assert.That(nonRaceFile.Exists, Is.True);
43 Assert.That(factory.CanHandleFileFormat(new LoadableFileObject(nonRaceFile)), Is.False);
44 }
46 [Test]
47 public void Bug380TestLoadingOfOSXesqueFile()
48 {
49 FileSearchingWarFoundryFactory factory = new FileSearchingWarFoundryFactory();
50 FileInfo file = new FileInfo("testdata/multifile-zips/Test-OSX-style.system");
51 Assert.That(factory.GetGameSystemZipEntries(file), Has.Count(3));
52 Assert.That(factory.GetRaceZipEntries(file), Has.Count(3));
53 Assert.That(factory.GetArmyZipEntries(file), Has.Count(3));
54 ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new LoadableFileObject(file));
55 Assert.That(objs, Has.Count(0));
56 }
57 }
58 }