feat: implement safe leave, profile reset, and full game reset semantics
This commit is contained in:
@@ -104,10 +104,35 @@ static void test_bot_lifecycle_and_stale_actions(void) {
|
||||
assert(memcmp(&before, &lifecycle, sizeof(lifecycle)) == 0);
|
||||
}
|
||||
|
||||
static void test_leave_and_full_reset(void) {
|
||||
test_random_t random = {.value = 23U};
|
||||
game_lifecycle_t lifecycle = new_lifecycle(&random);
|
||||
uint8_t player_1 = 0;
|
||||
uint8_t player_2 = 0;
|
||||
uint8_t spectator = 0;
|
||||
join_players(&lifecycle, &player_1, &player_2);
|
||||
assert(game_lifecycle_join(&lifecycle, ROLE_SPECTATOR, "Watch", &spectator) == LIFECYCLE_RESULT_OK);
|
||||
const uint32_t lobby_game_id = lifecycle.game.state.game_id;
|
||||
assert(game_lifecycle_leave(&lifecycle, spectator) == LIFECYCLE_RESULT_OK);
|
||||
assert(!lifecycle.sessions.entries[spectator].occupied && lifecycle.game.state.game_id == lobby_game_id);
|
||||
assert(game_lifecycle_start(&lifecycle, player_1, lobby_game_id) == LIFECYCLE_RESULT_OK);
|
||||
assert(game_lifecycle_leave(&lifecycle, player_2) == LIFECYCLE_RESULT_OK);
|
||||
assert(!lifecycle.sessions.entries[player_2].occupied && lifecycle.sessions.entries[player_1].occupied);
|
||||
assert(lifecycle.game.state.phase == PHASE_LOBBY && lifecycle.game.state.game_id != lobby_game_id);
|
||||
const uint32_t reset_game_id = lifecycle.game.state.game_id;
|
||||
lifecycle.cumulative[0].games = 3U;
|
||||
assert(game_lifecycle_reset(&lifecycle, player_1, reset_game_id) == LIFECYCLE_RESULT_OK);
|
||||
assert(lifecycle.game.state.phase == PHASE_LOBBY && lifecycle.game.state.game_id != reset_game_id);
|
||||
assert(!lifecycle.sessions.entries[0].occupied && !lifecycle.sessions.entries[1].occupied);
|
||||
assert(lifecycle.cumulative[0].games == 0U && lifecycle.recovery_reason == RECOVERY_REASON_GAME_RESET);
|
||||
assert(game_lifecycle_reset(&lifecycle, player_1, reset_game_id) == LIFECYCLE_RESULT_FORBIDDEN_ROLE);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_capacity_sanitize_and_resume();
|
||||
test_human_lifecycle_and_guards();
|
||||
test_bot_lifecycle_and_stale_actions();
|
||||
test_leave_and_full_reset();
|
||||
puts("game lifecycle tests passed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user