Skip to content

Commit

Permalink
Added simple implementation of SignalManager test
Browse files Browse the repository at this point in the history
  • Loading branch information
1aam2am1 committed Oct 3, 2019
1 parent a7bdcdc commit 085d343
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set(TEST_SOURCES
Outline.cpp
Sprite.cpp
Signal.cpp
SignalManager.cpp
String.cpp
SvgImage.cpp
Text.cpp
Expand Down
85 changes: 85 additions & 0 deletions tests/SignalManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// TGUI - Texus' Graphical User Interface
// Copyright (C) 2012-2019 Bruno Van de Velde (vdv_b@tgui.eu)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include "Tests.hpp"
#include <TGUI/SignalManager.hpp>
#include <TGUI/Widgets/Button.hpp>


TEST_CASE("[SignalManager]")
{
tgui::Widget::Ptr widget = tgui::Button::create();

SECTION("connect")
{
class MySignalManager : public tgui::SignalManager {
public:

virtual void connect(std::string signalName, tgui::Widget* widget){
last_signal_name = signalName;
last_widget = widget;
++connected;
}

virtual void remove(std::string signalName, tgui::Widget* widget){
last_signal_name = signalName;
last_widget = widget;
--connected;
}

std::string last_signal_name;
tgui::Widget* last_widget;
int connected = 0;
};

std::shared_ptr<MySignalManager> m = std::make_shared<MySignalManager>();
tgui::SignalManager::setDefaultSignalManager(m);
REQUIRE(tgui::SignalManager::getSignalManager().get() == m.get());
widget->setCallbackID("w1");
REQUIRE(m->last_signal_name == "w1");
REQUIRE(m->last_widget == widget.get());
REQUIRE(m->connected == 1);
widget->setCallbackID("w2");
REQUIRE(m->connected == 1);
{
tgui::Button::Ptr b = std::dynamic_pointer_cast<tgui::Button>(widget);
auto widget2 = tgui::Button::copy(b);
REQUIRE(m->connected == 2);
}
REQUIRE(m->connected == 1);
{
tgui::Button::Ptr widget2 = tgui::Button::create();
widget2->setCallbackID("w3");
REQUIRE(m->connected == 2);
*widget = std::move(*widget2);
REQUIRE(m->connected == 1);
}
REQUIRE(m->connected == 1);
widget->setCallbackID("");
REQUIRE(m->connected == 0);
widget->setCallbackID("w1");
widget = nullptr;
REQUIRE(m->connected == 0);
}
}

0 comments on commit 085d343

Please sign in to comment.