From edfa3ea0f0080eadf7f01b463ed0a8638de6ce04 Mon Sep 17 00:00:00 2001 From: James Holderness Date: Fri, 9 Aug 2024 00:45:16 +0100 Subject: [PATCH] Remove SetTextAttributes from the ITerminalApi interface (#17685) The only reason we had the `SetTextAttributes` method in `ITerminalApi` was to allow for conhost to remap the default color attributes when the VT PowerShell quirk was active. Since that quirk has now been removed, there's no need for this API anymore. ## References and Relevant Issues The PowerShell quirk was removed in PR #17666. ## Validation Steps Performed I've had to update all the attribute tests in adapterTest to manually check the expected attributes, since those checks were previously being handled in a `SetTextAttributes` mock which no longer exists. I've also performed some manual tests of the VT attribute operations to double check that they're still working as expected. --- src/cascadia/TerminalCore/Terminal.hpp | 1 - src/cascadia/TerminalCore/TerminalApi.cpp | 5 -- src/host/outputStream.cpp | 12 --- src/host/outputStream.hpp | 2 - src/terminal/adapter/ITerminalApi.hpp | 2 - src/terminal/adapter/PageManager.cpp | 9 +- src/terminal/adapter/PageManager.hpp | 2 +- src/terminal/adapter/adaptDispatch.cpp | 2 +- .../adapter/adaptDispatchGraphics.cpp | 4 +- .../adapter/ut_adapter/adapterTest.cpp | 87 ++++++++++++++----- 10 files changed, 72 insertions(+), 54 deletions(-) diff --git a/src/cascadia/TerminalCore/Terminal.hpp b/src/cascadia/TerminalCore/Terminal.hpp index 3991a8d17bf..fe095332542 100644 --- a/src/cascadia/TerminalCore/Terminal.hpp +++ b/src/cascadia/TerminalCore/Terminal.hpp @@ -132,7 +132,6 @@ class Microsoft::Terminal::Core::Terminal final : Microsoft::Console::VirtualTerminal::StateMachine& GetStateMachine() noexcept override; BufferState GetBufferAndViewport() noexcept override; void SetViewportPosition(const til::point position) noexcept override; - void SetTextAttributes(const TextAttribute& attrs) noexcept override; void SetSystemMode(const Mode mode, const bool enabled) noexcept override; bool GetSystemMode(const Mode mode) const noexcept override; void ReturnAnswerback() override; diff --git a/src/cascadia/TerminalCore/TerminalApi.cpp b/src/cascadia/TerminalCore/TerminalApi.cpp index 5e94972d58b..f10bc9c1a17 100644 --- a/src/cascadia/TerminalCore/TerminalApi.cpp +++ b/src/cascadia/TerminalCore/TerminalApi.cpp @@ -54,11 +54,6 @@ try } CATCH_LOG() -void Terminal::SetTextAttributes(const TextAttribute& attrs) noexcept -{ - _activeBuffer().SetCurrentAttributes(attrs); -} - void Terminal::SetSystemMode(const Mode mode, const bool enabled) noexcept { _assertLocked(); diff --git a/src/host/outputStream.cpp b/src/host/outputStream.cpp index 5edd6927c43..d88be99ef33 100644 --- a/src/host/outputStream.cpp +++ b/src/host/outputStream.cpp @@ -88,18 +88,6 @@ void ConhostInternalGetSet::SetViewportPosition(const til::point position) info.UpdateBottom(); } -// Method Description: -// - Sets the current TextAttribute of the active screen buffer. Text -// written to this buffer will be written with these attributes. -// Arguments: -// - attrs: The new TextAttribute to use -// Return Value: -// - -void ConhostInternalGetSet::SetTextAttributes(const TextAttribute& attrs) -{ - _io.GetActiveOutputBuffer().SetAttributes(attrs); -} - // Routine Description: // - Sets the state of one of the system modes. // Arguments: diff --git a/src/host/outputStream.hpp b/src/host/outputStream.hpp index 27ad3c025d8..6b564abbf8d 100644 --- a/src/host/outputStream.hpp +++ b/src/host/outputStream.hpp @@ -35,8 +35,6 @@ class ConhostInternalGetSet final : public Microsoft::Console::VirtualTerminal:: BufferState GetBufferAndViewport() override; void SetViewportPosition(const til::point position) override; - void SetTextAttributes(const TextAttribute& attrs) override; - void SetSystemMode(const Mode mode, const bool enabled) override; bool GetSystemMode(const Mode mode) const override; diff --git a/src/terminal/adapter/ITerminalApi.hpp b/src/terminal/adapter/ITerminalApi.hpp index ec6e1859011..b874bfb8cd4 100644 --- a/src/terminal/adapter/ITerminalApi.hpp +++ b/src/terminal/adapter/ITerminalApi.hpp @@ -52,8 +52,6 @@ namespace Microsoft::Console::VirtualTerminal virtual bool IsVtInputEnabled() const = 0; - virtual void SetTextAttributes(const TextAttribute& attrs) = 0; - enum class Mode : size_t { AutoWrap, diff --git a/src/terminal/adapter/PageManager.cpp b/src/terminal/adapter/PageManager.cpp index 7c9862611cc..d061bab96e9 100644 --- a/src/terminal/adapter/PageManager.cpp +++ b/src/terminal/adapter/PageManager.cpp @@ -40,16 +40,9 @@ const TextAttribute& Page::Attributes() const noexcept return _buffer.GetCurrentAttributes(); } -void Page::SetAttributes(const TextAttribute& attr, ITerminalApi* api) const +void Page::SetAttributes(const TextAttribute& attr) const noexcept { _buffer.SetCurrentAttributes(attr); - // If the api parameter was specified, we need to pass the new attributes - // through to the api. This occurs when there's a potential for the colors - // to be changed, which may require some legacy remapping in conhost. - if (api) - { - api->SetTextAttributes(attr); - } } til::size Page::Size() const noexcept diff --git a/src/terminal/adapter/PageManager.hpp b/src/terminal/adapter/PageManager.hpp index 7b498e62abe..4c244d71bda 100644 --- a/src/terminal/adapter/PageManager.hpp +++ b/src/terminal/adapter/PageManager.hpp @@ -25,7 +25,7 @@ namespace Microsoft::Console::VirtualTerminal til::CoordType Number() const noexcept; Cursor& Cursor() const noexcept; const TextAttribute& Attributes() const noexcept; - void SetAttributes(const TextAttribute& attr, ITerminalApi* api = nullptr) const; + void SetAttributes(const TextAttribute& attr) const noexcept; til::size Size() const noexcept; til::CoordType Top() const noexcept; til::CoordType Bottom() const noexcept; diff --git a/src/terminal/adapter/adaptDispatch.cpp b/src/terminal/adapter/adaptDispatch.cpp index 8bc5631e9af..d4a42e4ade4 100644 --- a/src/terminal/adapter/adaptDispatch.cpp +++ b/src/terminal/adapter/adaptDispatch.cpp @@ -555,7 +555,7 @@ bool AdaptDispatch::CursorRestoreState() } // Restore text attributes. - page.SetAttributes(savedCursorState.Attributes, &_api); + page.SetAttributes(savedCursorState.Attributes); // Restore designated character sets. _termOutput.RestoreFrom(savedCursorState.TermOutput); diff --git a/src/terminal/adapter/adaptDispatchGraphics.cpp b/src/terminal/adapter/adaptDispatchGraphics.cpp index f7dab41cd1c..afad6e5141a 100644 --- a/src/terminal/adapter/adaptDispatchGraphics.cpp +++ b/src/terminal/adapter/adaptDispatchGraphics.cpp @@ -425,7 +425,7 @@ bool AdaptDispatch::SetGraphicsRendition(const VTParameters options) const auto page = _pages.ActivePage(); auto attr = page.Attributes(); _ApplyGraphicsOptions(options, attr); - page.SetAttributes(attr, &_api); + page.SetAttributes(attr); return true; } @@ -487,6 +487,6 @@ bool AdaptDispatch::PopGraphicsRendition() { const auto page = _pages.ActivePage(); const auto& currentAttributes = page.Attributes(); - page.SetAttributes(_sgrStack.Pop(currentAttributes), &_api); + page.SetAttributes(_sgrStack.Pop(currentAttributes)); return true; } diff --git a/src/terminal/adapter/ut_adapter/adapterTest.cpp b/src/terminal/adapter/ut_adapter/adapterTest.cpp index e65788bc289..9e33ceaf7db 100644 --- a/src/terminal/adapter/ut_adapter/adapterTest.cpp +++ b/src/terminal/adapter/ut_adapter/adapterTest.cpp @@ -97,15 +97,6 @@ class TestGetSet final : public ITerminalApi return false; } - void SetTextAttributes(const TextAttribute& attrs) - { - Log::Comment(L"SetTextAttributes MOCK called..."); - - THROW_HR_IF(E_FAIL, !_setTextAttributesResult); - VERIFY_ARE_EQUAL(_expectedAttribute, attrs); - _textBuffer->SetCurrentAttributes(attrs); - } - void SetSystemMode(const Mode mode, const bool enabled) { Log::Comment(L"SetSystemMode MOCK called..."); @@ -251,7 +242,6 @@ class TestGetSet final : public ITerminalApi Log::Comment(L"Resetting mock data state."); // APIs succeed by default - _setTextAttributesResult = TRUE; _returnResponseResult = TRUE; _textBuffer = std::make_unique(til::size{ 100, 600 }, TextAttribute{}, 0, false, &_renderer); @@ -339,6 +329,11 @@ class TestGetSet final : public ITerminalApi VERIFY_ARE_EQUAL(_expectedCursorPos, _textBuffer->GetCursor().GetPosition()); } + void ValidateExpectedAttributes() + { + VERIFY_ARE_EQUAL(_expectedAttribute, _textBuffer->GetCurrentAttributes()); + } + void ValidateInputEvent(_In_ PCWSTR pwszExpectedResponse) { VERIFY_ARE_EQUAL(pwszExpectedResponse, _response); @@ -375,7 +370,6 @@ class TestGetSet final : public ITerminalApi unsigned int _expectedOutputCP = 0; bool _isPty = false; - bool _setTextAttributesResult = false; bool _returnResponseResult = false; til::enumset _systemMode{ Mode::AutoWrap }; @@ -721,6 +715,7 @@ class AdapterTest VERIFY_IS_TRUE(_pDispatch->CursorRestoreState(), L"By default, restore to top left corner (0,0 offset from viewport)."); _testGetSet->ValidateExpectedCursorPos(); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 2: Place cursor in center. Save. Move cursor to corner. Restore. Should come back to center."); _testGetSet->PrepData(CursorX::XCENTER, CursorY::YCENTER); @@ -739,6 +734,7 @@ class AdapterTest VERIFY_IS_TRUE(_pDispatch->CursorRestoreState(), L"Restoring to corner should succeed. API call inside will test that cursor matched expected position."); _testGetSet->ValidateExpectedCursorPos(); + _testGetSet->ValidateExpectedAttributes(); } TEST_METHOD(CursorHideShowTest) @@ -782,15 +778,7 @@ class AdapterTest size_t cOptions = 0; VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); - - Log::Comment(L"Test 2: Gracefully fail when setting attribute data fails."); - - _testGetSet->PrepData(); - _testGetSet->_setTextAttributesResult = FALSE; - // Need at least one option in order for the call to be able to fail. - rgOptions[0] = (DispatchTypes::GraphicsOptions)0; - cOptions = 1; - VERIFY_THROWS(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions }), std::exception); + _testGetSet->ValidateExpectedAttributes(); } TEST_METHOD(GraphicsSingleTests) @@ -1114,6 +1102,7 @@ class AdapterTest _testGetSet->_textBuffer->SetCurrentAttributes(startingAttribute); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); } TEST_METHOD(GraphicsSingleWithSubParamTests) @@ -1174,6 +1163,7 @@ class AdapterTest } _testGetSet->_textBuffer->SetCurrentAttributes(startingAttribute); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ std::span{ rgOptions, cOptions }, subParams, subParamRanges })); + _testGetSet->ValidateExpectedAttributes(); } TEST_METHOD(GraphicsPushPopTests) @@ -1193,11 +1183,13 @@ class AdapterTest rgOptions[0] = DispatchTypes::GraphicsOptions::Off; _testGetSet->_expectedAttribute = {}; VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); cOptions = 0; VERIFY_IS_TRUE(_pDispatch->PushGraphicsRendition({ rgStackOptions, cOptions })); VERIFY_IS_TRUE(_pDispatch->PopGraphicsRendition()); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 2: Push, change color, pop"); @@ -1209,10 +1201,12 @@ class AdapterTest _testGetSet->_expectedAttribute.SetIndexedForeground(TextColor::DARK_CYAN); _testGetSet->_expectedAttribute.SetDefaultBackground(); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); cOptions = 0; _testGetSet->_expectedAttribute = {}; VERIFY_IS_TRUE(_pDispatch->PopGraphicsRendition()); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 3: two pushes (nested) and pops"); @@ -1225,6 +1219,7 @@ class AdapterTest _testGetSet->_expectedAttribute.SetIndexedForeground(TextColor::DARK_RED); _testGetSet->_expectedAttribute.SetDefaultBackground(); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); // Second push: cOptions = 0; @@ -1236,6 +1231,7 @@ class AdapterTest _testGetSet->_expectedAttribute.SetIndexedForeground(TextColor::DARK_GREEN); _testGetSet->_expectedAttribute.SetDefaultBackground(); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); // First pop: cOptions = 0; @@ -1243,11 +1239,13 @@ class AdapterTest _testGetSet->_expectedAttribute.SetIndexedForeground(TextColor::DARK_RED); _testGetSet->_expectedAttribute.SetDefaultBackground(); VERIFY_IS_TRUE(_pDispatch->PopGraphicsRendition()); + _testGetSet->ValidateExpectedAttributes(); // Second pop: cOptions = 0; _testGetSet->_expectedAttribute = {}; VERIFY_IS_TRUE(_pDispatch->PopGraphicsRendition()); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 4: Save and restore partial attributes"); @@ -1257,6 +1255,7 @@ class AdapterTest _testGetSet->_expectedAttribute.SetIndexedForeground(TextColor::DARK_GREEN); _testGetSet->_expectedAttribute.SetDefaultBackground(); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); cOptions = 1; rgOptions[0] = DispatchTypes::GraphicsOptions::Intense; @@ -1265,6 +1264,7 @@ class AdapterTest _testGetSet->_expectedAttribute.SetIntense(true); _testGetSet->_expectedAttribute.SetDefaultBackground(); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); rgOptions[0] = DispatchTypes::GraphicsOptions::BackgroundBlue; _testGetSet->_expectedAttribute = {}; @@ -1272,6 +1272,7 @@ class AdapterTest _testGetSet->_expectedAttribute.SetIndexedBackground(TextColor::DARK_BLUE); _testGetSet->_expectedAttribute.SetIntense(true); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); // Push, specifying that we only want to save the background, the intensity, and double-underline-ness: cOptions = 3; @@ -1290,6 +1291,7 @@ class AdapterTest _testGetSet->_expectedAttribute.SetIntense(true); _testGetSet->_expectedAttribute.SetUnderlineStyle(UnderlineStyle::DoublyUnderlined); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); cOptions = 1; rgOptions[0] = DispatchTypes::GraphicsOptions::ForegroundRed; @@ -1299,6 +1301,7 @@ class AdapterTest _testGetSet->_expectedAttribute.SetIntense(true); _testGetSet->_expectedAttribute.SetUnderlineStyle(UnderlineStyle::DoublyUnderlined); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); rgOptions[0] = DispatchTypes::GraphicsOptions::NotIntenseOrFaint; _testGetSet->_expectedAttribute = {}; @@ -1306,6 +1309,7 @@ class AdapterTest _testGetSet->_expectedAttribute.SetIndexedBackground(TextColor::DARK_GREEN); _testGetSet->_expectedAttribute.SetUnderlineStyle(UnderlineStyle::DoublyUnderlined); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); // And then restore... cOptions = 0; @@ -1314,6 +1318,7 @@ class AdapterTest _testGetSet->_expectedAttribute.SetIndexedBackground(TextColor::DARK_BLUE); _testGetSet->_expectedAttribute.SetIntense(true); VERIFY_IS_TRUE(_pDispatch->PopGraphicsRendition()); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 5: Save 'no singly underline' state, set singly underlined, and pop. " L"Singly underlined is off after the pop."); @@ -1322,6 +1327,7 @@ class AdapterTest rgOptions[0] = DispatchTypes::GraphicsOptions::NoUnderline; _testGetSet->_expectedAttribute.SetUnderlineStyle(UnderlineStyle::NoUnderline); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); // save 'no underlined' state cOptions = 1; @@ -1333,10 +1339,12 @@ class AdapterTest rgOptions[0] = DispatchTypes::GraphicsOptions::Underline; _testGetSet->_expectedAttribute.SetUnderlineStyle(UnderlineStyle::SinglyUnderlined); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); // restore, expect no underline _testGetSet->_expectedAttribute.SetUnderlineStyle(UnderlineStyle::NoUnderline); VERIFY_IS_TRUE(_pDispatch->PopGraphicsRendition()); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 6: Save 'no singly underlined' state, set doubly underlined, and pop. " L"Doubly underlined is retained after the pop."); @@ -1345,6 +1353,7 @@ class AdapterTest rgOptions[0] = DispatchTypes::GraphicsOptions::NoUnderline; _testGetSet->_expectedAttribute.SetUnderlineStyle(UnderlineStyle::NoUnderline); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); // save no underline state cOptions = 1; @@ -1356,10 +1365,12 @@ class AdapterTest rgOptions[0] = DispatchTypes::GraphicsOptions::DoublyUnderlined; _testGetSet->_expectedAttribute.SetUnderlineStyle(UnderlineStyle::DoublyUnderlined); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); // restore, expect doubly underlined _testGetSet->_expectedAttribute.SetUnderlineStyle(UnderlineStyle::DoublyUnderlined); VERIFY_IS_TRUE(_pDispatch->PopGraphicsRendition()); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 7: Save 'curly underlined' state, set doubly underlined, and pop. " L"Curly underlined is restored after the pop."); @@ -1369,6 +1380,7 @@ class AdapterTest _testGetSet->MakeSubParamsAndRanges({ { 3 } }, subParams, subParamRanges); _testGetSet->_expectedAttribute.SetUnderlineStyle(UnderlineStyle::CurlyUnderlined); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ std::span{ rgOptions, cOptions }, subParams, subParamRanges })); + _testGetSet->ValidateExpectedAttributes(); // save curly underlined state cOptions = 1; @@ -1380,10 +1392,12 @@ class AdapterTest rgOptions[0] = DispatchTypes::GraphicsOptions::DoublyUnderlined; _testGetSet->_expectedAttribute.SetUnderlineStyle(UnderlineStyle::DoublyUnderlined); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); // restore, expect curly underlined _testGetSet->_expectedAttribute.SetUnderlineStyle(UnderlineStyle::CurlyUnderlined); VERIFY_IS_TRUE(_pDispatch->PopGraphicsRendition()); + _testGetSet->ValidateExpectedAttributes(); } TEST_METHOD(GraphicsPersistBrightnessTests) @@ -1400,17 +1414,20 @@ class AdapterTest rgOptions[0] = DispatchTypes::GraphicsOptions::Off; _testGetSet->_expectedAttribute = {}; VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Testing graphics 'Foreground Color Blue'"); rgOptions[0] = DispatchTypes::GraphicsOptions::ForegroundBlue; _testGetSet->_expectedAttribute.SetIndexedForeground(TextColor::DARK_BLUE); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Enabling brightness"); rgOptions[0] = DispatchTypes::GraphicsOptions::Intense; _testGetSet->_expectedAttribute.SetIntense(true); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); VERIFY_IS_TRUE(_testGetSet->_textBuffer->GetCurrentAttributes().IsIntense()); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Testing graphics 'Foreground Color Green, with brightness'"); rgOptions[0] = DispatchTypes::GraphicsOptions::ForegroundGreen; @@ -1418,6 +1435,7 @@ class AdapterTest VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); VERIFY_IS_TRUE(WI_IsFlagSet(_testGetSet->_textBuffer->GetCurrentAttributes().GetLegacyAttributes(), FOREGROUND_GREEN)); VERIFY_IS_TRUE(_testGetSet->_textBuffer->GetCurrentAttributes().IsIntense()); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 2: Disable brightness, use a bright color, next normal call remains not bright"); Log::Comment(L"Resetting graphics options"); @@ -1426,18 +1444,21 @@ class AdapterTest VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); VERIFY_IS_TRUE(WI_IsFlagClear(_testGetSet->_textBuffer->GetCurrentAttributes().GetLegacyAttributes(), FOREGROUND_INTENSITY)); VERIFY_IS_FALSE(_testGetSet->_textBuffer->GetCurrentAttributes().IsIntense()); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Testing graphics 'Foreground Color Bright Blue'"); rgOptions[0] = DispatchTypes::GraphicsOptions::BrightForegroundBlue; _testGetSet->_expectedAttribute.SetIndexedForeground(TextColor::BRIGHT_BLUE); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); VERIFY_IS_FALSE(_testGetSet->_textBuffer->GetCurrentAttributes().IsIntense()); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Testing graphics 'Foreground Color Blue', brightness of 9x series doesn't persist"); rgOptions[0] = DispatchTypes::GraphicsOptions::ForegroundBlue; _testGetSet->_expectedAttribute.SetIndexedForeground(TextColor::DARK_BLUE); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); VERIFY_IS_FALSE(_testGetSet->_textBuffer->GetCurrentAttributes().IsIntense()); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 3: Enable brightness, use a bright color, brightness persists to next normal call"); Log::Comment(L"Resetting graphics options"); @@ -1445,36 +1466,42 @@ class AdapterTest _testGetSet->_expectedAttribute = {}; VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); VERIFY_IS_FALSE(_testGetSet->_textBuffer->GetCurrentAttributes().IsIntense()); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Testing graphics 'Foreground Color Blue'"); rgOptions[0] = DispatchTypes::GraphicsOptions::ForegroundBlue; _testGetSet->_expectedAttribute.SetIndexedForeground(TextColor::DARK_BLUE); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); VERIFY_IS_FALSE(_testGetSet->_textBuffer->GetCurrentAttributes().IsIntense()); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Enabling brightness"); rgOptions[0] = DispatchTypes::GraphicsOptions::Intense; _testGetSet->_expectedAttribute.SetIntense(true); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); VERIFY_IS_TRUE(_testGetSet->_textBuffer->GetCurrentAttributes().IsIntense()); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Testing graphics 'Foreground Color Bright Blue'"); rgOptions[0] = DispatchTypes::GraphicsOptions::BrightForegroundBlue; _testGetSet->_expectedAttribute.SetIndexedForeground(TextColor::BRIGHT_BLUE); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); VERIFY_IS_TRUE(_testGetSet->_textBuffer->GetCurrentAttributes().IsIntense()); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Testing graphics 'Foreground Color Blue, with brightness', brightness of 9x series doesn't affect brightness"); rgOptions[0] = DispatchTypes::GraphicsOptions::ForegroundBlue; _testGetSet->_expectedAttribute.SetIndexedForeground(TextColor::DARK_BLUE); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); VERIFY_IS_TRUE(_testGetSet->_textBuffer->GetCurrentAttributes().IsIntense()); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Testing graphics 'Foreground Color Green, with brightness'"); rgOptions[0] = DispatchTypes::GraphicsOptions::ForegroundGreen; _testGetSet->_expectedAttribute.SetIndexedForeground(TextColor::DARK_GREEN); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); VERIFY_IS_TRUE(_testGetSet->_textBuffer->GetCurrentAttributes().IsIntense()); + _testGetSet->ValidateExpectedAttributes(); } TEST_METHOD(DeviceStatusReportTests) @@ -2697,6 +2724,7 @@ class AdapterTest rgOptions[2] = (DispatchTypes::GraphicsOptions)2; // Green _testGetSet->_expectedAttribute.SetIndexedForeground256(TextColor::DARK_GREEN); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 2: Change Background"); rgOptions[0] = DispatchTypes::GraphicsOptions::BackgroundExtended; @@ -2704,6 +2732,7 @@ class AdapterTest rgOptions[2] = (DispatchTypes::GraphicsOptions)9; // Bright Red _testGetSet->_expectedAttribute.SetIndexedBackground256(TextColor::BRIGHT_RED); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 3: Change Foreground to RGB color"); rgOptions[0] = DispatchTypes::GraphicsOptions::ForegroundExtended; @@ -2711,6 +2740,7 @@ class AdapterTest rgOptions[2] = (DispatchTypes::GraphicsOptions)42; // Arbitrary Color _testGetSet->_expectedAttribute.SetIndexedForeground256(42); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 4: Change Background to RGB color"); rgOptions[0] = DispatchTypes::GraphicsOptions::BackgroundExtended; @@ -2718,6 +2748,7 @@ class AdapterTest rgOptions[2] = (DispatchTypes::GraphicsOptions)142; // Arbitrary Color _testGetSet->_expectedAttribute.SetIndexedBackground256(142); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 5: Change Foreground to Legacy Attr while BG is RGB color"); // Unfortunately this test isn't all that good, because the adapterTest adapter isn't smart enough @@ -2728,6 +2759,7 @@ class AdapterTest rgOptions[2] = (DispatchTypes::GraphicsOptions)9; // Bright Red _testGetSet->_expectedAttribute.SetIndexedForeground256(TextColor::BRIGHT_RED); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, cOptions })); + _testGetSet->ValidateExpectedAttributes(); } TEST_METHOD(XtermExtendedColorDefaultParameterTest) @@ -2745,6 +2777,7 @@ class AdapterTest rgOptions[1] = DispatchTypes::GraphicsOptions::BlinkOrXterm256Index; _testGetSet->_expectedAttribute.SetIndexedForeground256(TextColor::DARK_BLACK); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, 2 })); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 2: Change Indexed Background with default index parameter"); rgOptions[0] = DispatchTypes::GraphicsOptions::BackgroundExtended; @@ -2752,12 +2785,14 @@ class AdapterTest rgOptions[2] = {}; _testGetSet->_expectedAttribute.SetIndexedBackground256(TextColor::DARK_BLACK); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, 3 })); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 3: Change RGB Foreground with all RGB parameters missing"); rgOptions[0] = DispatchTypes::GraphicsOptions::ForegroundExtended; rgOptions[1] = DispatchTypes::GraphicsOptions::RGBColorOrFaint; _testGetSet->_expectedAttribute.SetForeground(RGB(0, 0, 0)); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, 2 })); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 4: Change RGB Background with some missing RGB parameters"); rgOptions[0] = DispatchTypes::GraphicsOptions::BackgroundExtended; @@ -2765,6 +2800,7 @@ class AdapterTest rgOptions[2] = 123; _testGetSet->_expectedAttribute.SetBackground(RGB(123, 0, 0)); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, 3 })); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 5: Change RGB Foreground with some default RGB parameters"); rgOptions[0] = DispatchTypes::GraphicsOptions::ForegroundExtended; @@ -2774,6 +2810,7 @@ class AdapterTest rgOptions[4] = 123; _testGetSet->_expectedAttribute.SetForeground(RGB(0, 0, 123)); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, 5 })); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 6: Ignore Rgb color when R, G or B is out of range (>255)"); _testGetSet->PrepData(); // default color from here is gray on black, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED @@ -2785,6 +2822,7 @@ class AdapterTest // expect no change _testGetSet->_expectedAttribute = TextAttribute{ FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED }; VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, 5 })); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 7: Ignore indexed color when index is out of range (>255)"); _testGetSet->PrepData(); // default color from here is gray on black, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED @@ -2794,6 +2832,7 @@ class AdapterTest // expect no change _testGetSet->_expectedAttribute = TextAttribute{ FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED }; VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, 3 })); + _testGetSet->ValidateExpectedAttributes(); } TEST_METHOD(XtermExtendedSubParameterColorTest) @@ -2813,30 +2852,35 @@ class AdapterTest _testGetSet->MakeSubParamsAndRanges({ { 5 } }, rgSubParamOpts, subParamRanges); _testGetSet->_expectedAttribute.SetIndexedForeground256(TextColor::DARK_BLACK); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, rgSubParamOpts, subParamRanges })); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 2: Change Indexed Background with default index sub parameter"); rgOptions[0] = DispatchTypes::GraphicsOptions::BackgroundExtended; _testGetSet->MakeSubParamsAndRanges({ { 5, {} } }, rgSubParamOpts, subParamRanges); _testGetSet->_expectedAttribute.SetIndexedBackground256(TextColor::DARK_BLACK); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, rgSubParamOpts, subParamRanges })); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 3: Change RGB Foreground with all RGB sub parameters missing"); rgOptions[0] = DispatchTypes::GraphicsOptions::ForegroundExtended; _testGetSet->MakeSubParamsAndRanges({ { 2 } }, rgSubParamOpts, subParamRanges); _testGetSet->_expectedAttribute.SetForeground(RGB(0, 0, 0)); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, rgSubParamOpts, subParamRanges })); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 4: Change RGB Background with some missing RGB sub parameters"); rgOptions[0] = DispatchTypes::GraphicsOptions::BackgroundExtended; _testGetSet->MakeSubParamsAndRanges({ { 2, {}, 123 } }, rgSubParamOpts, subParamRanges); _testGetSet->_expectedAttribute.SetBackground(RGB(123, 0, 0)); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, rgSubParamOpts, subParamRanges })); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 5: Change RGB Foreground with some default RGB sub parameters"); rgOptions[0] = DispatchTypes::GraphicsOptions::ForegroundExtended; _testGetSet->MakeSubParamsAndRanges({ { 2, {}, {}, {}, 123 } }, rgSubParamOpts, subParamRanges); _testGetSet->_expectedAttribute.SetForeground(RGB(0, 0, 123)); VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, rgSubParamOpts, subParamRanges })); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 6: Ignore color when ColorSpaceID is not empty"); _testGetSet->PrepData(); // default color from here is gray on black, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED @@ -2845,6 +2889,7 @@ class AdapterTest // expect no change _testGetSet->_expectedAttribute = TextAttribute{ FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED }; VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, rgSubParamOpts, subParamRanges })); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 7: Ignore Rgb color when R, G or B is out of range (>255)"); _testGetSet->PrepData(); // default color from here is gray on black, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED @@ -2855,6 +2900,7 @@ class AdapterTest // expect no change _testGetSet->_expectedAttribute = TextAttribute{ FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED }; VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, rgSubParamOpts, subParamRanges })); + _testGetSet->ValidateExpectedAttributes(); Log::Comment(L"Test 8: Ignore indexed color when index is out of range (>255)"); _testGetSet->PrepData(); // default color from here is gray on black, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED @@ -2863,6 +2909,7 @@ class AdapterTest // expect no change _testGetSet->_expectedAttribute = TextAttribute{ FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED }; VERIFY_IS_TRUE(_pDispatch->SetGraphicsRendition({ rgOptions, rgSubParamOpts, subParamRanges })); + _testGetSet->ValidateExpectedAttributes(); } TEST_METHOD(SetColorTableValue)