| 4 | #include "fl/stl/string.h" |
| 5 | |
| 6 | FL_TEST_FILE(FL_FILEPATH) { |
| 7 | |
| 8 | using namespace fl; |
| 9 | using namespace fl::net::http; |
| 10 | |
| 11 | // Use unique high ports to avoid conflicts with other tests and services |
| 12 | static const int kTestPort = 47301; |
| 13 | |
| 14 | FL_TEST_CASE("HttpStreamClient - Construction") { |
| 15 | HttpStreamClient client("localhost", kTestPort); |
| 16 | FL_CHECK_FALSE(client.isConnected()); |
| 17 | } |
| 18 | |
| 19 | FL_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 | |
| 26 | FL_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 | |
| 35 | FL_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 | |
| 51 | FL_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 | |
| 59 | FL_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(); |
nothing calls this directly
no test coverage detected