GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/gui/windowmanager.cc Lines: 547 547 100.0 %
Date: 2021-03-17 Branches: 1210 2310 52.4 %

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 "client.h"
25
#include "configmanager.h"
26
#include "configuration.h"
27
#include "dirs.h"
28
#include "graphicsmanager.h"
29
#include "main.h"
30
#include "settings.h"
31
#include "textcommand.h"
32
33
#include "being/localplayer.h"
34
35
#include "const/sound.h"
36
37
#include "const/resources/currency.h"
38
39
#include "fs/virtfs/fs.h"
40
41
#include "gui/gui.h"
42
#include "gui/mailmessage.h"
43
#include "gui/userpalette.h"
44
#include "gui/windowmanager.h"
45
46
#include "gui/popups/beingpopup.h"
47
#include "gui/popups/itempopup.h"
48
#include "gui/popups/popupmenu.h"
49
#include "gui/popups/skillpopup.h"
50
#include "gui/popups/spellpopup.h"
51
#include "gui/popups/speechbubble.h"
52
#include "gui/popups/statuspopup.h"
53
#include "gui/popups/textboxpopup.h"
54
#include "gui/popups/textpopup.h"
55
56
#include "gui/widgets/desktop.h"
57
#include "gui/widgets/emoteshortcutcontainer.h"
58
#include "gui/widgets/createwidget.h"
59
60
#include "gui/windows/bankwindow.h"
61
#include "gui/windows/buydialog.h"
62
#include "gui/windows/buyingstoreselldialog.h"
63
#include "gui/windows/buyselldialog.h"
64
#include "gui/windows/charselectdialog.h"
65
#include "gui/windows/changeemaildialog.h"
66
#include "gui/windows/changepassworddialog.h"
67
#include "gui/windows/chatwindow.h"
68
#include "gui/windows/clanwindow.h"
69
#include "gui/windows/confirmdialog.h"
70
#include "gui/windows/connectiondialog.h"
71
#include "gui/windows/cutinwindow.h"
72
#include "gui/windows/debugwindow.h"
73
#include "gui/windows/didyouknowwindow.h"
74
#include "gui/windows/editdialog.h"
75
#include "gui/windows/editserverdialog.h"
76
#include "gui/windows/eggselectiondialog.h"
77
#include "gui/windows/emotewindow.h"
78
#include "gui/windows/equipmentwindow.h"
79
#include "gui/windows/helpwindow.h"
80
#include "gui/windows/insertcarddialog.h"
81
#include "gui/windows/inventorywindow.h"
82
#include "gui/windows/itemamountwindow.h"
83
#include "gui/windows/killstats.h"
84
#include "gui/windows/logindialog.h"
85
#include "gui/windows/maileditwindow.h"
86
#include "gui/windows/mailviewwindow.h"
87
#include "gui/windows/mailwindow.h"
88
#include "gui/windows/minimap.h"
89
#include "gui/windows/ministatuswindow.h"
90
#include "gui/windows/npcdialog.h"
91
#include "gui/windows/npcselldialog.h"
92
#include "gui/windows/okdialog.h"
93
#include "gui/windows/outfitwindow.h"
94
#include "gui/windows/questswindow.h"
95
#include "gui/windows/quitdialog.h"
96
#include "gui/windows/registerdialog.h"
97
#include "gui/windows/serverdialog.h"
98
#include "gui/windows/serverinfowindow.h"
99
#include "gui/windows/setupwindow.h"
100
#include "gui/windows/shopwindow.h"
101
#include "gui/windows/shortcutwindow.h"
102
#include "gui/windows/skilldialog.h"
103
#include "gui/windows/socialwindow.h"
104
#include "gui/windows/statuswindow.h"
105
#include "gui/windows/textcommandeditor.h"
106
#include "gui/windows/textdialog.h"
107
#include "gui/windows/textselectdialog.h"
108
#include "gui/windows/tradewindow.h"
109
#include "gui/windows/updaterwindow.h"
110
#include "gui/windows/whoisonline.h"
111
#include "gui/windows/worldselectdialog.h"
112
113
#include "input/touch/touchmanager.h"
114
115
#include "net/logindata.h"
116
117
#include "net/eathena/charserverhandler.h"
118
#include "net/eathena/inventoryhandler.h"
119
#include "net/eathena/serverfeatures.h"
120
#include "net/eathena/playerhandler.h"
121
122
#include "render/sdlgraphics.h"
123
124
#include "resources/groupinfo.h"
125
#include "resources/sdlimagehelper.h"
126
127
#include "resources/db/groupdb.h"
128
#include "resources/db/unitsdb.h"
129
130
#include "resources/item/item.h"
131
132
#include "resources/map/map.h"
133
134
#include "resources/resourcemanager/resourcemanager.h"
135
136
#include "utils/delete2.h"
137
#include "utils/env.h"
138
#include "utils/gettext.h"
139
140
#include "utils/translation/translationmanager.h"
141
142
#include "debug.h"
143
144
extern QuitDialog *quitDialog;
145
146
71
TEST_CASE("Windows tests", "windowmanager")
147
{
148
69
    setEnv("SDL_VIDEODRIVER", "dummy");
149
150
69
    client = new Client;
151
69
    XML::initXML();
152
69
    SDL_Init(SDL_INIT_VIDEO);
153
69
    ResourceManager::deleteInstance();
154
69
    ResourceManager::cleanOrphans(true);
155
276
    VirtFs::mountDirSilent("data", Append_false);
156
276
    VirtFs::mountDirSilent("../data", Append_false);
157
276
    VirtFs::mountDirSilent("data/test", Append_false);
158
276
    VirtFs::mountDirSilent("../data/test", Append_false);
159
69
    setPathsDefaults(paths);
160
276
    branding.setValue("onlineServerFile", "test/serverlistplus.xml");
161
69
    mainGraphics = new SDLGraphics;
162
138
    imageHelper = new SDLImageHelper;
163
164
69
    Dirs::initRootDir();
165
69
    Dirs::initHomeDir();
166
167
    const std::string cfgName = settings.configDir +
168
138
        "/nonexistserver/config.xml";
169
69
    ::remove(cfgName.c_str());
170
171
69
    ConfigManager::initConfiguration();
172
69
    setConfigDefaults2(config);
173
69
    setBrandingDefaults(branding);
174
69
    setFeaturesDefaults(features);
175

276
    ConfigManager::initServerConfig("nonexistserver");
176
177
#ifdef USE_SDL2
178

69
    SDLImageHelper::setRenderer(graphicsManager.createRenderer(
179
        GraphicsManager::createWindow(640, 480, 0,
180
69
        SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
181
#else  // USE_SDL2
182
183
    GraphicsManager::createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
184
#endif  // USE_SDL2
185
186

69
    userPalette = new UserPalette;
187

276
    config.setValue("fontSize", 16);
188
189

69
    theme = new Theme;
190
69
    Theme::selectSkin();
191
192
69
    localPlayer = new LocalPlayer(static_cast<BeingId>(1),
193

69
        BeingTypeId_zero);
194
195
69
    ActorSprite::load();
196

69
    gui = new Gui();
197
69
    gui->postInit(mainGraphics);
198
69
    touchManager.init();
199
69
    UnitsDb::load();
200

69
    charServerHandler = new EAthena::CharServerHandler;
201

69
    serverFeatures = new EAthena::ServerFeatures;
202

69
    inventoryHandler = new EAthena::InventoryHandler;
203

69
    playerHandler = new EAthena::PlayerHandler;
204

276
    paths.setValue("itemIcons", "");
205
206
69
    TranslationManager::init();
207
208
    mainGraphics->setVideoMode(640, 480,
209
        1,
210
        8,
211
        false,
212
        false,
213
        false,
214
        false,
215
69
        false);
216
217



483
    SECTION("bankWindow")
218
    {
219

1
        CREATEWIDGETV0(bankWindow, BankWindow);
220
1
        gui->draw();
221
1
        mainGraphics->updateScreen();
222
1
        delete2(bankWindow)
223
    }
224



483
    SECTION("buyDialog1")
225
    {
226
        BuyDialog *dialog;
227

1
        CREATEWIDGETV0(dialog, BuyDialog);
228
1
        gui->draw();
229
1
        mainGraphics->updateScreen();
230
1
        delete2(dialog)
231
    }
232



483
    SECTION("buyDialog2")
233
    {
234
        BuyDialog *dialog;
235

1
        CREATEWIDGETV(dialog, BuyDialog,
236
            BeingId_zero,
237
1
            DEFAULT_CURRENCY);
238
1
        gui->draw();
239
1
        mainGraphics->updateScreen();
240
1
        delete2(dialog)
241
    }
242
#ifdef TMWA_SUPPORT
243



483
    SECTION("buyDialog3")
244
    {
245
        BuyDialog *dialog;
246

5
        CREATEWIDGETV(dialog, BuyDialog,
247
            "user",
248
2
            DEFAULT_CURRENCY);
249
1
        gui->draw();
250
1
        mainGraphics->updateScreen();
251
1
        delete2(dialog)
252
    }
253
#endif  // TMWA_SUPPORT
254



483
    SECTION("buyDialog4")
255
    {
256
        BuyDialog *dialog;
257
1
        BeingTypeId id = static_cast<BeingTypeId>(1);
258
        Map *map = new Map("test map",
259
            10, 10,
260

4
            32, 32);
261
        Being *being = Being::createBeing(BeingId_zero,
262
            ActorType::Avatar,
263
            id,
264
1
            map);
265

1
        CREATEWIDGETV(dialog, BuyDialog,
266
            being,
267
1
            DEFAULT_CURRENCY);
268
1
        gui->draw();
269
1
        mainGraphics->updateScreen();
270
1
        delete2(dialog)
271
1
        delete2(being)
272
1
        delete2(map)
273
    }
274



483
    SECTION("BuyingStoreSellDialog")
275
    {
276
        BuyingStoreSellDialog *dialog;
277

1
        CREATEWIDGETV(dialog, BuyingStoreSellDialog,
278
1
            BeingId_zero, 0);
279
1
        gui->draw();
280
1
        mainGraphics->updateScreen();
281
1
        delete2(dialog)
282
    }
283



483
    SECTION("BuySellDialog1")
284
    {
285
        BuySellDialog *dialog;
286

1
        CREATEWIDGETV(dialog, BuySellDialog, BeingId_zero);
287
1
        gui->draw();
288
1
        mainGraphics->updateScreen();
289
1
        delete2(dialog)
290
    }
291



483
    SECTION("BuySellDialog2")
292
    {
293
        BuySellDialog *dialog;
294


4
        CREATEWIDGETV(dialog, BuySellDialog, "user");
295
1
        gui->draw();
296
1
        mainGraphics->updateScreen();
297
1
        delete2(dialog)
298
    }
299



483
    SECTION("ChangeEmailDialog")
300
    {
301
2
        LoginData data;
302
        ChangeEmailDialog *dialog;
303

1
        CREATEWIDGETV(dialog, ChangeEmailDialog, data);
304
1
        gui->draw();
305
1
        mainGraphics->updateScreen();
306
1
        delete2(dialog)
307
    }
308



483
    SECTION("ChangePasswordDialog")
309
    {
310
2
        LoginData data;
311
        ChangePasswordDialog *dialog;
312

1
        CREATEWIDGETV(dialog, ChangePasswordDialog, data);
313
1
        gui->draw();
314
1
        mainGraphics->updateScreen();
315
1
        delete2(dialog)
316
    }
317



483
    SECTION("CharSelectDialog")
318
    {
319
2
        LoginData data;
320
        CharSelectDialog *dialog;
321

1
        CREATEWIDGETV(dialog, CharSelectDialog, data);
322
1
        gui->draw();
323
1
        mainGraphics->updateScreen();
324
1
        delete2(dialog)
325
    }
326


414
    SECTION("CharCreateDialog")
327
    {
328
/*
329
        LoginData data;
330
        CharSelectDialog *dialog2;
331
        CREATEWIDGETV(dialog2, CharSelectDialog, data);
332
        CharCreateDialog *dialog;
333
        CREATEWIDGETV(dialog, CharCreateDialog, dialog2, 0);
334
        gui->draw();
335
        mainGraphics->updateScreen();
336
        delete2(dialog)
337
        delete2(dialog2)
338
*/
339
    }
340



483
    SECTION("ChatWindow")
341
    {
342

4
        CREATEWIDGETV(chatWindow, ChatWindow,
343
1
            "Chat");
344
1
        gui->draw();
345
1
        mainGraphics->updateScreen();
346
1
        delete2(chatWindow)
347
    }
348



483
    SECTION("ClanWindow")
349
    {
350

1
        CREATEWIDGETV0(clanWindow, ClanWindow);
351
1
        gui->draw();
352
1
        mainGraphics->updateScreen();
353
1
        delete2(clanWindow)
354
    }
355



483
    SECTION("ConfirmDialog")
356
    {
357
        ConfirmDialog *dialog;
358


7
        CREATEWIDGETV(dialog, ConfirmDialog,
359
1
            "", "", SOUND_REQUEST, false, Modal_false, nullptr);
360
1
        gui->draw();
361
1
        mainGraphics->updateScreen();
362
1
        delete2(dialog)
363
    }
364



483
    SECTION("CutinWindow")
365
    {
366

1
        CREATEWIDGETV0(cutInWindow, CutInWindow);
367
1
        gui->draw();
368
1
        mainGraphics->updateScreen();
369
1
        delete2(cutInWindow)
370
    }
371



483
    SECTION("DebugWindow")
372
    {
373

4
        CREATEWIDGETV(debugWindow, DebugWindow,
374
1
            "Debug");
375
1
        gui->draw();
376
1
        mainGraphics->updateScreen();
377
1
        delete2(debugWindow)
378
    }
379



483
    SECTION("didYouKnowWindow")
380
    {
381

1
        CREATEWIDGETV0(didYouKnowWindow, DidYouKnowWindow);
382
1
        gui->draw();
383
1
        mainGraphics->updateScreen();
384
1
        delete2(didYouKnowWindow)
385
    }
386



483
    SECTION("EditDialog")
387
    {
388
        EditDialog *dialog;
389


10
        CREATEWIDGETV(dialog, EditDialog,
390
1
            "", "", "", 100, nullptr, Modal_false);
391
1
        gui->draw();
392
1
        mainGraphics->updateScreen();
393
1
        delete2(dialog)
394
    }
395



483
    SECTION("EditServerDialog")
396
    {
397
2
        ServerInfo mCurrentServer;
398

5
        settings.configDir = VirtFs::getRealDir("test/serverlistplus.xml");
399

1
        ServerDialog *serverDialog = CREATEWIDGETR(ServerDialog,
400
            &mCurrentServer,
401
            settings.configDir);
402

1
        EditServerDialog *editServerDialog = CREATEWIDGETR(EditServerDialog,
403
            serverDialog, mCurrentServer, 0);
404
1
        gui->draw();
405
1
        mainGraphics->updateScreen();
406
1
        delete2(editServerDialog)
407
1
        delete2(serverDialog)
408
    }
409



483
    SECTION("EggSelectionDialog")
410
    {
411

1
        EggSelectionDialog *dialog = CREATEWIDGETR0(EggSelectionDialog);
412
1
        gui->draw();
413
1
        mainGraphics->updateScreen();
414
1
        delete2(dialog)
415
    }
416



483
    SECTION("EmoteWindow")
417
    {
418

1
        EmoteWindow *dialog = CREATEWIDGETR0(EmoteWindow);
419
1
        gui->draw();
420
1
        mainGraphics->updateScreen();
421
1
        delete2(dialog)
422
    }
423



483
    SECTION("EquipmentWindow")
424
    {
425
2
        Equipment *equipment = new Equipment;
426

4
        Map *map = new Map("test", 100, 100, 32, 32);
427
        Being *being = Being::createBeing(BeingId_zero,
428
            ActorType::Player,
429
            BeingTypeId_zero,
430
1
            map);
431

1
        EquipmentWindow *dialog = CREATEWIDGETR(EquipmentWindow,
432
            equipment, being, false);
433
1
        gui->draw();
434
1
        mainGraphics->updateScreen();
435
1
        delete2(dialog)
436
1
        delete2(being)
437
1
        delete2(map)
438
2
        delete2(equipment)
439
    }
440



483
    SECTION("helpWindow")
441
    {
442

1
        CREATEWIDGETV0(helpWindow, HelpWindow);
443
1
        gui->draw();
444
1
        mainGraphics->updateScreen();
445
2
        delete2(helpWindow)
446
    }
447



483
    SECTION("InsertCardDialog")
448
    {
449
        Item *item = new Item(5000,
450
            ItemType::Card,
451
            1,
452
            0,
453
            ItemColor_one,
454
            Identified_true,
455
            Damaged_false,
456
            Favorite_false,
457
            Equipm_true,
458

1
            Equipped_false);
459

1
        InsertCardDialog *dialog = CREATEWIDGETR(InsertCardDialog,
460
            0, item);
461
1
        gui->draw();
462
1
        mainGraphics->updateScreen();
463
1
        delete2(dialog)
464
1
        delete2(item)
465
    }
466



483
    SECTION("InventoryWindow")
467
    {
468

1
        Inventory *inventory = new Inventory(InventoryType::Inventory, -1);
469

1
        InventoryWindow *dialog = CREATEWIDGETR(InventoryWindow,
470
            inventory);
471
1
        gui->draw();
472
1
        mainGraphics->updateScreen();
473
1
        delete2(dialog)
474
1
        delete2(inventory)
475
    }
476



483
    SECTION("ItemAmountWindow")
477
    {
478
        Item *item = new Item(5000,
479
            ItemType::Card,
480
            1,
481
            0,
482
            ItemColor_one,
483
            Identified_true,
484
            Damaged_false,
485
            Favorite_false,
486
            Equipm_true,
487

1
            Equipped_false);
488

1
        ItemAmountWindow *dialog = CREATEWIDGETR(ItemAmountWindow,
489
            ItemAmountWindowUsage::ItemDrop,
490
            nullptr,
491
            item,
492
            0);
493
1
        gui->draw();
494
1
        mainGraphics->updateScreen();
495
1
        delete2(dialog)
496
1
        delete2(item)
497
    }
498



483
    SECTION("KillStats")
499
    {
500

1
        CREATEWIDGETV0(killStats, KillStats);
501
1
        gui->draw();
502
1
        mainGraphics->updateScreen();
503
2
        delete2(killStats)
504
    }
505



483
    SECTION("loginDialog")
506
    {
507
2
        ServerInfo mCurrentServer;
508

1
        LoginDialog *loginDialog = CREATEWIDGETR(LoginDialog,
509
            loginData,
510
            &mCurrentServer,
511
            &settings.options.updateHost);
512
1
        gui->draw();
513
1
        mainGraphics->updateScreen();
514
1
        delete2(loginDialog)
515
    }
516



483
    SECTION("MailEditWindow")
517
    {
518

1
        CREATEWIDGETV0(mailEditWindow, MailEditWindow);
519
1
        gui->draw();
520
1
        mainGraphics->updateScreen();
521
1
        delete2(mailEditWindow)
522
    }
523



483
    SECTION("MailViewWindow")
524
    {
525
2
        MailMessage *message = new MailMessage;
526

1
        CREATEWIDGETV(mailViewWindow, MailViewWindow,
527
            message,
528
1
            1);
529
1
        gui->draw();
530
1
        mainGraphics->updateScreen();
531
1
        delete2(mailViewWindow)
532
1
        delete message;
533
    }
534



483
    SECTION("MailWindow")
535
    {
536

1
        CREATEWIDGETV0(mailWindow, MailWindow);
537
1
        gui->draw();
538
1
        mainGraphics->updateScreen();
539
1
        delete2(mailWindow)
540
    }
541



483
    SECTION("Minimap")
542
    {
543

1
        CREATEWIDGETV0(minimap, Minimap);
544
1
        gui->draw();
545
1
        mainGraphics->updateScreen();
546
1
        delete2(minimap)
547
    }
548



483
    SECTION("MiniStatusWindow")
549
    {
550

1
        CREATEWIDGETV0(miniStatusWindow, MiniStatusWindow);
551
1
        gui->draw();
552
1
        mainGraphics->updateScreen();
553
1
        delete2(miniStatusWindow)
554
    }
555



483
    SECTION("NpcDialog")
556
    {
557

1
        NpcDialog *dialog = CREATEWIDGETR(NpcDialog, BeingId_zero);
558
1
        gui->draw();
559
1
        mainGraphics->updateScreen();
560
1
        delete2(dialog)
561
    }
562



483
    SECTION("NpcSellDialog")
563
    {
564

1
        NpcSellDialog *dialog = CREATEWIDGETR(NpcSellDialog, BeingId_zero);
565
1
        gui->draw();
566
1
        mainGraphics->updateScreen();
567
1
        delete2(dialog)
568
    }
569



483
    SECTION("OkDialog")
570
    {
571



10
        OkDialog *dialog = CREATEWIDGETR(OkDialog,
572
            "", "", "", DialogType::SILENCE, Modal_false,
573
            ShowCenter_true, nullptr, 100);
574
1
        gui->draw();
575
1
        mainGraphics->updateScreen();
576
1
        delete2(dialog)
577
    }
578



483
    SECTION("OutfitWindow")
579
    {
580

1
        CREATEWIDGETV0(outfitWindow, OutfitWindow);
581
1
        gui->draw();
582
1
        mainGraphics->updateScreen();
583
1
        delete2(outfitWindow)
584
    }
585



483
    SECTION("QuestsWindow")
586
    {
587

1
        CREATEWIDGETV0(questsWindow, QuestsWindow);
588
1
        gui->draw();
589
1
        mainGraphics->updateScreen();
590
1
        delete2(questsWindow)
591
    }
592



483
    SECTION("QuitDialog")
593
    {
594

1
        CREATEWIDGETV(quitDialog, QuitDialog,
595
1
            &quitDialog);
596
1
        gui->draw();
597
1
        mainGraphics->updateScreen();
598
1
        delete2(quitDialog)
599
    }
600



483
    SECTION("RegisterDialog")
601
    {
602

1
        RegisterDialog *dialog = CREATEWIDGETR(RegisterDialog,
603
            loginData);
604
1
        gui->draw();
605
1
        mainGraphics->updateScreen();
606
1
        delete2(dialog)
607
    }
608



483
    SECTION("serversDialog")
609
    {
610
2
        ServerInfo mCurrentServer;
611

5
        settings.configDir = VirtFs::getRealDir("test/serverlistplus.xml");
612

1
        ServerDialog *serverDialog = CREATEWIDGETR(ServerDialog,
613
            &mCurrentServer,
614
            settings.configDir);
615
1
        gui->draw();
616
1
        mainGraphics->updateScreen();
617
1
        delete2(serverDialog)
618
    }
619



483
    SECTION("serversInfoWindow")
620
    {
621
2
        ServerInfo mCurrentServer;
622

1
        CREATEWIDGETV(serverInfoWindow, ServerInfoWindow,
623
1
            mCurrentServer);
624
1
        gui->draw();
625
1
        mainGraphics->updateScreen();
626
1
        delete2(serverInfoWindow)
627
    }
628



483
    SECTION("setupWindow")
629
    {
630

1
        CREATEWIDGETV0(setupWindow, SetupWindow);
631
1
        gui->draw();
632
1
        mainGraphics->updateScreen();
633
1
        delete2(setupWindow)
634
    }
635


414
    SECTION("ShopSellDialog")
636
    {
637
        // only tmwa skipping
638
    }
639



483
    SECTION("ShopWindow")
640
    {
641

1
        CREATEWIDGETV0(shopWindow, ShopWindow);
642
1
        gui->draw();
643
1
        mainGraphics->updateScreen();
644
1
        delete2(shopWindow)
645
    }
646



483
    SECTION("ShortcutWindow1")
647
    {
648
        EmoteShortcutContainer *container =
649

1
            new EmoteShortcutContainer(nullptr);
650


8
        CREATEWIDGETV(itemShortcutWindow, ShortcutWindow,
651
            "name",
652
            container,
653
            "emotes.xml",
654
            0,
655
2
            0);
656
1
        gui->draw();
657
1
        mainGraphics->updateScreen();
658
1
        delete2(itemShortcutWindow)
659
    }
660



483
    SECTION("ShortcutWindow2")
661
    {
662

6
        CREATEWIDGETV(itemShortcutWindow, ShortcutWindow,
663
            std::string(),
664
            "items.xml",
665
            0,
666
2
            0);
667
1
        gui->draw();
668
1
        mainGraphics->updateScreen();
669
1
        delete2(itemShortcutWindow)
670
    }
671



483
    SECTION("SkillDialog")
672
    {
673

1
        CREATEWIDGETV0(skillDialog, SkillDialog);
674
1
        gui->draw();
675
1
        mainGraphics->updateScreen();
676
1
        delete2(skillDialog)
677
    }
678



483
    SECTION("SocialWindow")
679
    {
680

1
        CREATEWIDGETV0(socialWindow, SocialWindow);
681
1
        gui->draw();
682
1
        mainGraphics->updateScreen();
683
1
        delete2(socialWindow)
684
    }
685



483
    SECTION("StatusWindow")
686
    {
687
1
        GroupDb::GroupInfos &groups = GroupDb::getGroups();
688

1
        groups[0] = new GroupInfo;
689
2
        groups[0]->name = std::string();
690
2
        groups[0]->longName = std::string();
691

1
        CREATEWIDGETV0(statusWindow, StatusWindow);
692
1
        gui->draw();
693
1
        mainGraphics->updateScreen();
694
1
        delete2(statusWindow)
695

1
        delete groups[0];
696
        groups.clear();
697
    }
698



483
    SECTION("TextCommandEditor")
699
    {
700
        TextCommand *textCommand = new TextCommand(1, "", "", "",
701



13
            CommandTarget::NoTarget, "");
702

1
        TextCommandEditor *dialog = CREATEWIDGETR(TextCommandEditor,
703
            textCommand);
704
1
        gui->draw();
705
1
        mainGraphics->updateScreen();
706
1
        delete2(dialog)
707
1
        delete2(textCommand)
708
    }
709
710



483
    SECTION("TextDialog")
711
    {
712


7
        TextDialog *dialog = CREATEWIDGETR(TextDialog,
713
            "", "", nullptr, false);
714
1
        gui->draw();
715
1
        mainGraphics->updateScreen();
716
1
        delete2(dialog)
717
    }
718



483
    SECTION("TextSelectDialog")
719
    {
720


7
        TextSelectDialog *dialog = CREATEWIDGETR(TextSelectDialog,
721
            "", "", AllowQuit_false);
722
1
        gui->draw();
723
1
        mainGraphics->updateScreen();
724
1
        delete2(dialog)
725
    }
726



483
    SECTION("TradeWindow")
727
    {
728

1
        CREATEWIDGETV0(tradeWindow, TradeWindow);
729
1
        gui->draw();
730
1
        mainGraphics->updateScreen();
731
1
        delete2(tradeWindow)
732
    }
733



483
    SECTION("UpdaterWindow")
734
    {
735


7
        CREATEWIDGETV(updaterWindow, UpdaterWindow,
736
1
            "", "", false, UpdateType::Skip);
737
1
        gui->draw();
738
1
        mainGraphics->updateScreen();
739
1
        delete2(updaterWindow)
740
    }
741



483
    SECTION("WhoIsOnline")
742
    {
743

1
        CREATEWIDGETV0(whoIsOnline, WhoIsOnline);
744
1
        gui->draw();
745
1
        mainGraphics->updateScreen();
746
1
        delete2(whoIsOnline)
747
    }
748



483
    SECTION("WorldSelectDialog")
749
    {
750
2
        Worlds worlds;
751

1
        WorldSelectDialog *dialog = CREATEWIDGETR(WorldSelectDialog,
752
            worlds);
753
1
        gui->draw();
754
1
        mainGraphics->updateScreen();
755
1
        delete2(dialog)
756
    }
757



483
    SECTION("popupMenu")
758
    {
759

1
        CREATEWIDGETV0(popupMenu, PopupMenu);
760
1
        gui->draw();
761
1
        mainGraphics->updateScreen();
762
2
        delete2(popupMenu)
763
    }
764



483
    SECTION("skillPopup")
765
    {
766

1
        CREATEWIDGETV0(skillPopup, SkillPopup);
767
1
        gui->draw();
768
1
        mainGraphics->updateScreen();
769
1
        delete2(skillPopup)
770
    }
771



483
    SECTION("SpeechBubble")
772
    {
773

1
        SpeechBubble *bubble = CREATEWIDGETR0(SpeechBubble);
774
1
        gui->draw();
775
1
        mainGraphics->updateScreen();
776
1
        delete2(bubble)
777
    }
778



483
    SECTION("beingPopup")
779
    {
780

1
        CREATEWIDGETV0(beingPopup, BeingPopup);
781
1
        gui->draw();
782
1
        mainGraphics->updateScreen();
783
1
        delete2(beingPopup)
784
    }
785



483
    SECTION("textPopup")
786
    {
787

1
        CREATEWIDGETV0(textPopup, TextPopup);
788
1
        gui->draw();
789
1
        mainGraphics->updateScreen();
790
1
        delete2(textPopup)
791
    }
792



483
    SECTION("textBoxPopup")
793
    {
794

1
        CREATEWIDGETV0(textBoxPopup, TextBoxPopup);
795
1
        gui->draw();
796
1
        mainGraphics->updateScreen();
797
1
        delete2(textBoxPopup)
798
    }
799



483
    SECTION("itemPopup")
800
    {
801

1
        CREATEWIDGETV0(itemPopup, ItemPopup);
802
1
        gui->draw();
803
1
        mainGraphics->updateScreen();
804
1
        delete2(itemPopup)
805
    }
806



483
    SECTION("spellPopup")
807
    {
808

1
        CREATEWIDGETV0(spellPopup, SpellPopup);
809
1
        gui->draw();
810
1
        mainGraphics->updateScreen();
811
1
        delete2(spellPopup)
812
    }
813



483
    SECTION("StatusPopup")
814
    {
815

1
        StatusPopup *status = CREATEWIDGETR0(StatusPopup);
816
1
        gui->draw();
817
1
        mainGraphics->updateScreen();
818
1
        delete2(status)
819
    }
820



483
    SECTION("desktop")
821
    {
822

1
        CREATEWIDGETV(desktop, Desktop, nullptr);
823
1
        gui->draw();
824
1
        mainGraphics->updateScreen();
825
1
        delete2(desktop)
826
    }
827



483
    SECTION("connectionDialog")
828
    {
829


4
        ConnectionDialog *connectionDialog = CREATEWIDGETR(ConnectionDialog,
830
            // TRANSLATORS: connection dialog header
831
            _("Logging in"),
832
            State::SWITCH_SERVER);
833
1
        gui->draw();
834
1
        mainGraphics->updateScreen();
835
1
        delete2(connectionDialog)
836
    }
837
838
69
    UnitsDb::unload();
839
69
    delete2(localPlayer)
840
69
    delete2(userPalette)
841
69
    delete2(client)
842
69
    delete2(serverFeatures)
843
69
    delete2(inventoryHandler)
844
69
    delete2(charServerHandler)
845
69
    delete2(playerHandler)
846
69
    delete2(gui)
847
69
    ResourceManager::deleteInstance();
848

276
    VirtFs::unmountDirSilent("data");
849

276
    VirtFs::unmountDirSilent("../data");
850

276
    VirtFs::unmountDirSilent("data/test");
851

276
    VirtFs::unmountDirSilent("../data/test");
852
69
}
853
854
10
TEST_CASE("WindowManager", "create windows")
855
{
856
8
    setEnv("SDL_VIDEODRIVER", "dummy");
857
858
8
    client = new Client;
859
8
    XML::initXML();
860
8
    SDL_Init(SDL_INIT_VIDEO);
861
8
    ResourceManager::deleteInstance();
862
8
    ResourceManager::cleanOrphans(true);
863
32
    VirtFs::mountDirSilent("data", Append_false);
864
32
    VirtFs::mountDirSilent("../data", Append_false);
865
32
    VirtFs::mountDirSilent("data/test", Append_false);
866
32
    VirtFs::mountDirSilent("../data/test", Append_false);
867
8
    setPathsDefaults(paths);
868
32
    branding.setValue("onlineServerFile", "test/serverlistplus.xml");
869
8
    mainGraphics = new SDLGraphics;
870
16
    imageHelper = new SDLImageHelper;
871
872
8
    Dirs::initRootDir();
873
8
    Dirs::initHomeDir();
874
875
    const std::string cfgName = settings.configDir +
876
16
        "/nonexistserver/config.xml";
877
8
    ::remove(cfgName.c_str());
878
879
8
    ConfigManager::initConfiguration();
880
8
    setConfigDefaults2(config);
881
8
    setBrandingDefaults(branding);
882

32
    ConfigManager::initServerConfig("nonexistserver");
883
884
#ifdef USE_SDL2
885

8
    SDLImageHelper::setRenderer(graphicsManager.createRenderer(
886
        GraphicsManager::createWindow(640, 480, 0,
887
8
        SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
888
#else  // USE_SDL2
889
890
    GraphicsManager::createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
891
#endif  // USE_SDL2
892
893

32
    config.setValue("fontSize", 16);
894
895

8
    theme = new Theme;
896
8
    Theme::selectSkin();
897
898
8
    localPlayer = new LocalPlayer(static_cast<BeingId>(1),
899

8
        BeingTypeId_zero);
900
901
8
    ActorSprite::load();
902

8
    gui = new Gui();
903
8
    gui->postInit(mainGraphics);
904
8
    touchManager.init();
905
8
    UnitsDb::load();
906

8
    charServerHandler = new EAthena::CharServerHandler;
907

8
    serverFeatures = new EAthena::ServerFeatures;
908

8
    inventoryHandler = new EAthena::InventoryHandler;
909

8
    playerHandler = new EAthena::PlayerHandler;
910

32
    paths.setValue("itemIcons", "");
911
912
8
    TranslationManager::init();
913
914
    mainGraphics->setVideoMode(640, 480,
915
        1,
916
        8,
917
        false,
918
        false,
919
        false,
920
        false,
921
8
        false);
922
923



56
    SECTION("create windows")
924
    {
925
1
        WindowManager::createWindows();
926
1
        WindowManager::deleteWindows();
927
    }
928
929



56
    SECTION("init")
930
    {
931
1
        WindowManager::init();
932
    }
933
934



56
    SECTION("initTitle")
935
    {
936
1
        WindowManager::initTitle();
937





10
        REQUIRE(settings.windowCaption == strprintf("%s %s",
938
            branding.getStringValue("appName").c_str(),
939
            SMALL_VERSION));
940
    }
941
942



56
    SECTION("updateTitle1")
943
    {
944
2
        settings.serverName = std::string();
945
2
        settings.login = std::string();
946
1
        WindowManager::updateTitle();
947





10
        REQUIRE(settings.windowCaption == strprintf("%s %s",
948
            branding.getStringValue("appName").c_str(),
949
            SMALL_VERSION));
950
    }
951
952



56
    SECTION("updateTitle2")
953
    {
954
1
        settings.serverName = "server";
955
2
        settings.login = std::string();
956
1
        WindowManager::updateTitle();
957





11
        REQUIRE(settings.windowCaption == strprintf("%s %s - %s",
958
            branding.getStringValue("appName").c_str(),
959
            SMALL_VERSION,
960
            settings.serverName.c_str()));
961
    }
962
963



56
    SECTION("updateTitle3")
964
    {
965
1
        settings.serverName = "server";
966
1
        settings.login = "login";
967
1
        WindowManager::updateTitle();
968





12
        REQUIRE(settings.windowCaption == strprintf("%s %s - %s %s",
969
            branding.getStringValue("appName").c_str(),
970
            SMALL_VERSION,
971
            settings.login.c_str(),
972
            settings.serverName.c_str()));
973
    }
974
975



56
    SECTION("setFramerate1")
976
    {
977
1
        settings.limitFps = true;
978
1
        WindowManager::setFramerate(60);
979




4
        REQUIRE(WindowManager::getFramerate() == 60);
980
1
        WindowManager::setFramerate(10);
981




4
        REQUIRE(WindowManager::getFramerate() == 10);
982
1
        WindowManager::setFramerate(0);
983




4
        REQUIRE(WindowManager::getFramerate() == 10);
984
    }
985
986



56
    SECTION("setFramerate2")
987
    {
988
1
        settings.limitFps = false;
989
1
        WindowManager::setFramerate(60);
990




4
        REQUIRE(WindowManager::getFramerate() == 0);
991
1
        WindowManager::setFramerate(10);
992




4
        REQUIRE(WindowManager::getFramerate() == 0);
993
1
        WindowManager::setFramerate(0);
994




4
        REQUIRE(WindowManager::getFramerate() == 0);
995
    }
996
997
16
    settings.serverName = std::string();
998
16
    settings.login = std::string();
999
8
    settings.limitFps = true;
1000
1001
8
    UnitsDb::unload();
1002
8
    delete2(localPlayer)
1003
8
    delete2(client)
1004
8
    delete2(serverFeatures)
1005
8
    delete2(inventoryHandler)
1006
8
    delete2(charServerHandler)
1007
8
    delete2(playerHandler)
1008
8
    delete2(gui)
1009
8
    ResourceManager::deleteInstance();
1010

32
    VirtFs::unmountDirSilent("data");
1011

32
    VirtFs::unmountDirSilent("../data");
1012

32
    VirtFs::unmountDirSilent("data/test");
1013

32
    VirtFs::unmountDirSilent("../data/test");
1014

11
}