GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/utils/translation/poparser.cc Lines: 53 53 100.0 %
Date: 2017-11-29 Branches: 128 302 42.4 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2016-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 "configuration.h"
25
#include "configmanager.h"
26
#include "dirs.h"
27
#include "graphicsmanager.h"
28
29
#include "being/actorsprite.h"
30
31
#include "fs/virtfs/fs.h"
32
33
#include "gui/gui.h"
34
#include "gui/theme.h"
35
36
#include "utils/delete2.h"
37
#include "utils/env.h"
38
39
#include "utils/translation/podict.h"
40
#include "utils/translation/poparser.h"
41
42
#include "render/sdlgraphics.h"
43
44
#include "resources/sdlimagehelper.h"
45
46
#include "debug.h"
47
48
10
TEST_CASE("PoParser tests", "PoParser")
49
{
50
6
    setEnv("SDL_VIDEODRIVER", "dummy");
51
52
6
    client = new Client;
53

24
    VirtFs::mountDirSilent("data", Append_false);
54

24
    VirtFs::mountDirSilent("../data", Append_false);
55
56
6
    mainGraphics = new SDLGraphics;
57
12
    imageHelper = new SDLImageHelper();
58
59
6
    Dirs::initRootDir();
60
6
    Dirs::initHomeDir();
61
62
6
    ConfigManager::initConfiguration();
63
6
    setConfigDefaults2(config);
64
6
    setBrandingDefaults(branding);
65
66
#ifdef USE_SDL2
67
    SDLImageHelper::setRenderer(graphicsManager.createRenderer(
68
        graphicsManager.createWindow(640, 480, 0,
69
        SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
70
#else  // USE_SDL2
71
72
6
    graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
73
#endif  // USE_SDL2
74
75
6
    theme = new Theme;
76
6
    Theme::selectSkin();
77
78
6
    ActorSprite::load();
79
6
    gui = new Gui();
80
6
    gui->postInit(mainGraphics);
81
82



42
    SECTION("PoParser empty")
83
    {
84

2
        PoParser *parser = new PoParser;
85

14
        PoDict *dict = parser->load("ru",
86
            "unknownfilename.po",
87
2
            nullptr);
88
89



8
        REQUIRE(dict != nullptr);
90



10
        REQUIRE(dict->getMap() != nullptr);
91



8
        REQUIRE(dict->getMap()->empty());
92
93
2
        delete parser;
94
2
        delete dict;
95
    }
96
97



42
    SECTION("PoParser normal")
98
    {
99

2
        PoParser *parser = new PoParser;
100

14
        PoDict *dict = parser->load("ru",
101
            "test/test1",
102
2
            nullptr);
103
104



8
        REQUIRE(dict != nullptr);
105



10
        REQUIRE(dict->getMap() != nullptr);
106



10
        REQUIRE(dict->getMap()->size() == 1786);
107




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




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




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



42
    SECTION("PoParser fuzzy")
119
    {
120

2
        PoParser *parser = new PoParser;
121

14
        PoDict *dict = parser->load("ru",
122
            "test/test1",
123
2
            nullptr);
124
125



8
        REQUIRE(dict != nullptr);
126



10
        REQUIRE(dict->getMap() != nullptr);
127



10
        REQUIRE(dict->getMap()->size() == 1786);
128




16
        REQUIRE(dict->getStr("Atk +100%.") == "Atk +100%.");
129
130
2
        delete parser;
131
2
        delete dict;
132
    }
133
6
    delete2(client);
134

24
    VirtFs::unmountDirSilent("data");
135

24
    VirtFs::unmountDirSilent("../data");
136

12
}