Skip to content

Commit

Permalink
feat: add [window] minimize action (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
xeekworx authored Feb 3, 2024
1 parent eeae97b commit efb0b17
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Release Please
on:
push:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Test

on:
Expand Down
1 change: 1 addition & 0 deletions Tests/Tests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
<ClCompile Include="tests\action_button_click.cpp" />
<ClCompile Include="tests\action_close_window.cpp" />
<ClCompile Include="tests\action_find_window.cpp" />
<ClCompile Include="tests\action_minimize_window.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WindowTool.vcxproj">
Expand Down
6 changes: 6 additions & 0 deletions Tests/Tests.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<ClCompile Include="support\test_tools.cpp">
<Filter>support</Filter>
</ClCompile>
<ClCompile Include="tests\action_minimize_window.cpp">
<Filter>tests</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="source">
Expand All @@ -45,4 +48,7 @@
<Filter>support</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
</Project>
16 changes: 14 additions & 2 deletions Tests/support/test_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@

using namespace window_tool::tests;

test_window::test_window()
: _hwnd(NULL), _hwnd_button(NULL), _button_clicked(false), _window_closed(false)
test_window::test_window() :
_hwnd(NULL),
_hwnd_button(NULL),
_button_clicked(false),
_window_minimized(false),
_window_closed(false)
{
}

Expand Down Expand Up @@ -139,6 +143,11 @@ bool window_tool::tests::test_window::was_closed() const
return _window_closed;
}

bool window_tool::tests::test_window::was_minimized() const
{
return _window_minimized;
}

std::wstring test_window::get_title() const
{
return test_window::get_window_text(_hwnd);
Expand Down Expand Up @@ -168,6 +177,9 @@ LRESULT test_window::handle_message(test_window* current_window, UINT uMsg, WPAR
case WM_COMMAND:
_button_clicked = LOWORD(wParam) == 1;
break;
case WM_SIZE:
_window_minimized = wParam == SIZE_MINIMIZED;
break;
case WM_CLOSE:
_window_closed = true;
break;
Expand Down
2 changes: 2 additions & 0 deletions Tests/support/test_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace window_tool::tests {
bool was_button_clicked() const;
bool has_button() const;
bool was_closed() const;
bool was_minimized() const;
std::wstring get_title() const;
std::wstring get_button_text() const;

Expand All @@ -31,6 +32,7 @@ namespace window_tool::tests {
HWND _hwnd, _hwnd_button;
bool _button_clicked;
bool _window_closed;
bool _window_minimized;

test_window();

Expand Down
45 changes: 45 additions & 0 deletions Tests/tests/action_minimize_window.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "../../source/window_actions.h"
#include "../support/base_test.h"
#include "../support/test_tools.h"
#include "../support/test_window.h"
#include "gtest/gtest.h"
#include <memory>

namespace window_tool::tests {
class ActionMinimizeWindow : public base_test {

};

TEST_F(ActionMinimizeWindow, WithWindow) {
// Arrange
const std::wstring window_title = tools::random_string(L"Test Window ");
std::vector<std::wstring> arguments = { default_app_name, window_title, L"minimize" };
window_tool::window_actions actions(arguments);

auto win = std::unique_ptr<test_window>(test_window::create(window_title, true));

// Act
int result = actions.run();
std::wstring output_str = captured_out.str();

// Assert
EXPECT_TRUE(win->was_minimized());
EXPECT_EQ(tools::trim(output_str), L"True");
EXPECT_EQ(result, 0);
}

TEST_F(ActionMinimizeWindow, WithoutWindow) {
// Arrange
const std::wstring window_title = tools::random_string(L"Test Window ");
std::vector<std::wstring> arguments = { default_app_name, window_title, L"minimize" };
window_tool::window_actions actions(arguments);

// Act
int result = actions.run();
std::wstring output_str = captured_out.str();

// Assert
EXPECT_EQ(tools::trim(output_str), L"False");
EXPECT_EQ(result, 0);
}
}
2 changes: 2 additions & 0 deletions WindowTool.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
</ItemGroup>
<ItemGroup>
<None Include=".github\workflows\build.yml" />
<None Include=".github\workflows\release-please.yml" />
<None Include=".github\workflows\test.yml" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
Expand Down
6 changes: 6 additions & 0 deletions WindowTool.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,11 @@
<None Include=".github\workflows\build.yml">
<Filter>workflows</Filter>
</None>
<None Include=".github\workflows\release-please.yml">
<Filter>workflows</Filter>
</None>
<None Include=".github\workflows\test.yml">
<Filter>workflows</Filter>
</None>
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions source/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ bool window::is_visible() const
return ::IsWindowVisible(_hWnd) == TRUE;
}

bool window_tool::window::minimize() const
{
::ShowWindow(_hWnd, SW_MINIMIZE);
return ::IsIconic(_hWnd) == TRUE;
}

bool window::click_button(const std::wstring& name) const
{
if (!is_valid()) return false;
Expand Down
1 change: 1 addition & 0 deletions source/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace window_tool {
HWND get_handle() const;
bool is_valid() const;
bool is_visible() const;
bool minimize() const;
bool click_button(const std::wstring& name) const;
bool close() const;
std::wstring get_text() const;
Expand Down
7 changes: 7 additions & 0 deletions source/window_actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ int window_actions::run()
for (auto& win : windows) {
if (action == L"find") actionResult = on_find(win);
else if (action == L"close") actionResult = on_close(win);
else if (action == L"minimize") actionResult = on_minimize(win);
else if (action == L"click") actionResult = on_click_button(win, button_name);
else
{
Expand Down Expand Up @@ -87,6 +88,7 @@ void window_actions::display_usage() const
<< L"Actions that can be used:" << std::endl
<< L" find Outputs \"True\" if the window is found" << std::endl
<< L" close Attempt to close the window" << std::endl
<< L" minimize Minimize the window" << std::endl
<< L" click Click a button with the name given" << std::endl;
}

Expand All @@ -101,6 +103,11 @@ bool window_actions::on_close(const window& win) const
return win.close();
}

bool window_tool::window_actions::on_minimize(const window& win) const
{
return win.minimize();
}

bool window_actions::on_click_button(const window& win, const std::wstring& button_name) const
{
return win.click_button(button_name);
Expand Down
1 change: 1 addition & 0 deletions source/window_actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace window_tool {

bool on_find(const window& win) const;
bool on_close(const window& win) const;
bool on_minimize(const window& win) const;
bool on_click_button(const window& win, const std::wstring& button_name) const;
};
}

0 comments on commit efb0b17

Please sign in to comment.