| 22 | #include "fl/math/xymap.h" |
| 23 | |
| 24 | FL_TEST_FILE(FL_FILEPATH) { |
| 25 | |
| 26 | using namespace fl; |
| 27 | |
| 28 | FASTLED_SHARED_PTR(MockFx); |
| 29 | |
| 30 | class MockFx : public fl::Fx { |
| 31 | public: |
| 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 | |
| 43 | private: |
| 44 | CRGB mColor; |
| 45 | uint32_t mLastDrawTime = 0; |
| 46 | }; |
| 47 | |
| 48 | FL_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) { |
nothing calls this directly
no test coverage detected