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

Function FL_TEST_FILE

tests/fl/net/http/stream_client.cpp:6–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include "fl/stl/string.h"
5
6FL_TEST_FILE(FL_FILEPATH) {
7
8using namespace fl;
9using namespace fl::net::http;
10
11// Use unique high ports to avoid conflicts with other tests and services
12static const int kTestPort = 47301;
13
14FL_TEST_CASE("HttpStreamClient - Construction") {
15 HttpStreamClient client("localhost", kTestPort);
16 FL_CHECK_FALSE(client.isConnected());
17}
18
19FL_TEST_CASE("HttpStreamClient - Connect to invalid host fails") {
20 HttpStreamClient client("invalid.host.that.does.not.exist.test", kTestPort);
21 bool result = client.connect();
22 FL_CHECK_FALSE(result);
23 FL_CHECK_FALSE(client.isConnected());
24}
25
26FL_TEST_CASE("HttpStreamClient - Disconnect when not connected is safe") {
27 HttpStreamClient client("localhost", kTestPort);
28 FL_CHECK_FALSE(client.isConnected());
29
30 // Should not crash
31 client.disconnect();
32 FL_CHECK_FALSE(client.isConnected());
33}
34
35FL_TEST_CASE("HttpStreamClient - Write/read fail when disconnected") {
36 HttpStreamClient client("localhost", kTestPort);
37 FL_CHECK_FALSE(client.isConnected());
38
39 // writeResponse should not crash when disconnected
40 fl::json response = fl::json::object();
41 response.set("jsonrpc", "2.0");
42 response.set("result", 42);
43 response.set("id", 1);
44 client.writeResponse(response);
45
46 // readRequest should return nullopt when disconnected
47 fl::optional<fl::json> request = client.readRequest();
48 FL_CHECK_FALSE(request.has_value());
49}
50
51FL_TEST_CASE("HttpStreamClient - readRequest returns nullopt when disconnected") {
52 HttpStreamClient client("localhost", kTestPort);
53 FL_CHECK_FALSE(client.isConnected());
54
55 fl::optional<fl::json> request = client.readRequest();
56 FL_CHECK_FALSE(request.has_value());
57}
58
59FL_TEST_CASE("HttpStreamClient - Multiple writes when disconnected are safe") {
60 HttpStreamClient client("localhost", kTestPort);
61 FL_CHECK_FALSE(client.isConnected());
62
63 fl::json response = fl::json::object();

Callers

nothing calls this directly

Calls 14

writeResponseMethod · 0.80
readRequestMethod · 0.80
getHeartbeatIntervalMethod · 0.80
setHeartbeatIntervalMethod · 0.80
getTimeoutMethod · 0.80
setOnConnectMethod · 0.80
setOnDisconnectMethod · 0.80
isConnectedMethod · 0.45
connectMethod · 0.45
disconnectMethod · 0.45
setMethod · 0.45
has_valueMethod · 0.45

Tested by

no test coverage detected