UFO: Alien Invasion
Loading...
Searching...
No Matches
test_ui.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"
29
30class UITest: public ::testing::Test {
31protected:
32 static void SetUpTestCase() {
33 TEST_Init();
34 }
35
36 static void TearDownTestCase() {
38 }
39};
40
45TEST_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
57 ASSERT_TRUE(UI_PrivateGetFirstTimer() == b);
58
60 ASSERT_TRUE(UI_PrivateGetFirstTimer() == a);
61
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
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
81 ASSERT_TRUE(UI_PrivateGetFirstTimer() == a);
82 ASSERT_TRUE(UI_PrivateGetFirstTimer()->next == c);
83
85 ASSERT_TRUE(UI_PrivateGetFirstTimer() == c);
86
88 ASSERT_TRUE(UI_PrivateGetFirstTimer() == nullptr);
89 ASSERT_TRUE(c->owner == nullptr);
90}
static void TearDownTestCase()
Definition test_ui.cpp:36
static void SetUpTestCase()
Definition test_ui.cpp:32
Atomic structure used to define most of the UI.
Definition ui_nodes.h:80
uiNode_t * owner
Definition ui_timer.h:41
struct uiTimer_s * next
Definition ui_timer.h:37
void TEST_Shutdown(void)
void TEST_Init(void)
TEST_F(UITest, TimerDataStructure)
unittest around timer data structure. It not test timer execution.
Definition test_ui.cpp:45
void UI_TimerStop(uiTimer_t *timer)
Stop a timer.
Definition ui_timer.cpp:163
uiTimer_t * UI_AllocTimer(uiNode_t *node, int firstDelay, timerCallback_t callback)
Allocate a new time for a node.
Definition ui_timer.cpp:123
void UI_TimerStart(uiTimer_t *timer)
Restart a timer.
Definition ui_timer.cpp:150
void UI_TimerRelease(uiTimer_t *timer)
Release the timer. It no more exists.
Definition ui_timer.cpp:176
void(* timerCallback_t)(uiNode_t *node, struct uiTimer_s *timer)
Definition ui_timer.h:31