annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
165
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (AbstractNativeWarFoundryFactoryTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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.
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 using System;
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using NUnit.Framework;
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using IBBoard.WarFoundry.API.Factories.Mock;
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using System.Diagnostics;
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using NUnit.Framework.SyntaxHelpers;
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 using System.IO;
196
498396c77601 Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents: 168
diff changeset
10 using IBBoard.WarFoundry.API.Objects;
498396c77601 Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents: 168
diff changeset
11 using System.Collections.Generic;
228
7c21ca1482cb Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 196
diff changeset
12 using IBBoard.WarFoundry.API.Loading;
165
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 namespace IBBoard.WarFoundry.API.Factories
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 {
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 [TestFixture]
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 public class AbstractNativeWarFoundryFactoryTest
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 {
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 [Test]
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 public void Bug94TestLoadingTimesForNonZipFiles()
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 {
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 MockNativeWarFoundryFactory factory = new MockNativeWarFoundryFactory();
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 Stopwatch sw = Stopwatch.StartNew();
228
7c21ca1482cb Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 196
diff changeset
24 factory.CreateObjectsFromFile(new LoadableFileObject("testdata/Test.race"));
165
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 sw.Stop();
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 long successElapsed = sw.ElapsedMilliseconds;
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 sw.Reset();
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 sw.Start();
228
7c21ca1482cb Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 196
diff changeset
29 factory.CreateObjectsFromFile(new LoadableFileObject("testdata/NotARaceFile.txt"));
165
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 sw.Stop();
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 long failedElapsed = sw.ElapsedMilliseconds;
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 long timeRatio = failedElapsed / successElapsed;
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 Assert.That(timeRatio, Is.LessThan(10));
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 }
166
6b9e86d4be95 Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents: 165
diff changeset
35
6b9e86d4be95 Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents: 165
diff changeset
36 [Test]
6b9e86d4be95 Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents: 165
diff changeset
37 public void Bug358TestLoadingOfFailedFiles()
6b9e86d4be95 Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents: 165
diff changeset
38 {
6b9e86d4be95 Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents: 165
diff changeset
39 MockNativeWarFoundryFactory factory = new MockNativeWarFoundryFactory();
168
6dce5122caca Re #94: Slow file loading
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
40 //This will also be triggered by Bug94TestLoadingTimesForNonZipFiles, but this makes it separate and explicit
6dce5122caca Re #94: Slow file loading
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
41 FileInfo nonRaceFile = new FileInfo("testdata/NotARaceFile.txt");
6dce5122caca Re #94: Slow file loading
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
42 Assert.That(nonRaceFile.Exists, Is.True);
228
7c21ca1482cb Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 196
diff changeset
43 Assert.That(factory.CanHandleFileFormat(new LoadableFileObject(nonRaceFile)), Is.False);
166
6b9e86d4be95 Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents: 165
diff changeset
44 }
196
498396c77601 Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents: 168
diff changeset
45
498396c77601 Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents: 168
diff changeset
46 [Test]
498396c77601 Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents: 168
diff changeset
47 public void Bug380TestLoadingOfOSXesqueFile()
498396c77601 Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents: 168
diff changeset
48 {
498396c77601 Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents: 168
diff changeset
49 FileSearchingWarFoundryFactory factory = new FileSearchingWarFoundryFactory();
498396c77601 Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents: 168
diff changeset
50 FileInfo file = new FileInfo("testdata/multifile-zips/Test-OSX-style.system");
498396c77601 Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents: 168
diff changeset
51 Assert.That(factory.GetGameSystemZipEntries(file), Has.Count(3));
498396c77601 Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents: 168
diff changeset
52 Assert.That(factory.GetRaceZipEntries(file), Has.Count(3));
498396c77601 Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents: 168
diff changeset
53 Assert.That(factory.GetArmyZipEntries(file), Has.Count(3));
228
7c21ca1482cb Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 196
diff changeset
54 ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new LoadableFileObject(file));
196
498396c77601 Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents: 168
diff changeset
55 Assert.That(objs, Has.Count(0));
498396c77601 Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents: 168
diff changeset
56 }
165
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 }
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 }
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59