UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
test_ui.cpp
Go to the documentation of this file.
1 
6 /*
7 Copyright (C) 2002-2020 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 }
TEST_F(UITest, TimerDataStructure)
unittest around timer data structure. It not test timer execution.
Definition: test_ui.cpp:45
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 TEST_Shutdown(void)
Definition: test_shared.cpp:34
void UI_TimerRelease(uiTimer_t *timer)
Release the timer. It no more exists.
Definition: ui_timer.cpp:176
void UI_TimerStop(uiTimer_t *timer)
Stop a timer.
Definition: ui_timer.cpp:163
Atomic structure used to define most of the UI.
Definition: ui_nodes.h:80
uiNode_t * owner
Definition: ui_timer.h:41
void(* timerCallback_t)(uiNode_t *node, struct uiTimer_s *timer)
Definition: ui_timer.h:31
static void TearDownTestCase()
Definition: test_ui.cpp:36
void TEST_Init(void)
Definition: test_shared.cpp:72
static void SetUpTestCase()
Definition: test_ui.cpp:32
struct uiTimer_s * next
Definition: ui_timer.h:37
void UI_TimerStart(uiTimer_t *timer)
Restart a timer.
Definition: ui_timer.cpp:150