1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-15 14:47:18 +08:00

Add test coverage for romanised data transfer

This commit is contained in:
Bartłomiej Dach 2021-06-10 20:34:52 +02:00
parent e41a5a0fcd
commit 417aaacc53
3 changed files with 163 additions and 18 deletions

View File

@ -0,0 +1,144 @@
// 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.Framework.Allocation;
using osu.Game.Beatmaps;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Setup;
namespace osu.Game.Tests.Visual.Editing
{
public class TestSceneMetadataSection : OsuTestScene
{
[Cached]
private EditorBeatmap editorBeatmap = new EditorBeatmap(new Beatmap());
private TestMetadataSection metadataSection;
[Test]
public void TestMinimalMetadata()
{
AddStep("set metadata", () =>
{
editorBeatmap.Metadata.Artist = "Example Artist";
editorBeatmap.Metadata.ArtistUnicode = null;
editorBeatmap.Metadata.Title = "Example Title";
editorBeatmap.Metadata.TitleUnicode = null;
});
createSection();
assertArtist("Example Artist");
assertRomanisedArtist("Example Artist", false);
assertTitle("Example Title");
assertRomanisedTitle("Example Title", false);
}
[Test]
public void TestInitialisationFromNonRomanisedVariant()
{
AddStep("set metadata", () =>
{
editorBeatmap.Metadata.ArtistUnicode = "*なみりん";
editorBeatmap.Metadata.Artist = null;
editorBeatmap.Metadata.TitleUnicode = "コイシテイク・プラネット";
editorBeatmap.Metadata.Title = null;
});
createSection();
assertArtist("*なみりん");
assertRomanisedArtist(string.Empty, true);
assertTitle("コイシテイク・プラネット");
assertRomanisedTitle(string.Empty, true);
}
[Test]
public void TestInitialisationPreservesOriginalValues()
{
AddStep("set metadata", () =>
{
editorBeatmap.Metadata.ArtistUnicode = "*なみりん";
editorBeatmap.Metadata.Artist = "*namirin";
editorBeatmap.Metadata.TitleUnicode = "コイシテイク・プラネット";
editorBeatmap.Metadata.Title = "Koishiteiku Planet";
});
createSection();
assertArtist("*なみりん");
assertRomanisedArtist("*namirin", true);
assertTitle("コイシテイク・プラネット");
assertRomanisedTitle("Koishiteiku Planet", true);
}
[Test]
public void TestValueTransfer()
{
AddStep("set metadata", () =>
{
editorBeatmap.Metadata.ArtistUnicode = "*なみりん";
editorBeatmap.Metadata.Artist = null;
editorBeatmap.Metadata.TitleUnicode = "コイシテイク・プラネット";
editorBeatmap.Metadata.Title = null;
});
createSection();
AddStep("set romanised artist name", () => metadataSection.ArtistTextBox.Current.Value = "*namirin");
assertArtist("*namirin");
assertRomanisedArtist("*namirin", false);
AddStep("set native artist name", () => metadataSection.ArtistTextBox.Current.Value = "*なみりん");
assertArtist("*なみりん");
assertRomanisedArtist("*namirin", true);
AddStep("set romanised title", () => metadataSection.TitleTextBox.Current.Value = "Hitokoto no kyori");
assertTitle("Hitokoto no kyori");
assertRomanisedTitle("Hitokoto no kyori", false);
AddStep("set native title", () => metadataSection.TitleTextBox.Current.Value = "ヒトコトの距離");
assertTitle("ヒトコトの距離");
assertRomanisedTitle("Hitokoto no kyori", true);
}
private void createSection()
=> AddStep("create metadata section", () => Child = metadataSection = new TestMetadataSection());
private void assertArtist(string expected)
=> AddAssert($"artist is {expected}", () => metadataSection.ArtistTextBox.Current.Value == expected);
private void assertRomanisedArtist(string expected, bool editable)
{
AddAssert($"romanised artist is {expected}", () => metadataSection.RomanisedArtistTextBox.Current.Value == expected);
AddAssert($"romanised artist is {(editable ? "" : "not ")}editable", () => metadataSection.RomanisedArtistTextBox.ReadOnly == !editable);
}
private void assertTitle(string expected)
=> AddAssert($"title is {expected}", () => metadataSection.TitleTextBox.Current.Value == expected);
private void assertRomanisedTitle(string expected, bool editable)
{
AddAssert($"romanised title is {expected}", () => metadataSection.RomanisedTitleTextBox.Current.Value == expected);
AddAssert($"romanised title is {(editable ? "" : "not ")}editable", () => metadataSection.RomanisedTitleTextBox.ReadOnly == !editable);
}
private class TestMetadataSection : MetadataSection
{
public new LabelledTextBox ArtistTextBox => base.ArtistTextBox;
public new LabelledTextBox RomanisedArtistTextBox => base.RomanisedArtistTextBox;
public new LabelledTextBox TitleTextBox => base.TitleTextBox;
public new LabelledTextBox RomanisedTitleTextBox => base.RomanisedTitleTextBox;
}
}
}

