GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/gui/windowmanager.cc Lines: 528 528 100.0 %
Date: 2017-11-29 Branches: 1165 2222 52.4 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2013-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 "configmanager.h"
25
#include "configuration.h"
26
#include "dirs.h"
27
#include "graphicsmanager.h"
28
#include "main.h"
29
#include "settings.h"
30
#include "textcommand.h"
31
32
#include "being/localplayer.h"
33
34
#include "const/resources/currency.h"
35
36
#include "fs/virtfs/fs.h"
37
38
#include "gui/gui.h"
39
#include "gui/mailmessage.h"
40
#include "gui/userpalette.h"
41
#include "gui/windowmanager.h"
42
43
#include "gui/popups/beingpopup.h"
44
#include "gui/popups/itempopup.h"
45
#include "gui/popups/popupmenu.h"
46
#include "gui/popups/skillpopup.h"
47
#include "gui/popups/spellpopup.h"
48
#include "gui/popups/speechbubble.h"
49
#include "gui/popups/statuspopup.h"
50
#include "gui/popups/textboxpopup.h"
51
#include "gui/popups/textpopup.h"
52
53
#include "gui/widgets/desktop.h"
54
#include "gui/widgets/emoteshortcutcontainer.h"
55
#include "gui/widgets/createwidget.h"
56
57
#include "gui/windows/bankwindow.h"
58
#include "gui/windows/buydialog.h"
59
#include "gui/windows/buyingstoreselldialog.h"
60
#include "gui/windows/buyselldialog.h"
61
#include "gui/windows/charselectdialog.h"
62
#include "gui/windows/changeemaildialog.h"
63
#include "gui/windows/changepassworddialog.h"
64
#include "gui/windows/chatwindow.h"
65
#include "gui/windows/connectiondialog.h"
66
#include "gui/windows/confirmdialog.h"
67
#include "gui/windows/cutinwindow.h"
68
#include "gui/windows/debugwindow.h"
69
#include "gui/windows/didyouknowwindow.h"
70
#include "gui/windows/editdialog.h"
71
#include "gui/windows/editserverdialog.h"
72
#include "gui/windows/eggselectiondialog.h"
73
#include "gui/windows/emotewindow.h"
74
#include "gui/windows/equipmentwindow.h"
75
#include "gui/windows/helpwindow.h"
76
#include "gui/windows/insertcarddialog.h"
77
#include "gui/windows/inventorywindow.h"
78
#include "gui/windows/itemamountwindow.h"
79
#include "gui/windows/killstats.h"
80
#include "gui/windows/logindialog.h"
81
#include "gui/windows/maileditwindow.h"
82
#include "gui/windows/mailviewwindow.h"
83
#include "gui/windows/mailwindow.h"
84
#include "gui/windows/minimap.h"
85
#include "gui/windows/ministatuswindow.h"
86
#include "gui/windows/npcdialog.h"
87
#include "gui/windows/npcselldialog.h"
88
#include "gui/windows/okdialog.h"
89
#include "gui/windows/outfitwindow.h"
90
#include "gui/windows/questswindow.h"
91
#include "gui/windows/quitdialog.h"
92
#include "gui/windows/registerdialog.h"
93
#include "gui/windows/serverdialog.h"
94
#include "gui/windows/serverinfowindow.h"
95
#include "gui/windows/setupwindow.h"
96
#include "gui/windows/shopwindow.h"
97
#include "gui/windows/shortcutwindow.h"
98
#include "gui/windows/skilldialog.h"
99
#include "gui/windows/socialwindow.h"
100
#include "gui/windows/statuswindow.h"
101
#include "gui/windows/textcommandeditor.h"
102
#include "gui/windows/textdialog.h"
103
#include "gui/windows/textselectdialog.h"
104
#include "gui/windows/tradewindow.h"
105
#include "gui/windows/updaterwindow.h"
106
#include "gui/windows/whoisonline.h"
107
#include "gui/windows/worldselectdialog.h"
108
109
#include "input/touch/touchmanager.h"
110
111
#include "net/logindata.h"
112
113
#include "net/eathena/charserverhandler.h"
114
#include "net/eathena/inventoryhandler.h"
115
#include "net/eathena/serverfeatures.h"
116
#include "net/eathena/playerhandler.h"
117
118
#include "render/sdlgraphics.h"
119
120
#include "resources/groupinfo.h"
121
#include "resources/sdlimagehelper.h"
122
123
#include "resources/db/groupdb.h"
124
#include "resources/db/unitsdb.h"
125
126
#include "resources/item/item.h"
127
128
#include "resources/map/map.h"
129
130
#include "resources/resourcemanager/resourcemanager.h"
131
132
#include "utils/delete2.h"
133
#include "utils/env.h"
134
#include "utils/gettext.h"
135
136
#include "utils/translation/translationmanager.h"
137
138
#include "debug.h"
139
140
extern QuitDialog *quitDialog;
141
142
140
TEST_CASE("Windows tests", "windowmanager")
143
{
144
136
    setEnv("SDL_VIDEODRIVER", "dummy");
145
146
136
    client = new Client;
147
136
    XML::initXML();
148
136
    SDL_Init(SDL_INIT_VIDEO);
149
136
    ResourceManager::deleteInstance();
150
136
    ResourceManager::cleanOrphans(true);
151

544
    VirtFs::mountDirSilent("data", Append_false);
152

544
    VirtFs::mountDirSilent("../data", Append_false);
153

544
    VirtFs::mountDirSilent("data/test", Append_false);
154

544
    VirtFs::mountDirSilent("../data/test", Append_false);
155
136
    setPathsDefaults(paths);
156

544
    branding.setValue("onlineServerFile", "test/serverlistplus.xml");
157
136
    mainGraphics = new SDLGraphics;
158
272
    imageHelper = new SDLImageHelper;
159
160
136
    Dirs::initRootDir();
161
136
    Dirs::initHomeDir();
162
163
    const std::string cfgName = settings.configDir +
164
272
        "/nonexistserver/config.xml";
165
136
    ::remove(cfgName.c_str());
166
167
136
    ConfigManager::initConfiguration();
168
136
    setConfigDefaults2(config);
169
136
    setBrandingDefaults(branding);
170
136
    setFeaturesDefaults(features);
171

544
    ConfigManager::initServerConfig("nonexistserver");
172
173
#ifdef USE_SDL2
174
    SDLImageHelper::setRenderer(graphicsManager.createRenderer(
175
        graphicsManager.createWindow(640, 480, 0,
176
        SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
177
#else  // USE_SDL2
178
179
136
    graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
180
#endif  // USE_SDL2
181
182

136
    userPalette = new UserPalette;
183

544
    config.setValue("fontSize", 16);
184
185

136
    theme = new Theme;
186
136
    Theme::selectSkin();
187
188
136
    localPlayer = new LocalPlayer(static_cast<BeingId>(1),
189

136
        BeingTypeId_zero);
190
191
136
    ActorSprite::load();
192

136
    gui = new Gui();
193
136
    gui->postInit(mainGraphics);
194
136
    touchManager.init();
195
136
    UnitsDb::load();
196

136
    charServerHandler = new EAthena::CharServerHandler;
197

136
    serverFeatures = new EAthena::ServerFeatures;
198

136
    inventoryHandler = new EAthena::InventoryHandler;
199

136
    playerHandler = new EAthena::PlayerHandler;
200

544
    paths.setValue("itemIcons", "");
201
202
136
    TranslationManager::init();
203
204
272
    mainGraphics->setVideoMode(640, 480,
205
        1,
206
        8,
207
        false,
208
        false,
209
        false,
210
        false,
211
136
        false);
212
213



952
    SECTION("bankWindow")
214
    {
215

2
        CREATEWIDGETV0(bankWindow, BankWindow);
216
2
        gui->draw();
217
2
        mainGraphics->updateScreen();
218
2
        delete2(bankWindow);
219
    }
220



952
    SECTION("buyDialog1")
221
    {
222
        BuyDialog *dialog;
223

2
        CREATEWIDGETV0(dialog, BuyDialog);
224
2
        gui->draw();
225
2
        mainGraphics->updateScreen();
226
2
        delete2(dialog);
227
    }
228



952
    SECTION("buyDialog2")
229
    {
230
        BuyDialog *dialog;
231

2
        CREATEWIDGETV(dialog, BuyDialog,
232
            BeingId_zero,
233
            DEFAULT_CURRENCY);
234
2
        gui->draw();
235
2
        mainGraphics->updateScreen();
236
2
        delete2(dialog);
237
    }
238
#ifdef TMWA_SUPPORT
239



952
    SECTION("buyDialog3")
240
    {
241
        BuyDialog *dialog;
242


8
        CREATEWIDGETV(dialog, BuyDialog,
243
            "user",
244
            DEFAULT_CURRENCY);
245
2
        gui->draw();
246
2
        mainGraphics->updateScreen();
247
2
        delete2(dialog);
248
    }
249
#endif  // TMWA_SUPPORT
250



952
    SECTION("buyDialog4")
251
    {
252
        BuyDialog *dialog;
253
2
        BeingTypeId id = static_cast<BeingTypeId>(1);
254
        Map *map = new Map("test map",
255
            10, 10,
256

8
            32, 32);
257
        Being *being = Being::createBeing(BeingId_zero,
258
            ActorType::Avatar,
259
            id,
260
2
            map);
261

2
        CREATEWIDGETV(dialog, BuyDialog,
262
            being,
263
            DEFAULT_CURRENCY);
264
2
        gui->draw();
265
2
        mainGraphics->updateScreen();
266
2
        delete2(dialog);
267
2
        delete2(being);
268
2
        delete2(map);
269
    }
270



952
    SECTION("BuyingStoreSellDialog")
271
    {
272
        BuyingStoreSellDialog *dialog;
273

2
        CREATEWIDGETV(dialog, BuyingStoreSellDialog,
274
            BeingId_zero, 0);
275
2
        gui->draw();
276
2
        mainGraphics->updateScreen();
277
2
        delete2(dialog);
278
    }
279



952
    SECTION("BuySellDialog1")
280
    {
281
        BuySellDialog *dialog;
282

2
        CREATEWIDGETV(dialog, BuySellDialog, BeingId_zero);
283
2
        gui->draw();
284
2
        mainGraphics->updateScreen();
285
2
        delete2(dialog);
286
    }
287



952
    SECTION("BuySellDialog2")
288
    {
289
        BuySellDialog *dialog;
290


8
        CREATEWIDGETV(dialog, BuySellDialog, "user");
291
2
        gui->draw();
292
2
        mainGraphics->updateScreen();
293
2
        delete2(dialog);
294
    }
295



952
    SECTION("ChangeEmailDialog")
296
    {
297
4
        LoginData data;
298
        ChangeEmailDialog *dialog;
299

2
        CREATEWIDGETV(dialog, ChangeEmailDialog, data);
300
2
        gui->draw();
301
2
        mainGraphics->updateScreen();
302
2
        delete2(dialog);
303
    }
304



952
    SECTION("ChangePasswordDialog")
305
    {
306
4
        LoginData data;
307
        ChangePasswordDialog *dialog;
308

2
        CREATEWIDGETV(dialog, ChangePasswordDialog, data);
309
2
        gui->draw();
310
2
        mainGraphics->updateScreen();
311
2
        delete2(dialog);
312
    }
313



952
    SECTION("CharSelectDialog")
314
    {
315
4
        LoginData data;
316
        CharSelectDialog *dialog;
317

2
        CREATEWIDGETV(dialog, CharSelectDialog, data);
318
2
        gui->draw();
319
2
        mainGraphics->updateScreen();
320
2
        delete2(dialog);
321
    }
322


816
    SECTION("CharCreateDialog")
323
    {
324
//        LoginData data;
325
//        CharSelectDialog *dialog2;
326
//        CREATEWIDGETV(dialog2, CharSelectDialog, data);
327
//        CharCreateDialog *dialog;
328
//        CREATEWIDGETV(dialog, CharCreateDialog, dialog2, 0);
329
//        gui->draw();
330
//        mainGraphics->updateScreen();
331
//        delete2(dialog);
332
//        delete2(dialog2);
333
    }
334



952
    SECTION("ChatWindow")
335
    {
336


8
        CREATEWIDGETV(chatWindow, ChatWindow,
337
            "Chat");
338
2
        gui->draw();
339
2
        mainGraphics->updateScreen();
340
2
        delete2(chatWindow);
341
    }
342



952
    SECTION("ConfirmDialog")
343
    {
344
        ConfirmDialog *dialog;
345


14
        CREATEWIDGETV(dialog, ConfirmDialog,
346
            "", "", SOUND_REQUEST, false, Modal_false, nullptr);
347
2
        gui->draw();
348
2
        mainGraphics->updateScreen();
349
2
        delete2(dialog);
350
    }
351



952
    SECTION("CutinWindow")
352
    {
353

2
        CREATEWIDGETV0(cutInWindow, CutInWindow);
354
2
        gui->draw();
355
2
        mainGraphics->updateScreen();
356
2
        delete2(cutInWindow);
357
    }
358



952
    SECTION("DebugWindow")
359
    {
360


8
        CREATEWIDGETV(debugWindow, DebugWindow,
361
            "Debug");
362
2
        gui->draw();
363
2
        mainGraphics->updateScreen();
364
2
        delete2(debugWindow);
365
    }
366



952
    SECTION("didYouKnowWindow")
367
    {
368

2
        CREATEWIDGETV0(didYouKnowWindow, DidYouKnowWindow);
369
2
        gui->draw();
370
2
        mainGraphics->updateScreen();
371
2
        delete2(didYouKnowWindow);
372
    }
373



952
    SECTION("EditDialog")
374
    {
375
        EditDialog *dialog;
376



20
        CREATEWIDGETV(dialog, EditDialog,
377
            "", "", "", 100, nullptr, Modal_false);
378
2
        gui->draw();
379
2
        mainGraphics->updateScreen();
380
2
        delete2(dialog);
381
    }
382



952
    SECTION("EditServerDialog")
383
    {
384
4
        ServerInfo mCurrentServer;
385

10
        settings.configDir = VirtFs::getRealDir("test/serverlistplus.xml");
386

2
        ServerDialog *serverDialog = CREATEWIDGETR(ServerDialog,
387
            &mCurrentServer,
388
            settings.configDir);
389

2
        EditServerDialog *editServerDialog = CREATEWIDGETR(EditServerDialog,
390
            serverDialog, mCurrentServer, 0);
391
2
        gui->draw();
392
2
        mainGraphics->updateScreen();
393
2
        delete2(editServerDialog);
394
2
        delete2(serverDialog);
395
    }
396



952
    SECTION("EggSelectionDialog")
397
    {
398

2
        EggSelectionDialog *dialog = CREATEWIDGETR0(EggSelectionDialog);
399
2
        gui->draw();
400
2
        mainGraphics->updateScreen();
401
2
        delete2(dialog);
402
    }
403



952
    SECTION("EmoteWindow")
404
    {
405

2
        EmoteWindow *dialog = CREATEWIDGETR0(EmoteWindow);
406
2
        gui->draw();
407
2
        mainGraphics->updateScreen();
408
2
        delete2(dialog);
409
    }
410



952
    SECTION("EquipmentWindow")
411
    {
412
4
        Equipment *equipment = new Equipment;
413

8
        Map *map = new Map("test", 100, 100, 32, 32);
414
        Being *being = Being::createBeing(BeingId_zero,
415
            ActorType::Player,
416
            BeingTypeId_zero,
417
2
            map);
418

2
        EquipmentWindow *dialog = CREATEWIDGETR(EquipmentWindow,
419
            equipment, being, false);
420
2
        gui->draw();
421
2
        mainGraphics->updateScreen();
422
2
        delete2(dialog);
423
2
        delete2(being);
424
2
        delete2(map);
425
2
        delete2(equipment);
426
    }
427



952
    SECTION("helpWindow")
428
    {
429

2
        CREATEWIDGETV0(helpWindow, HelpWindow);
430
2
        gui->draw();
431
2
        mainGraphics->updateScreen();
432
4
        delete2(helpWindow);
433
    }
434



952
    SECTION("InsertCardDialog")
435
    {
436
        Item *item = new Item(5000,
437
            ItemType::Card,
438
            1,
439
            0,
440
            ItemColor_one,
441
            Identified_true,
442
            Damaged_false,
443
            Favorite_false,
444
            Equipm_true,
445

2
            Equipped_false);
446

2
        InsertCardDialog *dialog = CREATEWIDGETR(InsertCardDialog,
447
            0, item);
448
2
        gui->draw();
449
2
        mainGraphics->updateScreen();
450
2
        delete2(dialog);
451
2
        delete2(item);
452
    }
453



952
    SECTION("InventoryWindow")
454
    {
455

2
        Inventory *inventory = new Inventory(InventoryType::Inventory);
456

2
        InventoryWindow *dialog = CREATEWIDGETR(InventoryWindow,
457
            inventory);
458
2
        gui->draw();
459
2
        mainGraphics->updateScreen();
460
2
        delete2(dialog);
461
2
        delete2(inventory);
462
    }
463



952
    SECTION("ItemAmountWindow")
464
    {
465
        Item *item = new Item(5000,
466
            ItemType::Card,
467
            1,
468
            0,
469
            ItemColor_one,
470
            Identified_true,
471
            Damaged_false,
472
            Favorite_false,
473
            Equipm_true,
474

2
            Equipped_false);
475

2
        ItemAmountWindow *dialog = CREATEWIDGETR(ItemAmountWindow,
476
            ItemAmountWindowUsage::ItemDrop, nullptr, item);
477
2
        gui->draw();
478
2
        mainGraphics->updateScreen();
479
2
        delete2(dialog);
480
2
        delete2(item);
481
    }
482



952
    SECTION("KillStats")
483
    {
484

2
        CREATEWIDGETV0(killStats, KillStats);
485
2
        gui->draw();
486
2
        mainGraphics->updateScreen();
487
4
        delete2(killStats);
488
    }
489



952
    SECTION("loginDialog")
490
    {
491
4
        ServerInfo mCurrentServer;
492

2
        LoginDialog *loginDialog = CREATEWIDGETR(LoginDialog,
493
            loginData,
494
            &mCurrentServer,
495
            &settings.options.updateHost);
496
2
        gui->draw();
497
2
        mainGraphics->updateScreen();
498
2
        delete2(loginDialog);
499
    }
500



952
    SECTION("MailEditWindow")
501
    {
502

2
        CREATEWIDGETV0(mailEditWindow, MailEditWindow);
503
2
        gui->draw();
504
2
        mainGraphics->updateScreen();
505
2
        delete2(mailEditWindow);
506
    }
507



952
    SECTION("MailViewWindow")
508
    {
509
4
        MailMessage *message = new MailMessage;
510

2
        CREATEWIDGETV(mailViewWindow, MailViewWindow,
511
            message,
512
            1);
513
2
        gui->draw();
514
2
        mainGraphics->updateScreen();
515
2
        delete2(mailViewWindow);
516
2
        delete message;
517
    }
518



952
    SECTION("MailWindow")
519
    {
520

2
        CREATEWIDGETV0(mailWindow, MailWindow);
521
2
        gui->draw();
522
2
        mainGraphics->updateScreen();
523
2
        delete2(mailWindow);
524
    }
525



952
    SECTION("Minimap")
526
    {
527

2
        CREATEWIDGETV0(minimap, Minimap);
528
2
        gui->draw();
529
2
        mainGraphics->updateScreen();
530
2
        delete2(minimap);
531
    }
532



952
    SECTION("MiniStatusWindow")
533
    {
534

2
        CREATEWIDGETV0(miniStatusWindow, MiniStatusWindow);
535
2
        gui->draw();
536
2
        mainGraphics->updateScreen();
537
2
        delete2(miniStatusWindow);
538
    }
539



952
    SECTION("NpcDialog")
540
    {
541

2
        NpcDialog *dialog = CREATEWIDGETR(NpcDialog, BeingId_zero);
542
2
        gui->draw();
543
2
        mainGraphics->updateScreen();
544
2
        delete2(dialog);
545
    }
546



952
    SECTION("NpcSellDialog")
547
    {
548

2
        NpcSellDialog *dialog = CREATEWIDGETR(NpcSellDialog, BeingId_zero);
549
2
        gui->draw();
550
2
        mainGraphics->updateScreen();
551
2
        delete2(dialog);
552
    }
553



952
    SECTION("OkDialog")
554
    {
555



20
        OkDialog *dialog = CREATEWIDGETR(OkDialog,
556
            "", "", "", DialogType::SILENCE, Modal_false,
557
            ShowCenter_true, nullptr, 100);
558
2
        gui->draw();
559
2
        mainGraphics->updateScreen();
560
2
        delete2(dialog);
561
    }
562



952
    SECTION("OutfitWindow")
563
    {
564

2
        CREATEWIDGETV0(outfitWindow, OutfitWindow);
565
2
        gui->draw();
566
2
        mainGraphics->updateScreen();
567
2
        delete2(outfitWindow);
568
    }
569



952
    SECTION("QuestsWindow")
570
    {
571

2
        CREATEWIDGETV0(questsWindow, QuestsWindow);
572
2
        gui->draw();
573
2
        mainGraphics->updateScreen();
574
2
        delete2(questsWindow);
575
    }
576



952
    SECTION("QuitDialog")
577
    {
578

2
        CREATEWIDGETV(quitDialog, QuitDialog,
579
            &quitDialog);
580
2
        gui->draw();
581
2
        mainGraphics->updateScreen();
582
2
        delete2(quitDialog);
583
    }
584



952
    SECTION("RegisterDialog")
585
    {
586

2
        RegisterDialog *dialog = CREATEWIDGETR(RegisterDialog,
587
            loginData);
588
2
        gui->draw();
589
2
        mainGraphics->updateScreen();
590
2
        delete2(dialog);
591
    }
592



952
    SECTION("serversDialog")
593
    {
594
4
        ServerInfo mCurrentServer;
595

10
        settings.configDir = VirtFs::getRealDir("test/serverlistplus.xml");
596

2
        ServerDialog *serverDialog = CREATEWIDGETR(ServerDialog,
597
            &mCurrentServer,
598
            settings.configDir);
599
2
        gui->draw();
600
2
        mainGraphics->updateScreen();
601
2
        delete2(serverDialog);
602
    }
603



952
    SECTION("serversInfoWindow")
604
    {
605
4
        ServerInfo mCurrentServer;
606

2
        CREATEWIDGETV(serverInfoWindow, ServerInfoWindow,
607
            mCurrentServer);
608
2
        gui->draw();
609
2
        mainGraphics->updateScreen();
610
2
        delete2(serverInfoWindow);
611
    }
612



952
    SECTION("setupWindow")
613
    {
614

2
        CREATEWIDGETV0(setupWindow, SetupWindow);
615
2
        gui->draw();
616
2
        mainGraphics->updateScreen();
617
2
        delete2(setupWindow);
618
    }
619


816
    SECTION("ShopSellDialog")
620
    {
621
        // only tmwa skipping
622
    }
623



952
    SECTION("ShopWindow")
624
    {
625

2
        CREATEWIDGETV0(shopWindow, ShopWindow);
626
2
        gui->draw();
627
2
        mainGraphics->updateScreen();
628
2
        delete2(shopWindow);
629
    }
630



952
    SECTION("ShortcutWindow1")
631
    {
632
        EmoteShortcutContainer *container =
633

2
            new EmoteShortcutContainer(nullptr);
634


14
        CREATEWIDGETV(itemShortcutWindow, ShortcutWindow,
635
            "name",
636
            container);
637
2
        gui->draw();
638
2
        mainGraphics->updateScreen();
639
2
        delete2(itemShortcutWindow);
640
    }
641



952
    SECTION("ShortcutWindow2")
642
    {
643


14
        CREATEWIDGETV(itemShortcutWindow, ShortcutWindow, "");
644
2
        gui->draw();
645
2
        mainGraphics->updateScreen();
646
2
        delete2(itemShortcutWindow);
647
    }
648



952
    SECTION("SkillDialog")
649
    {
650

2
        CREATEWIDGETV0(skillDialog, SkillDialog);
651
2
        gui->draw();
652
2
        mainGraphics->updateScreen();
653
2
        delete2(skillDialog);
654
    }
655



952
    SECTION("SocialWindow")
656
    {
657

2
        CREATEWIDGETV0(socialWindow, SocialWindow);
658
2
        gui->draw();
659
2
        mainGraphics->updateScreen();
660
2
        delete2(socialWindow);
661
    }
662



952
    SECTION("StatusWindow")
663
    {
664
2
        GroupDb::GroupInfos &groups = GroupDb::getGroups();
665

2
        groups[0] = new GroupInfo;
666
4
        groups[0]->name = std::string();
667
4
        groups[0]->longName = std::string();
668

2
        CREATEWIDGETV0(statusWindow, StatusWindow);
669
2
        gui->draw();
670
2
        mainGraphics->updateScreen();
671
2
        delete2(statusWindow);
672

2
        delete groups[0];
673
        groups.clear();
674
    }
675



952
    SECTION("TextCommandEditor")
676
    {
677
        TextCommand *textCommand = new TextCommand(1, "", "", "",
678



26
            CommandTarget::NoTarget, "");
679

2
        TextCommandEditor *dialog = CREATEWIDGETR(TextCommandEditor,
680
            textCommand);
681
2
        gui->draw();
682
2
        mainGraphics->updateScreen();
683
2
        delete2(dialog);
684
2
        delete2(textCommand);
685
    }
686
687



952
    SECTION("TextDialog")
688
    {
689


14
        TextDialog *dialog = CREATEWIDGETR(TextDialog,
690
            "", "", nullptr, false);
691
2
        gui->draw();
692
2
        mainGraphics->updateScreen();
693
2
        delete2(dialog);
694
    }
695



952
    SECTION("TextSelectDialog")
696
    {
697


14
        TextSelectDialog *dialog = CREATEWIDGETR(TextSelectDialog,
698
            "", "", AllowQuit_false);
699
2
        gui->draw();
700
2
        mainGraphics->updateScreen();
701
2
        delete2(dialog);
702
    }
703



952
    SECTION("TradeWindow")
704
    {
705

2
        CREATEWIDGETV0(tradeWindow, TradeWindow);
706
2
        gui->draw();
707
2
        mainGraphics->updateScreen();
708
2
        delete2(tradeWindow);
709
    }
710



952
    SECTION("UpdaterWindow")
711
    {
712


14
        CREATEWIDGETV(updaterWindow, UpdaterWindow,
713
            "", "", false, UpdateType::Skip);
714
2
        gui->draw();
715
2
        mainGraphics->updateScreen();
716
2
        delete2(updaterWindow);
717
    }
718



952
    SECTION("WhoIsOnline")
719
    {
720

2
        CREATEWIDGETV0(whoIsOnline, WhoIsOnline);
721
2
        gui->draw();
722
2
        mainGraphics->updateScreen();
723
2
        delete2(whoIsOnline);
724
    }
725



952
    SECTION("WorldSelectDialog")
726
    {
727
4
        Worlds worlds;
728

2
        WorldSelectDialog *dialog = CREATEWIDGETR(WorldSelectDialog,
729
            worlds);
730
2
        gui->draw();
731
2
        mainGraphics->updateScreen();
732
2
        delete2(dialog);
733
    }
734



952
    SECTION("popupMenu")
735
    {
736

2
        CREATEWIDGETV0(popupMenu, PopupMenu);
737
2
        gui->draw();
738
2
        mainGraphics->updateScreen();
739
4
        delete2(popupMenu);
740
    }
741



952
    SECTION("skillPopup")
742
    {
743

2
        CREATEWIDGETV0(skillPopup, SkillPopup);
744
2
        gui->draw();
745
2
        mainGraphics->updateScreen();
746
2
        delete2(skillPopup);
747
    }
748



952
    SECTION("SpeechBubble")
749
    {
750

2
        SpeechBubble *bubble = CREATEWIDGETR0(SpeechBubble);
751
2
        gui->draw();
752
2
        mainGraphics->updateScreen();
753
2
        delete2(bubble);
754
    }
755



952
    SECTION("beingPopup")
756
    {
757

2
        CREATEWIDGETV0(beingPopup, BeingPopup);
758
2
        gui->draw();
759
2
        mainGraphics->updateScreen();
760
2
        delete2(beingPopup);
761
    }
762



952
    SECTION("textPopup")
763
    {
764

2
        CREATEWIDGETV0(textPopup, TextPopup);
765
2
        gui->draw();
766
2
        mainGraphics->updateScreen();
767
2
        delete2(textPopup);
768
    }
769



952
    SECTION("textBoxPopup")
770
    {
771

2
        CREATEWIDGETV0(textBoxPopup, TextBoxPopup);
772
2
        gui->draw();
773
2
        mainGraphics->updateScreen();
774
2
        delete2(textBoxPopup);
775
    }
776



952
    SECTION("itemPopup")
777
    {
778

2
        CREATEWIDGETV0(itemPopup, ItemPopup);
779
2
        gui->draw();
780
2
        mainGraphics->updateScreen();
781
2
        delete2(itemPopup);
782
    }
783



952
    SECTION("spellPopup")
784
    {
785

2
        CREATEWIDGETV0(spellPopup, SpellPopup);
786
2
        gui->draw();
787
2
        mainGraphics->updateScreen();
788
2
        delete2(spellPopup);
789
    }
790



952
    SECTION("StatusPopup")
791
    {
792

2
        StatusPopup *status = CREATEWIDGETR0(StatusPopup);
793
2
        gui->draw();
794
2
        mainGraphics->updateScreen();
795
2
        delete2(status);
796
    }
797



952
    SECTION("desktop")
798
    {
799

2
        CREATEWIDGETV(desktop, Desktop, nullptr);
800
2
        gui->draw();
801
2
        mainGraphics->updateScreen();
802
2
        delete2(desktop);
803
    }
804



952
    SECTION("connectionDialog")
805
    {
806


8
        ConnectionDialog *connectionDialog = CREATEWIDGETR(ConnectionDialog,
807
            // TRANSLATORS: connection dialog header
808
            _("Logging in"),
809
            State::SWITCH_SERVER);
810
2
        gui->draw();
811
2
        mainGraphics->updateScreen();
812
2
        delete2(connectionDialog);
813
    }
814
815
136
    UnitsDb::unload();
816
136
    delete2(localPlayer);
817
136
    delete2(userPalette);
818
136
    delete2(client);
819
136
    delete2(serverFeatures);
820
136
    delete2(inventoryHandler);
821
136
    delete2(charServerHandler);
822
136
    delete2(playerHandler);
823
136
    delete2(gui);
824
136
    ResourceManager::deleteInstance();
825

544
    VirtFs::unmountDirSilent("data");
826

544
    VirtFs::unmountDirSilent("../data");
827

544
    VirtFs::unmountDirSilent("data/test");
828

544
    VirtFs::unmountDirSilent("../data/test");
829
136
}
830
831
20
TEST_CASE("WindowManager", "create windows")
832
{
833
16
    setEnv("SDL_VIDEODRIVER", "dummy");
834
835
16
    client = new Client;
836
16
    XML::initXML();
837
16
    SDL_Init(SDL_INIT_VIDEO);
838
16
    ResourceManager::deleteInstance();
839
16
    ResourceManager::cleanOrphans(true);
840

64
    VirtFs::mountDirSilent("data", Append_false);
841

64
    VirtFs::mountDirSilent("../data", Append_false);
842

64
    VirtFs::mountDirSilent("data/test", Append_false);
843

64
    VirtFs::mountDirSilent("../data/test", Append_false);
844
16
    setPathsDefaults(paths);
845

64
    branding.setValue("onlineServerFile", "test/serverlistplus.xml");
846
16
    mainGraphics = new SDLGraphics;
847
32
    imageHelper = new SDLImageHelper;
848
849
16
    Dirs::initRootDir();
850
16
    Dirs::initHomeDir();
851
852
    const std::string cfgName = settings.configDir +
853
32
        "/nonexistserver/config.xml";
854
16
    ::remove(cfgName.c_str());
855
856
16
    ConfigManager::initConfiguration();
857
16
    setConfigDefaults2(config);
858
16
    setBrandingDefaults(branding);
859

64
    ConfigManager::initServerConfig("nonexistserver");
860
861
#ifdef USE_SDL2
862
    SDLImageHelper::setRenderer(graphicsManager.createRenderer(
863
        graphicsManager.createWindow(640, 480, 0,
864
        SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
865
#else  // USE_SDL2
866
867
16
    graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
868
#endif  // USE_SDL2
869
870

64
    config.setValue("fontSize", 16);
871
872

16
    theme = new Theme;
873
16
    Theme::selectSkin();
874
875
16
    localPlayer = new LocalPlayer(static_cast<BeingId>(1),
876

16
        BeingTypeId_zero);
877
878
16
    ActorSprite::load();
879

16
    gui = new Gui();
880
16
    gui->postInit(mainGraphics);
881
16
    touchManager.init();
882
16
    UnitsDb::load();
883

16
    charServerHandler = new EAthena::CharServerHandler;
884

16
    serverFeatures = new EAthena::ServerFeatures;
885

16
    inventoryHandler = new EAthena::InventoryHandler;
886

16
    playerHandler = new EAthena::PlayerHandler;
887

64
    paths.setValue("itemIcons", "");
888
889
16
    TranslationManager::init();
890
891
32
    mainGraphics->setVideoMode(640, 480,
892
        1,
893
        8,
894
        false,
895
        false,
896
        false,
897
        false,
898
16
        false);
899
900



112
    SECTION("create windows")
901
    {
902
2
        WindowManager::createWindows();
903
2
        WindowManager::deleteWindows();
904
    }
905
906



112
    SECTION("init")
907
    {
908
2
        WindowManager::init();
909
    }
910
911



112
    SECTION("initTitle")
912
    {
913
2
        WindowManager::initTitle();
914





20
        REQUIRE(settings.windowCaption == strprintf("%s %s",
915
            branding.getStringValue("appName").c_str(),
916
            SMALL_VERSION));
917
    }
918
919



112
    SECTION("updateTitle1")
920
    {
921
4
        settings.serverName = std::string();
922
4
        settings.login = std::string();
923
2
        WindowManager::updateTitle();
924





20
        REQUIRE(settings.windowCaption == strprintf("%s %s",
925
            branding.getStringValue("appName").c_str(),
926
            SMALL_VERSION));
927
    }
928
929



112
    SECTION("updateTitle2")
930
    {
931
2
        settings.serverName = "server";
932
4
        settings.login = std::string();
933
2
        WindowManager::updateTitle();
934





22
        REQUIRE(settings.windowCaption == strprintf("%s %s - %s",
935
            branding.getStringValue("appName").c_str(),
936
            SMALL_VERSION,
937
            settings.serverName.c_str()));
938
    }
939
940



112
    SECTION("updateTitle3")
941
    {
942
2
        settings.serverName = "server";
943
2
        settings.login = "login";
944
2
        WindowManager::updateTitle();
945





24
        REQUIRE(settings.windowCaption == strprintf("%s %s - %s %s",
946
            branding.getStringValue("appName").c_str(),
947
            SMALL_VERSION,
948
            settings.login.c_str(),
949
            settings.serverName.c_str()));
950
    }
951
952



112
    SECTION("setFramerate1")
953
    {
954
2
        settings.limitFps = true;
955
2
        WindowManager::setFramerate(60);
956




8
        REQUIRE(WindowManager::getFramerate() == 60);
957
2
        WindowManager::setFramerate(10);
958




8
        REQUIRE(WindowManager::getFramerate() == 10);
959
2
        WindowManager::setFramerate(0);
960




8
        REQUIRE(WindowManager::getFramerate() == 10);
961
    }
962
963



112
    SECTION("setFramerate2")
964
    {
965
2
        settings.limitFps = false;
966
2
        WindowManager::setFramerate(60);
967




8
        REQUIRE(WindowManager::getFramerate() == 0);
968
2
        WindowManager::setFramerate(10);
969




8
        REQUIRE(WindowManager::getFramerate() == 0);
970
2
        WindowManager::setFramerate(0);
971




8
        REQUIRE(WindowManager::getFramerate() == 0);
972
    }
973
974
32
    settings.serverName = std::string();
975
32
    settings.login = std::string();
976
16
    settings.limitFps = true;
977
978
16
    UnitsDb::unload();
979
16
    delete2(localPlayer);
980
16
    delete2(client);
981
16
    delete2(serverFeatures);
982
16
    delete2(inventoryHandler);
983
16
    delete2(charServerHandler);
984
16
    delete2(playerHandler);
985
16
    delete2(gui);
986
16
    ResourceManager::deleteInstance();
987

64
    VirtFs::unmountDirSilent("data");
988

64
    VirtFs::unmountDirSilent("../data");
989

64
    VirtFs::unmountDirSilent("data/test");
990

64
    VirtFs::unmountDirSilent("../data/test");
991

22
}