diff --git a/src/CE.sln.DotSettings b/src/CE.sln.DotSettings index ae508dde9..eca1c0988 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 09c097339..a45348de5 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 8b25bfea8..5ae333100 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 9862b2dee..a3a179699 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 cb017385d..f5adc2fbb 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