From 5c78e42338b54ded0a0f7313f4d5d876647bc4c7 Mon Sep 17 00:00:00 2001 From: Maximus5 Date: Mon, 18 Apr 2022 19:38:51 +0200 Subject: [PATCH] Internal. Stabilize tests --- src/CE.sln.DotSettings | 2 +- src/ConEmu/ConEmuCD_test.cpp | 2 +- src/UnitTests/ansi_test.cpp | 10 +++++++ src/UnitTests/gtest.h | 13 +++++++++ src/UnitTests/test_stubs.cpp | 52 +++++++++++++++++++++++++++++++++++- 5 files changed, 76 insertions(+), 3 deletions(-) diff --git a/src/CE.sln.DotSettings b/src/CE.sln.DotSettings index ae508dde9b..eca1c09881 100644 --- a/src/CE.sln.DotSettings +++ b/src/CE.sln.DotSettings @@ -38,7 +38,7 @@ <NamingElement Priority="7"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="local variable" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></NamingElement> <NamingElement Priority="19"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="macro" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB"><ExtraRule Prefix="" Suffix="" Style="AaBb" /></Policy></NamingElement> <NamingElement Priority="17"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="namespace" /><type Name="namespace alias" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aa_bb"><ExtraRule Prefix="" Suffix="" Style="AaBb" /></Policy></NamingElement> - <NamingElement Priority="6"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="function parameter" /><type Name="lambda parameter" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></NamingElement> + <NamingElement Priority="6"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="function parameter" /><type Name="lambda parameter" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb"><ExtraRule Prefix="V" Suffix="" Style="AaBb" /><ExtraRule Prefix="R" Suffix="" Style="AaBb" /></Policy></NamingElement> <NamingElement Priority="18"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="type alias" /><type Name="typedef" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="_t" Style="AaBb" /></NamingElement> <NamingElement Priority="4"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="union" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></NamingElement> LIVE_MONITOR diff --git a/src/ConEmu/ConEmuCD_test.cpp b/src/ConEmu/ConEmuCD_test.cpp index 09c0973398..a45348de58 100644 --- a/src/ConEmu/ConEmuCD_test.cpp +++ b/src/ConEmu/ConEmuCD_test.cpp @@ -201,7 +201,7 @@ class ServerDllTest : public testing::Test if (rc == 0 && ::GetLastError() == ERROR_ENVVAR_NOT_FOUND) return nullptr; return szResult; - }; + } MModule LoadServerDll() { diff --git a/src/UnitTests/ansi_test.cpp b/src/UnitTests/ansi_test.cpp index 8b25bfea8a..5ae333100b 100644 --- a/src/UnitTests/ansi_test.cpp +++ b/src/UnitTests/ansi_test.cpp @@ -382,6 +382,15 @@ int RunXTermTestParent() } } + // To post UpArrow to the proper console we should activate proper tab + if (result == 0) + { + cdbg() << "Trying to activate our console" << std::endl; + const auto macroRc = conemu::tests::GuiMacro().Execute(L"Tab 7 -2"); + EXPECT_EQ(macroRc, L"OK"); + } + + cdbg() << "Waiting 10 seconds, console should be active" << std::endl; Sleep(10000); // Clean the input buffer @@ -399,6 +408,7 @@ int RunXTermTestParent() // Check what is sent through input queue if (result == 0) { + // MessageBox(nullptr, L"Continue to posting UpArrow", L"AnsiText", MB_SYSTEMMODAL); cdbg() << "Posting UpArrow keypress" << std::endl; PostMessage(srvMap.hConEmuWndDc, WM_KEYDOWN, VK_UP, 0); PostMessage(srvMap.hConEmuWndDc, WM_KEYUP, VK_UP, (1U << 31) | (1U << 30)); diff --git a/src/UnitTests/gtest.h b/src/UnitTests/gtest.h index 9862b2dee8..a3a179699e 100644 --- a/src/UnitTests/gtest.h +++ b/src/UnitTests/gtest.h @@ -19,6 +19,19 @@ namespace tests { void InitConEmuPathVars(); void WaitDebugger(const std::string& label, const DWORD milliseconds = 15000); extern std::vector gTestArgs; + +class GuiMacro final +{ + HMODULE m_ConEmuCD{nullptr}; + GuiMacro(const GuiMacro&) = delete; + GuiMacro(GuiMacro&&) = delete; + GuiMacro& operator=(const GuiMacro&) = delete; + GuiMacro& operator=(GuiMacro&&) = delete; +public: + GuiMacro(); + ~GuiMacro(); + std::wstring Execute(const std::wstring& macro) const; +}; } // namespace tests } // namespace conemu diff --git a/src/UnitTests/test_stubs.cpp b/src/UnitTests/test_stubs.cpp index cb017385d9..f5adc2fbbb 100644 --- a/src/UnitTests/test_stubs.cpp +++ b/src/UnitTests/test_stubs.cpp @@ -28,7 +28,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../common/Common.h" #include "../common/ConEmuCheck.h" -#include "../common/StartupEnvDef.h" #include "../common/wcwidth.h" #include "../ConEmu/helper.h" #include "../ConEmu/ConEmu.h" @@ -37,6 +36,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../ConEmu/Options.h" #include "../ConEmu/OptionsClass.h" #include "../ConEmuHk/Ansi.h" +#include "../ConEmuCD/ExportedFunctions.h" +#include "../ConEmuCD/ExitCodes.h" #include @@ -187,5 +188,54 @@ void WaitDebugger(const std::string& label, const DWORD milliseconds) cdbg("", false) << std::endl; } +GuiMacro::GuiMacro() +{ + wchar_t szConEmuCD[MAX_PATH] = L""; + if (!GetModuleFileName(nullptr, szConEmuCD, LODWORD(std::size(szConEmuCD)))) + throw std::runtime_error("GuiMacro failed: GetModuleFileName returns false"); + auto* slash = const_cast(PointToName(szConEmuCD)); + if (!slash) + throw std::runtime_error("GuiMacro failed: GetModuleFileName returns invalid data"); + // Expected to be run from gtest suite + wcscpy_s(slash, std::size(szConEmuCD) - (slash - szConEmuCD), L"\\ConEmu\\" ConEmuCD_DLL_3264); + m_ConEmuCD = LoadLibrary(szConEmuCD); + if (!m_ConEmuCD) + throw std::runtime_error("GuiMacro failed: ConEmuCD LoadLibrary failed"); +} + +GuiMacro::~GuiMacro() +{ + if (m_ConEmuCD) + { + FreeLibrary(m_ConEmuCD); + m_ConEmuCD = nullptr; + } +} + +std::wstring GuiMacro::Execute(const std::wstring& macro) const +{ + // ReSharper disable once CppLocalVariableMayBeConst + GuiMacro_t guiMacro = reinterpret_cast(GetProcAddress(m_ConEmuCD, FN_CONEMUCD_GUIMACRO_NAME)); + if (!guiMacro) + { + return L""; + } + + BSTR result = nullptr; + // ReSharper disable once CppLocalVariableMayBeConst + wchar_t szInstance[128] = L"T-2"; + const auto macroRc = guiMacro(szInstance, macro.c_str(), &result); + if (macroRc != CERR_GUIMACRO_SUCCEEDED) + { + return L""; + } + + std::wstring ret{result ? result : L""}; + if (result) + SysFreeString(result); + + return ret; +} + } // namespace tests } // namespace conemu