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

Function FL_TEST_FILE

tests/fl/fx/fx_engine.cpp:24–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22#include "fl/math/xymap.h"
23
24FL_TEST_FILE(FL_FILEPATH) {
25
26using namespace fl;
27
28FASTLED_SHARED_PTR(MockFx);
29
30class MockFx : public fl::Fx {
31public:
32 MockFx(uint16_t numLeds, CRGB color) : fl::Fx(numLeds), mColor(color) {}
33
34 void draw(fl::Fx::DrawContext ctx) override {
35 mLastDrawTime = ctx.now;
36 for (uint16_t i = 0; i < mNumLeds; ++i) {
37 ctx.leds[i] = mColor;
38 }
39 }
40
41 fl::string fxName() const override { return "MockFx"; }
42
43private:
44 CRGB mColor;
45 uint32_t mLastDrawTime = 0;
46};
47
48FL_TEST_CASE("test_fx_engine") {
49 constexpr uint16_t NUM_LEDS = 10;
50 fl::FxEngine driver(NUM_LEDS, false);
51 CRGB leds[NUM_LEDS];
52
53 MockFxPtr redFx = fl::make_shared<MockFx>(NUM_LEDS, CRGB::Red);
54 MockFxPtr blueFx = fl::make_shared<MockFx>(NUM_LEDS, CRGB::Blue);
55
56 int id0 = driver.addFx(redFx);
57 int id1 = driver.addFx(blueFx);
58
59 FL_REQUIRE_EQ(0, id0);
60 FL_REQUIRE_EQ(1, id1);
61
62 FL_SUBCASE("Initial state") {
63 int currId = driver.getCurrentFxId();
64 FL_CHECK(currId == id0);
65 const bool ok = driver.draw(0, leds);
66 FL_CHECK(ok);
67 for (uint16_t i = 0; i < NUM_LEDS; ++i) {
68 // FL_CHECK(leds[i] == CRGB::Red);
69 bool is_red = leds[i] == CRGB::Red;
70 if (!is_red) {
71 fl::string err = leds[i].toString();
72 printf("leds[%d] is not red, was instead: %s\n", i, err.c_str());
73 FL_CHECK(is_red);
74 }
75 }
76 }
77
78
79 FL_SUBCASE("Transition") {
80 bool ok = driver.nextFx(1000);
81 if (!ok) {

Callers

nothing calls this directly

Calls 15

printfFunction · 0.85
getCurrentFxIdMethod · 0.80
toStringMethod · 0.80
nextFxMethod · 0.80
isTransitioningMethod · 0.80
CRGBClass · 0.50
addFxMethod · 0.45
drawMethod · 0.45
c_strMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
fxNameMethod · 0.45

Tested by

no test coverage detected