1
0

main.cpp 970 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #define CR_HOST
  2. #include <cr.h>
  3. #include <gtest/gtest.h>
  4. #include <entt/core/type_info.hpp>
  5. #include <entt/signal/dispatcher.hpp>
  6. #include "type_context.h"
  7. #include "types.h"
  8. template<typename Type>
  9. struct entt::type_seq<Type> {
  10. [[nodiscard]] static id_type value() ENTT_NOEXCEPT {
  11. static const entt::id_type value = type_context::instance()->value(entt::type_hash<Type>::value());
  12. return value;
  13. }
  14. };
  15. struct listener {
  16. void on(message msg) { value = msg.payload; }
  17. int value{};
  18. };
  19. TEST(Lib, Dispatcher) {
  20. entt::dispatcher dispatcher;
  21. listener listener;
  22. ASSERT_EQ(listener.value, 0);
  23. dispatcher.sink<message>().connect<&listener::on>(listener);
  24. cr_plugin ctx;
  25. cr_plugin_load(ctx, PLUGIN);
  26. ctx.userdata = type_context::instance();
  27. cr_plugin_update(ctx);
  28. ctx.userdata = &dispatcher;
  29. cr_plugin_update(ctx);
  30. ASSERT_EQ(listener.value, 42);
  31. dispatcher = {};
  32. cr_plugin_close(ctx);
  33. }