]> git.lizzy.rs Git - dragonfireclient.git/blob - src/unittest/test_gameui.cpp
Require 'basic_debug' priv to view gameplay-relevant debug info, require 'debug'...
[dragonfireclient.git] / src / unittest / test_gameui.cpp
1 /*
2 Minetest
3 Copyright (C) 2018 nerzhul, Loic BLOT <loic.blot@unix-experience.fr>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "test.h"
21
22 #include "client/gameui.h"
23
24 class TestGameUI : public TestBase
25 {
26 public:
27         TestGameUI() { TestManager::registerTestModule(this); }
28         const char *getName() { return "TestGameUI"; }
29
30         void runTests(IGameDef *gamedef);
31
32         void testInit();
33         void testFlagSetters();
34         void testInfoText();
35         void testStatusText();
36 };
37
38 static TestGameUI g_test_instance;
39
40 void TestGameUI::runTests(IGameDef *gamedef)
41 {
42         TEST(testInit);
43         TEST(testFlagSetters);
44         TEST(testInfoText);
45         TEST(testStatusText);
46 }
47
48 void TestGameUI::testInit()
49 {
50         GameUI gui{};
51         // Ensure flags on GameUI init
52         UASSERT(gui.getFlags().show_chat)
53         UASSERT(gui.getFlags().show_hud)
54         UASSERT(!gui.getFlags().show_minimap)
55         UASSERT(!gui.getFlags().show_profiler_graph)
56
57         // And after the initFlags init stage
58         gui.initFlags();
59         UASSERT(gui.getFlags().show_chat)
60         UASSERT(gui.getFlags().show_hud)
61         UASSERT(!gui.getFlags().show_minimap)
62         UASSERT(!gui.getFlags().show_profiler_graph)
63
64         // @TODO verify if we can create non UI nulldevice to test this function
65         // gui.init();
66 }
67
68 void TestGameUI::testFlagSetters()
69 {
70         GameUI gui{};
71         gui.showMinimap(true);
72         UASSERT(gui.getFlags().show_minimap);
73
74         gui.showMinimap(false);
75         UASSERT(!gui.getFlags().show_minimap);
76 }
77
78 void TestGameUI::testStatusText()
79 {
80         GameUI gui{};
81         gui.showStatusText(L"test status");
82
83         UASSERT(gui.m_statustext_time == 0.0f);
84         UASSERT(gui.m_statustext == L"test status");
85 }
86
87 void TestGameUI::testInfoText()
88 {
89         GameUI gui{};
90         gui.setInfoText(L"test info");
91
92         UASSERT(gui.m_infotext == L"test info");
93 }