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

Function FL_TEST_FILE

tests/fl/audio_url.cpp:14–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12#include "test.h"
13
14FL_TEST_FILE(FL_FILEPATH) {
15
16using namespace fl;
17
18FL_TEST_CASE("UIAudio URL constructor serializes url field") {
19 // Set up JSON UI handler to capture serialized output
20 fl::string capturedJson;
21 auto updateEngineState = fl::setJsonUiHandlers(
22 [&](const char* jsonStr) {
23 capturedJson = jsonStr;
24 }
25 );
26 FL_REQUIRE(updateEngineState);
27
28 {
29 // Create audio element with URL (like the AudioUrl example sketch)
30 fl::JsonAudioImpl audio("Audio",
31 fl::url("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3"));
32
33 // Trigger serialization
34 fl::processJsonUiPendingUpdates();
35
36 // Must have captured something
37 FL_REQUIRE(!capturedJson.empty());
38 FL_WARN("Captured JSON: " << capturedJson.c_str());
39
40 // Parse the JSON array
41 fl::json parsed = fl::json::parse(capturedJson.c_str());
42 FL_REQUIRE(parsed.is_array());
43 FL_REQUIRE(parsed.size() >= 1);
44
45 // Find the audio element
46 bool foundAudio = false;
47 for (size_t i = 0; i < parsed.size(); ++i) {
48 fl::json component = parsed[i];
49 fl::string type = component["type"].as_or(fl::string(""));
50 if (type == "audio") {
51 foundAudio = true;
52
53 // Verify name
54 fl::string name = component["name"].as_or(fl::string(""));
55 FL_CHECK_EQ(name, fl::string("Audio"));
56
57 // Verify url field is present and correct
58 FL_CHECK(component.contains("url"));
59 fl::string url = component["url"].as_or(fl::string(""));
60 FL_CHECK_EQ(url, fl::string(
61 "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3"));
62
63 FL_WARN("Audio URL field present: " << url.c_str());
64 break;
65 }
66 }
67 FL_CHECK(foundAudio);
68 }
69}
70
71FL_TEST_CASE("UIAudio without URL does not emit url field") {

Callers

nothing calls this directly

Calls 14

setJsonUiHandlersFunction · 0.85
urlClass · 0.85
urlMethod · 0.80
stringClass · 0.50
emptyMethod · 0.45
c_strMethod · 0.45
is_arrayMethod · 0.45
sizeMethod · 0.45
as_orMethod · 0.45
containsMethod · 0.45
toJsonMethod · 0.45

Tested by

no test coverage detected