GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/utils/langs.cc Lines: 62 62 100.0 %
Date: 2018-07-14 Branches: 170 452 37.6 %

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 "configuration.h"
24
25
#include "utils/env.h"
26
#include "utils/langs.h"
27
28
#include "debug.h"
29
30
3
TEST_CASE("Langs getLang", "")
31
{
32
2
    LangVect langs;
33
34

3
    config.setValue("lang", "C");
35
2
    langs = getLang();
36



5
    REQUIRE(langs.size() == 1);
37



4
    REQUIRE(langs[0] == "C");
38
39

3
    config.setValue("lang", "ru_RU");
40
2
    langs = getLang();
41



5
    REQUIRE(langs.size() == 2);
42



4
    REQUIRE(langs[0] == "ru_RU");
43



5
    REQUIRE(langs[1] == "ru");
44
45

3
    config.setValue("lang", "ru_RU.UTF-8");
46
2
    langs = getLang();
47



5
    REQUIRE(langs.size() == 2);
48



4
    REQUIRE(langs[0] == "ru_RU");
49



5
    REQUIRE(langs[1] == "ru");
50
51

3
    config.setValue("lang", "");
52
53
1
    setEnv("LANG", "C");
54
2
    langs = getLang();
55



5
    REQUIRE(langs.size() == 1);
56



4
    REQUIRE(langs[0] == "C");
57
58
1
    setEnv("LANG", "ru_RU");
59
2
    langs = getLang();
60



5
    REQUIRE(langs.size() == 2);
61



4
    REQUIRE(langs[0] == "ru_RU");
62



5
    REQUIRE(langs[1] == "ru");
63
64
1
    setEnv("LANG", "ru_RU.UTF-8");
65
2
    langs = getLang();
66



5
    REQUIRE(langs.size() == 2);
67



4
    REQUIRE(langs[0] == "ru_RU");
68



5
    REQUIRE(langs[1] == "ru");
69
1
}
70
71
3
TEST_CASE("Langs getLangSimple", "")
72
{
73
3
    config.setValue("lang", "C");
74



5
    REQUIRE(getLangSimple() == "C");
75
76
3
    config.setValue("lang", "ru_RU");
77



5
    REQUIRE(getLangSimple() == "ru_RU");
78
79
3
    config.setValue("lang", "ru_RU.UTF-8");
80



5
    REQUIRE(getLangSimple() == "ru_RU.UTF-8");
81
82
3
    config.setValue("lang", "");
83
84
1
    setEnv("LANG", "C");
85



5
    REQUIRE(getLangSimple() == "C");
86
87
1
    setEnv("LANG", "ru_RU");
88



5
    REQUIRE(getLangSimple() == "ru_RU");
89
90
1
    setEnv("LANG", "ru_RU.UTF-8");
91



5
    REQUIRE(getLangSimple() == "ru_RU.UTF-8");
92
1
}
93
94
3
TEST_CASE("Langs getLangShort", "")
95
{
96
3
    config.setValue("lang", "C");
97



5
    REQUIRE(getLangShort() == "C");
98
99
3
    config.setValue("lang", "ru_RU");
100



5
    REQUIRE(getLangShort() == "ru");
101
102
3
    config.setValue("lang", "ru_RU.UTF-8");
103



5
    REQUIRE(getLangShort() == "ru");
104
105
3
    config.setValue("lang", "");
106
107
1
    setEnv("LANG", "C");
108



5
    REQUIRE(getLangShort() == "C");
109
110
1
    setEnv("LANG", "ru_RU");
111



5
    REQUIRE(getLangShort() == "ru");
112
113
1
    setEnv("LANG", "ru_RU.UTF-8");
114



5
    REQUIRE(getLangShort() == "ru");
115

4
}