| 12 | #include "test.h" |
| 13 | |
| 14 | FL_TEST_FILE(FL_FILEPATH) { |
| 15 | |
| 16 | using namespace fl; |
| 17 | |
| 18 | FL_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 | |
| 71 | FL_TEST_CASE("UIAudio without URL does not emit url field") { |
nothing calls this directly
no test coverage detected