From 92c75c3e8c081c932cc9d5fe3cb39f22dbae7cf1 Mon Sep 17 00:00:00 2001 From: James Holderness Date: Thu, 9 Jan 2020 19:51:24 +0000 Subject: [PATCH] Add a state machine test to confirm the control characters are dispatched correctly. --- .../parser/ut_parser/OutputEngineTest.cpp | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/terminal/parser/ut_parser/OutputEngineTest.cpp b/src/terminal/parser/ut_parser/OutputEngineTest.cpp index 794265428063..6b20f057907e 100644 --- a/src/terminal/parser/ut_parser/OutputEngineTest.cpp +++ b/src/terminal/parser/ut_parser/OutputEngineTest.cpp @@ -677,6 +677,10 @@ class StatefulDispatch final : public TermDispatch _cursorKeysMode{ false }, _cursorBlinking{ true }, _isOriginModeRelative{ false }, + _warningBell{ false }, + _carriageReturn{ false }, + _forwardTab{ false }, + _numTabs{ 0 }, _isDECCOLMAllowed{ false }, _windowWidth{ 80 }, _options{ s_cMaxOptions, static_cast(s_uiGraphicsCleared) } // fill with cleared option @@ -904,6 +908,25 @@ class StatefulDispatch final : public TermDispatch return true; } + bool WarningBell() noexcept override + { + _warningBell = true; + return true; + } + + bool CarriageReturn() noexcept override + { + _carriageReturn = true; + return true; + } + + bool ForwardTab(const size_t numTabs) noexcept override + { + _forwardTab = true; + _numTabs = numTabs; + return true; + } + bool EnableDECCOLMSupport(const bool fEnabled) noexcept override { _isDECCOLMAllowed = fEnabled; @@ -950,6 +973,10 @@ class StatefulDispatch final : public TermDispatch bool _cursorKeysMode; bool _cursorBlinking; bool _isOriginModeRelative; + bool _warningBell; + bool _carriageReturn; + bool _forwardTab; + size_t _numTabs; bool _isDECCOLMAllowed; size_t _windowWidth; @@ -1783,4 +1810,42 @@ class StateMachineExternalTest final pDispatch->ClearState(); } + + TEST_METHOD(TestControlCharacters) + { + auto dispatch = std::make_unique(); + auto pDispatch = dispatch.get(); + auto engine = std::make_unique(std::move(dispatch)); + StateMachine mach(std::move(engine)); + + Log::Comment(L"BEL (Warning Bell) control character"); + mach.ProcessCharacter(AsciiChars::BEL); + + VERIFY_IS_TRUE(pDispatch->_warningBell); + + pDispatch->ClearState(); + + Log::Comment(L"BS (Back Space) control character"); + mach.ProcessCharacter(AsciiChars::BS); + + VERIFY_IS_TRUE(pDispatch->_cursorBackward); + VERIFY_ARE_EQUAL(1u, pDispatch->_cursorDistance); + + pDispatch->ClearState(); + + Log::Comment(L"CR (Carriage Return) control character"); + mach.ProcessCharacter(AsciiChars::CR); + + VERIFY_IS_TRUE(pDispatch->_carriageReturn); + + pDispatch->ClearState(); + + Log::Comment(L"HT (Horizontal Tab) control character"); + mach.ProcessCharacter(AsciiChars::TAB); + + VERIFY_IS_TRUE(pDispatch->_forwardTab); + VERIFY_ARE_EQUAL(1u, pDispatch->_numTabs); + + pDispatch->ClearState(); + } };