| 60 | } |
| 61 | |
| 62 | void update() { |
| 63 | // State machine advances through RUNNING -> WAITING -> RUNNING transitions |
| 64 | // Callbacks (in runTest) handle WAITING -> RUNNING_NEXT transitions |
| 65 | switch (state) { |
| 66 | case RUNNING_GET_ROOT: |
| 67 | runTest("GET /", "http://localhost:8080/", |
| 68 | "Hello from loopback test!\n", RUNNING_GET_PING); |
| 69 | break; |
| 70 | |
| 71 | case RUNNING_GET_PING: |
| 72 | runTest("GET /ping", "http://localhost:8080/ping", |
| 73 | "pong\n", RUNNING_GET_TEST); |
| 74 | break; |
| 75 | |
| 76 | case RUNNING_GET_TEST: |
| 77 | runTest("GET /test", "http://localhost:8080/test", |
| 78 | "test response\n", COMPLETED); |
| 79 | break; |
| 80 | |
| 81 | case COMPLETED: |
| 82 | if (!callback_invoked && completion_callback) { |
| 83 | // Print summary |
| 84 | Serial.println(); |
| 85 | Serial.println("======================"); |
| 86 | Serial.print("Test Results: "); |
| 87 | Serial.print(tests_passed); |
| 88 | Serial.print("/"); |
| 89 | Serial.print(tests_run); |
| 90 | Serial.println(" passed"); |
| 91 | Serial.println("======================"); |
| 92 | |
| 93 | bool success = !has_failure && tests_passed == tests_run; |
| 94 | if (success) { |
| 95 | Serial.println("✓ All loopback tests PASSED"); |
| 96 | } else { |
| 97 | Serial.println("✗ Loopback tests FAILED"); |
| 98 | } |
| 99 | |
| 100 | // Invoke user callback with results |
| 101 | completion_callback(success, tests_passed, tests_run); |
| 102 | callback_invoked = true; |
| 103 | } |
| 104 | state = IDLE; |
| 105 | break; |
| 106 | |
| 107 | default: |
| 108 | // WAITING states or IDLE - nothing to do |
| 109 | break; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | bool isRunning() const { |
| 114 | return state != IDLE && state != COMPLETED; |
no test coverage detected