UFO: Alien Invasion
Toggle main menu visibility
Loading...
Searching...
No Matches
test_ui.cpp
Go to the documentation of this file.
1
5
6
/*
7
Copyright (C) 2002-2025 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/ui/ui_nodes.h
"
28
#include "
../client/ui/ui_timer.h
"
29
30
class
UITest
:
public
::testing::Test {
31
protected
:
32
static
void
SetUpTestCase
() {
33
TEST_Init
();
34
}
35
36
static
void
TearDownTestCase
() {
37
TEST_Shutdown
();
38
}
39
};
40
45
TEST_F
(
UITest
, TimerDataStructure)
46
{
47
uiNode_t
* dummyNode = (
uiNode_t
*) 0x1;
48
timerCallback_t
dummyCallback = (
timerCallback_t
) 0x1;
49
50
uiTimer_t
* a, *b, *c;
51
a =
UI_AllocTimer
(dummyNode, 10, dummyCallback);
52
b =
UI_AllocTimer
(dummyNode, 20, dummyCallback);
53
c =
UI_AllocTimer
(dummyNode, 30, dummyCallback);
54
ASSERT_TRUE(UI_PrivateGetFirstTimer() ==
nullptr
);
55
56
UI_TimerStart
(b);
57
ASSERT_TRUE(UI_PrivateGetFirstTimer() == b);
58
59
UI_TimerStart
(a);
60
ASSERT_TRUE(UI_PrivateGetFirstTimer() == a);
61
62
UI_TimerStart
(c);
63
ASSERT_TRUE(UI_PrivateGetFirstTimer()->next->next == c);
64
65
UI_TimerStop
(a);
66
UI_TimerStop
(b);
67
ASSERT_TRUE(a->
owner
!=
nullptr
);
68
ASSERT_TRUE(UI_PrivateGetFirstTimer() == c);
69
ASSERT_TRUE(UI_PrivateGetFirstTimer()->next ==
nullptr
);
70
71
UI_TimerStart
(a);
72
ASSERT_TRUE(UI_PrivateGetFirstTimer() == a);
73
ASSERT_TRUE(UI_PrivateGetFirstTimer()->next == c);
74
75
UI_PrivateInsertTimerInActiveList(a->
next
, b);
76
ASSERT_TRUE(UI_PrivateGetFirstTimer() == a);
77
ASSERT_TRUE(UI_PrivateGetFirstTimer()->next == b);
78
ASSERT_TRUE(UI_PrivateGetFirstTimer()->next->next == c);
79
80
UI_TimerRelease
(b);
81
ASSERT_TRUE(UI_PrivateGetFirstTimer() == a);
82
ASSERT_TRUE(UI_PrivateGetFirstTimer()->next == c);
83
84
UI_TimerRelease
(a);
85
ASSERT_TRUE(UI_PrivateGetFirstTimer() == c);
86
87
UI_TimerRelease
(c);
88
ASSERT_TRUE(UI_PrivateGetFirstTimer() ==
nullptr
);
89
ASSERT_TRUE(c->
owner
==
nullptr
);
90
}
UITest
Definition
test_ui.cpp:30
UITest::TearDownTestCase
static void TearDownTestCase()
Definition
test_ui.cpp:36
UITest::SetUpTestCase
static void SetUpTestCase()
Definition
test_ui.cpp:32
uiNode_t
Atomic structure used to define most of the UI.
Definition
ui_nodes.h:80
uiTimer_t
Definition
ui_timer.h:36
uiTimer_t::owner
uiNode_t * owner
Definition
ui_timer.h:41
uiTimer_t::next
struct uiTimer_s * next
Definition
ui_timer.h:37
TEST_Shutdown
void TEST_Shutdown(void)
Definition
test_shared.cpp:34
TEST_Init
void TEST_Init(void)
Definition
test_shared.cpp:72
test_shared.h
TEST_F
TEST_F(UITest, TimerDataStructure)
unittest around timer data structure. It not test timer execution.
Definition
test_ui.cpp:45
ui_nodes.h
UI_TimerStop
void UI_TimerStop(uiTimer_t *timer)
Stop a timer.
Definition
ui_timer.cpp:163
UI_AllocTimer
uiTimer_t * UI_AllocTimer(uiNode_t *node, int firstDelay, timerCallback_t callback)
Allocate a new time for a node.
Definition
ui_timer.cpp:123
UI_TimerStart
void UI_TimerStart(uiTimer_t *timer)
Restart a timer.
Definition
ui_timer.cpp:150
UI_TimerRelease
void UI_TimerRelease(uiTimer_t *timer)
Release the timer. It no more exists.
Definition
ui_timer.cpp:176
ui_timer.h
timerCallback_t
void(* timerCallback_t)(uiNode_t *node, struct uiTimer_s *timer)
Definition
ui_timer.h:31
src
tests
test_ui.cpp
Generated on __DATE__ __TIME__ for UFO: Alien Invasion by
1.17.0