A game framework written with osu! in mind.
at master 70 lines 2.6 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using NUnit.Framework; 5using osu.Framework.Configuration; 6using osu.Framework.Platform; 7using osu.Framework.Testing; 8 9namespace osu.Framework.Tests.Platform 10{ 11 [TestFixture] 12 public class PortableInstallationTest 13 { 14 private readonly Storage startupStorage = new NativeStorage(RuntimeInfo.StartupDirectory); 15 16 [Test] 17 public void TestPortableInstall() 18 { 19 Assert.IsFalse(startupStorage.Exists(FrameworkConfigManager.FILENAME)); 20 21 using (var portable = new HeadlessGameHost(@"portable", portableInstallation: true)) 22 { 23 portable.Run(new TestGame()); 24 Assert.AreEqual(startupStorage.GetFullPath(FrameworkConfigManager.FILENAME), portable.Storage.GetFullPath(FrameworkConfigManager.FILENAME)); 25 } 26 27 // portable mode should write the configuration 28 Assert.IsTrue(startupStorage.Exists(FrameworkConfigManager.FILENAME)); 29 30 // subsequent startups should detect the portable config and continue running in portable mode, even though it is not explicitly specified 31 using (var portable = new HeadlessGameHost(@"portable")) 32 { 33 portable.Run(new TestGame()); 34 Assert.AreEqual(startupStorage.GetFullPath(FrameworkConfigManager.FILENAME), portable.Storage.GetFullPath(FrameworkConfigManager.FILENAME)); 35 } 36 37 Assert.IsTrue(startupStorage.Exists(FrameworkConfigManager.FILENAME)); 38 } 39 40 [Test] 41 public void TestNonPortableInstall() 42 { 43 Assert.IsFalse(startupStorage.Exists(FrameworkConfigManager.FILENAME)); 44 45 using (var nonPortable = new TestRunHeadlessGameHost(@"non-portable")) 46 { 47 nonPortable.Run(new TestGame()); 48 Assert.AreNotEqual(startupStorage.GetFullPath(FrameworkConfigManager.FILENAME), nonPortable.Storage.GetFullPath(FrameworkConfigManager.FILENAME)); 49 } 50 51 Assert.IsFalse(startupStorage.Exists(FrameworkConfigManager.FILENAME)); 52 } 53 54 [TearDown] 55 [SetUp] 56 public void TearDown() 57 { 58 startupStorage.Delete(FrameworkConfigManager.FILENAME); 59 } 60 61 private class TestGame : Game 62 { 63 protected override void Update() 64 { 65 base.Update(); 66 Exit(); 67 } 68 } 69 } 70}