1+ /*
2+ server/tests/test_rounds.qc
3+
4+ Unit tests related to rounds.
5+
6+ Copyright (C) 2021-2025 NZ:P Team
7+
8+ This program is free software; you can redistribute it and/or
9+ modify it under the terms of the GNU General Public License
10+ as published by the Free Software Foundation; either version 2
11+ of the License, or (at your option) any later version.
12+
13+ This program is distributed in the hope that it will be useful,
14+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16+
17+ See the GNU General Public License for more details.
18+
19+ You should have received a copy of the GNU General Public License
20+ along with this program; if not, write to:
21+
22+ Free Software Foundation, Inc.
23+ 59 Temple Place - Suite 330
24+ Boston, MA 02111-1307, USA
25+
26+ */
27+ float (float condition, string message) Test_Assert;
28+ void (string message) Test_Skip;
29+
30+ //
31+ // Test_Round_PlayerSpawnSetsRoundProperly()
32+ // Validate that PlayerSpawn() only sets the round when needed (at the game start).
33+ // This prevents the round resetting whenever a player joins the game.
34+ // (https://github.com/nzp-team/nzportable/issues/1185)
35+ //
36+ void () Test_Round_PlayerSpawnSetsRoundProperly =
37+ {
38+ float backup_round, backup_startround;
39+
40+ // Backup our rounds / start round, and then set them.
41+ backup_round = rounds;
42+ backup_startround = cvar("sv_startround" );
43+ rounds = 21 ;
44+ cvar_set("sv_startround" , "0" );
45+
46+ // Make sure that our rounds value is still 21.
47+ PlayerSpawn();
48+ Test_Assert(rounds == 21 , "Rounds value is being incorrectly reset!" );
49+
50+ // Make sure that a negative round value properly sets as well.
51+ rounds = -3 ;
52+ PlayerSpawn();
53+ Test_Assert(rounds == 0 , "Rounds value is not being correctly reset!" );
54+
55+ // Restore original values.
56+ rounds = backup_round;
57+ cvar_set("sv_startround" , ftos(backup_startround));
58+ };
0 commit comments