Files
lilygo-t-deck/emulator/tests/integration_tests.h
T

123 lines
4.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[7].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[7].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"));
}