UFO: Alien Invasion
Loading...
Searching...
No Matches
test_shared.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"
28#include "../client/cl_lua.h"
31#include <stdio.h>
32#include <stdarg.h>
33
34void TEST_Shutdown (void)
35{
38 SV_Shutdown("test shutdown", false);
43 developer = nullptr;
49
50 com_aliasSysPool = nullptr;
51 com_cmdSysPool = nullptr;
52 com_cmodelSysPool = nullptr;
53 com_cvarSysPool = nullptr;
54 com_fileSysPool = nullptr;
55 com_genericPool = nullptr;
56}
57
58void TEST_vPrintfSilent (const char* fmt, va_list argptr)
59{
60}
61
62void TEST_vPrintf (const char* fmt, va_list argptr)
63{
64 char text[1024];
65 Q_vsnprintf(text, sizeof(text), fmt, argptr);
66
67 fprintf(stderr, "%s", text);
68
69 fflush(stderr);
70}
71
72void TEST_Init (void)
73{
74 try {
75 com_aliasSysPool = Mem_CreatePool("Common: Alias system");
76 com_cmdSysPool = Mem_CreatePool("Common: Command system");
77 com_cmodelSysPool = Mem_CreatePool("Common: Collision model");
78 com_cvarSysPool = Mem_CreatePool("Common: Cvar system");
79 com_fileSysPool = Mem_CreatePool("Common: File system");
81
82 Mem_Init();
83 Cbuf_Init();
84 Cmd_Init();
85 Cvar_Init();
87 FS_AddGameDirectory("./unittest", false);
88 FS_AddHomeAsGameDirectory("unittest", true);
89 Swap_Init();
90 SV_Init();
91 NET_Init();
92
94
95 OBJZERO(csi);
96 } catch (comDrop_t const&) {
97 Sys_Error("Error during initialization");
98 }
99
100 http_timeout = Cvar_Get("noname");
101 http_proxy = Cvar_Get("noname");
102 hwclass = Cvar_Get("hwclass", "5");
103}
104
105
106#define PROPERTY_HASH_SIZE 32
107
108#define MAX_PROPERTY_NAME 32
109
110typedef struct test_property_s {
112 const char* value;
113 struct test_property_s* hash_next;
114 struct test_property_s* next;
116
119
125void TEST_RegisterProperty (const char* name, const char* value)
126{
127 unsigned int hash;
128 test_property_t* element;
129
130 /* if the alias already exists, reuse it */
132 for (element = test_property_hash[hash]; element; element = element->hash_next) {
133 if (Q_streq(name, element->name)) {
134 break;
135 }
136 }
137
138 if (!element) {
139 element = (test_property_t*) malloc(sizeof(*element));
140 Q_strncpyz(element->name, name, sizeof(element->name));
142 element->value = value;
143 element->next = test_property;
145 test_property_hash[hash] = element;
146 test_property = element;
147 Com_Printf("Register test property \"%s\" = \"%s\"\n", name, value);
148 }
149}
150
156static const test_property_t* TEST_GetProperty (const char* name)
157{
158 unsigned int hash;
159 const test_property_t* element;
160
162 for (element = test_property_hash[hash]; element; element = element->hash_next) {
163 if (!Q_strcasecmp(name, element->name)) {
164 return element;
165 }
166 }
167 return nullptr;
168}
169
175bool TEST_ExistsProperty (const char* name)
176{
177 return TEST_GetProperty(name) != nullptr;
178}
179
185const char* TEST_GetStringProperty (const char* name)
186{
187 const test_property_t* element = TEST_GetProperty(name);
188 if (element == nullptr) {
189 Com_Printf("WARNING: Test property \"%s\" not found. nullptr returned.\n", name);
190 return nullptr;
191 }
192 return element->value;
193}
194
200int TEST_GetIntProperty (const char* name)
201{
202 const test_property_t* element = TEST_GetProperty(name);
203 if (element == nullptr) {
204 Com_Printf("WARNING: Test property \"%s\" not found. 0 returned.\n", name);
205 return 0;
206 }
207 return atoi(element->value);
208}
209
215long TEST_GetLongProperty (const char* name)
216{
217 const test_property_t* element = TEST_GetProperty(name);
218 if (element == nullptr) {
219 Com_Printf("WARNING: Test property \"%s\" not found. 0 returned.\n", name);
220 return 0;
221 }
222 return atol(element->value);
223}
void Swap_Init(void)
Definition byte.cpp:31
void CL_ShutdownLua(void)
Shutdown the ui-lua interfacing environment.
Definition cl_lua.cpp:155
void PTL_InitStartup(void)
Clears particle data.
void Cbuf_Shutdown(void)
Definition cmd.cpp:117
void Cmd_Init(void)
Definition cmd.cpp:1127
void Cbuf_Init(void)
allocates an initial text buffer that will grow as needed
Definition cmd.cpp:109
void Cmd_Shutdown(void)
Definition cmd.cpp:1145
cvar_t * http_proxy
Definition common.cpp:47
memPool_t * com_cmdSysPool
Definition common.cpp:68
csi_t csi
Definition common.cpp:39
memPool_t * com_cvarSysPool
Definition common.cpp:70
cvar_t * hwclass
Definition common.cpp:62
cvar_t * http_timeout
Definition common.cpp:48
memPool_t * com_aliasSysPool
Definition common.cpp:67
cvar_t * developer
Definition common.cpp:46
void Com_Printf(const char *const fmt,...)
Definition common.cpp:428
memPool_t * com_genericPool
Definition common.cpp:72
memPool_t * com_cmodelSysPool
Definition common.cpp:69
memPool_t * com_fileSysPool
Definition common.cpp:71
void SV_Shutdown(const char *finalmsg, bool reconnect)
Called when each game quits, before Sys_Quit or Sys_Error.
Definition sv_main.cpp:1042
void SV_Init(void)
Only called once at startup, not for each game.
Definition sv_main.cpp:960
void Cvar_Shutdown(void)
Definition cvar.cpp:1100
void Cvar_Init(void)
Reads in all archived cvars.
Definition cvar.cpp:1087
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 FS_InitFilesystem(bool writeToHomeDir)
Definition files.cpp:890
void FS_AddHomeAsGameDirectory(const char *dir, bool write)
Definition files.cpp:655
void FS_Shutdown(void)
Cleanup function.
Definition files.cpp:1604
void FS_AddGameDirectory(const char *dir, bool write)
Adds the directory to the head of the search path.
Definition files.cpp:495
void FS_ExecAutoexec(void)
void Sys_Error(const char *error,...)
Definition g_main.cpp:421
void Mem_Init(void)
Definition mem.cpp:506
void Mem_Shutdown(void)
Definition mem.cpp:518
#define Mem_CreatePool(name)
Definition mem.h:32
void NET_Init(void)
Definition net.cpp:305
void NET_Shutdown(void)
Definition net.cpp:337
static wrapCache_t * hash[MAX_WRAP_HASH]
Definition r_font.cpp:86
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition r_gl.h:110
void R_ShutdownImages(void)
Definition r_image.cpp:796
void Com_Shutdown(void)
Definition scripts.cpp:3732
#define Q_strcasecmp(a, b)
Definition shared.h:131
#define Q_streq(a, b)
Definition shared.h:136
#define OBJZERO(obj)
Definition shared.h:178
unsigned int Com_HashKey(const char *name, int hashsize)
returns hash key for a string
Definition shared.cpp:336
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
Definition shared.cpp:457
int Q_vsnprintf(char *str, size_t size, const char *format, va_list ap)
Safe (null terminating) vsnprintf implementation.
Definition shared.cpp:535
char name[MAX_PROPERTY_NAME]
const char * value
struct test_property_s * hash_next
struct test_property_s * next
void TEST_RegisterProperty(const char *name, const char *value)
void TEST_Shutdown(void)
static const test_property_t * TEST_GetProperty(const char *name)
static test_property_t * test_property_hash[PROPERTY_HASH_SIZE]
#define MAX_PROPERTY_NAME
bool TEST_ExistsProperty(const char *name)
const char * TEST_GetStringProperty(const char *name)
void TEST_vPrintfSilent(const char *fmt, va_list argptr)
static test_property_t * test_property
void TEST_Init(void)
#define PROPERTY_HASH_SIZE
int TEST_GetIntProperty(const char *name)
long TEST_GetLongProperty(const char *name)
void TEST_vPrintf(const char *fmt, va_list argptr)
void UI_Shutdown(void)
Reset and free the UI data hunk.
Definition ui_main.cpp:205