A game framework written with osu! in mind.

Add test coverage of user storage fallback ordering

Changed files
+141
osu.Framework.Tests
+141
osu.Framework.Tests/Platform/UserStorageLookupTest.cs
··· 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 + 4 + using System; 5 + using System.Collections.Generic; 6 + using System.IO; 7 + using NUnit.Framework; 8 + using osu.Framework.Testing; 9 + 10 + namespace osu.Framework.Tests.Platform 11 + { 12 + [TestFixture] 13 + public class UserStorageLookupTest 14 + { 15 + private static readonly string path1 = Path.Combine(TestRunHeadlessGameHost.TemporaryTestDirectory, "path1"); 16 + private static readonly string path2 = Path.Combine(TestRunHeadlessGameHost.TemporaryTestDirectory, "path2"); 17 + 18 + private const string game_name = "test_game"; 19 + 20 + [TearDown] 21 + public void TearDown() 22 + { 23 + try 24 + { 25 + Directory.Delete(path1, true); 26 + Directory.Delete(path2, true); 27 + } 28 + catch 29 + { 30 + } 31 + } 32 + 33 + [Test] 34 + public void TestFirstBaseExisting() 35 + { 36 + Directory.CreateDirectory(path1); 37 + 38 + using (var host = new StorageLookupHeadlessGameHost()) 39 + { 40 + runHost(host); 41 + Assert.IsTrue(host.Storage.GetFullPath(string.Empty).StartsWith(path1, StringComparison.Ordinal)); 42 + } 43 + } 44 + 45 + [Test] 46 + public void TestSecondBaseExisting() 47 + { 48 + Directory.CreateDirectory(path2); 49 + 50 + using (var host = new StorageLookupHeadlessGameHost()) 51 + { 52 + runHost(host); 53 + Assert.IsTrue(host.Storage.GetFullPath(string.Empty).StartsWith(path2, StringComparison.Ordinal)); 54 + } 55 + } 56 + 57 + [Test] 58 + public void TestPrefersFirstBase() 59 + { 60 + Directory.CreateDirectory(path1); 61 + Directory.CreateDirectory(path2); 62 + 63 + using (var host = new StorageLookupHeadlessGameHost()) 64 + { 65 + runHost(host); 66 + Assert.IsTrue(host.Storage.GetFullPath(string.Empty).StartsWith(path1, StringComparison.Ordinal)); 67 + } 68 + } 69 + 70 + [Test] 71 + public void TestFirstDataExisting() 72 + { 73 + Directory.CreateDirectory(Path.Combine(path1, game_name)); 74 + 75 + using (var host = new StorageLookupHeadlessGameHost()) 76 + { 77 + runHost(host); 78 + Assert.IsTrue(host.Storage.GetFullPath(string.Empty).StartsWith(path1, StringComparison.Ordinal)); 79 + } 80 + } 81 + 82 + [Test] 83 + public void TestSecondDataExisting() 84 + { 85 + Directory.CreateDirectory(Path.Combine(path2, game_name)); 86 + 87 + using (var host = new StorageLookupHeadlessGameHost()) 88 + { 89 + runHost(host); 90 + Assert.IsTrue(host.Storage.GetFullPath(string.Empty).StartsWith(path2, StringComparison.Ordinal)); 91 + } 92 + } 93 + 94 + [Test] 95 + public void TestPrefersFirstData() 96 + { 97 + Directory.CreateDirectory(Path.Combine(path1, game_name)); 98 + Directory.CreateDirectory(Path.Combine(path2, game_name)); 99 + 100 + using (var host = new StorageLookupHeadlessGameHost()) 101 + { 102 + runHost(host); 103 + Assert.IsTrue(host.Storage.GetFullPath(string.Empty).StartsWith(path1, StringComparison.Ordinal)); 104 + } 105 + } 106 + 107 + [Test] 108 + public void TestPrefersSecondDataOverFirstBase() 109 + { 110 + Directory.CreateDirectory(path1); 111 + Directory.CreateDirectory(Path.Combine(path2, game_name)); 112 + 113 + using (var host = new StorageLookupHeadlessGameHost()) 114 + { 115 + runHost(host); 116 + Assert.IsTrue(host.Storage.GetFullPath(string.Empty).StartsWith(path2, StringComparison.Ordinal)); 117 + } 118 + } 119 + 120 + private static void runHost(StorageLookupHeadlessGameHost host) 121 + { 122 + TestGame game = new TestGame(); 123 + game.Schedule(() => game.Exit()); 124 + host.Run(game); 125 + } 126 + 127 + private class StorageLookupHeadlessGameHost : TestRunHeadlessGameHost 128 + { 129 + public StorageLookupHeadlessGameHost() 130 + : base(game_name) 131 + { 132 + } 133 + 134 + public override IEnumerable<string> UserStoragePaths => new[] 135 + { 136 + path1, 137 + path2, 138 + }; 139 + } 140 + } 141 + }