| 10 | #include "test.h" |
| 11 | |
| 12 | FL_TEST_FILE(FL_FILEPATH) { |
| 13 | |
| 14 | // ============================================================================= |
| 15 | // Test Fixtures and Helpers |
| 16 | // ============================================================================= |
| 17 | |
| 18 | // Test helper to create JSON-RPC request |
| 19 | fl::json makeRequest(const char* method, fl::json params = fl::json::array(), int id = 1, fl::u32 timestamp = 0) { |
| 20 | fl::json req = fl::json::object(); |
| 21 | req.set("method", method); |
| 22 | req.set("params", params); |
| 23 | req.set("id", id); |
| 24 | if (timestamp > 0) { |
| 25 | req.set("timestamp", static_cast<fl::i64>(timestamp)); |
| 26 | } |
| 27 | return req; |
| 28 | } |
| 29 | |
| 30 | // Request/Response queues for testing |
| 31 | struct TestIO { |
| 32 | fl::vector<fl::json> requests; |
| 33 | fl::vector<fl::json> responses; |
| 34 | size_t requestIndex = 0; |
| 35 | |
| 36 | fl::optional<fl::json> pullRequest() { |
| 37 | if (requestIndex >= requests.size()) { |
| 38 | return fl::nullopt; |
| 39 | } |
| 40 | return requests[requestIndex++]; |
| 41 | } |
| 42 | |
| 43 | void pushResponse(const fl::json& response) { |
| 44 | responses.push_back(response); |
| 45 | } |
| 46 | |
| 47 | void reset() { |
| 48 | requests.clear(); |
| 49 | responses.clear(); |
| 50 | requestIndex = 0; |
| 51 | } |
| 52 | }; |
| 53 | |
| 54 | // ============================================================================= |
| 55 | // Construction Tests |
| 56 | // ============================================================================= |
| 57 | |
| 58 | FL_TEST_CASE("Remote: Construction with callbacks") { |
| 59 | TestIO io; |
| 60 | |
| 61 | fl::Remote remote( |
| 62 | [&io]() { return io.pullRequest(); }, |
| 63 | [&io](const fl::json& r) { io.pushResponse(r); } |
| 64 | ); |
| 65 | |
| 66 | FL_REQUIRE(remote.count() == 0); // No methods registered yet |
| 67 | } |
| 68 | |
| 69 | // ============================================================================= |
nothing calls this directly
no test coverage detected