Files
Dejvino b38d5d4b56 Extract map-specific data into a generic MapSource interface
One interface (nd_mapsource.h) now owns everything map-specific: tiles,
rooms/doors/cameras, the network graph (nodes + edges with roles replacing
the hardcoded N_AIRLK/N_DOOR/N_HIVE indices) and the entity spawn list.
The scenario populates its structures once via selectMap() and never checks
which map is active.

- DemoMapSource: self-contained demo grid (moved out of the sketch), demo
  node/edge/spawn tables
- GenMapSource: adapts the random MapGenerator — now with L-corridors for
  guaranteed connectivity, doors that lead somewhere, airlock pad, terminal
  and crates (never on corridor tiles); network graph derived from the room
  chain, marine-first spawn list with droid patrols
- NetDeck.ino: all source branching removed; red trace follows the real
  active-link path (BFS HIVE->ROOT); reinforcement spawns near the blast door
- Tests: MapTest validates 50 generated runs + demo via the interface with
  an airlock flood-fill; new generated-map integration journey; test node
  handles resolve through the source (no hardcoded indices)
2026-11-15 18:21:35 +01:00

166 lines
6.6 KiB
C

/**
* @file integration_tests.h
* @brief Integration tests: several sketch subsystems cooperating —
* keyboard device -> pollKeyboard -> handleKey, cursor clicks ->
* registerClick -> beacon/node routing, sim ticks -> combat/objective
* flow. Still deterministic (fixed seed, direct tick stepping, no
* wall time, no rendering — pixels are the E2E layer's job).
*
* Included by test_main.cpp AFTER the sketch and unit_tests.h.
*/
#include "sim_helpers.h"
TEST(integration/keyboard_device_pipeline)
{
freshScenario();
test::resetInput();
test::typeKey('p'); // keyboard device @0x55
pollKeyboard(); // -> handleKey
EXPECT_EQ(viewMode, VM_NETWORK);
test::typeKey(' ');
pollKeyboard();
EXPECT(!paused); // freeze OFF
test::typeKey('p');
pollKeyboard();
EXPECT_EQ(viewMode, VM_CAMERAS);
test::typeKey('r');
pollKeyboard();
EXPECT(test::serialHas("[key] RESET"));
EXPECT(paused); // reset re-arms paused
}
TEST(integration/beacon_click_paths_the_squad)
{
freshScenario();
clickTile(20, 12); // corridor floor
EXPECT_EQ(beaconTX, 20);
EXPECT_EQ(beaconTY, 12);
EXPECT(test::serialHas("[click] beacon -> tile 20,12"));
stepTicks(200); // marines march + engage
bool progressed = units[0].tx >= 6 || !units[2].alive;
EXPECT(progressed); // moving and/or fighting
EXPECT(test::serialHas("[combat]")); // contact was made
for (const auto &t : tracers) EXPECT(t.ttl >= 0 && t.ttl <= 2);
}
TEST(integration/click_blocked_tile_keeps_beacon)
{
freshScenario();
clickTile(20, 12); // valid first
int bx = beaconTX, by = beaconTY;
clickTile(5, 0); // wall tile
EXPECT(test::serialHas("beacon ignored"));
EXPECT_EQ(beaconTX, bx); // unchanged
EXPECT_EQ(beaconTY, by);
}
TEST(integration/full_network_journey)
{
freshScenario();
handleKey('p'); // Network view
clickNode(N_JUNC); // route AIRLK-JUNC
stepTicks(LINK_TICKS);
EXPECT(nodeOnline[N_JUNC]);
clickNode(N_DOOR); // route JUNC-DOOR
stepTicks(LINK_TICKS);
EXPECT(nodeOnline[N_DOOR]);
EXPECT(!doorOpen);
clickNode(N_DOOR); // online DOOR toggles
EXPECT(doorOpen);
clickNode(N_HIVE); // 3 s ICE
stepTicks(ICE_TICKS);
EXPECT(hiveCracked);
EXPECT(traceActive);
stepTicks(TRACE_TICKS);
EXPECT(heatT > 0); // feedback spike cooldown
EXPECT(units[g_reinforceIdx].alive); // reinforcement spawned
EXPECT(!nodeOnline[N_JUNC]); // spike dropped the net
}
TEST(integration/sever_via_hovered_link)
{
freshScenario();
handleKey('p');
clickNode(N_JUNC);
stepTicks(LINK_TICKS);
EXPECT(nodeOnline[N_JUNC]);
// midpoint of the AIRLK(36,164)-JUNC(148,52) segment
curX = (nodePx(N_AIRLK) + nodePx(N_JUNC)) / 2;
curY = (nodePy(N_AIRLK) + nodePy(N_JUNC)) / 2;
EXPECT_EQ(hoverLink(), linkIdx(0));
handleKey('x');
EXPECT(test::serialHas("[net] severed AIRLK-JUNC"));
EXPECT(!nodeOnline[N_JUNC]);
}
TEST(integration/sever_during_trace_is_safe)
{
freshScenario();
handleKey('p');
clickNode(N_JUNC); stepTicks(LINK_TICKS);
clickNode(N_HIVE); stepTicks(ICE_TICKS);
EXPECT(traceActive); // trace running
curX = (nodePx(N_JUNC) + nodePx(N_HIVE)) / 2; // hover the ICE link
curY = (nodePy(N_JUNC) + nodePy(N_HIVE)) / 2;
handleKey('x'); // sever before arrival
EXPECT(!traceActive); // trace reset safely
EXPECT_EQ(heatT, 0); // no feedback spike
EXPECT(!units[g_reinforceIdx].alive); // no reinforcement
}
TEST(integration/daemon_gating_messages)
{
freshScenario();
handleKey('1'); // no HIVE link yet
EXPECT_EQ(strcmp(msgText, "NO HIVE LINK"), 0);
handleKey('p');
clickNode(N_JUNC); stepTicks(LINK_TICKS);
clickNode(N_HIVE); stepTicks(ICE_TICKS);
handleKey('1'); // HIVE online -> FRENZY.EXE activated
EXPECT_EQ(strcmp(msgText, "FRENZY ACTIVE"), 0); // FRENZY effect lands in M4
EXPECT(test::serialHas("[key] frenzy"));
}
TEST(integration/generated_map_source_journey)
{
// Switch to the random generator: the SAME scenario code (spawns, node
// roles, link routing, fog) must drive it with no map-source checks.
// The generator is seedless by design (random_device); assertions are
// therefore structural — layout invariants are fuzz-covered by
// src/netdeck/MapTest.cpp.
selectMap(false);
EXPECT(g_map == &g_genSource);
EXPECT(ROOT_NODE >= 0 && HIVE_NODE >= 0 && DOOR_NODE >= 0);
EXPECT(TERM_TX >= 0 && AIRLOCK_TX >= 0); // terminal + airlock found
EXPECT(g_map->spawnCount() >= 2);
EXPECT(g_map->spawnCount() < nd::MAX_UNITS); // reinforcement slot exists
resetScenario();
EXPECT(units[0].alive && units[1].alive); // marines come from the spawn list
EXPECT(nodeOnline[ROOT_NODE]); // root up after reset
EXPECT(!nodeOnline[HIVE_NODE]);
// route a link from the root to any adjacent offline node (source-agnostic)
// (the previous test may leave either view; make the mode explicit)
viewMode = VM_NETWORK;
int target = -1;
for (int e = 0; e < edgeCount() && target < 0; e++) {
int a = g_map->edge(e).a, b = g_map->edge(e).b;
if (a == ROOT_NODE && !nodeOnline[b]) target = b;
if (b == ROOT_NODE && !nodeOnline[a]) target = a;
}
EXPECT(target >= 0);
clickNode(target);
stepTicks(ICE_TICKS); // covers plain + ICE durations
EXPECT(nodeOnline[target]); // link built on a generated map
stepTicks(60); // combat/fog run a while: no crash
for (int i = 0; i < g_map->spawnCount(); i++)
EXPECT(units[i].alive || true); // slots exist (alive or KIA)
// back to the demo map — the other tests expect it
selectMap(true);
resetScenario();
EXPECT(nodeOnline[ROOT_NODE]);
EXPECT_EQ(nd::DEMO_MAP[7][34], 'T');
}