GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
/* |
||
2 |
* The ManaPlus Client |
||
3 |
* Copyright (C) 2013-2019 The ManaPlus Developers |
||
4 |
* Copyright (C) 2019-2021 Andrei Karas |
||
5 |
* |
||
6 |
* This file is part of The ManaPlus Client. |
||
7 |
* |
||
8 |
* This program is free software; you can redistribute it and/or modify |
||
9 |
* it under the terms of the GNU General Public License as published by |
||
10 |
* the Free Software Foundation; either version 2 of the License, or |
||
11 |
* any later version. |
||
12 |
* |
||
13 |
* This program is distributed in the hope that it will be useful, |
||
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 |
* GNU General Public License for more details. |
||
17 |
* |
||
18 |
* You should have received a copy of the GNU General Public License |
||
19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
20 |
*/ |
||
21 |
|||
22 |
#include "unittests/unittests.h" |
||
23 |
|||
24 |
#include "configuration.h" |
||
25 |
#include "configmanager.h" |
||
26 |
#include "client.h" |
||
27 |
#include "dirs.h" |
||
28 |
#include "graphicsmanager.h" |
||
29 |
|||
30 |
#include "const/resources/spriteaction.h" |
||
31 |
|||
32 |
#include "being/actorsprite.h" |
||
33 |
|||
34 |
#include "fs/virtfs/fs.h" |
||
35 |
|||
36 |
#include "gui/gui.h" |
||
37 |
#include "gui/theme.h" |
||
38 |
|||
39 |
#include "render/sdlgraphics.h" |
||
40 |
|||
41 |
#include "resources/sdlimagehelper.h" |
||
42 |
|||
43 |
#include "resources/animation/animation.h" |
||
44 |
|||
45 |
#include "resources/sprite/animatedsprite.h" |
||
46 |
|||
47 |
#include "utils/env.h" |
||
48 |
#include "utils/delete2.h" |
||
49 |
#include "utils/mrand.h" |
||
50 |
|||
51 |
PRAGMA48(GCC diagnostic push) |
||
52 |
PRAGMA48(GCC diagnostic ignored "-Wshadow") |
||
53 |
#ifndef USE_SDL2 |
||
54 |
#include <SDL.h> |
||
55 |
#endif // USE_SDL2 |
||
56 |
PRAGMA48(GCC diagnostic pop) |
||
57 |
|||
58 |
#include "debug.h" |
||
59 |
|||
60 |
✓✗ | 5 |
TEST_CASE("AnimatedSprite tests", "animatedsprite") |
61 |
{ |
||
62 |
3 |
setEnv("SDL_VIDEODRIVER", "dummy"); |
|
63 |
|||
64 |
3 |
initRand(); |
|
65 |
✓✗ | 3 |
client = new Client; |
66 |
3 |
XML::initXML(); |
|
67 |
3 |
SDL_Init(SDL_INIT_VIDEO); |
|
68 |
✓✗ | 9 |
VirtFs::mountDirSilent("data", Append_false); |
69 |
✓✗ | 9 |
VirtFs::mountDirSilent("../data", Append_false); |
70 |
✓✗ | 3 |
mainGraphics = new SDLGraphics; |
71 |
6 |
imageHelper = new SDLImageHelper(); |
|
72 |
|||
73 |
3 |
Dirs::initRootDir(); |
|
74 |
3 |
Dirs::initHomeDir(); |
|
75 |
|||
76 |
3 |
ConfigManager::initConfiguration(); |
|
77 |
3 |
setConfigDefaults2(config); |
|
78 |
3 |
setBrandingDefaults(branding); |
|
79 |
|||
80 |
#ifdef USE_SDL2 |
||
81 |
SDLImageHelper::setRenderer(graphicsManager.createRenderer( |
||
82 |
GraphicsManager::createWindow(640, 480, 0, |
||
83 |
SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE)); |
||
84 |
#else // USE_SDL2 |
||
85 |
|||
86 |
3 |
GraphicsManager::createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE); |
|
87 |
#endif // USE_SDL2 |
||
88 |
|||
89 |
✓✗ | 3 |
theme = new Theme; |
90 |
3 |
Theme::selectSkin(); |
|
91 |
|||
92 |
3 |
ActorSprite::load(); |
|
93 |
✓✗ | 3 |
gui = new Gui(); |
94 |
3 |
gui->postInit(mainGraphics); |
|
95 |
|||
96 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✓ |
21 |
SECTION("basic test 1") |
97 |
{ |
||
98 |
✓✗✓✗ |
3 |
AnimatedSprite *sprite = AnimatedSprite::load( |
99 |
1 |
"graphics/sprites/error.xml", 0); |
|
100 |
✓✗ | 1 |
sprite->play(SpriteAction::DEFAULT); |
101 |
|||
102 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE_FALSE(sprite == nullptr); |
103 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE_FALSE(sprite->getSprite() == nullptr); |
104 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE_FALSE(sprite->getAnimation() == nullptr); |
105 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE_FALSE(sprite->getFrame() == nullptr); |
106 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(0 == sprite->getFrameIndex()); |
107 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(0 == sprite->getFrameTime()); |
108 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
4 |
REQUIRE(false == sprite->update(1)); |
109 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(0 == sprite->getFrameTime()); |
110 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
4 |
REQUIRE(false == sprite->update(11)); |
111 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(10 == sprite->getFrameTime()); |
112 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(0 == sprite->getFrameIndex()); |
113 |
✓✗ | 1 |
delete sprite; |
114 |
✓✗ | 1 |
logger->log("test4"); |
115 |
} |
||
116 |
|||
117 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✓ |
21 |
SECTION("basic test 2") |
118 |
{ |
||
119 |
✓✗✓✗ |
3 |
AnimatedSprite *sprite = AnimatedSprite::load( |
120 |
1 |
"graphics/sprites/test.xml", 0); |
|
121 |
✓✗ | 1 |
sprite->play(SpriteAction::STAND); |
122 |
|||
123 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
5 |
REQUIRE(10 == const_cast<Animation*>(sprite->getAnimation()) |
124 |
->getFrames().size()); |
||
125 |
|||
126 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE_FALSE(nullptr == sprite); |
127 |
|||
128 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
4 |
REQUIRE(false == sprite->update(1)); |
129 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(0 == sprite->getFrameTime()); |
130 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(10 == sprite->getFrame()->delay); |
131 |
|||
132 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
4 |
REQUIRE(false == sprite->update(1 + 10)); |
133 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(0 == sprite->getFrameIndex()); |
134 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(10 == sprite->getFrameTime()); |
135 |
|||
136 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
4 |
REQUIRE(true == sprite->update(1 + 10 + 5)); |
137 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(1 == sprite->getFrameIndex()); |
138 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(5 == sprite->getFrameTime()); |
139 |
|||
140 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
4 |
REQUIRE(false == sprite->update(1 + 10 + 5)); |
141 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(1 == sprite->getFrameIndex()); |
142 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(5 == sprite->getFrameTime()); |
143 |
|||
144 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
4 |
REQUIRE(false == sprite->update(1 + 10 + 20)); |
145 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(1 == sprite->getFrameIndex()); |
146 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(20 == sprite->getFrameTime()); |
147 |
|||
148 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
4 |
REQUIRE(true == sprite->update(1 + 10 + 20 + 1)); |
149 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(2 == sprite->getFrameIndex()); |
150 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(1 == sprite->getFrameTime()); |
151 |
|||
152 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
4 |
REQUIRE(false == sprite->update(1 + 10 + 20 + 10)); |
153 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(2 == sprite->getFrameIndex()); |
154 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(10 == sprite->getFrameTime()); |
155 |
|||
156 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
4 |
REQUIRE(true == sprite->update(1 + 10 + 20 + 10 + 1)); |
157 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(4 == sprite->getFrameIndex()); |
158 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(1 == sprite->getFrameTime()); |
159 |
|||
160 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
4 |
REQUIRE(false == sprite->update(1 + 10 + 20 + 10 + 25)); |
161 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(4 == sprite->getFrameIndex()); |
162 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(25 == sprite->getFrameTime()); |
163 |
|||
164 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
4 |
REQUIRE(true == sprite->update(1 + 10 + 20 + 10 + 25 + 1)); |
165 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(6 == sprite->getFrameIndex()); |
166 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(1 == sprite->getFrameTime()); |
167 |
|||
168 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
4 |
REQUIRE(true == sprite->update(1 + 10 + 20 + 10 + 25 + 10 + 1)); |
169 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(8 == sprite->getFrameIndex()); |
170 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(1 == sprite->getFrameTime()); |
171 |
|||
172 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
4 |
REQUIRE(true == sprite->update(1 + 10 + 20 + 10 + 25 + 10 + 10 + 1)); |
173 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(4 == sprite->getFrameIndex()); |
174 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(1 == sprite->getFrameTime()); |
175 |
✓✗ | 1 |
delete sprite; |
176 |
} |
||
177 |
|||
178 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✓ |
21 |
SECTION("basic test 3") |
179 |
{ |
||
180 |
✓✗ | 3 |
AnimatedSprite *sprite2 = AnimatedSprite::load( |
181 |
✓✗ | 1 |
"graphics/sprites/test.xml", 0); |
182 |
✓✗ | 1 |
sprite2->play(SpriteAction::SIT); |
183 |
|||
184 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
4 |
REQUIRE(false == sprite2->update(1)); |
185 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
5 |
REQUIRE(2 == const_cast<Animation*>(sprite2->getAnimation()) |
186 |
->getFrames().size()); |
||
187 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(0 == sprite2->getFrameTime()); |
188 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(85 == sprite2->getFrame()->delay); |
189 |
|||
190 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
4 |
REQUIRE(true == sprite2->update(1 + 10 + 20 + 10 + 25 + 10 + 10 + 1)); |
191 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(1 == sprite2->getFrameIndex()); |
192 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(1 == sprite2->getFrameTime()); |
193 |
✓✗ | 1 |
delete sprite2; |
194 |
} |
||
195 |
|||
196 |
✓✗ | 3 |
delete2(client) |
197 |
✓✗ | 9 |
VirtFs::unmountDirSilent("data"); |
198 |
✓✗ | 9 |
VirtFs::unmountDirSilent("../data"); |
199 |
✓✗✓✗ |
6 |
} |
Generated by: GCOVR (Version 3.3) |