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

Function FL_TEST_FILE

tests/fl/remote/rpc_http_stream.cpp:14–732  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12#include "fl/stl/asio/http/test_utils/mock_http_client.h"
13
14FL_TEST_FILE(FL_FILEPATH) {
15
16using namespace fl;
17using namespace fl::net::http;
18
19// Helper to create JSON-RPC request
20static json createRequest(const char* method, const json& params, const json& id) {
21 json req = json::object();
22 req.set("jsonrpc", "2.0");
23 req.set("method", method);
24 req.set("params", params);
25 req.set("id", id);
26 return req;
27}
28
29// Helper to extract result from JSON-RPC response
30static fl::optional<json> getResult(const json& response) {
31 if (!response.contains("result")) {
32 return fl::nullopt;
33 }
34 return response["result"];
35}
36
37// Helper to extract error from JSON-RPC response
38static fl::optional<json> getError(const json& response) {
39 if (!response.contains("error")) {
40 return fl::nullopt;
41 }
42 return response["error"];
43}
44
45//=============================================================================
46// TEST CASE: SYNC Mode - Immediate Response
47//=============================================================================
48
49FL_TEST_CASE("RPC-HTTP - SYNC mode - Simple add function") {
50 // Setup: Server with RPC method
51 MockHttpServer server(47701);
52 server.connect();
53
54 Remote remoteServer(
55 [&server]() { return server.readRequest(); },
56 [&server](const json& r) { server.writeResponse(r); }
57 );
58
59 remoteServer.bind("add", [](int a, int b) -> int {
60 return a + b;
61 });
62
63 // Setup: Client
64 MockHttpClient client(server);
65 client.connect();
66
67 // Create request
68 json params = json::array();
69 params.push_back(json(5));
70 params.push_back(json(7));
71 json request = createRequest("add", params, json(1));

Callers

nothing calls this directly

Calls 15

createRequestFunction · 0.85
getResultFunction · 0.85
getErrorFunction · 0.85
readRequestMethod · 0.80
writeResponseMethod · 0.80
sendUpdateMethod · 0.80
sendFinalMethod · 0.80
getTimeoutMethod · 0.80
setOnConnectMethod · 0.80
setOnDisconnectMethod · 0.80
arrayClass · 0.50
jsonClass · 0.50

Tested by

no test coverage detected