From d26353bb32587a38d595ee75fa0b5a737dc3123d Mon Sep 17 00:00:00 2001 From: Dustin Howett Date: Tue, 21 Sep 2021 20:51:44 +0000 Subject: [PATCH] Merged PR 6303540: Prepare command history before COOKED_READ in tests [Git2Git] Merged PR 6303114: Prepare command history before COOKED_READ in tests PR !6278637 introduced a dependency from COOKED_READ_DATA on the ability to locate a command history for a process handle (here, `nullptr`). The tests were blowing up because no such history had been allocated. Closes MSFT-34812916 Closes MSFT-34813774 Closes MSFT-34815941 Closes MSFT-34817558 Closes MSFT-34817540 (Watson) Retrieved from https://microsoft.visualstudio.com os.2020 OS official/rs_wdx_dxp_windev f7517e686447fc0469f6b83df19760dc3dafd577 --- src/host/ut_host/ApiRoutinesTests.cpp | 10 ++++++++++ src/host/ut_host/CommandLineTests.cpp | 3 ++- src/host/ut_host/CommandListPopupTests.cpp | 3 ++- src/host/ut_host/CommandNumberPopupTests.cpp | 3 ++- src/host/ut_host/CopyFromCharPopupTests.cpp | 9 +++++++++ src/host/ut_host/CopyToCharPopupTests.cpp | 3 ++- src/host/ut_host/SelectionTests.cpp | 9 +++++++++ 7 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/host/ut_host/ApiRoutinesTests.cpp b/src/host/ut_host/ApiRoutinesTests.cpp index bf0f7ed36..cf0e8cd18 100644 --- a/src/host/ut_host/ApiRoutinesTests.cpp +++ b/src/host/ut_host/ApiRoutinesTests.cpp @@ -27,6 +27,7 @@ class ApiRoutinesTests ApiRoutines _Routines; IApiRoutines* _pApiRoutines = &_Routines; + CommandHistory* m_pHistory; TEST_METHOD_SETUP(MethodSetup) { @@ -37,11 +38,20 @@ class ApiRoutinesTests m_state->PrepareGlobalInputBuffer(); + m_pHistory = CommandHistory::s_Allocate(L"cmd.exe", nullptr); + if (!m_pHistory) + { + return false; + } + // History must be prepared before COOKED_READ return true; } TEST_METHOD_CLEANUP(MethodCleanup) { + CommandHistory::s_Free(nullptr); + m_pHistory = nullptr; + m_state->CleanupGlobalInputBuffer(); m_state->CleanupGlobalScreenBuffer(); diff --git a/src/host/ut_host/CommandLineTests.cpp b/src/host/ut_host/CommandLineTests.cpp index c5988c8e9..78f253b1b 100644 --- a/src/host/ut_host/CommandLineTests.cpp +++ b/src/host/ut_host/CommandLineTests.cpp @@ -43,12 +43,13 @@ class CommandLineTests m_state->PrepareGlobalScreenBuffer(); m_state->PrepareGlobalInputBuffer(); m_state->PrepareReadHandle(); - m_state->PrepareCookedReadData(); m_pHistory = CommandHistory::s_Allocate(L"cmd.exe", nullptr); if (!m_pHistory) { return false; } + // History must be prepared before COOKED_READ (as it uses s_Find to get at it) + m_state->PrepareCookedReadData(); return true; } diff --git a/src/host/ut_host/CommandListPopupTests.cpp b/src/host/ut_host/CommandListPopupTests.cpp index 2bd19ebae..b0bfe7425 100644 --- a/src/host/ut_host/CommandListPopupTests.cpp +++ b/src/host/ut_host/CommandListPopupTests.cpp @@ -49,7 +49,6 @@ class CommandListPopupTests m_state->PrepareGlobalScreenBuffer(); m_state->PrepareGlobalInputBuffer(); m_state->PrepareReadHandle(); - m_state->PrepareCookedReadData(); m_pHistory = CommandHistory::s_Allocate(L"cmd.exe", nullptr); // resize command history storage to 50 items so that we don't cycle on accident // when PopupTestHelper::InitLongHistory() is called. @@ -58,6 +57,8 @@ class CommandListPopupTests { return false; } + // History must be prepared before COOKED_READ (as it uses s_Find to get at it) + m_state->PrepareCookedReadData(); return true; } diff --git a/src/host/ut_host/CommandNumberPopupTests.cpp b/src/host/ut_host/CommandNumberPopupTests.cpp index 822045223..871ed5f46 100644 --- a/src/host/ut_host/CommandNumberPopupTests.cpp +++ b/src/host/ut_host/CommandNumberPopupTests.cpp @@ -45,12 +45,13 @@ class CommandNumberPopupTests m_state->PrepareGlobalScreenBuffer(); m_state->PrepareGlobalInputBuffer(); m_state->PrepareReadHandle(); - m_state->PrepareCookedReadData(); m_pHistory = CommandHistory::s_Allocate(L"cmd.exe", nullptr); if (!m_pHistory) { return false; } + // History must be prepared before COOKED_READ (as it uses s_Find to get at it) + m_state->PrepareCookedReadData(); return true; } diff --git a/src/host/ut_host/CopyFromCharPopupTests.cpp b/src/host/ut_host/CopyFromCharPopupTests.cpp index 52b147535..e4a42ee5b 100644 --- a/src/host/ut_host/CopyFromCharPopupTests.cpp +++ b/src/host/ut_host/CopyFromCharPopupTests.cpp @@ -24,6 +24,7 @@ class CopyFromCharPopupTests TEST_CLASS(CopyFromCharPopupTests); std::unique_ptr m_state; + CommandHistory* m_pHistory; TEST_CLASS_SETUP(ClassSetup) { @@ -43,12 +44,20 @@ class CopyFromCharPopupTests m_state->PrepareGlobalScreenBuffer(); m_state->PrepareGlobalInputBuffer(); m_state->PrepareReadHandle(); + m_pHistory = CommandHistory::s_Allocate(L"cmd.exe", nullptr); + if (!m_pHistory) + { + return false; + } + // History must be prepared before COOKED_READ (as it uses s_Find to get at it) m_state->PrepareCookedReadData(); return true; } TEST_METHOD_CLEANUP(MethodCleanup) { + CommandHistory::s_Free(nullptr); + m_pHistory = nullptr; m_state->CleanupCookedReadData(); m_state->CleanupReadHandle(); m_state->CleanupGlobalInputBuffer(); diff --git a/src/host/ut_host/CopyToCharPopupTests.cpp b/src/host/ut_host/CopyToCharPopupTests.cpp index 750991074..752922a91 100644 --- a/src/host/ut_host/CopyToCharPopupTests.cpp +++ b/src/host/ut_host/CopyToCharPopupTests.cpp @@ -44,12 +44,13 @@ class CopyToCharPopupTests m_state->PrepareGlobalScreenBuffer(); m_state->PrepareGlobalInputBuffer(); m_state->PrepareReadHandle(); - m_state->PrepareCookedReadData(); m_pHistory = CommandHistory::s_Allocate(L"cmd.exe", nullptr); if (!m_pHistory) { return false; } + // History must be prepared before COOKED_READ (as it uses s_Find to get at it) + m_state->PrepareCookedReadData(); return true; } diff --git a/src/host/ut_host/SelectionTests.cpp b/src/host/ut_host/SelectionTests.cpp index 80515ceb6..9380990f2 100644 --- a/src/host/ut_host/SelectionTests.cpp +++ b/src/host/ut_host/SelectionTests.cpp @@ -412,6 +412,7 @@ class SelectionInputTests TEST_CLASS(SelectionInputTests); CommonState* m_state; + CommandHistory* m_pHistory; TEST_CLASS_SETUP(ClassSetup) { @@ -420,12 +421,20 @@ class SelectionInputTests m_state->PrepareGlobalFont(); m_state->PrepareGlobalScreenBuffer(); m_state->PrepareGlobalInputBuffer(); + m_pHistory = CommandHistory::s_Allocate(L"cmd.exe", nullptr); + if (!m_pHistory) + { + return false; + } + // History must be prepared before COOKED_READ (as it uses s_Find to get at it) return true; } TEST_CLASS_CLEANUP(ClassCleanup) { + CommandHistory::s_Free(nullptr); + m_pHistory = nullptr; m_state->CleanupGlobalScreenBuffer(); m_state->CleanupGlobalFont(); m_state->CleanupGlobalInputBuffer();