UFO: Alien Invasion
Loading...
Searching...
No Matches
test_mapdef.cpp
Go to the documentation of this file.
1
5
6/*
7Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24*/
25
26#include "test_shared.h"
27#include "../client/client.h"
28#include "../client/cl_shared.h"
29#include "../client/cl_lua.h"
32#include "../common/routing.h"
33#include "../server/server.h"
34#include "../server/sv_rma.h"
35
36#define RMA_HIGHEST_SUPPORTED_SEED 50
37
38class MapDefTest: public ::testing::Test {
39protected:
40 static void SetUpTestCase() {
41 TEST_Init();
42
43 sv_genericPool = Mem_CreatePool("mapdef-test");
45 vid_imagePool = Mem_CreatePool("Vid: Image system");
46 sv_dumpmapassembly = Cvar_Get("sv_dumpassembly", "0");
47 sv_public = Cvar_Get("sv_public", "0");
48 port = Cvar_Get("testport", "27909");
49 masterserver_url = Cvar_Get("masterserver_test", "http://localhost");
50
51 cl_genericPool = Mem_CreatePool("Client: Generic");
52
53 r_state.active_texunit = &r_state.texunits[0];
54 R_FontInit();
55 CL_InitLua();
56 UI_Init();
57
58 OBJZERO(cls);
59 Com_ParseScripts(false);
60 }
61
62 static void TearDownTestCase() {
65 }
66};
67
72TEST_F(MapDefTest, MapDefsSingleplayer)
73{
74 const char* filterId = TEST_GetStringProperty("mapdef-id");
75 const mapDef_t* md;
76
77 ASSERT_TRUE(csi.numMDs > 0);
78
79 MapDef_Foreach(md) {
80 if (md->mapTheme[0] == '.')
81 continue;
82 if (filterId && !Q_streq(filterId, md->id))
83 continue;
84
85 /* use a known seed to reproduce an error */
86 unsigned int seed;
87 if (TEST_ExistsProperty("mapdef-seed")) {
88 seed = TEST_GetLongProperty("mapdef-seed");
89 } else {
90 seed = (unsigned int) time(nullptr);
91 }
92 srand(seed);
93
94 Com_Printf("testMapDefsSingleplayer: Mapdef %s (seed %u)\n", md->id, seed);
95 if (LIST_IsEmpty(md->params)) {
96 std::cout << "[ ] testing mapdef: " << md->id << std::endl;
97 SV_Map(true, md->mapTheme, nullptr);
99 } else {
100 LIST_Foreach(md->params, const char, param) {
101 Com_Printf("testMapDefsSingleplayer: Mapdef %s (param %s)\n", md->id, param);
102 std::cout << "[ ] testing mapdef: " << md->id << ", assembly: "
103 << param << std::endl;
104 SV_Map(true, md->mapTheme, param);
106 }
107 }
108 }
109}
110
111TEST_F(MapDefTest, MapDefsMultiplayer)
112{
113 const char* filterId = TEST_GetStringProperty("mapdef-id");
114 char userinfo[MAX_INFO_STRING];
115 const mapDef_t* md;
116
117 ASSERT_TRUE(csi.numMDs > 0);
118
119 Cvar_Set("sv_maxclients", "2");
120
122 unsigned int seed;
123
124 if (filterId && !Q_streq(filterId, md->id))
125 continue;
126
127 /* @todo remove hardcoded gametype id here */
128 if (!LIST_ContainsString(md->gameTypes, "fight"))
129 Cvar_Set("sv_teamplay", "1");
130
131 /* use a known seed to reproduce an error */
132 if (TEST_ExistsProperty("mapdef-seed")) {
133 seed = TEST_GetLongProperty("mapdef-seed");
134 } else {
135 seed = (unsigned int) time(nullptr);
136 }
137 srand(seed);
138
139 Com_Printf("testMapDefsMultiplayer: Mapdef %s (seed %u)\n", md->id, seed);
140 if (LIST_IsEmpty(md->params)) {
141 std::cout << "[ ] testing mapdef: " << md->id << std::endl;
142 SV_Map(true, md->mapTheme, nullptr);
143
144 SrvPlayer* player = PLAYER_NUM(0);
145 Info_SetValueForKey(userinfo, sizeof(userinfo), "cl_teamnum", "-1");
146 ASSERT_TRUE(svs.ge->ClientConnect(player, userinfo, sizeof(userinfo)));
147
149 } else {
150 LIST_Foreach(md->params, const char, param) {
151 Com_Printf("testMapDefsMultiplayer: Mapdef %s (param %s)\n", md->id, param);
152 SV_Map(true, md->mapTheme, param);
153 std::cout << "[ ] testing mapdef: " << md->id << ", assembly: "
154 << param << std::endl;
155 SrvPlayer* player = PLAYER_NUM(0);
156 Info_SetValueForKey(userinfo, sizeof(userinfo), "cl_teamnum", "-1");
157 ASSERT_TRUE(svs.ge->ClientConnect(player, userinfo, sizeof(userinfo)));
158
160 }
161 }
162 }
163}
void CL_InitLua(void)
Initializes the ui-lua interfacing environment.
Definition cl_lua.cpp:130
memPool_t * vid_imagePool
Definition cl_main.cpp:88
client_static_t cls
Definition cl_main.cpp:83
memPool_t * cl_genericPool
Definition cl_main.cpp:86
void R_FontInit(void)
Definition r_font.cpp:716
Share stuff between the different cgame implementations.
static void SetUpTestCase()
static void TearDownTestCase()
Primary header for client.
csi_t csi
Definition common.cpp:39
cvar_t * port
Definition common.cpp:58
void Com_Printf(const char *const fmt,...)
Definition common.cpp:428
memPool_t * com_networkPool
Definition common.cpp:73
cvar_t * masterserver_url
Definition common.cpp:57
cvar_t * Cvar_Set(const char *varName, const char *value,...)
Sets a cvar value.
Definition cvar.cpp:615
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags, const char *desc)
Init or return a cvar.
Definition cvar.cpp:342
void Info_SetValueForKey(char *s, const size_t size, const char *key, const char *value)
Adds a new entry into string with given value.
#define MAX_INFO_STRING
Definition infostring.h:36
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
bool LIST_IsEmpty(const linkedList_t *list)
Checks whether the given list is empty.
Definition list.cpp:335
const linkedList_t * LIST_ContainsString(const linkedList_t *list, const char *string)
Searches for the first occurrence of a given string.
Definition list.cpp:73
#define LIST_Foreach(list, type, var)
Iterates over a linked list, it's safe to delete the returned entry from the list while looping over ...
Definition list.h:41
#define Mem_CreatePool(name)
Definition mem.h:32
void NET_Shutdown(void)
Definition net.cpp:337
#define MapDef_ForeachCondition(var, condition)
Definition q_shared.h:501
#define MapDef_Foreach(var)
Definition q_shared.h:505
rstate_t r_state
Definition r_main.cpp:48
grid pathfinding and routing
void Com_ParseScripts(bool onlyServer)
Definition scripts.cpp:3619
Main server include file.
memPool_t * sv_genericPool
Definition sv_main.cpp:55
void SV_Map(bool day, const char *levelstring, const char *assembly, bool verbose=true)
Change the server to a new map, taking all connected clients along with it.
Definition sv_init.cpp:113
void SV_ShutdownGameProgs(void)
Called when either the entire server is being killed, or it is changing to a different game directory...
Definition sv_game.cpp:681
#define PLAYER_NUM(n)
Definition server.h:137
serverInstanceStatic_t svs
Definition sv_init.cpp:35
cvar_t * sv_public
Definition sv_main.cpp:52
cvar_t * sv_dumpmapassembly
Definition sv_main.cpp:47
#define Q_streq(a, b)
Definition shared.h:136
#define OBJZERO(obj)
Definition shared.h:178
linkedList_t * gameTypes
Definition q_shared.h:476
char * mapTheme
Definition q_shared.h:464
char * id
Definition q_shared.h:463
linkedList_t * params
Definition q_shared.h:465
bool multiplayer
Definition q_shared.h:474
TEST_F(MapDefTest, MapDefsSingleplayer)
This test cycles through the list of map definitions found in the maps.ufo script and tries to load (...
void TEST_Shutdown(void)
bool TEST_ExistsProperty(const char *name)
const char * TEST_GetStringProperty(const char *name)
void TEST_Init(void)
long TEST_GetLongProperty(const char *name)
void UI_Init(void)
Definition ui_main.cpp:278