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

Function FL_TEST_FILE

tests/fl/channels/manager.cpp:26–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24#include "test.h"
25
26FL_TEST_FILE(FL_FILEPATH) {
27
28namespace draining_state_test {
29
30using namespace fl;
31using DriverState = IChannelDriver::DriverState;
32
33/// Mock driver that lets tests control what poll() returns.
34class StatefulMockDriver : public IChannelDriver {
35public:
36 explicit StatefulMockDriver(const char* name) : mName(name) {}
37
38 // Controllable state
39 DriverState::Value mState = DriverState::READY;
40 int showCount = 0;
41 int enqueueCount = 0;
42 int pollCount = 0;
43
44 bool canHandle(const ChannelDataPtr&) const override { return true; }
45 void enqueue(ChannelDataPtr) override { enqueueCount++; }
46 void show() override { showCount++; }
47 DriverState poll() override { pollCount++; return DriverState(mState); }
48 fl::string getName() const override { return mName; }
49
50 Capabilities getCapabilities() const override {
51 return Capabilities(true, false);
52 }
53
54private:
55 fl::string mName;
56};
57
58FL_TEST_CASE("ChannelManager::poll propagates each state correctly") {
59 auto driver = fl::make_shared<StatefulMockDriver>("DRAIN_POLL");
60 ChannelManager& mgr = ChannelManager::instance();
61 mgr.addDriver(5000, driver);
62
63 // Step through the full lifecycle: READY → BUSY → DRAINING → READY
64 // Each mgr.poll() call is a single poll - no looping, no timeouts.
65
66 driver->mState = DriverState::READY;
67 FL_CHECK_EQ(static_cast<int>(mgr.poll().state),
68 static_cast<int>(DriverState::READY));
69
70 driver->mState = DriverState::BUSY;
71 FL_CHECK_EQ(static_cast<int>(mgr.poll().state),
72 static_cast<int>(DriverState::BUSY));
73
74 driver->mState = DriverState::DRAINING;
75 FL_CHECK_EQ(static_cast<int>(mgr.poll().state),
76 static_cast<int>(DriverState::DRAINING));
77
78 driver->mState = DriverState::READY;
79 FL_CHECK_EQ(static_cast<int>(mgr.poll().state),
80 static_cast<int>(DriverState::READY));
81
82 // Verify poll was called exactly 4 times (once per mgr.poll())
83 FL_CHECK_EQ(driver->pollCount, 4);

Callers

nothing calls this directly

Calls 5

addDriverMethod · 0.80
removeDriverMethod · 0.80
pollMethod · 0.45
waitForReadyMethod · 0.45

Tested by

no test coverage detected