diff options
author | Logan Stromberg <loganstromberg@gmail.com> | 2022-11-16 14:53:17 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-16 23:53:17 +0100 |
commit | 2c9ab5e45fd45d45909b9b348580c44bdfc4d36f (patch) | |
tree | 204dec18131dcdf05837999600ad1a32435a566c /Ryujinx.Tests/HLE/SoftwareKeyboardTests.cs | |
parent | d536cc8ae6d6725780365d858f2fd64b66d90b7f (diff) |
Prevent raw Unicode control codes from showing on software keyboard applet. (#3845)1.1.350
* Revert "Add support for releasing a semaphore to DmaClass (#2926)"
This reverts commit 521a07e6125d3a5d9781512639387a9be5f09107.
* Revert "Revert "Add support for releasing a semaphore to DmaClass (#2926)""
This reverts commit ec8a5fd05362f04cc77436ee3e45a9188777f75e.
* Strip non-visible control codes from strings before they are sent to the software keyboard to prevent ugly unicode blocks from being shown on the UI.
* remove debugging junk
* Initialize stringbuilder capacity at the start to prevent resizing (a tiny tiny microoptimization)
* Update remarks documentation. Remove unneeded imports.
* Removing a test that's actually just redundant
Co-authored-by: Logan Stromberg <lostromb@microsoft.com>
Diffstat (limited to 'Ryujinx.Tests/HLE/SoftwareKeyboardTests.cs')
-rw-r--r-- | Ryujinx.Tests/HLE/SoftwareKeyboardTests.cs | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/Ryujinx.Tests/HLE/SoftwareKeyboardTests.cs b/Ryujinx.Tests/HLE/SoftwareKeyboardTests.cs new file mode 100644 index 00000000..d16039ad --- /dev/null +++ b/Ryujinx.Tests/HLE/SoftwareKeyboardTests.cs @@ -0,0 +1,71 @@ +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 = new string[] + { + "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)); + } + } +} |