2020-04-09 12:56:36 +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.
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
using osu.Game.Screens.Edit;
|
|
|
|
|
2020-04-23 08:07:55 +00:00
|
|
|
namespace osu.Game.Tests.Visual.Editing
|
2020-04-09 12:56:36 +00:00
|
|
|
{
|
2020-04-22 10:49:21 +00:00
|
|
|
public class TestSceneEditorChangeStates : EditorTestScene
|
2020-04-09 12:56:36 +00:00
|
|
|
{
|
2020-04-22 10:49:21 +00:00
|
|
|
public TestSceneEditorChangeStates()
|
|
|
|
: base(new OsuRuleset())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-04-09 12:56:36 +00:00
|
|
|
private EditorBeatmap editorBeatmap;
|
|
|
|
|
|
|
|
public override void SetUpSteps()
|
|
|
|
{
|
|
|
|
base.SetUpSteps();
|
|
|
|
|
2020-04-22 10:49:21 +00:00
|
|
|
AddStep("get beatmap", () => editorBeatmap = Editor.ChildrenOfType<EditorBeatmap>().Single());
|
2020-04-09 12:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestUndoFromInitialState()
|
|
|
|
{
|
|
|
|
int hitObjectCount = 0;
|
|
|
|
|
|
|
|
AddStep("get initial state", () => hitObjectCount = editorBeatmap.HitObjects.Count);
|
|
|
|
|
|
|
|
addUndoSteps();
|
|
|
|
|
|
|
|
AddAssert("no change occurred", () => hitObjectCount == editorBeatmap.HitObjects.Count);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestRedoFromInitialState()
|
|
|
|
{
|
|
|
|
int hitObjectCount = 0;
|
|
|
|
|
|
|
|
AddStep("get initial state", () => hitObjectCount = editorBeatmap.HitObjects.Count);
|
|
|
|
|
|
|
|
addRedoSteps();
|
|
|
|
|
|
|
|
AddAssert("no change occurred", () => hitObjectCount == editorBeatmap.HitObjects.Count);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAddObjectAndUndo()
|
|
|
|
{
|
|
|
|
HitObject addedObject = null;
|
|
|
|
HitObject removedObject = null;
|
|
|
|
HitObject expectedObject = null;
|
|
|
|
|
|
|
|
AddStep("bind removal", () =>
|
|
|
|
{
|
|
|
|
editorBeatmap.HitObjectAdded += h => addedObject = h;
|
|
|
|
editorBeatmap.HitObjectRemoved += h => removedObject = h;
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("add hitobject", () => editorBeatmap.Add(expectedObject = new HitCircle { StartTime = 1000 }));
|
|
|
|
AddAssert("hitobject added", () => addedObject == expectedObject);
|
|
|
|
|
|
|
|
addUndoSteps();
|
|
|
|
AddAssert("hitobject removed", () => removedObject == expectedObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAddObjectThenUndoThenRedo()
|
|
|
|
{
|
|
|
|
HitObject addedObject = null;
|
|
|
|
HitObject removedObject = null;
|
|
|
|
HitObject expectedObject = null;
|
|
|
|
|
|
|
|
AddStep("bind removal", () =>
|
|
|
|
{
|
|
|
|
editorBeatmap.HitObjectAdded += h => addedObject = h;
|
|
|
|
editorBeatmap.HitObjectRemoved += h => removedObject = h;
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("add hitobject", () => editorBeatmap.Add(expectedObject = new HitCircle { StartTime = 1000 }));
|
|
|
|
addUndoSteps();
|
|
|
|
|
|
|
|
AddStep("reset variables", () =>
|
|
|
|
{
|
|
|
|
addedObject = null;
|
|
|
|
removedObject = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
addRedoSteps();
|
|
|
|
AddAssert("hitobject added", () => addedObject.StartTime == expectedObject.StartTime); // Can't compare via equality (new hitobject instance)
|
|
|
|
AddAssert("no hitobject removed", () => removedObject == null);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestRemoveObjectThenUndo()
|
|
|
|
{
|
|
|
|
HitObject addedObject = null;
|
|
|
|
HitObject removedObject = null;
|
|
|
|
HitObject expectedObject = null;
|
|
|
|
|
|
|
|
AddStep("bind removal", () =>
|
|
|
|
{
|
|
|
|
editorBeatmap.HitObjectAdded += h => addedObject = h;
|
|
|
|
editorBeatmap.HitObjectRemoved += h => removedObject = h;
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("add hitobject", () => editorBeatmap.Add(expectedObject = new HitCircle { StartTime = 1000 }));
|
|
|
|
AddStep("remove object", () => editorBeatmap.Remove(expectedObject));
|
|
|
|
AddStep("reset variables", () =>
|
|
|
|
{
|
|
|
|
addedObject = null;
|
|
|
|
removedObject = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
addUndoSteps();
|
|
|
|
AddAssert("hitobject added", () => addedObject.StartTime == expectedObject.StartTime); // Can't compare via equality (new hitobject instance)
|
|
|
|
AddAssert("no hitobject removed", () => removedObject == null);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestRemoveObjectThenUndoThenRedo()
|
|
|
|
{
|
|
|
|
HitObject addedObject = null;
|
|
|
|
HitObject removedObject = null;
|
|
|
|
HitObject expectedObject = null;
|
|
|
|
|
|
|
|
AddStep("bind removal", () =>
|
|
|
|
{
|
|
|
|
editorBeatmap.HitObjectAdded += h => addedObject = h;
|
|
|
|
editorBeatmap.HitObjectRemoved += h => removedObject = h;
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("add hitobject", () => editorBeatmap.Add(expectedObject = new HitCircle { StartTime = 1000 }));
|
|
|
|
AddStep("remove object", () => editorBeatmap.Remove(expectedObject));
|
|
|
|
addUndoSteps();
|
|
|
|
|
|
|
|
AddStep("reset variables", () =>
|
|
|
|
{
|
|
|
|
addedObject = null;
|
|
|
|
removedObject = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
addRedoSteps();
|
|
|
|
AddAssert("hitobject removed", () => removedObject.StartTime == expectedObject.StartTime); // Can't compare via equality (new hitobject instance after undo)
|
|
|
|
AddAssert("no hitobject added", () => addedObject == null);
|
|
|
|
}
|
|
|
|
|
2020-04-23 01:37:05 +00:00
|
|
|
private void addUndoSteps() => AddStep("undo", () => ((TestEditor)Editor).Undo());
|
2020-04-09 12:56:36 +00:00
|
|
|
|
2020-04-23 01:37:05 +00:00
|
|
|
private void addRedoSteps() => AddStep("redo", () => ((TestEditor)Editor).Redo());
|
|
|
|
|
2020-04-24 01:57:35 +00:00
|
|
|
protected override Editor CreateEditor() => new TestEditor();
|
2020-04-09 12:56:36 +00:00
|
|
|
|
2020-04-23 08:07:55 +00:00
|
|
|
private class TestEditor : Editor
|
2020-04-09 12:56:36 +00:00
|
|
|
{
|
2020-04-22 09:14:21 +00:00
|
|
|
public new void Undo() => base.Undo();
|
2020-04-09 12:56:36 +00:00
|
|
|
|
2020-04-22 09:14:21 +00:00
|
|
|
public new void Redo() => base.Redo();
|
2020-04-09 12:56:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|