DC004 body: rapid create/destroy cycles.
| 179 | |
| 180 | // DC004 body: rapid create/destroy cycles. |
| 181 | static void runDC004() { |
| 182 | auto* engine = ::agenui::getAGenUIEngine(); |
| 183 | if (!engine) _exit(1); |
| 184 | |
| 185 | // Rapid cycles — intentionally skip WaitForWorkerIdle to let |
| 186 | // worker-thread tasks pile up. No listener in the loop because the |
| 187 | // SM is destroyed without draining; a stack-local listener would be |
| 188 | // use-after-scope by the time the worker thread dispatches callbacks. |
| 189 | for (int i = 0; i < 10; ++i) { |
| 190 | auto* sm = engine->createSurfaceManager(); |
| 191 | if (!sm) _exit(2); |
| 192 | |
| 193 | sm->beginTextStream(); |
| 194 | sm->receiveTextChunk( |
| 195 | createSurfaceJson("dc004-" + std::to_string(i))); |
| 196 | sm->endTextStream(); |
| 197 | |
| 198 | engine->destroySurfaceManager(sm); |
| 199 | // No drain — tasks accumulate on worker thread |
| 200 | } |
| 201 | |
| 202 | // Drain all accumulated tasks |
| 203 | ::agenui::testing::WaitForWorkerIdle(5000); |
| 204 | |
| 205 | // Final SM — proves engine is still fully operational after churn |
| 206 | auto* smFinal = engine->createSurfaceManager(); |
| 207 | if (!smFinal) _exit(3); |
| 208 | ::agenui::testing::WaitForWorkerIdle(); |
| 209 | |
| 210 | ::agenui::testing::MockMessageListener listenerFinal; |
| 211 | smFinal->addSurfaceEventListener(&listenerFinal); |
| 212 | |
| 213 | smFinal->beginTextStream(); |
| 214 | smFinal->receiveTextChunk(createSurfaceJson("dc004-final")); |
| 215 | smFinal->endTextStream(); |
| 216 | ::agenui::testing::WaitForWorkerIdle(); |
| 217 | |
| 218 | smFinal->removeSurfaceEventListener(&listenerFinal); |
| 219 | engine->destroySurfaceManager(smFinal); |
| 220 | |
| 221 | // No drain — engine->stop() drains the worker thread itself. |
| 222 | ::agenui::destroyAGenUIEngine(); |
| 223 | |
| 224 | _exit(0); |
| 225 | } |
| 226 | |
| 227 | // --------------------------------------------------------------------------- |
| 228 | // Test suite — "DeathTest" suffix makes GTest default to threadsafe style. |
no test coverage detected