ulib/tests/3party/eventbus/eventbus_unittest.cpp
tqcq 925efe8abe
All checks were successful
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Successful in 1m15s
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Successful in 1m12s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Successful in 1m8s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Successful in 1m10s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Successful in 1m23s
linux-mips64-gcc / linux-gcc-mips64el (push) Successful in 1m31s
linux-x64-gcc / linux-gcc (push) Successful in 1m57s
feat/add_eventbus (#9)
Co-authored-by: tqcq <99722391+tqcq@users.noreply.github.com>
Reviewed-on: #9
2024-01-19 04:51:24 +00:00

21 lines
398 B
C++

#include <gtest/gtest.h>
#include <eventbus.h>
TEST(EventBus, BaseTest)
{
struct Event {
int x;
};
ulib::eventbus bus;
int calls = 0;
ulib::scoped_subscription<Event> ss(bus, [&](const Event &e) noexcept {
EXPECT_EQ(calls, e.x);
++calls;
});
bus.publish(Event{0});
EXPECT_EQ(calls, 1);
bus.publish(Event{1});
EXPECT_EQ(calls, 2);
}