2019-06-15 00:00:46 +02:00
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
|
|
// Licensed under the MIT license.
|
|
|
|
|
2020-08-07 16:46:52 +02:00
|
|
|
#include "pch.h"
|
2019-06-15 00:00:46 +02:00
|
|
|
#include <WexTestClass.h>
|
|
|
|
|
|
|
|
#include "../cascadia/TerminalCore/Terminal.hpp"
|
|
|
|
#include "../renderer/inc/DummyRenderTarget.hpp"
|
|
|
|
#include "consoletaeftemplates.hpp"
|
|
|
|
|
|
|
|
using namespace WEX::Logging;
|
|
|
|
using namespace WEX::TestExecution;
|
|
|
|
|
|
|
|
using namespace Microsoft::Terminal::Core;
|
|
|
|
using namespace Microsoft::Console::Render;
|
|
|
|
|
|
|
|
namespace TerminalCoreUnitTests
|
|
|
|
{
|
|
|
|
class InputTest
|
|
|
|
{
|
|
|
|
TEST_CLASS(InputTest);
|
|
|
|
TEST_CLASS_SETUP(ClassSetup)
|
|
|
|
{
|
|
|
|
DummyRenderTarget emptyRT;
|
|
|
|
term.Create({ 100, 100 }, 0, emptyRT);
|
|
|
|
auto inputFn = std::bind(&InputTest::_VerifyExpectedInput, this, std::placeholders::_1);
|
|
|
|
term.SetWriteInputCallback(inputFn);
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_METHOD(AltShiftKey);
|
2020-08-06 03:03:58 +02:00
|
|
|
TEST_METHOD(InvalidKeyEvent);
|
2019-06-15 00:00:46 +02:00
|
|
|
|
|
|
|
void _VerifyExpectedInput(std::wstring& actualInput)
|
|
|
|
{
|
|
|
|
VERIFY_ARE_EQUAL(expectedinput.size(), actualInput.size());
|
|
|
|
VERIFY_ARE_EQUAL(expectedinput, actualInput);
|
|
|
|
};
|
|
|
|
|
|
|
|
Terminal term{};
|
|
|
|
std::wstring expectedinput{};
|
|
|
|
};
|
|
|
|
|
|
|
|
void InputTest::AltShiftKey()
|
|
|
|
{
|
|
|
|
// Tests GH:637
|
|
|
|
|
|
|
|
// Verify that Alt+a generates a lowercase a on the input
|
|
|
|
expectedinput = L"\x1b"
|
|
|
|
"a";
|
2020-04-07 21:09:28 +02:00
|
|
|
VERIFY_IS_TRUE(term.SendCharEvent(L'a', 0, ControlKeyStates::LeftAltPressed));
|
2019-06-15 00:00:46 +02:00
|
|
|
|
|
|
|
// Verify that Alt+shift+a generates a uppercase a on the input
|
|
|
|
expectedinput = L"\x1b"
|
|
|
|
"A";
|
2020-04-07 21:09:28 +02:00
|
|
|
VERIFY_IS_TRUE(term.SendCharEvent(L'A', 0, ControlKeyStates::LeftAltPressed | ControlKeyStates::ShiftPressed));
|
2019-06-15 00:00:46 +02:00
|
|
|
}
|
|
|
|
|
2020-08-06 03:03:58 +02:00
|
|
|
void InputTest::InvalidKeyEvent()
|
|
|
|
{
|
|
|
|
// Certain applications like AutoHotKey and its keyboard remapping feature,
|
|
|
|
// send us key events using SendInput() whose values are outside of the valid range.
|
|
|
|
VERIFY_IS_FALSE(term.SendKeyEvent(0, 123, {}, true));
|
|
|
|
VERIFY_IS_FALSE(term.SendKeyEvent(255, 123, {}, true));
|
|
|
|
}
|
2019-06-15 00:00:46 +02:00
|
|
|
}
|