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

Function FL_TEST_FILE

tests/fl/ui/ui.cpp:38–1092  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36#include "fl/stl/weak_ptr.h"
37
38FL_TEST_FILE(FL_FILEPATH) {
39using namespace fl;
40class MockJsonUiInternal : public fl::JsonUiInternal {
41public:
42 MockJsonUiInternal(const fl::string& name) : fl::JsonUiInternal(name) {}
43 void toJson(fl::json& json) const override { FL_UNUSED(json); }
44 void updateInternal(const fl::json& json) override { FL_UNUSED(json); }
45};
46
47FL_TEST_CASE("no updateJs handler") {
48 // Set up handler WITHOUT updateJs callback - should return empty function
49 auto updateEngineState = fl::setJsonUiHandlers(fl::function<void(const char*)>{});
50
51 // Should return empty function when no updateJs handler
52 FL_CHECK(!updateEngineState);
53
54 // Create a mock component for testing
55 auto mockComponent = fl::make_shared<MockJsonUiInternal>("test_id");
56 fl::weak_ptr<fl::JsonUiInternal> weakComponent(mockComponent);
57
58 // Test addJsonUiComponent - should go to pending since no manager
59 fl::addJsonUiComponent(weakComponent);
60
61 // Test removeJsonUiComponent - should remove from pending
62 fl::removeJsonUiComponent(weakComponent);
63}
64
65FL_TEST_CASE("internal manager with updateJs") {
66 // Test variables to track handler calls
67 int updateJsCallCount = 0;
68
69 // Set up handler WITH updateJs callback - should use internal JsonUiManager
70 auto updateEngineState = fl::setJsonUiHandlers(
71 [&](const char*) {
72 updateJsCallCount++; // This might be called by internal manager
73 }
74 );
75
76 // Should return valid function when updateJs handler is provided
77 FL_CHECK(updateEngineState);
78
79 // Create a mock component for testing
80 class MockJsonUiInternal : public fl::JsonUiInternal {
81 public:
82 MockJsonUiInternal(const fl::string& name) : fl::JsonUiInternal(name) {}
83 void toJson(fl::json& json) const override { FL_UNUSED(json); }
84 void updateInternal(const fl::json& json) override { FL_UNUSED(json); }
85 };
86 auto mockComponent = fl::make_shared<MockJsonUiInternal>("test_id");
87 fl::weak_ptr<fl::JsonUiInternal> weakComponent(mockComponent);
88
89 // Test addJsonUiComponent - should add to internal manager
90 fl::addJsonUiComponent(weakComponent);
91
92 // Test removeJsonUiComponent - should remove from internal manager
93 fl::removeJsonUiComponent(weakComponent);
94
95 // Test the returned updateEngineState function

Callers

nothing calls this directly

Calls 15

setJsonUiHandlersFunction · 0.85
addJsonUiComponentFunction · 0.85
removeJsonUiComponentFunction · 0.85
skipFunction · 0.85
strstrFunction · 0.85
containsFunction · 0.85
printfFunction · 0.85
executeCommandMethod · 0.80
serializeMethod · 0.80
hasGroupMethod · 0.80

Tested by

no test coverage detected