UFO: Alien Invasion
Loading...
Searching...
No Matches
test_ui_level2.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/cl_video.h" /* vid_imagePool */
28#include "../client/cl_lua.h"
30#include "../client/renderer/r_state.h" /* r_state */
31
32class UILevel2Test: public ::testing::Test {
33protected:
34 static void SetUpTestCase() {
35 TEST_Init();
36 CL_InitLua();
37 UI_Init();
38
39 vid_imagePool = Mem_CreatePool("Vid: Image system");
40
41 r_state.active_texunit = &texunit_diffuse;
42 }
43
44 static void TearDownTestCase() {
47 }
48};
49
51static void TEST_ParseScript (const char* scriptName)
52{
53 const char* type, *name, *text;
54 int nbWrongScripts = 0;
55
56 /* parse ui node script */
57 Com_Printf("Load \"%s\": %i script file(s)\n", scriptName, FS_BuildFileList(scriptName));
58 FS_NextScriptHeader(nullptr, nullptr, nullptr);
59 text = nullptr;
60 while ((type = FS_NextScriptHeader(scriptName, &name, &text)) != nullptr) {
61 try {
63 } catch (const comDrop_t& e) {
64 ASSERT_TRUE(false) << "Failed to parse needed scripts for type: " << type << " and id " << name;
65 nbWrongScripts++;
66 }
67 }
68 ASSERT_TRUE(nbWrongScripts == 0);
69}
70
76static void UFO_AnalyseTestWindow (const char* windowName)
77{
78 const uiBehaviour_t* stringBehaviour = UI_GetNodeBehaviour("string");
79 const uiNode_t* node;
80 const uiNode_t* window = UI_GetWindow(windowName);
81 ASSERT_TRUE(window != nullptr);
82 ASSERT_TRUE(stringBehaviour != nullptr);
83
84 for (node = window->firstChild; node != nullptr; node = node->next) {
85 bool isGreen;
86 bool isRed;
87 /* skip non "string" nodes */
88 if (node->behaviour != stringBehaviour)
89 continue;
90 if (node->invis)
91 continue;
92 /* skip nodes without "test" prefix */
93 if (!Q_strstart(node->name, "test"))
94 continue;
95
96 isGreen = node->color[0] < 0.1 && node->color[1] > 0.9 && node->color[2] < 0.1;
97 isRed = node->color[0] > 0.9 && node->color[1] < 0.1 && node->color[2] < 0.1;
98
99 if (isGreen) {
101 ASSERT_TRUE(true);
102 } else if (isRed) {
103 const char* message = va("%s.%s failed.", windowName, node->name);
104 ASSERT_TRUE(false) << message << " base/ufos/uitest/" << windowName << ".ufo";
105 } else {
106 const char* message = va("%s.%s have an unknown status.", windowName, node->name);
107 ASSERT_TRUE(false) << message << " base/ufos/uitest/" << windowName << ".ufo";
108 }
109 }
110}
111
115static void UFO_ExecuteTestWindow (const char* windowName)
116{
117 /* look and feed */
118 Com_Printf("\n");
119
120 TEST_ParseScript(va("ufos/uitest/%s.ufo", windowName));
121
122 Cmd_ExecuteString("ui_push %s", windowName);
123
124 /* while the execution buffer is not empty */
125 for (int i = 0; i < 20; i++) {
126 Cbuf_Execute();
127 }
128
129 UFO_AnalyseTestWindow(windowName);
130
131 /* look and feed */
132 Com_Printf(" ---> ");
133}
134
138TEST_F(UILevel2Test, KnownBehaviours)
139{
140 uiBehaviour_t* behaviour;
141
142 behaviour = UI_GetNodeBehaviour("button");
143 ASSERT_TRUE(behaviour != nullptr);
144 ASSERT_STREQ(behaviour->name, "button");
145
146 /* first one */
147 behaviour = UI_GetNodeBehaviour("");
148 ASSERT_TRUE(behaviour != nullptr);
149
150 /* last one */
151 behaviour = UI_GetNodeBehaviour("zone");
152 ASSERT_TRUE(behaviour != nullptr);
153 ASSERT_STREQ(behaviour->name, "zone");
154
155 /* unknown */
156 behaviour = UI_GetNodeBehaviour("dahu");
157 ASSERT_TRUE(behaviour == nullptr);
158}
159
164{
165 UFO_ExecuteTestWindow("test_action");
166}
167
172{
173 UFO_ExecuteTestWindow("test_action2");
174}
175
180{
181 UFO_ExecuteTestWindow("test_condition");
182}
183
188{
189 UFO_ExecuteTestWindow("test_function");
190}
191
196{
197 UFO_ExecuteTestWindow("test_setter");
198}
199
204{
205 UFO_ExecuteTestWindow("test_cvar");
206}
207
212{
213 UFO_ExecuteTestWindow("test_component");
214}
215
220TEST_F(UILevel2Test, InheritedConfunc)
221{
222 TEST_ParseScript("ufos/uitest/_test_inheritedconfunc.ufo");
223 TEST_ParseScript("ufos/uitest/_test_inheritedconfunc_lua.ufo");
224 UFO_ExecuteTestWindow("test_inheritedconfunc");
225 UFO_ExecuteTestWindow("test_inheritedconfunc_lua");
226}
227
233TEST_F(UILevel2Test, RuntimeError)
234{
235 UFO_ExecuteTestWindow("test_runtimeerror");
236}
237
243{
244 UFO_ExecuteTestWindow("test_video");
245}
246
252{
253 UFO_ExecuteTestWindow("test_cvarlistener");
254}
255
261{
262 //UFO_ExecuteTestWindow("test_keybinding");
263}
264
269{
270 TEST_ParseScript("ufos/uisample/*.ufo");
271}
void CL_InitLua(void)
Initializes the ui-lua interfacing environment.
Definition cl_lua.cpp:130
bool CL_ParseClientData(const char *type, const char *name, const char **text)
Called at client startup.
Definition cl_main.cpp:770
memPool_t * vid_imagePool
Definition cl_main.cpp:88
Video driver defs.
Listener for cvar changes.
Definition cvar.h:98
static void SetUpTestCase()
static void TearDownTestCase()
void Cmd_ExecuteString(const char *text,...)
A complete command line has been parsed, so try to execute it.
Definition cmd.cpp:1007
void Cbuf_Execute(void)
Pulls off terminated lines of text from the command buffer and sends them through Cmd_ExecuteString...
Definition cmd.cpp:214
void Com_Printf(const char *const fmt,...)
Definition common.cpp:428
char * FS_NextScriptHeader(const char *files, const char **name, const char **text)
Definition files.cpp:1196
int FS_BuildFileList(const char *fileList)
Build a filelist.
Definition files.cpp:962
#define Mem_CreatePool(name)
Definition mem.h:32
QGL_EXTERN GLint i
Definition r_gl.h:113
QGL_EXTERN GLint GLenum type
Definition r_gl.h:94
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition r_gl.h:110
rstate_t r_state
Definition r_main.cpp:48
#define texunit_diffuse
Definition r_state.h:68
char const * Q_strstart(char const *str, char const *start)
Matches the start of a string.
Definition shared.cpp:587
const char * va(const char *format,...)
does a varargs printf into a temp buffer, so I don't need to have varargs versions of all text functi...
Definition shared.cpp:410
node behaviour, how a node work
const char * name
Atomic structure used to define most of the UI.
Definition ui_nodes.h:80
uiNode_t * firstChild
Definition ui_nodes.h:89
bool invis
Definition ui_nodes.h:101
uiNode_t * next
Definition ui_nodes.h:91
vec4_t color
Definition ui_nodes.h:127
uiBehaviour_t * behaviour
Definition ui_nodes.h:83
char name[MAX_VAR]
Definition ui_nodes.h:82
void TEST_Shutdown(void)
void TEST_Init(void)
static void UFO_ExecuteTestWindow(const char *windowName)
Parse and execute a test windows.
static void UFO_AnalyseTestWindow(const char *windowName)
after execution of a unittest window, it analyse color of normalized indicator, and create asserts....
static void TEST_ParseScript(const char *scriptName)
TEST_F(UILevel2Test, KnownBehaviours)
test behaviour name
Internal data use by the UI package.
void UI_Shutdown(void)
Reset and free the UI data hunk.
Definition ui_main.cpp:205
void UI_Init(void)
Definition ui_main.cpp:278
uiBehaviour_t * UI_GetNodeBehaviour(const char *name)
Return a node behaviour by name.
Definition ui_nodes.cpp:559
uiNode_t * UI_GetWindow(const char *name)
Searches all windows for the specified one.