2019-01-24 08:43:03 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-09-17 07:24:21 +00:00
|
|
|
|
using System;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using System.IO;
|
2019-01-28 09:19:57 +00:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using osu.Framework.IO.Stores;
|
2021-09-17 07:24:21 +00:00
|
|
|
|
using osu.Framework.Testing;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Resources
|
|
|
|
|
{
|
2019-01-28 09:19:57 +00:00
|
|
|
|
public static class TestResources
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2021-08-24 04:20:01 +00:00
|
|
|
|
public const double QUICK_BEATMAP_LENGTH = 10000;
|
|
|
|
|
|
2021-09-17 07:24:21 +00:00
|
|
|
|
private static readonly TemporaryNativeStorage temp_storage = new TemporaryNativeStorage("TestResources");
|
|
|
|
|
|
2019-12-28 13:13:18 +00:00
|
|
|
|
public static DllResourceStore GetStore() => new DllResourceStore(typeof(TestResources).Assembly);
|
2019-01-28 09:19:57 +00:00
|
|
|
|
|
2019-12-13 10:00:28 +00:00
|
|
|
|
public static Stream OpenResource(string name) => GetStore().GetStream($"Resources/{name}");
|
|
|
|
|
|
2021-02-24 03:45:00 +00:00
|
|
|
|
public static Stream GetTestBeatmapStream(bool virtualTrack = false) => OpenResource($"Archives/241526 Soleily - Renatus{(virtualTrack ? "_virtual" : "")}.osz");
|
2019-01-28 09:19:57 +00:00
|
|
|
|
|
2021-02-22 05:48:04 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieve a path to a copy of a shortened (~10 second) beatmap archive with a virtual track.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This is intended for use in tests which need to run to completion as soon as possible and don't need to test a full length beatmap.</remarks>
|
|
|
|
|
/// <returns>A path to a copy of a beatmap archive (osz). Should be deleted after use.</returns>
|
|
|
|
|
public static string GetQuickTestBeatmapForImport()
|
|
|
|
|
{
|
2021-09-17 07:24:21 +00:00
|
|
|
|
var tempPath = getTempFilename();
|
2021-02-24 03:46:35 +00:00
|
|
|
|
using (var stream = OpenResource("Archives/241526 Soleily - Renatus_virtual_quick.osz"))
|
2021-02-22 05:48:04 +00:00
|
|
|
|
using (var newFile = File.Create(tempPath))
|
|
|
|
|
stream.CopyTo(newFile);
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(File.Exists(tempPath));
|
|
|
|
|
return tempPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieve a path to a copy of a full-fledged beatmap archive.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="virtualTrack">Whether the audio track should be virtual.</param>
|
|
|
|
|
/// <returns>A path to a copy of a beatmap archive (osz). Should be deleted after use.</returns>
|
2019-10-10 08:39:41 +00:00
|
|
|
|
public static string GetTestBeatmapForImport(bool virtualTrack = false)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2021-09-17 07:24:21 +00:00
|
|
|
|
var tempPath = getTempFilename();
|
2019-01-28 09:19:57 +00:00
|
|
|
|
|
2019-10-10 08:39:41 +00:00
|
|
|
|
using (var stream = GetTestBeatmapStream(virtualTrack))
|
2020-06-01 08:57:32 +00:00
|
|
|
|
using (var newFile = File.Create(tempPath))
|
2019-01-28 09:19:57 +00:00
|
|
|
|
stream.CopyTo(newFile);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-06-01 08:57:32 +00:00
|
|
|
|
Assert.IsTrue(File.Exists(tempPath));
|
|
|
|
|
return tempPath;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
2021-09-17 07:24:21 +00:00
|
|
|
|
|
|
|
|
|
private static string getTempFilename() => temp_storage.GetFullPath(Guid.NewGuid() + ".osz");
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|