main.cpp 985 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #define CR_HOST
  2. #include <gtest/gtest.h>
  3. #include <cr.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_index<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) {
  17. value = msg.payload;
  18. }
  19. int value{};
  20. };
  21. TEST(Lib, Dispatcher) {
  22. entt::dispatcher dispatcher;
  23. listener listener;
  24. ASSERT_EQ(listener.value, 0);
  25. dispatcher.sink<message>().connect<&listener::on>(listener);
  26. cr_plugin ctx;
  27. cr_plugin_load(ctx, PLUGIN);
  28. ctx.userdata = type_context::instance();
  29. cr_plugin_update(ctx);
  30. ctx.userdata = &dispatcher;
  31. cr_plugin_update(ctx);
  32. ASSERT_EQ(listener.value, 42);
  33. dispatcher = {};
  34. cr_plugin_close(ctx);
  35. }