Update LegacyBeatmapEncoderTest.cs

This commit is contained in:
Craftplacer 2020-08-30 21:13:06 +02:00
parent db413686bb
commit 07f6a68179
1 changed files with 51 additions and 14 deletions

View File

@ -7,8 +7,10 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using osu.Framework.Audio.Track;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics.Textures;
using osu.Framework.IO.Stores;
using osu.Game.Beatmaps;
@ -61,24 +63,59 @@ private void sort((IBeatmap beatmap, IBeatmapSkin beatmapSkin) tuple)
{
var beatmap = new LegacyBeatmapDecoder { ApplyOffsets = false }.Decode(reader);
beatmap.BeatmapInfo.Path = name;
beatmap.BeatmapInfo.BeatmapSet = new BeatmapSetInfo
using (var rs = new MemoryBeatmapResourceStore(stream, name))
{
Files = new List<BeatmapSetFileInfo>
{
new BeatmapSetFileInfo
{
Filename = name,
FileInfo = new osu.Game.IO.FileInfo { Hash = name }
}
},
};
var beatmapSkin = new TestLegacySkin(beatmap, beatmaps_resource_store, name);
return (convert(beatmap), beatmapSkin);
var beatmapSkin = new TestLegacySkin(beatmap, rs, name);
return (convert(beatmap), beatmapSkin);
}
}
}
private class MemoryBeatmapResourceStore : IResourceStore<byte[]>
{
private readonly Stream beatmapData;
private readonly string beatmapName;
public MemoryBeatmapResourceStore(Stream beatmapData, string beatmapName)
{
this.beatmapData = beatmapData;
this.beatmapName = beatmapName;
}
public void Dispose() => beatmapData.Dispose();
public byte[] Get(string name)
{
if (name != beatmapName)
return null;
byte[] buffer = new byte[beatmapData.Length];
beatmapData.Read(buffer, 0, buffer.Length);
return buffer;
}
public async Task<byte[]> GetAsync(string name)
{
if (name != beatmapName)
return null;
byte[] buffer = new byte[beatmapData.Length];
await beatmapData.ReadAsync(buffer.AsMemory());
return buffer;
}
public Stream GetStream(string name)
{
if (name != beatmapName)
return null;
beatmapData.Seek(0, SeekOrigin.Begin);
return beatmapData;
}
public IEnumerable<string> GetAvailableResources() => beatmapName.Yield();
}
private class TestLegacySkin : LegacySkin, IBeatmapSkin
{
public TestLegacySkin(Beatmap beatmap, IResourceStore<byte[]> storage, string fileName)