| 11 | #include "fl/stl/move.h" |
| 12 | |
| 13 | FL_TEST_FILE(FL_FILEPATH) { |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | namespace { |
| 19 | |
| 20 | // Helper class to track frame events for testing |
| 21 | class TestFrameListener : public fl::EngineEvents::Listener { |
| 22 | public: |
| 23 | TestFrameListener() { |
| 24 | fl::EngineEvents::addListener(this); |
| 25 | } |
| 26 | |
| 27 | ~TestFrameListener() { |
| 28 | fl::EngineEvents::removeListener(this); |
| 29 | } |
| 30 | |
| 31 | void onEndFrame() override { |
| 32 | frame_count++; |
| 33 | // Pump the scheduler to execute after_frame tasks specifically |
| 34 | fl::task::Scheduler::instance().update_after_frame_tasks(); |
| 35 | } |
| 36 | |
| 37 | int frame_count = 0; |
| 38 | }; |
| 39 | |
| 40 | } // anonymous namespace |
| 41 | |
| 42 | FL_TEST_CASE("Task self-registration and destruction behavior [task]") { |
| 43 | |
| 44 | FL_SUBCASE("Task auto-registers when callback is set - SUCCESS") { |
| 45 | // Clear any leftover tasks from previous tests |
| 46 | fl::task::Scheduler::instance().clear_all_tasks(); |
| 47 | |
| 48 | bool task_executed = false; |
| 49 | |
| 50 | // Create task without manually adding to scheduler |
| 51 | // Auto-registration happens when .then() is called |
| 52 | { |
| 53 | fl::task::after_frame() |
| 54 | .then([&task_executed]() { |
| 55 | task_executed = true; |
| 56 | }); |
| 57 | // Task temporary object destructs here, but it's already registered |
| 58 | } |
| 59 | |
| 60 | // Simulate frame end event |
| 61 | TestFrameListener listener; |
| 62 | fl::EngineEvents::onEndFrame(); |
| 63 | |
| 64 | // Task should now execute due to auto-registration |
| 65 | FL_CHECK(task_executed); |
| 66 | |
| 67 | // Clean up |
| 68 | fl::task::Scheduler::instance().clear_all_tasks(); |
| 69 | } |
| 70 |
nothing calls this directly
no test coverage detected