UFO: Alien Invasion
Toggle main menu visibility
Loading...
Searching...
No Matches
test_all.cpp
Go to the documentation of this file.
1
4
5
/*
6
Copyright (C) 2002-2025 UFO: Alien Invasion.
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 the Free Software
21
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23
*/
24
25
#include "stdlib.h"
26
#include "stdio.h"
27
#include <gtest/gtest.h>
28
#include <SDL_main.h>
29
30
#include "
test_shared.h
"
31
32
void
Sys_Init
(
void
);
33
void
Sys_Init
(
void
)
34
{
35
}
36
37
typedef
struct
config_s {
38
bool
log
;
39
bool
verbose
;
40
}
config_t
;
41
42
static
const
char
*
resultPrefix
=
"ufoai"
;
43
static
config_t
config
;
44
static
FILE
*
logFile
;
45
46
static
void
Test_Parameters
(
const
int
argc,
char
** argv)
47
{
48
int
i
;
49
50
for
(
i
= 1;
i
< argc;
i
++) {
51
if
(
char
const
*
const
arg =
Q_strstart
(argv[
i
],
"-D"
)) {
52
if
(
char
const
*
const
value = strchr(arg,
'='
)) {
53
char
name
[32];
54
size_t
const
size
= value - arg + 1;
55
if
(
size
>=
sizeof
(
name
)) {
56
fprintf(stderr,
"Error: Argument \"%s\" use a property name too much big.\n"
, argv[
i
]);
57
exit(2);
58
}
59
Q_strncpyz
(
name
, arg,
size
);
60
TEST_RegisterProperty
(
name
, value + 1);
61
}
else
{
62
fprintf(stderr,
"Warning: \"%s\" do not value. Command line argument ignored.\n"
, argv[
i
]);
63
}
64
}
else
if
(
char
const
*
const
prefix =
Q_strstart
(argv[
i
],
"--output-prefix="
)) {
65
resultPrefix
= prefix;
66
}
else
if
(
Q_streq
(argv[
i
],
"--log"
)) {
67
config
.log =
true
;
68
}
else
if
(
Q_streq
(argv[
i
],
"-v"
) ||
Q_streq
(argv[
i
],
"--verbose"
)) {
69
config
.verbose =
true
;
70
}
else
if
(
Q_streq
(argv[
i
],
"-h"
) ||
Q_streq
(argv[
i
],
"--help"
)) {
71
printf(
"Usage:\n"
);
72
printf(
"-h --help | show this help screen\n"
);
73
printf(
"-v --verbose | be verbose\n"
);
74
printf(
"-Dprop=value | defines a test property\n"
);
75
printf(
" --log | log ufo output to file (testall.log in working dir)\n"
);
76
printf(
" --output-prefix=PREFIX | set a prefix for the xml result\n"
);
77
printf(
" | default value is \"ufoai\"\n"
);
78
exit(0);
79
}
else
{
80
fprintf(stderr,
"Error: Param \"%s\" unknown\n"
, argv[
i
]);
81
fprintf(stderr,
"Use \"%s -h\" to show the help screen\n"
, argv[0]);
82
exit(2);
83
}
84
}
85
}
86
87
static
void
TEST_vPrintfLog
(
const
char
* fmt, va_list ap)
88
{
89
if
(!
logFile
)
90
return
;
91
static
char
msg[2048];
92
Q_vsnprintf
(msg,
sizeof
(msg), fmt, ap);
93
94
fprintf(
logFile
,
"%s"
, msg);
95
fflush(
logFile
);
96
}
97
98
class
LocalEnv
:
public
::testing::Environment {
99
public
:
100
virtual
~LocalEnv
() {
101
}
102
virtual
void
SetUp
()
override
{
103
}
104
virtual
void
TearDown
()
override
{
105
}
106
};
107
113
extern
"C"
int
main
(
int
argc,
char
** argv)
114
{
115
Sys_InitSignals
();
116
117
::testing::AddGlobalTestEnvironment(
new
LocalEnv
);
118
//::testing::GTEST_FLAG(throw_on_failure) = true;
119
::testing::InitGoogleTest(&argc, argv);
120
121
Test_Parameters
(argc, argv);
122
123
if
(
config
.log) {
124
const
char
* path =
"testall.log"
;
125
logFile
=
Sys_Fopen
(path,
"wb"
);
126
Qcommon_SetPrintFunction
(
TEST_vPrintfLog
);
127
}
else
if
(
config
.verbose){
128
Qcommon_SetPrintFunction
(
TEST_vPrintf
);
129
}
else
{
130
Qcommon_SetPrintFunction
(
TEST_vPrintfSilent
);
131
}
132
133
try
{
134
try
{
135
return
RUN_ALL_TESTS();
136
}
catch
(
const
std::exception& e) {
137
std::cerr << e.what() << std::endl;
138
return
EXIT_FAILURE;
139
}
140
}
catch
(
comDrop_t
const
&) {
141
Sys_Error
(
"There was a Com_Error or Com_Drop call during the execution of this test"
);
142
}
143
144
if
(
logFile
)
145
fclose(
logFile
);
146
147
return
EXIT_SUCCESS;
148
}
LocalEnv
Definition
test_all.cpp:98
LocalEnv::SetUp
virtual void SetUp() override
Definition
test_all.cpp:102
LocalEnv::TearDown
virtual void TearDown() override
Definition
test_all.cpp:104
LocalEnv::~LocalEnv
virtual ~LocalEnv()
Definition
test_all.cpp:100
Qcommon_SetPrintFunction
void Qcommon_SetPrintFunction(vPrintfPtr_t func)
Definition
common.cpp:1078
Sys_Error
void Sys_Error(const char *error,...)
Definition
g_main.cpp:421
size
voidpf void uLong size
Definition
ioapi.h:42
i
QGL_EXTERN GLint i
Definition
r_gl.h:113
name
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition
r_gl.h:110
Q_streq
#define Q_streq(a, b)
Definition
shared.h:136
Q_strncpyz
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
Definition
shared.cpp:457
Q_vsnprintf
int Q_vsnprintf(char *str, size_t size, const char *format, va_list ap)
Safe (null terminating) vsnprintf implementation.
Definition
shared.cpp:535
Q_strstart
char const * Q_strstart(char const *str, char const *start)
Matches the start of a string.
Definition
shared.cpp:587
comDrop_t
Definition
common.h:245
config_t
Definition
test_all.cpp:37
config_t::log
bool log
Definition
test_all.cpp:38
config_t::verbose
bool verbose
Definition
test_all.cpp:39
Sys_Fopen
FILE * Sys_Fopen(const char *filename, const char *mode)
Definition
unix_files.cpp:240
Sys_InitSignals
void Sys_InitSignals(void)
Definition
unix_shared.cpp:182
config
static config_t config
Definition
test_all.cpp:43
main
int main(int argc, char **argv)
Definition
test_all.cpp:113
logFile
static FILE * logFile
Definition
test_all.cpp:44
Test_Parameters
static void Test_Parameters(const int argc, char **argv)
Definition
test_all.cpp:46
resultPrefix
static const char * resultPrefix
Definition
test_all.cpp:42
TEST_vPrintfLog
static void TEST_vPrintfLog(const char *fmt, va_list ap)
Definition
test_all.cpp:87
Sys_Init
void Sys_Init(void)
Definition
test_all.cpp:33
TEST_RegisterProperty
void TEST_RegisterProperty(const char *name, const char *value)
Definition
test_shared.cpp:125
TEST_vPrintfSilent
void TEST_vPrintfSilent(const char *fmt, va_list argptr)
Definition
test_shared.cpp:58
TEST_vPrintf
void TEST_vPrintf(const char *fmt, va_list argptr)
Definition
test_shared.cpp:62
test_shared.h
FILE
#define FILE
Definition
test_webapi.cpp:30
src
tests
test_all.cpp
Generated on __DATE__ __TIME__ for UFO: Alien Invasion by
1.17.0