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

Function FL_TEST_FILE

tests/fl/active_strip_data_json.cpp:27–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25#include "rgbw.h"
26
27FL_TEST_FILE(FL_FILEPATH) {
28using namespace fl;
29FL_TEST_CASE("ActiveStripData JSON Round-Trip Test") {
30 FL_WARN("Testing ActiveStripData JSON round-trip...");
31
32 // Create a simple stub controller for testing
33 class StubController : public CPixelLEDController<RGB> {
34 private:
35 int mStripId;
36
37 public:
38 StubController(int stripId) : CPixelLEDController<RGB>(), mStripId(stripId) {}
39
40 void init() override {}
41
42 void showPixels(PixelController<RGB>& pixels) override {
43 fl::ActiveStripData& data = fl::ActiveStripData::Instance();
44
45 // Create RGB buffer from pixels
46 fl::vector<uint8_t> rgbBuffer;
47 auto iterator = pixels.as_iterator(RgbwInvalid());
48 iterator.writeWS2812(&rgbBuffer);
49
50 data.update(mStripId, 1000, rgbBuffer);
51 }
52
53 uint16_t getMaxRefreshRate() const override { return 60; }
54 };
55
56 // Set up test data
57 CRGB leds1[2] = {CRGB::Red, CRGB::Green};
58 CRGB leds2[3] = {CRGB::Blue, CRGB::Yellow, CRGB::Magenta};
59
60 static StubController controller10(10);
61 static StubController controller20(20);
62
63 FastLED.addLeds(&controller10, leds1, 2);
64 FastLED.addLeds(&controller20, leds2, 3);
65
66 // Trigger data population
67 FastLED.show();
68
69 FL_WARN("Populated ActiveStripData with 2 strips (IDs: 10, 20)");
70
71 // Test only the legacy method first
72 fl::ActiveStripData& data = fl::ActiveStripData::Instance();
73 fl::string legacyJson = data.infoJsonString();
74
75 FL_WARN("Legacy JSON: " << legacyJson);
76
77 // Parse back to verify data
78 auto parsed = fl::json::parse(legacyJson.c_str());
79
80 FL_CHECK(parsed.has_value());
81 FL_CHECK(parsed.is_array());
82 FL_CHECK_EQ(parsed.getSize(), 2);
83
84 // Verify strip data

Callers

nothing calls this directly

Calls 9

infoJsonStringMethod · 0.80
infoJsonStringNewMethod · 0.80
stringClass · 0.50
showMethod · 0.45
c_strMethod · 0.45
has_valueMethod · 0.45
is_arrayMethod · 0.45
getSizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected