Skip to content

Commit

Permalink
Merge pull request #155 from rmpowell77/dev/generic_tests
Browse files Browse the repository at this point in the history
Issue #154: Generic constructor overload takes wxWindow, should have …
  • Loading branch information
rmpowell77 authored Nov 21, 2023
2 parents 0d7cb42 + b83c0af commit e9939d1
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 7 deletions.
7 changes: 2 additions & 5 deletions LATEST_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# wxUI release notes for v0.1.7
# wxUI release notes for v0.1.8

Bugs addressed in this release:

* [#150](../../issues/150) ComboBox asserts if given an empty list
* [#154](../../issues/154) Generic constructor overload takes wxWindow, should have been Window

Other changes:

* [#147](../../issues/147) Change GenericProxy to Generic::Proxy
* [#148](../../issues/148) Make sure operator-> returns controller on proxies

6 changes: 4 additions & 2 deletions include/wxUI/Generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ struct Generic {
using CreateWindowFunction = std::function<Window*(wxWindow*)>;

struct Proxy;
Generic(wxSizerFlags const& flags, wxWindow* window)

Generic(wxSizerFlags const& flags, Window* window)
: flags(flags)
, child(window)
{
Expand All @@ -48,7 +49,8 @@ struct Generic {
{
}

Generic(wxSizerFlags const& flags, CreateWindowFunction windowFunction)
template <typename Function>
Generic(wxSizerFlags const& flags, Function windowFunction)
: flags(flags)
, child(windowFunction)
{
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ add_executable(wxUI_Tests
${CMAKE_CURRENT_SOURCE_DIR}/wxUI_CheckBoxTests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wxUI_ChoiceTests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wxUI_ComboBoxTests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wxUI_GenericTests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wxUI_GetterSetterTests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wxUI_HSplitterTests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wxUI_HyperlinkTests.cpp
Expand Down
107 changes: 107 additions & 0 deletions tests/wxUI_GenericTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
MIT License
Copyright (c) 2022 Richard Powell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <catch2/catch_test_macros.hpp>
#include <wx/button.h>
#include <wxUI/Generic.h>

#include <wx/wx.h>

// NOLINTBEGIN(cppcoreguidelines-avoid-magic-numbers, readability-magic-numbers, readability-function-cognitive-complexity)

TEST_CASE("Generic")
{
SECTION("flags.window.generic")
{
// using type = wxWindow;
wxFrame frame { nullptr, wxID_ANY, "" };
auto* button = new wxButton(&frame, wxID_ANY, "Generic");
auto uut = wxUI::Generic { wxSizerFlags(1), button };
[[maybe_unused]] wxWindow* window = uut.create(&frame);
}

SECTION("window.generic")
{
wxFrame frame { nullptr, wxID_ANY, "" };
auto* button = new wxButton(&frame, wxID_ANY, "Generic");
auto uut = wxUI::Generic { button };
[[maybe_unused]] wxWindow* window = uut.create(&frame);
}

SECTION("flags.func.generic")
{
wxFrame frame { nullptr, wxID_ANY, "" };
auto uut = wxUI::Generic { wxSizerFlags(1), [](wxWindow* parent) {
return new wxButton(parent, wxID_ANY, "Generic");
} };
[[maybe_unused]] wxWindow* window = uut.create(&frame);
}

SECTION("func.generic")
{
wxFrame frame { nullptr, wxID_ANY, "" };
auto uut = wxUI::Generic { [](wxWindow* parent) {
return new wxButton(parent, wxID_ANY, "Generic");
} };
[[maybe_unused]] wxWindow* window = uut.create(&frame);
}

SECTION("flags.window")
{
using Type = wxButton;
wxFrame frame { nullptr, wxID_ANY, "" };
auto* button = new wxButton(&frame, wxID_ANY, "Generic");
auto uut = wxUI::Generic<Type> { wxSizerFlags(1), button };
[[maybe_unused]] Type* window = uut.create(&frame);
}

SECTION("window")
{
using Type = wxButton;
wxFrame frame { nullptr, wxID_ANY, "" };
auto* button = new wxButton(&frame, wxID_ANY, "Generic");
auto uut = wxUI::Generic<Type> { button };
[[maybe_unused]] Type* window = uut.create(&frame);
}

SECTION("flags.func")
{
using Type = wxButton;
wxFrame frame { nullptr, wxID_ANY, "" };
auto uut = wxUI::Generic<Type> { wxSizerFlags(1), [](wxWindow* parent) {
return new wxButton(parent, wxID_ANY, "Generic");
} };
[[maybe_unused]] Type* window = uut.create(&frame);
}

SECTION("func")
{
using Type = wxButton;
wxFrame frame { nullptr, wxID_ANY, "" };
auto uut = wxUI::Generic<Type> { [](wxWindow* parent) {
return new wxButton(parent, wxID_ANY, "Generic");
} };
[[maybe_unused]] Type* window = uut.create(&frame);
}
}
// NOLINTEND(cppcoreguidelines-avoid-magic-numbers, readability-magic-numbers, readability-function-cognitive-complexity)

0 comments on commit e9939d1

Please sign in to comment.