Skip to content

Commit

Permalink
Add some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
j4james committed Sep 19, 2024
1 parent 1118f54 commit ed33afd
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/terminal/adapter/ut_adapter/adapterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> _testGetSet;
Expand Down
18 changes: 18 additions & 0 deletions src/terminal/adapter/ut_adapter/inputTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}

0 comments on commit ed33afd

Please sign in to comment.