main.cpp 859 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #define CR_HOST
  2. #include <cr.h>
  3. #include <gtest/gtest.h>
  4. #include <entt/core/type_info.hpp>
  5. #include <entt/signal/emitter.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. TEST(Lib, Emitter) {
  16. test_emitter emitter;
  17. int value{};
  18. ASSERT_EQ(value, 0);
  19. emitter.once<message>([&](message msg, test_emitter &) { value = msg.payload; });
  20. cr_plugin ctx;
  21. cr_plugin_load(ctx, PLUGIN);
  22. ctx.userdata = type_context::instance();
  23. cr_plugin_update(ctx);
  24. ctx.userdata = &emitter;
  25. cr_plugin_update(ctx);
  26. ASSERT_EQ(value, 42);
  27. emitter = {};
  28. cr_plugin_close(ctx);
  29. }