feat: add event test
This commit is contained in:
@@ -0,0 +1,37 @@
|
|||||||
|
#include "tests.h"
|
||||||
|
|
||||||
|
#include <seallib/events.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace seallib;
|
||||||
|
|
||||||
|
class EventTest : ITest
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
EventTest() : ITest() {};
|
||||||
|
|
||||||
|
virtual void run() override
|
||||||
|
{
|
||||||
|
Event<std::string> testEvent;
|
||||||
|
|
||||||
|
auto listener1 = testEvent.addListener(
|
||||||
|
[](std::string str) { std::cout << "(Listener 1) Event has been fired with string: " << str << std::endl; });
|
||||||
|
|
||||||
|
auto listener2 = testEvent.addListener(
|
||||||
|
[](std::string str) { std::cout << "(Listener 2) Event has been fired, string: " << str << std::endl; });
|
||||||
|
|
||||||
|
const char* str1 = "somestring";
|
||||||
|
testEvent.run(str1);
|
||||||
|
|
||||||
|
std::string str2("hello world");
|
||||||
|
testEvent.run(str2);
|
||||||
|
|
||||||
|
testEvent.removeListener(listener2);
|
||||||
|
|
||||||
|
testEvent.run("event without listener 2");
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
static EventTest g_eventTest;
|
||||||
Reference in New Issue
Block a user