mirror of
https://github.com/SK-la/osu-framework.git
synced 2026-03-13 11:20:31 +00:00
Make LocalisationManager IDisposable to allow reuse in tests
This commit is contained in:
@@ -25,6 +25,7 @@ namespace osu.Framework.Benchmarks
|
||||
[GlobalCleanup]
|
||||
public void GlobalCleanup()
|
||||
{
|
||||
manager.Dispose();
|
||||
storage.Dispose();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,10 +31,18 @@ namespace osu.Framework.Tests.Localisation
|
||||
manager.AddLanguage("en", new FakeStorage("en"));
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void Teardown()
|
||||
{
|
||||
manager?.Dispose();
|
||||
config?.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestNoLanguagesAdded()
|
||||
{
|
||||
// reinitialise without the default language
|
||||
manager.Dispose();
|
||||
manager = new LocalisationManager(config);
|
||||
|
||||
var localisedText = manager.GetLocalisedBindableString(new TranslatableString(FakeStorage.LOCALISABLE_STRING_EN, FakeStorage.LOCALISABLE_STRING_EN));
|
||||
|
||||
@@ -74,6 +74,12 @@ namespace osu.Framework.Tests.Visual.Localisation
|
||||
}));
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
manager?.Dispose();
|
||||
base.Dispose(isDisposing);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestTextFlowLocalisation()
|
||||
{
|
||||
|
||||
@@ -259,6 +259,12 @@ namespace osu.Framework.Tests.Visual.Sprites
|
||||
|
||||
config.SetValue(FrameworkSetting.Locale, "ja");
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
localisation?.Dispose();
|
||||
base.Dispose(isDisposing);
|
||||
}
|
||||
}
|
||||
|
||||
private class FakeFrameworkConfigManager : FrameworkConfigManager
|
||||
|
||||
@@ -56,6 +56,12 @@ namespace osu.Framework.Tests.Visual.UserInterface
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
manager?.Dispose();
|
||||
base.Dispose(isDisposing);
|
||||
}
|
||||
|
||||
private const string goodbye = "goodbye";
|
||||
|
||||
[SetUp]
|
||||
|
||||
@@ -447,6 +447,9 @@ namespace osu.Framework
|
||||
|
||||
localFonts?.Dispose();
|
||||
localFonts = null;
|
||||
|
||||
Localisation?.Dispose();
|
||||
Localisation = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using osu.Framework.Bindables;
|
||||
@@ -8,7 +9,7 @@ using osu.Framework.Configuration;
|
||||
|
||||
namespace osu.Framework.Localisation
|
||||
{
|
||||
public partial class LocalisationManager
|
||||
public partial class LocalisationManager : IDisposable
|
||||
{
|
||||
public IBindable<LocalisationParameters> CurrentParameters => currentParameters;
|
||||
|
||||
@@ -119,5 +120,18 @@ namespace osu.Framework.Localisation
|
||||
/// </remarks>
|
||||
/// <returns>The resultant <see cref="LocalisationParameters"/>.</returns>
|
||||
protected virtual LocalisationParameters CreateLocalisationParameters() => new LocalisationParameters(currentLocale?.Storage, configPreferUnicode.Value);
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
currentParameters.UnbindAll();
|
||||
configLocale.UnbindAll();
|
||||
configPreferUnicode.UnbindAll();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user