mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-18 10:53:17 +00:00
37 lines
802 B
C++
37 lines
802 B
C++
#include "doctest.h"
|
|
#include <Tactility/PubSub.h>
|
|
|
|
using namespace tt;
|
|
|
|
TEST_CASE("PubSub publishing with no subscriptions should not crash") {
|
|
PubSub<int> pubsub;
|
|
pubsub.publish(1);
|
|
}
|
|
|
|
TEST_CASE("PubSub subscription receives published data") {
|
|
PubSub<int> pubsub;
|
|
int value = 0;
|
|
|
|
auto subscription = pubsub.subscribe([&value](auto newValue) {
|
|
value = newValue;
|
|
});
|
|
pubsub.publish(1);
|
|
|
|
pubsub.unsubscribe(subscription);
|
|
|
|
CHECK_EQ(value, 1);
|
|
}
|
|
|
|
TEST_CASE("PubSub unsubscribed subscription does not receive published data") {
|
|
PubSub<int> pubsub;
|
|
int value = 0;
|
|
|
|
auto subscription = pubsub.subscribe([&value](auto newValue) {
|
|
value = newValue;
|
|
});
|
|
pubsub.unsubscribe(subscription);
|
|
pubsub.publish(1);
|
|
|
|
CHECK_EQ(value, 0);
|
|
}
|