From ed33afdc9b5f6e3d710ec7eb1f3966135be177cf Mon Sep 17 00:00:00 2001 From: James Holderness Date: Thu, 19 Sep 2024 18:49:41 +0100 Subject: [PATCH] Add some unit tests --- .../adapter/ut_adapter/adapterTest.cpp | 33 +++++++++++++++++++ src/terminal/adapter/ut_adapter/inputTest.cpp | 18 ++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/terminal/adapter/ut_adapter/adapterTest.cpp b/src/terminal/adapter/ut_adapter/adapterTest.cpp index 91c7ee5ce02..5fab90f3d39 100644 --- a/src/terminal/adapter/ut_adapter/adapterTest.cpp +++ b/src/terminal/adapter/ut_adapter/adapterTest.cpp @@ -3972,6 +3972,39 @@ class AdapterTest _pDispatch->PagePositionAbsolute(1); } + TEST_METHOD(SendC1ControlTest) + { + const auto S7C1T = L"\033 F"; + const auto S8C1T = L"\033 G"; + + _testGetSet->PrepData(); + _testGetSet->_expectedCodePage = CP_UTF8; + + Log::Comment(L"Generating reports with C1 control sequences"); + _stateMachine->ProcessString(S8C1T); + + _pDispatch->SecondaryDeviceAttributes(); + _testGetSet->ValidateInputEvent(L"\x9b>0;10;1c"); + + _pDispatch->TertiaryDeviceAttributes(); + _testGetSet->ValidateInputEvent(L"\x90!|00000000\x9c"); + + _pDispatch->RequestColorTableEntry(0); + _testGetSet->ValidateInputEvent(L"\x9d\x34;0;rgb:0c0c/0c0c/0c0c\x9c"); + + Log::Comment(L"Generating reports with 7-bit escape sequence"); + _stateMachine->ProcessString(S7C1T); + + _pDispatch->SecondaryDeviceAttributes(); + _testGetSet->ValidateInputEvent(L"\x1b[>0;10;1c"); + + _pDispatch->TertiaryDeviceAttributes(); + _testGetSet->ValidateInputEvent(L"\x1bP!|00000000\x1b\\"); + + _pDispatch->RequestColorTableEntry(0); + _testGetSet->ValidateInputEvent(L"\x1b]4;0;rgb:0c0c/0c0c/0c0c\x1b\\"); + } + private: TerminalInput _terminalInput; std::unique_ptr _testGetSet; diff --git a/src/terminal/adapter/ut_adapter/inputTest.cpp b/src/terminal/adapter/ut_adapter/inputTest.cpp index d3c4c3d0d06..ab893be7724 100644 --- a/src/terminal/adapter/ut_adapter/inputTest.cpp +++ b/src/terminal/adapter/ut_adapter/inputTest.cpp @@ -36,6 +36,7 @@ class Microsoft::Console::VirtualTerminal::InputTest TEST_METHOD(CtrlNumTest); TEST_METHOD(BackarrowKeyModeTest); TEST_METHOD(AutoRepeatModeTest); + TEST_METHOD(SendC1ControlTest); wchar_t GetModifierChar(const bool fShift, const bool fAlt, const bool fCtrl) { @@ -790,3 +791,20 @@ void InputTest::AutoRepeatModeTest() VERIFY_ARE_EQUAL(TerminalInput::MakeOutput(L"A"), input.HandleKey(down)); VERIFY_ARE_EQUAL(TerminalInput::MakeOutput({}), input.HandleKey(up)); } + +void InputTest::SendC1ControlTest() +{ + TerminalInput input; + + Log::Comment(L"Sending keys with C1 control sequences"); + input.SetInputMode(TerminalInput::Mode::SendC1, true); + + TestKey(TerminalInput::MakeOutput(L"\x9bH"), input, 0, VK_HOME); + TestKey(TerminalInput::MakeOutput(L"\x8fP"), input, 0, VK_F1); + + Log::Comment(L"Sending keys with 7-bit escape sequence"); + input.SetInputMode(TerminalInput::Mode::SendC1, false); + + TestKey(TerminalInput::MakeOutput(L"\x1b[H"), input, 0, VK_HOME); + TestKey(TerminalInput::MakeOutput(L"\x1bOP"), input, 0, VK_F1); +}