main.cpp 698 B

1234567891011121314151617181920212223242526272829303132333435
  1. #define CR_HOST
  2. #include <gtest/gtest.h>
  3. #include "common/boxed_type.h"
  4. #include "common/listener.h"
  5. #include <cr.h>
  6. #include <entt/signal/dispatcher.hpp>
  7. struct listener {
  8. void on(test::boxed_int msg) {
  9. value = msg.value;
  10. }
  11. int value{};
  12. };
  13. TEST(Lib, Dispatcher) {
  14. entt::dispatcher dispatcher;
  15. test::listener<test::boxed_int> listener;
  16. ASSERT_EQ(listener.value, 0);
  17. dispatcher.sink<test::boxed_int>().connect<&test::listener<test::boxed_int>::on>(listener);
  18. cr_plugin ctx;
  19. cr_plugin_load(ctx, PLUGIN);
  20. ctx.userdata = &dispatcher;
  21. cr_plugin_update(ctx);
  22. ASSERT_EQ(listener.value, 4);
  23. dispatcher = {};
  24. cr_plugin_close(ctx);
  25. }