1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 14:52:55 +08:00
osu-lazer/osu.Game.Tests/Visual/Editing/TestSceneEditorChangeStates.cs

176 lines
6.7 KiB
C#
Raw Normal View History

2020-04-09 20:56:36 +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.
2022-06-17 15:37:17 +08:00
#nullable disable
2020-04-09 20:56:36 +08:00
using NUnit.Framework;
using osu.Game.Rulesets;
2020-04-09 20:56:36 +08:00
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Objects;
namespace osu.Game.Tests.Visual.Editing
2020-04-09 20:56:36 +08:00
{
public class TestSceneEditorChangeStates : EditorTestScene
2020-04-09 20:56:36 +08:00
{
protected override Ruleset CreateEditorRuleset() => new OsuRuleset();
2020-09-11 19:27:04 +08:00
[Test]
public void TestSelectedObjects()
{
HitCircle obj = null;
AddStep("add hitobject", () => EditorBeatmap.Add(obj = new HitCircle { StartTime = 1000 }));
AddStep("select hitobject", () => EditorBeatmap.SelectedHitObjects.Add(obj));
AddAssert("confirm 1 selected", () => EditorBeatmap.SelectedHitObjects.Count == 1);
AddStep("deselect hitobject", () => EditorBeatmap.SelectedHitObjects.Remove(obj));
AddAssert("confirm 0 selected", () => EditorBeatmap.SelectedHitObjects.Count == 0);
2020-09-11 19:27:04 +08:00
}
2020-04-09 20:56:36 +08:00
[Test]
public void TestUndoFromInitialState()
{
int hitObjectCount = 0;
AddStep("get initial state", () => hitObjectCount = EditorBeatmap.HitObjects.Count);
2020-04-09 20:56:36 +08:00
addUndoSteps();
AddAssert("no change occurred", () => hitObjectCount == EditorBeatmap.HitObjects.Count);
2020-09-09 18:57:28 +08:00
AddAssert("no unsaved changes", () => !Editor.HasUnsavedChanges);
2020-04-09 20:56:36 +08:00
}
[Test]
public void TestRedoFromInitialState()
{
int hitObjectCount = 0;
AddStep("get initial state", () => hitObjectCount = EditorBeatmap.HitObjects.Count);
2020-04-09 20:56:36 +08:00
addRedoSteps();
AddAssert("no change occurred", () => hitObjectCount == EditorBeatmap.HitObjects.Count);
2020-09-09 18:57:28 +08:00
AddAssert("no unsaved changes", () => !Editor.HasUnsavedChanges);
2020-04-09 20:56:36 +08:00
}
[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;
2020-04-09 20:56:36 +08:00
});
AddStep("add hitobject", () => EditorBeatmap.Add(expectedObject = new HitCircle { StartTime = 1000 }));
2020-04-09 20:56:36 +08:00
AddAssert("hitobject added", () => addedObject == expectedObject);
2020-09-09 18:57:28 +08:00
AddAssert("unsaved changes", () => Editor.HasUnsavedChanges);
2020-04-09 20:56:36 +08:00
addUndoSteps();
AddAssert("hitobject removed", () => removedObject == expectedObject);
2020-09-09 18:57:28 +08:00
AddAssert("no unsaved changes", () => !Editor.HasUnsavedChanges);
2020-04-09 20:56:36 +08:00
}
[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;
2020-04-09 20:56:36 +08:00
});
AddStep("add hitobject", () => EditorBeatmap.Add(expectedObject = new HitCircle { StartTime = 1000 }));
2020-04-09 20:56:36 +08:00
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);
2020-09-09 18:57:28 +08:00
AddAssert("unsaved changes", () => Editor.HasUnsavedChanges);
}
[Test]
public void TestAddObjectThenSaveHasNoUnsavedChanges()
{
AddStep("add hitobject", () => EditorBeatmap.Add(new HitCircle { StartTime = 1000 }));
2020-09-09 18:57:28 +08:00
AddAssert("unsaved changes", () => Editor.HasUnsavedChanges);
AddStep("save changes", () => Editor.Save());
AddAssert("no unsaved changes", () => !Editor.HasUnsavedChanges);
2020-04-09 20:56:36 +08:00
}
[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;
2020-04-09 20:56:36 +08:00
});
AddStep("add hitobject", () => EditorBeatmap.Add(expectedObject = new HitCircle { StartTime = 1000 }));
AddStep("remove object", () => EditorBeatmap.Remove(expectedObject));
2020-04-09 20:56:36 +08:00
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);
2020-09-09 18:57:28 +08:00
AddAssert("unsaved changes", () => Editor.HasUnsavedChanges); // 2 steps performed, 1 undone
2020-04-09 20:56:36 +08:00
}
[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;
2020-04-09 20:56:36 +08:00
});
AddStep("add hitobject", () => EditorBeatmap.Add(expectedObject = new HitCircle { StartTime = 1000 }));
AddStep("remove object", () => EditorBeatmap.Remove(expectedObject));
2020-04-09 20:56:36 +08:00
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-09-09 18:57:28 +08:00
AddAssert("no changes", () => !Editor.HasUnsavedChanges); // end result is empty beatmap, matching original state
2020-04-09 20:56:36 +08:00
}
2020-09-09 18:57:28 +08:00
private void addUndoSteps() => AddStep("undo", () => Editor.Undo());
2020-04-09 20:56:36 +08:00
2020-09-09 18:57:28 +08:00
private void addRedoSteps() => AddStep("redo", () => Editor.Redo());
2020-04-09 20:56:36 +08:00
}
}