GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/gui/windowmanager.cc Lines: 533 533 100.0 %
Date: 2018-05-23 22:10:27 Branches: 1177 2244 52.5 %

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
142
TEST_CASE("Windows tests", "windowmanager")
146
{
147
138
    setEnv("SDL_VIDEODRIVER", "dummy");
148
149
138
    client = new Client;
150
138
    XML::initXML();
151
138
    SDL_Init(SDL_INIT_VIDEO);
152
138
    ResourceManager::deleteInstance();
153
138
    ResourceManager::cleanOrphans(true);
154

552
    VirtFs::mountDirSilent("data", Append_false);
155

552
    VirtFs::mountDirSilent("../data", Append_false);
156

552
    VirtFs::mountDirSilent("data/test", Append_false);
157

552
    VirtFs::mountDirSilent("../data/test", Append_false);
158
138
    setPathsDefaults(paths);
159

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

552
    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
138
    graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
183
#endif  // USE_SDL2
184
185

138
    userPalette = new UserPalette;
186

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

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

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

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

138
    charServerHandler = new EAthena::CharServerHandler;
200

138
    serverFeatures = new EAthena::ServerFeatures;
201

138
    inventoryHandler = new EAthena::InventoryHandler;
202

138
    playerHandler = new EAthena::PlayerHandler;
203

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



966
    SECTION("bankWindow")
217
    {
218

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



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

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



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

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



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


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



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

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

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



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

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



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

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



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


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



966
    SECTION("ChangeEmailDialog")
299
    {
300
4
        LoginData data;
301
        ChangeEmailDialog *dialog;
302

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



966
    SECTION("ChangePasswordDialog")
308
    {
309
4
        LoginData data;
310
        ChangePasswordDialog *dialog;
311

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



966
    SECTION("CharSelectDialog")
317
    {
318
4
        LoginData data;
319
        CharSelectDialog *dialog;
320

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


828
    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



966
    SECTION("ChatWindow")
340
    {
341


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



966
    SECTION("ClanWindow")
348
    {
349

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



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


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



966
    SECTION("CutinWindow")
364
    {
365

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



966
    SECTION("DebugWindow")
371
    {
372


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



966
    SECTION("didYouKnowWindow")
379
    {
380

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



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



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



966
    SECTION("EditServerDialog")
395
    {
396
4
        ServerInfo mCurrentServer;
397

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

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

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



966
    SECTION("EggSelectionDialog")
409
    {
410

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



966
    SECTION("EmoteWindow")
416
    {
417

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



966
    SECTION("EquipmentWindow")
423
    {
424
4
        Equipment *equipment = new Equipment;
425

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

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



966
    SECTION("helpWindow")
440
    {
441

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



966
    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

2
            Equipped_false);
458

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



966
    SECTION("InventoryWindow")
466
    {
467

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

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



966
    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

2
            Equipped_false);
487

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



966
    SECTION("KillStats")
498
    {
499

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



966
    SECTION("loginDialog")
505
    {
506
4
        ServerInfo mCurrentServer;
507

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



966
    SECTION("MailEditWindow")
516
    {
517

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



966
    SECTION("MailViewWindow")
523
    {
524
4
        MailMessage *message = new MailMessage;
525

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



966
    SECTION("MailWindow")
534
    {
535

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



966
    SECTION("Minimap")
541
    {
542

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



966
    SECTION("MiniStatusWindow")
548
    {
549

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



966
    SECTION("NpcDialog")
555
    {
556

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



966
    SECTION("NpcSellDialog")
562
    {
563

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



966
    SECTION("OkDialog")
569
    {
570



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



966
    SECTION("OutfitWindow")
578
    {
579

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



966
    SECTION("QuestsWindow")
585
    {
586

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



966
    SECTION("QuitDialog")
592
    {
593

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



966
    SECTION("RegisterDialog")
600
    {
601

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



966
    SECTION("serversDialog")
608
    {
609
4
        ServerInfo mCurrentServer;
610

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

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



966
    SECTION("serversInfoWindow")
619
    {
620
4
        ServerInfo mCurrentServer;
621

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



966
    SECTION("setupWindow")
628
    {
629

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


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



966
    SECTION("ShopWindow")
639
    {
640

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



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

2
            new EmoteShortcutContainer(nullptr);
649


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



966
    SECTION("ShortcutWindow2")
660
    {
661


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



966
    SECTION("SkillDialog")
671
    {
672

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



966
    SECTION("SocialWindow")
678
    {
679

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



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

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

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

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



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



26
            CommandTarget::NoTarget, "");
701

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



966
    SECTION("TextDialog")
710
    {
711


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



966
    SECTION("TextSelectDialog")
718
    {
719


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



966
    SECTION("TradeWindow")
726
    {
727

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



966
    SECTION("UpdaterWindow")
733
    {
734


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



966
    SECTION("WhoIsOnline")
741
    {
742

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



966
    SECTION("WorldSelectDialog")
748
    {
749
4
        Worlds worlds;
750

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



966
    SECTION("popupMenu")
757
    {
758

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



966
    SECTION("skillPopup")
764
    {
765

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



966
    SECTION("SpeechBubble")
771
    {
772

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



966
    SECTION("beingPopup")
778
    {
779

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



966
    SECTION("textPopup")
785
    {
786

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



966
    SECTION("textBoxPopup")
792
    {
793

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



966
    SECTION("itemPopup")
799
    {
800

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



966
    SECTION("spellPopup")
806
    {
807

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



966
    SECTION("StatusPopup")
813
    {
814

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



966
    SECTION("desktop")
820
    {
821

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



966
    SECTION("connectionDialog")
827
    {
828


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

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

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

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

552
    VirtFs::unmountDirSilent("../data/test");
851
138
}
852
853
20
TEST_CASE("WindowManager", "create windows")
854
{
855
16
    setEnv("SDL_VIDEODRIVER", "dummy");
856
857
16
    client = new Client;
858
16
    XML::initXML();
859
16
    SDL_Init(SDL_INIT_VIDEO);
860
16
    ResourceManager::deleteInstance();
861
16
    ResourceManager::cleanOrphans(true);
862

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

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

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

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

64
    branding.setValue("onlineServerFile", "test/serverlistplus.xml");
868
16
    mainGraphics = new SDLGraphics;
869
32
    imageHelper = new SDLImageHelper;
870
871
16
    Dirs::initRootDir();
872
16
    Dirs::initHomeDir();
873
874
    const std::string cfgName = settings.configDir +
875
32
        "/nonexistserver/config.xml";
876
16
    ::remove(cfgName.c_str());
877
878
16
    ConfigManager::initConfiguration();
879
16
    setConfigDefaults2(config);
880
16
    setBrandingDefaults(branding);
881

64
    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
16
    graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
890
#endif  // USE_SDL2
891
892

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

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

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

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

16
    charServerHandler = new EAthena::CharServerHandler;
906

16
    serverFeatures = new EAthena::ServerFeatures;
907

16
    inventoryHandler = new EAthena::InventoryHandler;
908

16
    playerHandler = new EAthena::PlayerHandler;
909

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



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



112
    SECTION("init")
929
    {
930
2
        WindowManager::init();
931
    }
932
933



112
    SECTION("initTitle")
934
    {
935
2
        WindowManager::initTitle();
936





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



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





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



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





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



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





24
        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



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




8
        REQUIRE(WindowManager::getFramerate() == 60);
979
2
        WindowManager::setFramerate(10);
980




8
        REQUIRE(WindowManager::getFramerate() == 10);
981
2
        WindowManager::setFramerate(0);
982




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



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




8
        REQUIRE(WindowManager::getFramerate() == 0);
990
2
        WindowManager::setFramerate(10);
991




8
        REQUIRE(WindowManager::getFramerate() == 0);
992
2
        WindowManager::setFramerate(0);
993




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

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

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

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

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

22
}