aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Tests/HLE/SoftwareKeyboardTests.cs
blob: b5bcc213f6ea8f8afaca7241092d622a41940585 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using NUnit.Framework;
using Ryujinx.HLE.HOS.Applets;
using System.Text;

namespace Ryujinx.Tests.HLE
{
    public class SoftwareKeyboardTests
    {
        [Test]
        public void StripUnicodeControlCodes_NullInput()
        {
            Assert.IsNull(SoftwareKeyboardApplet.StripUnicodeControlCodes(null));
        }

        [Test]
        public void StripUnicodeControlCodes_EmptyInput()
        {
            Assert.AreEqual(string.Empty, SoftwareKeyboardApplet.StripUnicodeControlCodes(string.Empty));
        }

        [Test]
        public void StripUnicodeControlCodes_Passthrough()
        {
            string[] prompts = {
                "Please name him.",
                "Name her, too.",
                "Name your friend.",
                "Name another friend.",
                "Name your pet.",
                "Favorite homemade food?",
                "What’s your favorite thing?",
                "Are you sure?",
            };

            foreach (string prompt in prompts)
            {
                Assert.AreEqual(prompt, SoftwareKeyboardApplet.StripUnicodeControlCodes(prompt));
            }
        }

        [Test]
        public void StripUnicodeControlCodes_StripsNewlines()
        {
            Assert.AreEqual("I am very tall", SoftwareKeyboardApplet.StripUnicodeControlCodes("I \r\nam \r\nvery \r\ntall"));
        }

        [Test]
        public void StripUnicodeControlCodes_StripsDeviceControls()
        {
            // 0x13 is control code DC3 used by some games
            string specialInput = Encoding.UTF8.GetString(new byte[] { 0x13, 0x53, 0x68, 0x69, 0x6E, 0x65, 0x13 });
            Assert.AreEqual("Shine", SoftwareKeyboardApplet.StripUnicodeControlCodes(specialInput));
        }

        [Test]
        public void StripUnicodeControlCodes_StripsToEmptyString()
        {
            string specialInput = Encoding.UTF8.GetString(new byte[] { 17, 18, 19, 20 }); // DC1 - DC4 special codes
            Assert.AreEqual(string.Empty, SoftwareKeyboardApplet.StripUnicodeControlCodes(specialInput));
        }

        [Test]
        public void StripUnicodeControlCodes_PreservesMultiCodePoints()
        {
            // Turtles are a good example of multi-codepoint Unicode chars
            string specialInput = "♀ 🐢 🐢 ♂ ";
            Assert.AreEqual(specialInput, SoftwareKeyboardApplet.StripUnicodeControlCodes(specialInput));
        }
    }
}