UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
test_mapdef.cpp
Go to the documentation of this file.
1 
6 /*
7 Copyright (C) 2002-2020 UFO: Alien Invasion.
8 
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 
18 See the GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, 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"
30 #include "../client/renderer/r_state.h"
31 #include "../client/ui/ui_main.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 
38 class MapDefTest: public ::testing::Test {
39 protected:
40  static void SetUpTestCase() {
41  TEST_Init();
42 
43  sv_genericPool = Mem_CreatePool("mapdef-test");
44  com_networkPool = Mem_CreatePool("Network");
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 
54  R_FontInit();
55  CL_InitLua();
56  UI_Init();
57 
58  OBJZERO(cls);
59  Com_ParseScripts(false);
60  }
61 
62  static void TearDownTestCase() {
63  TEST_Shutdown();
64  NET_Shutdown();
65  }
66 };
67 
72 TEST_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 
111 TEST_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 }
static void SetUpTestCase()
Definition: test_mapdef.cpp:40
void UI_Init(void)
Definition: ui_main.cpp:278
void NET_Shutdown(void)
Definition: net.cpp:337
char * id
Definition: q_shared.h:463
int numMDs
Definition: q_shared.h:572
#define PLAYER_NUM(n)
Definition: server.h:137
Definition: game.h:45
csi_t csi
Definition: common.cpp:39
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 Com_ParseScripts(bool onlyServer)
Definition: scripts.cpp:3641
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
void Com_Printf(const char *const fmt,...)
Definition: common.cpp:386
linkedList_t * gameTypes
Definition: q_shared.h:476
gltexunit_t texunits[MAX_GL_TEXUNITS]
Definition: r_state.h:114
cvar_t * masterserver_url
Definition: common.cpp:57
memPool_t * cl_genericPool
Definition: cl_main.cpp:86
client_static_t cls
Definition: cl_main.cpp:83
#define MAX_INFO_STRING
Definition: infostring.h:36
gltexunit_t * active_texunit
Definition: r_state.h:117
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
#define OBJZERO(obj)
Definition: shared.h:178
#define MapDef_ForeachCondition(var, condition)
Definition: q_shared.h:501
void TEST_Shutdown(void)
Definition: test_shared.cpp:34
void CL_InitLua(void)
Initializes the ui-lua interfacing environment.
Definition: cl_lua.cpp:126
bool multiplayer
Definition: q_shared.h:474
static void TearDownTestCase()
Definition: test_mapdef.cpp:62
#define Mem_CreatePool(name)
Definition: mem.h:32
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
char * mapTheme
Definition: q_shared.h:464
void Info_SetValueForKey(char *s, const size_t size, const char *key, const char *value)
Adds a new entry into string with given value.
Definition: infostring.cpp:169
bool TEST_ExistsProperty(const char *name)
long TEST_GetLongProperty(const char *name)
memPool_t * com_networkPool
Definition: common.cpp:74
cvar_t * sv_public
Definition: sv_main.cpp:52
const char * TEST_GetStringProperty(const char *name)
void TEST_Init(void)
Definition: test_shared.cpp:72
cvar_t * port
Definition: common.cpp:58
#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
memPool_t * vid_imagePool
Definition: cl_main.cpp:88
rstate_t r_state
Definition: r_main.cpp:48
#define MapDef_Foreach(var)
Definition: q_shared.h:505
cvar_t * Cvar_Set(const char *varName, const char *value,...)
Sets a cvar value.
Definition: cvar.cpp:615
#define Q_streq(a, b)
Definition: shared.h:136
bool LIST_IsEmpty(const linkedList_t *list)
Checks whether the given list is empty.
Definition: list.cpp:335
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:703
cvar_t * sv_dumpmapassembly
Definition: sv_main.cpp:47
serverInstanceStatic_t svs
Definition: sv_init.cpp:35
TEST_F(MapDefTest, MapDefsSingleplayer)
This test cycles through the list of map definitions found in the maps.ufo script and tries to load (...
Definition: test_mapdef.cpp:72
void R_FontInit(void)
Definition: r_font.cpp:722
linkedList_t * params
Definition: q_shared.h:465
game_export_t * ge
Definition: server.h:92