GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/gui/windowmanager.cc Lines: 545 545 100.0 %
Date: 2018-09-20 Branches: 1208 2306 52.4 %

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

276
    ConfigManager::initServerConfig("nonexistserver");
175
176
#ifdef USE_SDL2
177
    SDLImageHelper::setRenderer(graphicsManager.createRenderer(
178
        graphicsManager.createWindow(640, 480, 0,
179
        SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
180
#else  // USE_SDL2
181
182
69
    graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
183
#endif  // USE_SDL2
184
185

69
    userPalette = new UserPalette;
186

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

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

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

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

69
    charServerHandler = new EAthena::CharServerHandler;
200

69
    serverFeatures = new EAthena::ServerFeatures;
201

69
    inventoryHandler = new EAthena::InventoryHandler;
202

69
    playerHandler = new EAthena::PlayerHandler;
203

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



483
    SECTION("bankWindow")
217
    {
218

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



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

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



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

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



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

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



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

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

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



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

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



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

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



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


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



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

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



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

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



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

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


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



483
    SECTION("ChatWindow")
340
    {
341

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



483
    SECTION("ClanWindow")
348
    {
349

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



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


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



483
    SECTION("CutinWindow")
364
    {
365

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



483
    SECTION("DebugWindow")
371
    {
372

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



483
    SECTION("didYouKnowWindow")
379
    {
380

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



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


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



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

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

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

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



483
    SECTION("EggSelectionDialog")
409
    {
410

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



483
    SECTION("EmoteWindow")
416
    {
417

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



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

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

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



483
    SECTION("helpWindow")
440
    {
441

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



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

1
            Equipped_false);
458

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



483
    SECTION("InventoryWindow")
466
    {
467

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

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



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

1
            Equipped_false);
487

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



483
    SECTION("KillStats")
498
    {
499

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



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

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



483
    SECTION("MailEditWindow")
516
    {
517

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



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

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



483
    SECTION("MailWindow")
534
    {
535

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



483
    SECTION("Minimap")
541
    {
542

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



483
    SECTION("MiniStatusWindow")
548
    {
549

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



483
    SECTION("NpcDialog")
555
    {
556

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



483
    SECTION("NpcSellDialog")
562
    {
563

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



483
    SECTION("OkDialog")
569
    {
570



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



483
    SECTION("OutfitWindow")
578
    {
579

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



483
    SECTION("QuestsWindow")
585
    {
586

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



483
    SECTION("QuitDialog")
592
    {
593

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



483
    SECTION("RegisterDialog")
600
    {
601

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



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

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

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



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

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



483
    SECTION("setupWindow")
628
    {
629

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


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



483
    SECTION("ShopWindow")
639
    {
640

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



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

1
            new EmoteShortcutContainer(nullptr);
649


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



483
    SECTION("ShortcutWindow2")
660
    {
661

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



483
    SECTION("SkillDialog")
671
    {
672

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



483
    SECTION("SocialWindow")
678
    {
679

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



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

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

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

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



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



13
            CommandTarget::NoTarget, "");
701

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



483
    SECTION("TextDialog")
710
    {
711


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



483
    SECTION("TextSelectDialog")
718
    {
719


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



483
    SECTION("TradeWindow")
726
    {
727

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



483
    SECTION("UpdaterWindow")
733
    {
734


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



483
    SECTION("WhoIsOnline")
741
    {
742

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



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

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



483
    SECTION("popupMenu")
757
    {
758

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



483
    SECTION("skillPopup")
764
    {
765

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



483
    SECTION("SpeechBubble")
771
    {
772

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



483
    SECTION("beingPopup")
778
    {
779

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



483
    SECTION("textPopup")
785
    {
786

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



483
    SECTION("textBoxPopup")
792
    {
793

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



483
    SECTION("itemPopup")
799
    {
800

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



483
    SECTION("spellPopup")
806
    {
807

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



483
    SECTION("StatusPopup")
813
    {
814

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



483
    SECTION("desktop")
820
    {
821

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



483
    SECTION("connectionDialog")
827
    {
828


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

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

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

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

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

32
    ConfigManager::initServerConfig("nonexistserver");
882
883
#ifdef USE_SDL2
884
    SDLImageHelper::setRenderer(graphicsManager.createRenderer(
885
        graphicsManager.createWindow(640, 480, 0,
886
        SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
887
#else  // USE_SDL2
888
889
8
    graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
890
#endif  // USE_SDL2
891
892

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

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

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

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

8
    charServerHandler = new EAthena::CharServerHandler;
906

8
    serverFeatures = new EAthena::ServerFeatures;
907

8
    inventoryHandler = new EAthena::InventoryHandler;
908

8
    playerHandler = new EAthena::PlayerHandler;
909

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



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



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



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





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



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





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



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





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



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





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



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




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




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




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



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




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




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




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

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

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

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

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

11
}