From eaf012f6e94767eff0a38c38c588547097553d79 Mon Sep 17 00:00:00 2001 From: Xeek Date: Sat, 3 Feb 2024 16:29:33 -0600 Subject: [PATCH] feat: add [window] minimize action --- .github/workflows/release-please.yml | 1 + .github/workflows/test.yml | 1 + Tests/Tests.vcxproj | 1 + Tests/Tests.vcxproj.filters | 6 ++++ Tests/support/test_window.cpp | 16 +++++++-- Tests/support/test_window.h | 2 ++ Tests/tests/action_minimize_window.cpp | 45 ++++++++++++++++++++++++++ WindowTool.vcxproj | 2 ++ WindowTool.vcxproj.filters | 6 ++++ source/window.cpp | 6 ++++ source/window.h | 1 + source/window_actions.cpp | 7 ++++ source/window_actions.h | 1 + 13 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 Tests/tests/action_minimize_window.cpp diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 21b6ce7..78ad6a1 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -1,3 +1,4 @@ +--- name: Release Please on: push: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 18fd936..035a0e5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,3 +1,4 @@ +--- name: Test on: diff --git a/Tests/Tests.vcxproj b/Tests/Tests.vcxproj index 2657067..885b8be 100644 --- a/Tests/Tests.vcxproj +++ b/Tests/Tests.vcxproj @@ -123,6 +123,7 @@ + diff --git a/Tests/Tests.vcxproj.filters b/Tests/Tests.vcxproj.filters index 431ff57..74062fd 100644 --- a/Tests/Tests.vcxproj.filters +++ b/Tests/Tests.vcxproj.filters @@ -22,6 +22,9 @@ support + + tests + @@ -45,4 +48,7 @@ support + + + \ No newline at end of file diff --git a/Tests/support/test_window.cpp b/Tests/support/test_window.cpp index 44c3f78..294d574 100644 --- a/Tests/support/test_window.cpp +++ b/Tests/support/test_window.cpp @@ -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) { } @@ -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); @@ -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; diff --git a/Tests/support/test_window.h b/Tests/support/test_window.h index 712f5da..a0bfd03 100644 --- a/Tests/support/test_window.h +++ b/Tests/support/test_window.h @@ -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; @@ -31,6 +32,7 @@ namespace window_tool::tests { HWND _hwnd, _hwnd_button; bool _button_clicked; bool _window_closed; + bool _window_minimized; test_window(); diff --git a/Tests/tests/action_minimize_window.cpp b/Tests/tests/action_minimize_window.cpp new file mode 100644 index 0000000..fa4f237 --- /dev/null +++ b/Tests/tests/action_minimize_window.cpp @@ -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 + +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 arguments = { default_app_name, window_title, L"minimize" }; + window_tool::window_actions actions(arguments); + + auto win = std::unique_ptr(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 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); + } +} diff --git a/WindowTool.vcxproj b/WindowTool.vcxproj index fd9d9f9..2840c5f 100644 --- a/WindowTool.vcxproj +++ b/WindowTool.vcxproj @@ -30,6 +30,8 @@ + + 17.0 diff --git a/WindowTool.vcxproj.filters b/WindowTool.vcxproj.filters index 69894b7..2249ff2 100644 --- a/WindowTool.vcxproj.filters +++ b/WindowTool.vcxproj.filters @@ -38,5 +38,11 @@ workflows + + workflows + + + workflows + \ No newline at end of file diff --git a/source/window.cpp b/source/window.cpp index a4a1ef7..35f37b8 100644 --- a/source/window.cpp +++ b/source/window.cpp @@ -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; diff --git a/source/window.h b/source/window.h index 49a8a7d..2421848 100644 --- a/source/window.h +++ b/source/window.h @@ -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; diff --git a/source/window_actions.cpp b/source/window_actions.cpp index 1497589..9bb4d31 100644 --- a/source/window_actions.cpp +++ b/source/window_actions.cpp @@ -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 { @@ -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; } @@ -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); diff --git a/source/window_actions.h b/source/window_actions.h index 2d8b771..7cfca06 100644 --- a/source/window_actions.h +++ b/source/window_actions.h @@ -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; }; }