Skip to content

Commit

Permalink
Internal. Stabilize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Maximus5 committed Apr 18, 2022
1 parent 3a8b983 commit 5c78e42
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/CE.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/CppNaming/Rules/=Local_0020variables/@EntryIndexedValue">&lt;NamingElement Priority="7"&gt;&lt;Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"&gt;&lt;type Name="local variable" /&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;&lt;/NamingElement&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CppNaming/Rules/=Macros/@EntryIndexedValue">&lt;NamingElement Priority="19"&gt;&lt;Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"&gt;&lt;type Name="macro" /&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;&lt;/NamingElement&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CppNaming/Rules/=Namespaces/@EntryIndexedValue">&lt;NamingElement Priority="17"&gt;&lt;Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"&gt;&lt;type Name="namespace" /&gt;&lt;type Name="namespace alias" /&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aa_bb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;&lt;/NamingElement&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CppNaming/Rules/=Parameters/@EntryIndexedValue">&lt;NamingElement Priority="6"&gt;&lt;Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"&gt;&lt;type Name="function parameter" /&gt;&lt;type Name="lambda parameter" /&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;&lt;/NamingElement&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CppNaming/Rules/=Parameters/@EntryIndexedValue">&lt;NamingElement Priority="6"&gt;&lt;Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"&gt;&lt;type Name="function parameter" /&gt;&lt;type Name="lambda parameter" /&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb"&gt;&lt;ExtraRule Prefix="V" Suffix="" Style="AaBb" /&gt;&lt;ExtraRule Prefix="R" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;&lt;/NamingElement&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CppNaming/Rules/=Typedefs/@EntryIndexedValue">&lt;NamingElement Priority="18"&gt;&lt;Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"&gt;&lt;type Name="type alias" /&gt;&lt;type Name="typedef" /&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="_t" Style="AaBb" /&gt;&lt;/NamingElement&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CppNaming/Rules/=Unions/@EntryIndexedValue">&lt;NamingElement Priority="4"&gt;&lt;Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"&gt;&lt;type Name="union" /&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;&lt;/NamingElement&gt;</s:String>
<s:String x:Key="/Default/Environment/PerformanceGuide/SwitchBehaviour/=Format/@EntryIndexedValue">LIVE_MONITOR</s:String>
Expand Down
2 changes: 1 addition & 1 deletion src/ConEmu/ConEmuCD_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class ServerDllTest : public testing::Test
if (rc == 0 && ::GetLastError() == ERROR_ENVVAR_NOT_FOUND)
return nullptr;
return szResult;
};
}

MModule LoadServerDll()
{
Expand Down
10 changes: 10 additions & 0 deletions src/UnitTests/ansi_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
Expand Down
13 changes: 13 additions & 0 deletions src/UnitTests/gtest.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ namespace tests {
void InitConEmuPathVars();
void WaitDebugger(const std::string& label, const DWORD milliseconds = 15000);
extern std::vector<std::string> 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

Expand Down
52 changes: 51 additions & 1 deletion src/UnitTests/test_stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 <iostream>

Expand Down Expand Up @@ -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<wchar_t*>(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<GuiMacro_t>(GetProcAddress(m_ConEmuCD, FN_CONEMUCD_GUIMACRO_NAME));
if (!guiMacro)
{
return L"<GuiMacro exported name was not found>";
}

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"<GuiMacro execution failed>";
}

std::wstring ret{result ? result : L"<nullptr>"};
if (result)
SysFreeString(result);

return ret;
}

} // namespace tests
} // namespace conemu

0 comments on commit 5c78e42

Please sign in to comment.