mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 23:24:04 +09:00
Merge branch 'master' into fix-resume-from-player-audio
This commit is contained in:
@ -29,7 +29,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
public async Task TestImportWhenClosed()
|
||||
{
|
||||
//unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here.
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestImportWhenClosed"))
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestImportWhenClosed)))
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -46,7 +46,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
public async Task TestImportThenDelete()
|
||||
{
|
||||
//unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here.
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestImportThenDelete"))
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestImportThenDelete)))
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -67,7 +67,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
public async Task TestImportThenImport()
|
||||
{
|
||||
//unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here.
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestImportThenImport"))
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestImportThenImport)))
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -94,7 +94,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
public async Task TestImportCorruptThenImport()
|
||||
{
|
||||
//unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here.
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestImportThenImport"))
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestImportCorruptThenImport)))
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -136,7 +136,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
public async Task TestRollbackOnFailure()
|
||||
{
|
||||
//unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here.
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestRollbackOnFailure"))
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestRollbackOnFailure)))
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -213,7 +213,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
public async Task TestImportThenImportDifferentHash()
|
||||
{
|
||||
//unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here.
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestImportThenImportDifferentHash"))
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestImportThenImportDifferentHash)))
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -244,7 +244,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
public async Task TestImportThenDeleteThenImport()
|
||||
{
|
||||
//unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here.
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestImportThenDeleteThenImport"))
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestImportThenDeleteThenImport)))
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -272,7 +272,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
public async Task TestImportThenDeleteThenImportWithOnlineIDMismatch(bool set)
|
||||
{
|
||||
//unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here.
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost($"TestImportThenDeleteThenImport-{set}"))
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost($"{nameof(TestImportThenDeleteThenImportWithOnlineIDMismatch)}-{set}"))
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -306,7 +306,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
public async Task TestImportWithDuplicateBeatmapIDs()
|
||||
{
|
||||
//unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here.
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestImportWithDuplicateBeatmapID"))
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestImportWithDuplicateBeatmapIDs)))
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -392,7 +392,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
[Test]
|
||||
public async Task TestImportWhenFileOpen()
|
||||
{
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestImportWhenFileOpen"))
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestImportWhenFileOpen)))
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -414,7 +414,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
[Test]
|
||||
public async Task TestImportNestedStructure()
|
||||
{
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestImportNestedStructure"))
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestImportNestedStructure)))
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -456,6 +456,60 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestImportWithIgnoredDirectoryInArchive()
|
||||
{
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestImportWithIgnoredDirectoryInArchive)))
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
|
||||
var temp = TestResources.GetTestBeatmapForImport();
|
||||
|
||||
string extractedFolder = $"{temp}_extracted";
|
||||
string dataFolder = Path.Combine(extractedFolder, "actual_data");
|
||||
string resourceForkFolder = Path.Combine(extractedFolder, "__MACOSX");
|
||||
string resourceForkFilePath = Path.Combine(resourceForkFolder, ".extracted");
|
||||
|
||||
Directory.CreateDirectory(dataFolder);
|
||||
Directory.CreateDirectory(resourceForkFolder);
|
||||
|
||||
using (var resourceForkFile = File.CreateText(resourceForkFilePath))
|
||||
{
|
||||
resourceForkFile.WriteLine("adding content so that it's not empty");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (var zip = ZipArchive.Open(temp))
|
||||
zip.WriteToDirectory(dataFolder);
|
||||
|
||||
using (var zip = ZipArchive.Create())
|
||||
{
|
||||
zip.AddAllFromDirectory(extractedFolder);
|
||||
zip.SaveTo(temp, new ZipWriterOptions(CompressionType.Deflate));
|
||||
}
|
||||
|
||||
var imported = await osu.Dependencies.Get<BeatmapManager>().Import(temp);
|
||||
|
||||
ensureLoaded(osu);
|
||||
|
||||
Assert.IsFalse(imported.Files.Any(f => f.Filename.Contains("__MACOSX")), "Files contain resource fork folder, which should be ignored");
|
||||
Assert.IsFalse(imported.Files.Any(f => f.Filename.Contains("actual_data")), "Files contain common subfolder");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Directory.Delete(extractedFolder, true);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
host.Exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<BeatmapSetInfo> LoadOszIntoOsu(OsuGameBase osu, string path = null, bool virtualTrack = false)
|
||||
{
|
||||
var temp = path ?? TestResources.GetTestBeatmapForImport(virtualTrack);
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
@ -14,9 +15,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
[Test]
|
||||
public void TestReadLineByLine()
|
||||
{
|
||||
const string contents = @"line 1
|
||||
line 2
|
||||
line 3";
|
||||
const string contents = "line 1\rline 2\nline 3";
|
||||
|
||||
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(contents)))
|
||||
using (var bufferedReader = new LineBufferedReader(stream))
|
||||
@ -31,9 +30,7 @@ line 3";
|
||||
[Test]
|
||||
public void TestPeekLineOnce()
|
||||
{
|
||||
const string contents = @"line 1
|
||||
peek this
|
||||
line 3";
|
||||
const string contents = "line 1\r\npeek this\nline 3";
|
||||
|
||||
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(contents)))
|
||||
using (var bufferedReader = new LineBufferedReader(stream))
|
||||
@ -49,9 +46,7 @@ line 3";
|
||||
[Test]
|
||||
public void TestPeekLineMultipleTimes()
|
||||
{
|
||||
const string contents = @"peek this once
|
||||
line 2
|
||||
peek this a lot";
|
||||
const string contents = "peek this once\nline 2\rpeek this a lot";
|
||||
|
||||
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(contents)))
|
||||
using (var bufferedReader = new LineBufferedReader(stream))
|
||||
@ -70,8 +65,7 @@ peek this a lot";
|
||||
[Test]
|
||||
public void TestPeekLineAtEndOfStream()
|
||||
{
|
||||
const string contents = @"first line
|
||||
second line";
|
||||
const string contents = "first line\r\nsecond line";
|
||||
|
||||
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(contents)))
|
||||
using (var bufferedReader = new LineBufferedReader(stream))
|
||||
@ -100,8 +94,7 @@ second line";
|
||||
[Test]
|
||||
public void TestReadToEndNoPeeks()
|
||||
{
|
||||
const string contents = @"first line
|
||||
second line";
|
||||
const string contents = "first line\r\nsecond line";
|
||||
|
||||
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(contents)))
|
||||
using (var bufferedReader = new LineBufferedReader(stream))
|
||||
@ -113,20 +106,19 @@ second line";
|
||||
[Test]
|
||||
public void TestReadToEndAfterReadsAndPeeks()
|
||||
{
|
||||
const string contents = @"this line is gone
|
||||
this one shouldn't be
|
||||
these ones
|
||||
definitely not";
|
||||
const string contents = "this line is gone\rthis one shouldn't be\r\nthese ones\ndefinitely not";
|
||||
|
||||
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(contents)))
|
||||
using (var bufferedReader = new LineBufferedReader(stream))
|
||||
{
|
||||
Assert.AreEqual("this line is gone", bufferedReader.ReadLine());
|
||||
Assert.AreEqual("this one shouldn't be", bufferedReader.PeekLine());
|
||||
const string ending = @"this one shouldn't be
|
||||
these ones
|
||||
definitely not";
|
||||
Assert.AreEqual(ending, bufferedReader.ReadToEnd());
|
||||
|
||||
var endingLines = bufferedReader.ReadToEnd().Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
Assert.AreEqual(3, endingLines.Length);
|
||||
Assert.AreEqual("this one shouldn't be", endingLines[0]);
|
||||
Assert.AreEqual("these ones", endingLines[1]);
|
||||
Assert.AreEqual("definitely not", endingLines[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user