MCPcopy Create free account
hub / github.com/FastLED/FastLED / FL_TEST_FILE

Function FL_TEST_FILE

tests/fl/task/task.cpp:13–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11#include "fl/stl/move.h"
12
13FL_TEST_FILE(FL_FILEPATH) {
14
15
16
17
18namespace {
19
20// Helper class to track frame events for testing
21class TestFrameListener : public fl::EngineEvents::Listener {
22public:
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
42FL_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

Callers

nothing calls this directly

Calls 10

after_frameFunction · 0.85
every_msFunction · 0.85
clear_all_tasksMethod · 0.80
add_taskMethod · 0.80
cancelMethod · 0.80
millisFunction · 0.50
has_thenMethod · 0.45
is_validMethod · 0.45
updateMethod · 0.45
set_last_run_timeMethod · 0.45

Tested by

no test coverage detected