GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/gui/widgets/browserbox.cc Lines: 123 123 100.0 %
Date: 2018-07-14 Branches: 74 152 48.7 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2012-2018  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "unittests/unittests.h"
22
23
#include "client.h"
24
#include "configuration.h"
25
#include "configmanager.h"
26
#include "dirs.h"
27
#include "graphicsmanager.h"
28
29
#include "being/actorsprite.h"
30
31
#include "fs/virtfs/fs.h"
32
33
#include "gui/gui.h"
34
35
#include "gui/fonts/font.h"
36
37
#include "gui/widgets/browserbox.h"
38
39
#include "utils/delete2.h"
40
#include "utils/env.h"
41
42
#include "render/sdlgraphics.h"
43
44
#include "resources/sdlimagehelper.h"
45
46
#include "debug.h"
47
48
3
TEST_CASE("BrowserBox tests", "browserbox")
49
{
50
1
    setEnv("SDL_VIDEODRIVER", "dummy");
51
52
1
    client = new Client;
53
3
    VirtFs::mountDirSilent("data", Append_false);
54
3
    VirtFs::mountDirSilent("../data", Append_false);
55
56
1
    mainGraphics = new SDLGraphics;
57
2
    imageHelper = new SDLImageHelper;
58
59
1
    Dirs::initRootDir();
60
1
    Dirs::initHomeDir();
61
62
1
    ConfigManager::initConfiguration();
63
1
    setConfigDefaults2(config);
64
1
    setBrandingDefaults(branding);
65
66
#ifdef USE_SDL2
67
    SDLImageHelper::setRenderer(graphicsManager.createRenderer(
68
        graphicsManager.createWindow(640, 480, 0,
69
        SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
70
#else  // USE_SDL2
71
72
1
    graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
73
#endif  // USE_SDL2
74
75
1
    theme = new Theme;
76
1
    Theme::selectSkin();
77
78
1
    ActorSprite::load();
79
1
    gui = new Gui();
80
1
    gui->postInit(mainGraphics);
81
82
3
    Widget::setGlobalFont(new Font(
83
        "fonts/dejavusans.ttf",
84
        18,
85

1
        TTF_STYLE_NORMAL));
86
    BrowserBox *const box = new BrowserBox(nullptr,
87
        Opaque_true,
88

3
        "");
89
1
    box->setWidth(100);
90
3
    std::string row = "test";
91
1
    box->addRow(row, false);
92



5
    REQUIRE(box->hasRows() == true);
93
1
    box->clearRows();
94
1
    row = "@@";
95
1
    box->addRow(row, false);
96
1
    row = "@@|";
97
1
    box->addRow(row, false);
98
1
    row = "|@@";
99
1
    box->addRow(row, false);
100
1
    row = "@@|@@";
101
1
    box->addRow(row, false);
102
1
    row = "|@@@@";
103
1
    box->addRow(row, false);
104
1
    row = "@@11|[email protected]@";
105
1
    box->addRow(row, false);
106
1
    row = "##@@11|[email protected]@";
107
1
    box->addRow(row, false);
108
1
    row = "@@##|[email protected]@";
109
1
    box->addRow(row, false);
110
1
    row = "@@11|##[email protected]@";
111
1
    box->addRow(row, false);
112
1
    row = "@@11|22##@@";
113
1
    box->addRow(row, false);
114
1
    row = "@@11|[email protected]@##";
115
1
    box->addRow(row, false);
116
1
    row = "<##@@11|[email protected]@";
117
1
    box->addRow(row, false);
118
1
    row = "@@<##|[email protected]@";
119
1
    box->addRow(row, false);
120
1
    row = "@@11|<##[email protected]@";
121
1
    box->addRow(row, false);
122
1
    row = "@@11|22<##@@";
123
1
    box->addRow(row, false);
124
1
    row = "@@11|[email protected]@<##";
125
1
    box->addRow(row, false);
126
1
    row = "<##11|[email protected]@";
127
1
    box->addRow(row, false);
128
1
    row = "<##|[email protected]@";
129
1
    box->addRow(row, false);
130
1
    row = "11|<##[email protected]@";
131
1
    box->addRow(row, false);
132
1
    row = "11|22<##@@";
133
1
    box->addRow(row, false);
134
1
    row = "11|[email protected]@<##";
135
1
    box->addRow(row, false);
136
1
    row = "##>@@11|[email protected]@";
137
1
    box->addRow(row, false);
138
1
    row = "@@##>|[email protected]@";
139
1
    box->addRow(row, false);
140
1
    row = "@@11|##>[email protected]@";
141
1
    box->addRow(row, false);
142
1
    row = "@@11|22##>@@";
143
1
    box->addRow(row, false);
144
1
    row = "@@11|[email protected]@##>";
145
1
    box->addRow(row, false);
146
1
    row = "<##11|22##>";
147
1
    box->addRow(row, false);
148
1
    row = "<##|22##>";
149
1
    box->addRow(row, false);
150
1
    row = "11|<##22##>";
151
1
    box->addRow(row, false);
152
1
    row = "11|22<####>";
153
1
    box->addRow(row, false);
154
1
    row = "11|22##><##";
155
1
    box->addRow(row, false);
156
1
    row = "%%@@11|[email protected]@";
157
1
    box->addRow(row, false);
158
1
    row = "%%[email protected]@11|[email protected]@";
159
1
    box->addRow(row, false);
160
1
    row = "<%%11|[email protected]@";
161
1
    box->addRow(row, false);
162
1
    row = "@@%%>|[email protected]@";
163
1
    box->addRow(row, false);
164
1
    row = "<%%|22%%>";
165
1
    box->addRow(row, false);
166
1
    row = "11|22<%%%%>";
167
1
    box->addRow(row, false);
168
1
    row = "%%";
169
1
    box->addRow(row, false);
170
1
    row = "%%1";
171
1
    box->addRow(row, false);
172
1
    row = "%%##";
173
1
    box->addRow(row, false);
174
1
    row = "%%###";
175
1
    box->addRow(row, false);
176
1
    row = "##%%";
177
1
    box->addRow(row, false);
178
1
    row = "##1%%";
179
1
    box->addRow(row, false);
180
1
    row = "##%%2";
181
1
    box->addRow(row, false);
182
1
    row = "##1%%2";
183
1
    box->addRow(row, false);
184
185
1
    delete Widget::getGloablFont();
186
1
    Widget::setGlobalFont(nullptr);
187
1
    delete box;
188
1
    delete2(client);
189

3
    VirtFs::unmountDirSilent("data");
190

4
    VirtFs::unmountDirSilent("../data");
191

4
}