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

Function main

tests/fl/stl/asio/http/server_loopback.cpp:13–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11#include "fl/task/executor.h"
12
13int main() {
14 FL_WARN("Phase 3: Internal Loopback Test");
15 FL_WARN("=================================");
16
17 // Create HTTP server
18 fl::HttpServer server;
19
20 // Register routes
21 server.get("/", [](const fl::http_request& req) {
22 return fl::http_response::ok("Hello from loopback!\n");
23 });
24
25 server.get("/ping", [](const fl::http_request& req) {
26 return fl::http_response::ok("pong\n");
27 });
28
29 server.get("/test", [](const fl::http_request& req) {
30 fl::json data = fl::json::object();
31 data.set("test", true);
32 data.set("value", 42);
33 return fl::http_response::ok().json(data);
34 });
35
36 // Start server
37 if (!server.start(47801)) {
38 FL_WARN("✗ FAILED: Could not start server");
39 FL_WARN("Error: " << server.last_error());
40 return 1;
41 }
42
43 FL_WARN("✓ Server started on port 47801");
44
45 // Give server a moment to bind
46 fl::delay(100);
47
48 int passed = 0;
49 int failed = 0;
50
51 // Test 1: GET /
52 {
53 FL_WARN("\nTest 1: GET /");
54 server.update(); // Process any pending
55
56 fl::task::Promise<fl::net::http::Response> promise = fl::net::http::fetch_get("http://localhost:47801/");
57 fl::task::PromiseResult<fl::net::http::Response> result = fl::task::await_top_level(promise);
58
59 if (!result.ok()) {
60 FL_WARN(" ✗ FAILED: " << result.error_message());
61 failed++;
62 } else {
63 const fl::net::http::Response& response = result.value();
64 if (response.status() != 200) {
65 FL_WARN(" ✗ FAILED: Status code " << response.status());
66 failed++;
67 } else if (response.text() != "Hello from loopback!\n") {
68 FL_WARN(" ✗ FAILED: Unexpected response: " << response.text());
69 failed++;
70 } else {

Callers

nothing calls this directly

Calls 15

fetch_getFunction · 0.85
await_top_levelFunction · 0.85
last_errorMethod · 0.80
statusMethod · 0.80
is_jsonMethod · 0.80
delayFunction · 0.50
getMethod · 0.45
setMethod · 0.45
jsonMethod · 0.45
startMethod · 0.45
updateMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected