GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/utils/translation/poparser.cc Lines: 54 54 100.0 %
Date: 2021-03-17 Branches: 127 300 42.3 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2016-2019  The ManaPlus Developers
4
 *  Copyright (C) 2019-2021  Andrei Karas
5
 *
6
 *  This file is part of The ManaPlus Client.
7
 *
8
 *  This program is free software; you can redistribute it and/or modify
9
 *  it under the terms of the GNU General Public License as published by
10
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  any later version.
12
 *
13
 *  This program is distributed in the hope that it will be useful,
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *  GNU General Public License for more details.
17
 *
18
 *  You should have received a copy of the GNU General Public License
19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
#include "unittests/unittests.h"
23
24
#include "client.h"
25
#include "configuration.h"
26
#include "configmanager.h"
27
#include "dirs.h"
28
#include "graphicsmanager.h"
29
30
#include "being/actorsprite.h"
31
32
#include "fs/virtfs/fs.h"
33
34
#include "gui/gui.h"
35
#include "gui/theme.h"
36
37
#include "utils/delete2.h"
38
#include "utils/env.h"
39
40
#include "utils/translation/podict.h"
41
#include "utils/translation/poparser.h"
42
43
#include "render/sdlgraphics.h"
44
45
#include "resources/sdlimagehelper.h"
46
47
#include "debug.h"
48
49
5
TEST_CASE("PoParser tests", "PoParser")
50
{
51
3
    setEnv("SDL_VIDEODRIVER", "dummy");
52
53
3
    client = new Client;
54
9
    VirtFs::mountDirSilent("data", Append_false);
55
9
    VirtFs::mountDirSilent("../data", Append_false);
56
57
3
    mainGraphics = new SDLGraphics;
58
6
    imageHelper = new SDLImageHelper();
59
60
3
    Dirs::initRootDir();
61
3
    Dirs::initHomeDir();
62
63
3
    ConfigManager::initConfiguration();
64
3
    setConfigDefaults2(config);
65
3
    setBrandingDefaults(branding);
66
67
#ifdef USE_SDL2
68
3
    SDLImageHelper::setRenderer(graphicsManager.createRenderer(
69
        GraphicsManager::createWindow(640, 480, 0,
70
3
        SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
71
#else  // USE_SDL2
72
73
    GraphicsManager::createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
74
#endif  // USE_SDL2
75
76
3
    theme = new Theme;
77
3
    Theme::selectSkin();
78
79
3
    ActorSprite::load();
80
3
    gui = new Gui();
81
3
    gui->postInit(mainGraphics);
82
83



21
    SECTION("PoParser empty")
84
    {
85

1
        PoParser *parser = new PoParser;
86

6
        PoDict *dict = parser->load("ru",
87
            "unknownfilename.po",
88
1
            nullptr);
89
90



4
        REQUIRE(dict != nullptr);
91



5
        REQUIRE(dict->getMap() != nullptr);
92



4
        REQUIRE(dict->getMap()->empty());
93
94
1
        delete parser;
95
1
        delete dict;
96
    }
97
98



21
    SECTION("PoParser normal")
99
    {
100

1
        PoParser *parser = new PoParser;
101

6
        PoDict *dict = parser->load("ru",
102
            "test/test1",
103
1
            nullptr);
104
105



4
        REQUIRE(dict != nullptr);
106



5
        REQUIRE(dict->getMap() != nullptr);
107



5
        REQUIRE(dict->getMap()->size() == 1786);
108




8
        REQUIRE(dict->getStr("Unknown skill message.") ==
109
            "Неизвестная ошибка скилов.");
110




8
        REQUIRE(dict->getStr("Full strip failed because of coating.") ==
111
            "Full strip failed because of coating.");
112




8
        REQUIRE(dict->getStr("You picked up %d [@@%d|%s@@].") ==
113
            "Вы подняли %d [@@%d|%s@@].");
114
115
1
        delete parser;
116
1
        delete dict;
117
    }
118
119



21
    SECTION("PoParser fuzzy")
120
    {
121

1
        PoParser *parser = new PoParser;
122

6
        PoDict *dict = parser->load("ru",
123
            "test/test1",
124
1
            nullptr);
125
126



4
        REQUIRE(dict != nullptr);
127



5
        REQUIRE(dict->getMap() != nullptr);
128



5
        REQUIRE(dict->getMap()->size() == 1786);
129




8
        REQUIRE(dict->getStr("Atk +100%.") == "Atk +100%.");
130
131
1
        delete parser;
132
1
        delete dict;
133
    }
134
3
    delete2(client)
135
9
    VirtFs::unmountDirSilent("data");
136
9
    VirtFs::unmountDirSilent("../data");
137

6
}