Skip to content

Commit

Permalink
Add a state machine test to confirm the control characters are dispat…
Browse files Browse the repository at this point in the history
…ched correctly.
  • Loading branch information
j4james committed Jan 10, 2020
1 parent f7c2480 commit 92c75c3
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/terminal/parser/ut_parser/OutputEngineTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DispatchTypes::GraphicsOptions>(s_uiGraphicsCleared) } // fill with cleared option
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -1783,4 +1810,42 @@ class StateMachineExternalTest final

pDispatch->ClearState();
}

TEST_METHOD(TestControlCharacters)
{
auto dispatch = std::make_unique<StatefulDispatch>();
auto pDispatch = dispatch.get();
auto engine = std::make_unique<OutputStateMachineEngine>(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();
}
};

0 comments on commit 92c75c3

Please sign in to comment.