| 36 | #include "fl/stl/weak_ptr.h" |
| 37 | |
| 38 | FL_TEST_FILE(FL_FILEPATH) { |
| 39 | using namespace fl; |
| 40 | class MockJsonUiInternal : public fl::JsonUiInternal { |
| 41 | public: |
| 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 | |
| 47 | FL_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 | |
| 65 | FL_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 |
nothing calls this directly
no test coverage detected