| 3 | #include "test.h" |
| 4 | |
| 5 | FL_TEST_FILE(FL_FILEPATH) { |
| 6 | |
| 7 | using namespace fl; |
| 8 | |
| 9 | FL_TEST_CASE("HttpConnection - Initial state is DISCONNECTED") { |
| 10 | HttpConnection conn; |
| 11 | FL_CHECK(conn.getState() == ConnectionState::DISCONNECTED); |
| 12 | FL_CHECK(conn.isDisconnected()); |
| 13 | FL_CHECK_FALSE(conn.isConnected()); |
| 14 | FL_CHECK_FALSE(conn.shouldReconnect()); |
| 15 | } |
| 16 | |
| 17 | FL_TEST_CASE("HttpConnection - Connect transitions to CONNECTING") { |
| 18 | HttpConnection conn; |
| 19 | conn.connect(); |
| 20 | FL_CHECK(conn.getState() == ConnectionState::CONNECTING); |
| 21 | } |
| 22 | |
| 23 | FL_TEST_CASE("HttpConnection - onConnected transitions to CONNECTED") { |
| 24 | HttpConnection conn; |
| 25 | conn.connect(); |
| 26 | conn.onConnected(); |
| 27 | FL_CHECK(conn.getState() == ConnectionState::CONNECTED); |
| 28 | FL_CHECK(conn.isConnected()); |
| 29 | } |
| 30 | |
| 31 | FL_TEST_CASE("HttpConnection - Disconnect from CONNECTED") { |
| 32 | HttpConnection conn; |
| 33 | conn.connect(); |
| 34 | conn.onConnected(); |
| 35 | conn.disconnect(); |
| 36 | FL_CHECK(conn.getState() == ConnectionState::DISCONNECTED); |
| 37 | } |
| 38 | |
| 39 | FL_TEST_CASE("HttpConnection - onDisconnected triggers RECONNECTING") { |
| 40 | HttpConnection conn; |
| 41 | conn.connect(); |
| 42 | conn.onConnected(); |
| 43 | conn.onDisconnected(); |
| 44 | FL_CHECK(conn.getState() == ConnectionState::RECONNECTING); |
| 45 | FL_CHECK(conn.shouldReconnect()); |
| 46 | } |
| 47 | |
| 48 | FL_TEST_CASE("HttpConnection - Exponential backoff calculation") { |
| 49 | ConnectionConfig config; |
| 50 | config.reconnectInitialDelayMs = 1000; |
| 51 | config.reconnectMaxDelayMs = 30000; |
| 52 | config.reconnectBackoffMultiplier = 2; |
| 53 | |
| 54 | HttpConnection conn(config); |
| 55 | conn.connect(); |
| 56 | |
| 57 | // Rapid disconnect without successful connection establishes |
| 58 | // First disconnect: delay = 1000ms (attempts = 0 → 1) |
| 59 | conn.onDisconnected(); |
| 60 | FL_CHECK(conn.getState() == ConnectionState::RECONNECTING); |
| 61 | FL_CHECK(conn.getReconnectAttempts() == 1); |
| 62 | FL_CHECK(conn.getReconnectDelayMs() == 1000); |
nothing calls this directly
no test coverage detected