UFO: Alien Invasion
Loading...
Searching...
No Matches
test_all.cpp
Go to the documentation of this file.
1
4
5/*
6Copyright (C) 2002-2025 UFO: Alien Invasion.
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17See the GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, 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
32void Sys_Init(void);
33void Sys_Init (void)
34{
35}
36
37typedef struct config_s {
38 bool log;
39 bool verbose;
40} config_t;
41
42static const char* resultPrefix = "ufoai";
44static FILE* logFile;
45
46static 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
87static 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
98class LocalEnv: public ::testing::Environment {
99public:
100 virtual ~LocalEnv() {
101 }
102 virtual void SetUp() override {
103 }
104 virtual void TearDown() override {
105 }
106};
107
113extern "C" int main (int argc, char** argv)
114{
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");
127 } else if (config.verbose){
129 } else {
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}
virtual void SetUp() override
Definition test_all.cpp:102
virtual void TearDown() override
Definition test_all.cpp:104
virtual ~LocalEnv()
Definition test_all.cpp:100
void Qcommon_SetPrintFunction(vPrintfPtr_t func)
Definition common.cpp:1078
void Sys_Error(const char *error,...)
Definition g_main.cpp:421
voidpf void uLong size
Definition ioapi.h:42
QGL_EXTERN GLint i
Definition r_gl.h:113
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition r_gl.h:110
#define Q_streq(a, b)
Definition shared.h:136
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 const * Q_strstart(char const *str, char const *start)
Matches the start of a string.
Definition shared.cpp:587
bool log
Definition test_all.cpp:38
bool verbose
Definition test_all.cpp:39
FILE * Sys_Fopen(const char *filename, const char *mode)
void Sys_InitSignals(void)
static config_t config
Definition test_all.cpp:43
int main(int argc, char **argv)
Definition test_all.cpp:113
static FILE * logFile
Definition test_all.cpp:44
static void Test_Parameters(const int argc, char **argv)
Definition test_all.cpp:46
static const char * resultPrefix
Definition test_all.cpp:42
static void TEST_vPrintfLog(const char *fmt, va_list ap)
Definition test_all.cpp:87
void Sys_Init(void)
Definition test_all.cpp:33
void TEST_RegisterProperty(const char *name, const char *value)
void TEST_vPrintfSilent(const char *fmt, va_list argptr)
void TEST_vPrintf(const char *fmt, va_list argptr)
#define FILE