Documentation for Signal

Former-commit-id: 8c69830fe9e23ec85ced5f29ce43c96ea26298eb
This commit is contained in:
Gawaboumga
2016-02-21 14:26:10 +01:00
parent 1d5518b0d3
commit fe12806c6b
2 changed files with 226 additions and 1 deletions

View File

@@ -0,0 +1,48 @@
#include <Nazara/Core/Signal.hpp>
#include <Catch/catch.hpp>
struct Incrementer
{
void increment(int* inc)
{
*inc += 1;
}
};
void increment(int* inc)
{
*inc += 1;
}
SCENARIO("Signal", "[CORE][SIGNAL]")
{
GIVEN("A signal")
{
Nz::Signal<int*> signal;
WHEN("We connection different callbacks")
{
auto connection = signal.Connect(increment);
signal.Connect([](int* inc){ *inc += 1; });
Incrementer incrementer;
signal.Connect(incrementer, &Incrementer::increment);
THEN("The call of signal with inc = 0 must return 3")
{
int inc = 0;
signal(&inc);
REQUIRE(inc == 3);
}
AND_THEN("When we disconnect one function, there should be only two listeners")
{
connection.Disconnect();
REQUIRE(!connection.IsConnected());
int inc = 0;
signal(&inc);
REQUIRE(inc == 2);
}
}
}
}