A game framework written with osu! in mind.
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 System;
5using System.IO;
6using NUnit.Framework;
7using osu.Framework.Testing;
8
9namespace osu.Framework.Tests.IO
10{
11 [TestFixture]
12 public class TestDesktopStorage
13 {
14 [Test]
15 public void TestRelativePaths()
16 {
17 var guid = new Guid().ToString();
18
19 using (var storage = new TemporaryNativeStorage(guid))
20 {
21 var basePath = storage.GetFullPath(string.Empty);
22
23 Assert.IsTrue(basePath.EndsWith(guid, StringComparison.Ordinal));
24
25 Assert.Throws<ArgumentException>(() => storage.GetFullPath("../"));
26 Assert.Throws<ArgumentException>(() => storage.GetFullPath(".."));
27 Assert.Throws<ArgumentException>(() => storage.GetFullPath("./../"));
28
29 Assert.AreEqual(Path.GetFullPath(Path.Combine(basePath, "sub", "test")) + Path.DirectorySeparatorChar, storage.GetFullPath("sub/test/"));
30 Assert.AreEqual(Path.GetFullPath(Path.Combine(basePath, "sub", "test")), storage.GetFullPath("sub/test"));
31 }
32 }
33
34 [Test]
35 public void TestAttemptEscapeRoot()
36 {
37 var guid = new Guid().ToString();
38
39 using (var storage = new TemporaryNativeStorage(guid))
40 {
41 Assert.Throws<ArgumentException>(() => storage.GetStream("../test"));
42 Assert.Throws<ArgumentException>(() => storage.GetStorageForDirectory("../"));
43 }
44 }
45
46 [Test]
47 public void TestGetSubDirectoryStorage()
48 {
49 var guid = new Guid().ToString();
50
51 using (var storage = new TemporaryNativeStorage(guid))
52 {
53 Assert.That(storage.GetStorageForDirectory("subdir").GetFullPath(string.Empty), Is.EqualTo(Path.Combine(storage.GetFullPath(string.Empty), "subdir")));
54 }
55 }
56
57 [Test]
58 public void TestGetEmptySubDirectoryStorage()
59 {
60 var guid = new Guid().ToString();
61
62 using (var storage = new TemporaryNativeStorage(guid))
63 {
64 Assert.That(storage.GetStorageForDirectory(string.Empty).GetFullPath(string.Empty), Is.EqualTo(storage.GetFullPath(string.Empty)));
65 }
66 }
67 }
68}