2019-02-05 16:50:32 +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 System.Collections.Generic;
|
|
|
|
using NUnit.Framework;
|
2019-09-10 06:43:30 +08:00
|
|
|
using osu.Game.IO;
|
2019-02-05 16:50:32 +08:00
|
|
|
using osu.Game.Skinning;
|
|
|
|
using osu.Game.Tests.Resources;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Skins
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2019-02-05 17:09:15 +08:00
|
|
|
public class LegacySkinDecoderTest
|
2019-02-05 16:50:32 +08:00
|
|
|
{
|
2019-11-07 20:51:03 +08:00
|
|
|
[TestCase(true)]
|
|
|
|
[TestCase(false)]
|
|
|
|
[TestCase(false, false)]
|
|
|
|
public void TestDecodeSkinColours(bool hasColours, bool canFallback = true)
|
2019-02-05 16:50:32 +08:00
|
|
|
{
|
|
|
|
var decoder = new LegacySkinDecoder();
|
2019-04-01 11:44:46 +08:00
|
|
|
|
2019-11-07 20:51:03 +08:00
|
|
|
using (var resStream = TestResources.OpenResource(hasColours ? "skin.ini" : "skin-empty.ini"))
|
2019-09-10 06:43:30 +08:00
|
|
|
using (var stream = new LineBufferedReader(resStream))
|
2019-02-05 16:50:32 +08:00
|
|
|
{
|
2019-11-07 20:51:03 +08:00
|
|
|
var skinConfiguration = decoder.Decode(stream);
|
|
|
|
skinConfiguration.AllowDefaultComboColoursFallback = canFallback;
|
|
|
|
|
|
|
|
var comboColors = skinConfiguration.ComboColours;
|
|
|
|
|
|
|
|
if (!canFallback && !hasColours)
|
|
|
|
{
|
|
|
|
Assert.IsNull(comboColors);
|
|
|
|
return;
|
|
|
|
}
|
2019-02-05 16:50:32 +08:00
|
|
|
|
2019-11-07 20:51:03 +08:00
|
|
|
List<Color4> expectedColors;
|
2019-11-07 21:13:10 +08:00
|
|
|
|
2019-11-07 20:51:03 +08:00
|
|
|
if (hasColours)
|
2019-11-07 21:13:10 +08:00
|
|
|
{
|
2019-11-07 20:51:03 +08:00
|
|
|
expectedColors = new List<Color4>
|
2019-11-07 23:42:17 +08:00
|
|
|
{
|
|
|
|
new Color4(142, 199, 255, 255),
|
|
|
|
new Color4(255, 128, 128, 255),
|
|
|
|
new Color4(128, 255, 255, 255),
|
|
|
|
new Color4(100, 100, 100, 100),
|
|
|
|
};
|
2019-11-07 21:13:10 +08:00
|
|
|
}
|
2019-11-07 20:51:03 +08:00
|
|
|
else
|
2019-11-07 21:13:10 +08:00
|
|
|
{
|
2019-11-07 20:51:03 +08:00
|
|
|
expectedColors = SkinConfiguration.DefaultComboColours;
|
2019-11-07 21:13:10 +08:00
|
|
|
}
|
2019-02-05 16:50:32 +08:00
|
|
|
|
|
|
|
Assert.AreEqual(expectedColors.Count, comboColors.Count);
|
|
|
|
for (int i = 0; i < expectedColors.Count; i++)
|
|
|
|
Assert.AreEqual(expectedColors[i], comboColors[i]);
|
|
|
|
}
|
|
|
|
}
|
2019-09-03 17:59:11 +08:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestDecodeGeneral()
|
|
|
|
{
|
|
|
|
var decoder = new LegacySkinDecoder();
|
|
|
|
|
|
|
|
using (var resStream = TestResources.OpenResource("skin.ini"))
|
2019-09-10 06:43:30 +08:00
|
|
|
using (var stream = new LineBufferedReader(resStream))
|
2019-09-03 17:59:11 +08:00
|
|
|
{
|
|
|
|
var config = decoder.Decode(stream);
|
|
|
|
|
|
|
|
Assert.AreEqual("test skin", config.SkinInfo.Name);
|
|
|
|
Assert.AreEqual("TestValue", config.ConfigDictionary["TestLookup"]);
|
|
|
|
}
|
|
|
|
}
|
2019-02-05 16:50:32 +08:00
|
|
|
}
|
|
|
|
}
|