#include // stupid hack to allow access to private/protected members under test #define private public #define protected public #include #include #include #include #include #include #include #include using namespace std; using namespace crepe; using namespace testing; class ScriptEventTest : public Test { Mediator m; public: ComponentManager component_manager{m}; ScriptSystem system{m}; EventManager & event_manager = m.event_manager; class MyEvent : public Event {}; class MyScript : public Script {}; OptionalRef behaviorscript; OptionalRef script; void SetUp() override { auto & mgr = this->component_manager; GameObject entity = mgr.new_object("name"); BehaviorScript & component = entity.add_component(); this->behaviorscript = component; ASSERT_TRUE(this->behaviorscript); EXPECT_EQ(component.script.get(), nullptr); component.set_script(); ASSERT_NE(component.script.get(), nullptr); this->script = *(MyScript *) component.script.get(); ASSERT_TRUE(this->script); } }; TEST_F(ScriptEventTest, Inactive) { BehaviorScript & behaviorscript = this->behaviorscript; MyScript & script = this->script; EventManager & evmgr = this->event_manager; unsigned event_count = 0; script.subscribe([&](const MyEvent &){ event_count++; return true; }); system.update(); behaviorscript.active = false; EXPECT_EQ(0, event_count); evmgr.trigger_event(); EXPECT_EQ(0, event_count); behaviorscript.active = true; evmgr.trigger_event(); EXPECT_EQ(1, event_count); }