View File

@ -21,6 +21,7 @@ namespace osu.Game.Graphics.UserInterfaceV2
public bool ReadOnly
{
get => Component.ReadOnly;
set => Component.ReadOnly = value;
}

View File

@ -12,11 +12,11 @@ namespace osu.Game.Screens.Edit.Setup
{
internal class MetadataSection : SetupSection
{
private LabelledTextBox artistTextBox;
private LabelledTextBox romanisedArtistTextBox;
protected LabelledTextBox ArtistTextBox;
protected LabelledTextBox RomanisedArtistTextBox;
private LabelledTextBox titleTextBox;
private LabelledTextBox romanisedTitleTextBox;
protected LabelledTextBox TitleTextBox;
protected LabelledTextBox RomanisedTitleTextBox;
private LabelledTextBox creatorTextBox;
private LabelledTextBox difficultyTextBox;
@ -32,16 +32,16 @@ namespace osu.Game.Screens.Edit.Setup
Children = new[]
{
artistTextBox = createTextBox<LabelledTextBox>("Artist",
ArtistTextBox = createTextBox<LabelledTextBox>("Artist",
!string.IsNullOrEmpty(metadata.ArtistUnicode) ? metadata.ArtistUnicode : metadata.Artist),
romanisedArtistTextBox = createTextBox<LabelledRomanisedTextBox>("Romanised Artist",
RomanisedArtistTextBox = createTextBox<LabelledRomanisedTextBox>("Romanised Artist",
!string.IsNullOrEmpty(metadata.Artist) ? metadata.Artist : MetadataUtils.StripNonRomanisedCharacters(metadata.ArtistUnicode)),
Empty(),
titleTextBox = createTextBox<LabelledTextBox>("Title",
TitleTextBox = createTextBox<LabelledTextBox>("Title",
!string.IsNullOrEmpty(metadata.TitleUnicode) ? metadata.TitleUnicode : metadata.Title),
romanisedTitleTextBox = createTextBox<LabelledRomanisedTextBox>("Romanised Title",
RomanisedTitleTextBox = createTextBox<LabelledRomanisedTextBox>("Romanised Title",
!string.IsNullOrEmpty(metadata.Title) ? metadata.Title : MetadataUtils.StripNonRomanisedCharacters(metadata.ArtistUnicode)),
Empty(),
@ -70,11 +70,11 @@ namespace osu.Game.Screens.Edit.Setup
{
base.LoadComplete();
if (string.IsNullOrEmpty(artistTextBox.Current.Value))
GetContainingInputManager().ChangeFocus(artistTextBox);
if (string.IsNullOrEmpty(ArtistTextBox.Current.Value))
GetContainingInputManager().ChangeFocus(ArtistTextBox);
artistTextBox.Current.BindValueChanged(artist => transferIfRomanised(artist.NewValue, romanisedArtistTextBox));
titleTextBox.Current.BindValueChanged(title => transferIfRomanised(title.NewValue, romanisedTitleTextBox));
ArtistTextBox.Current.BindValueChanged(artist => transferIfRomanised(artist.NewValue, RomanisedArtistTextBox));
TitleTextBox.Current.BindValueChanged(title => transferIfRomanised(title.NewValue, RomanisedTitleTextBox));
updateReadOnlyState();
}
@ -89,8 +89,8 @@ namespace osu.Game.Screens.Edit.Setup
private void updateReadOnlyState()
{
romanisedArtistTextBox.ReadOnly = MetadataUtils.IsRomanised(artistTextBox.Current.Value);
romanisedTitleTextBox.ReadOnly = MetadataUtils.IsRomanised(titleTextBox.Current.Value);
RomanisedArtistTextBox.ReadOnly = MetadataUtils.IsRomanised(ArtistTextBox.Current.Value);
RomanisedTitleTextBox.ReadOnly = MetadataUtils.IsRomanised(TitleTextBox.Current.Value);
}
private void onCommit(TextBox sender, bool newText)
@ -104,11 +104,11 @@ namespace osu.Game.Screens.Edit.Setup
private void updateMetadata()
{
Beatmap.Metadata.ArtistUnicode = artistTextBox.Current.Value;
Beatmap.Metadata.Artist = romanisedArtistTextBox.Current.Value;
Beatmap.Metadata.ArtistUnicode = ArtistTextBox.Current.Value;
Beatmap.Metadata.Artist = RomanisedArtistTextBox.Current.Value;
Beatmap.Metadata.TitleUnicode = titleTextBox.Current.Value;
Beatmap.Metadata.Title = romanisedTitleTextBox.Current.Value;
Beatmap.Metadata.TitleUnicode = TitleTextBox.Current.Value;
Beatmap.Metadata.Title = RomanisedTitleTextBox.Current.Value;
Beatmap.Metadata.AuthorString = creatorTextBox.Current.Value;
Beatmap.BeatmapInfo.Version = difficultyTextBox.Current.Value;