GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/gui/widgets/browserbox.cc Lines: 123 123 100.0 %
Date: 2017-11-29 Branches: 77 158 48.7 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2012-2017  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
6
TEST_CASE("BrowserBox tests", "browserbox")
49
{
50
2
    setEnv("SDL_VIDEODRIVER", "dummy");
51
52
2
    client = new Client;
53

8
    VirtFs::mountDirSilent("data", Append_false);
54

8
    VirtFs::mountDirSilent("../data", Append_false);
55
56
2
    mainGraphics = new SDLGraphics;
57
4
    imageHelper = new SDLImageHelper;
58
59
2
    Dirs::initRootDir();
60
2
    Dirs::initHomeDir();
61
62
2
    ConfigManager::initConfiguration();
63
2
    setConfigDefaults2(config);
64
2
    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
2
    graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
73
#endif  // USE_SDL2
74
75
2
    theme = new Theme;
76
2
    Theme::selectSkin();
77
78
2
    ActorSprite::load();
79
2
    gui = new Gui();
80
2
    gui->postInit(mainGraphics);
81
82

10
    Widget::setGlobalFont(new Font(
83
        "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Oblique.ttf",
84
        18,
85

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

8
        "");
89
2
    box->setWidth(100);
90
8
    std::string row = "test";
91
2
    box->addRow(row);
92



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

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

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

8
}