GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/utils/langs.cc Lines: 62 62 100.0 %
Date: 2017-11-29 Branches: 178 468 38.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2013-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 "configuration.h"
24
25
#include "utils/env.h"
26
#include "utils/langs.h"
27
28
#include "debug.h"
29
30
6
TEST_CASE("Langs getLang", "")
31
{
32
4
    LangVect langs;
33
34

8
    config.setValue("lang", "C");
35
4
    langs = getLang();
36



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



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

8
    config.setValue("lang", "ru_RU");
40
4
    langs = getLang();
41



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



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



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

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



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



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



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

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



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



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



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



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



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



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



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



10
    REQUIRE(langs[1] == "ru");
69
2
}
70
71
6
TEST_CASE("Langs getLangSimple", "")
72
{
73

8
    config.setValue("lang", "C");
74



10
    REQUIRE(getLangSimple() == "C");
75
76

8
    config.setValue("lang", "ru_RU");
77



10
    REQUIRE(getLangSimple() == "ru_RU");
78
79

8
    config.setValue("lang", "ru_RU.UTF-8");
80



10
    REQUIRE(getLangSimple() == "ru_RU.UTF-8");
81
82

8
    config.setValue("lang", "");
83
84
2
    setEnv("LANG", "C");
85



10
    REQUIRE(getLangSimple() == "C");
86
87
2
    setEnv("LANG", "ru_RU");
88



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



10
    REQUIRE(getLangSimple() == "ru_RU.UTF-8");
92
2
}
93
94
6
TEST_CASE("Langs getLangShort", "")
95
{
96

8
    config.setValue("lang", "C");
97



10
    REQUIRE(getLangShort() == "C");
98
99

8
    config.setValue("lang", "ru_RU");
100



10
    REQUIRE(getLangShort() == "ru");
101
102

8
    config.setValue("lang", "ru_RU.UTF-8");
103



10
    REQUIRE(getLangShort() == "ru");
104
105

8
    config.setValue("lang", "");
106
107
2
    setEnv("LANG", "C");
108



10
    REQUIRE(getLangShort() == "C");
109
110
2
    setEnv("LANG", "ru_RU");
111



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



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

8
}