Repository: microsoft/terminal
File: src/terminal/adapter/ut_adapter/inputTest.cpp (C++)

Code before:

        auto inputEvent = IInputEvent::Create(irTest);
        // Send key into object (will trigger callback and verification)
        VERIFY_ARE_EQUAL(false, pInput->HandleKey(inputEvent.get()), L"Verify key was NOT handled.");
    }

    Log::Comment(L"Verify other types of events are not handled/intercepted.");

    INPUT_RECORD irUnhandled = { 0 };

    Log::Comment(L"Testing MOUSE_EVENT");
    irUnhandled.EventType = MOUSE_EVENT;
    auto inputEvent = IInputEvent::Create(irUnhandled);
    VERIFY_ARE_EQUAL(false, pInput->HandleKey(inputEvent.get()), L"Verify MOUSE_EVENT was NOT handled.");

    Log::Comment(L"Testing WINDOW_BUFFER_SIZE_EVENT");
    irUnhandled.EventType = WINDOW_BUFFER_SIZE_EVENT;
    inputEvent = IInputEvent::Create(irUnhandled);
    VERIFY_ARE_EQUAL(false, pInput->HandleKey(inputEvent.get()), L"Verify WINDOW_BUFFER_SIZE_EVENT was NOT handled.");

    Log::Comment(L"Testing MENU_EVENT");
    irUnhandled.EventType = MENU_EVENT;
    inputEvent = IInputEvent::Create(irUnhandled);
    VERIFY_ARE_EQUAL(false, pInput->HandleKey(inputEvent.get()), L"Verify MENU_EVENT was NOT handled.");

    Log::Comment(L"Testing FOCUS_EVENTs is handled by TestFocusEvents");
}

void InputTest::TestFocusEvents()
{
    // GH#12900, #13238
    // Focus events that come in from the API should never be translated to VT sequences.
    // We're relying on the fact that the INPUT_RECORD version of the ctor is only called by the API
    const auto pInput = new TerminalInput(s_TerminalInputTestCallback);

    INPUT_RECORD irTest = { 0 };
    irTest.EventType = FOCUS_EVENT;

    {
        irTest.Event.FocusEvent.bSetFocus = false;
        auto inputEvent = IInputEvent::Create(irTest);
        VERIFY_ARE_EQUAL(false, pInput->HandleKey(inputEvent.get()), L"Verify FOCUS_EVENT from API was NOT handled.");
    }
    {
        irTest.Event.FocusEvent.bSetFocus = true;
        auto inputEvent = IInputEvent::Create(irTest);
        VERIFY_ARE_EQUAL(false, pInput->HandleKey(inputEvent.get()), L"Verify FOCUS_EVENT from API was NOT handled.");
    }
    {
        auto inputEvent = std::make_unique<FocusEvent>(false);
        VERIFY_ARE_EQUAL(false, pInput->HandleKey(inputEvent.get()), L"Verify FocusEvent from any other source was NOT handled.");

Review comment (suggestion):
This seems more like noise than signal -- it'll print in every test run, _moments before TestFocusEvents runs_

Code after:

        auto inputEvent = IInputEvent::Create(irTest);
        // Send key into object (will trigger callback and verification)
        VERIFY_ARE_EQUAL(false, pInput->HandleKey(inputEvent.get()), L"Verify key was NOT handled.");
    }

    Log::Comment(L"Verify other types of events are not handled/intercepted.");

    INPUT_RECORD irUnhandled = { 0 };

    Log::Comment(L"Testing MOUSE_EVENT");
    irUnhandled.EventType = MOUSE_EVENT;
    auto inputEvent = IInputEvent::Create(irUnhandled);
    VERIFY_ARE_EQUAL(false, pInput->HandleKey(inputEvent.get()), L"Verify MOUSE_EVENT was NOT handled.");

    Log::Comment(L"Testing WINDOW_BUFFER_SIZE_EVENT");
    irUnhandled.EventType = WINDOW_BUFFER_SIZE_EVENT;
    inputEvent = IInputEvent::Create(irUnhandled);
    VERIFY_ARE_EQUAL(false, pInput->HandleKey(inputEvent.get()), L"Verify WINDOW_BUFFER_SIZE_EVENT was NOT handled.");

    Log::Comment(L"Testing MENU_EVENT");
    irUnhandled.EventType = MENU_EVENT;
    inputEvent = IInputEvent::Create(irUnhandled);
    VERIFY_ARE_EQUAL(false, pInput->HandleKey(inputEvent.get()), L"Verify MENU_EVENT was NOT handled.");

    // Testing FOCUS_EVENTs is handled by TestFocusEvents
}

void InputTest::TestFocusEvents()
{
    // GH#12900, #13238
    // Focus events that come in from the API should never be translated to VT sequences.
    // We're relying on the fact that the INPUT_RECORD version of the ctor is only called by the API
    const auto pInput = new TerminalInput(s_TerminalInputTestCallback);

    INPUT_RECORD irTest = { 0 };
    irTest.EventType = FOCUS_EVENT;

    {
        irTest.Event.FocusEvent.bSetFocus = false;
        auto inputEvent = IInputEvent::Create(irTest);
        VERIFY_ARE_EQUAL(false, pInput->HandleKey(inputEvent.get()), L"Verify FOCUS_EVENT from API was NOT handled.");
    }
    {
        irTest.Event.FocusEvent.bSetFocus = true;
        auto inputEvent = IInputEvent::Create(irTest);
        VERIFY_ARE_EQUAL(false, pInput->HandleKey(inputEvent.get()), L"Verify FOCUS_EVENT from API was NOT handled.");
    }
    {
        auto inputEvent = std::make_unique<FocusEvent>(false);
        VERIFY_ARE_EQUAL(false, pInput->HandleKey(inputEvent.get()), L"Verify FocusEvent from any other source was NOT handled.");