2020-04-13 19:34:18 +08: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.
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Screens.Edit;
|
|
|
|
|
2020-04-23 16:07:55 +08:00
|
|
|
namespace osu.Game.Tests.Editing
|
2020-04-13 19:34:18 +08:00
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class EditorChangeHandlerTest
|
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void TestSaveRestoreState()
|
|
|
|
{
|
2020-08-16 04:03:24 +08:00
|
|
|
var handler = new EditorChangeHandler(new EditorBeatmap(new Beatmap()), null);
|
2020-04-13 19:34:18 +08:00
|
|
|
|
2020-04-15 14:50:43 +08:00
|
|
|
Assert.That(handler.CanUndo.Value, Is.False);
|
|
|
|
Assert.That(handler.CanRedo.Value, Is.False);
|
2020-04-13 19:34:18 +08:00
|
|
|
|
|
|
|
handler.SaveState();
|
|
|
|
|
2020-04-15 14:50:43 +08:00
|
|
|
Assert.That(handler.CanUndo.Value, Is.True);
|
|
|
|
Assert.That(handler.CanRedo.Value, Is.False);
|
2020-04-13 19:34:18 +08:00
|
|
|
|
|
|
|
handler.RestoreState(-1);
|
|
|
|
|
2020-04-15 14:50:43 +08:00
|
|
|
Assert.That(handler.CanUndo.Value, Is.False);
|
|
|
|
Assert.That(handler.CanRedo.Value, Is.True);
|
2020-04-13 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMaxStatesSaved()
|
|
|
|
{
|
2020-08-16 04:03:24 +08:00
|
|
|
var handler = new EditorChangeHandler(new EditorBeatmap(new Beatmap()), null);
|
2020-04-13 19:34:18 +08:00
|
|
|
|
2020-04-15 14:50:43 +08:00
|
|
|
Assert.That(handler.CanUndo.Value, Is.False);
|
2020-04-13 19:34:18 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < EditorChangeHandler.MAX_SAVED_STATES; i++)
|
|
|
|
handler.SaveState();
|
|
|
|
|
2020-04-15 14:50:43 +08:00
|
|
|
Assert.That(handler.CanUndo.Value, Is.True);
|
2020-04-13 19:34:18 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < EditorChangeHandler.MAX_SAVED_STATES; i++)
|
|
|
|
{
|
2020-04-15 14:50:43 +08:00
|
|
|
Assert.That(handler.CanUndo.Value, Is.True);
|
2020-04-13 19:34:18 +08:00
|
|
|
handler.RestoreState(-1);
|
|
|
|
}
|
|
|
|
|
2020-04-15 14:50:43 +08:00
|
|
|
Assert.That(handler.CanUndo.Value, Is.False);
|
2020-04-13 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMaxStatesExceeded()
|
|
|
|
{
|
2020-08-16 04:03:24 +08:00
|
|
|
var handler = new EditorChangeHandler(new EditorBeatmap(new Beatmap()), null);
|
2020-04-13 19:34:18 +08:00
|
|
|
|
2020-04-15 14:50:43 +08:00
|
|
|
Assert.That(handler.CanUndo.Value, Is.False);
|
2020-04-13 19:34:18 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < EditorChangeHandler.MAX_SAVED_STATES * 2; i++)
|
|
|
|
handler.SaveState();
|
|
|
|
|
2020-04-15 14:50:43 +08:00
|
|
|
Assert.That(handler.CanUndo.Value, Is.True);
|
2020-04-13 19:34:18 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < EditorChangeHandler.MAX_SAVED_STATES; i++)
|
|
|
|
{
|
2020-04-15 14:50:43 +08:00
|
|
|
Assert.That(handler.CanUndo.Value, Is.True);
|
2020-04-13 19:34:18 +08:00
|
|
|
handler.RestoreState(-1);
|
|
|
|
}
|
|
|
|
|
2020-04-15 14:50:43 +08:00
|
|
|
Assert.That(handler.CanUndo.Value, Is.False);
|
2020-04-13 19:34:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|