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

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2013-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 "configuration.h"
25
26
#include "utils/env.h"
27
#include "utils/langs.h"
28
29
#include "debug.h"
30
31
✓✗
3
TEST_CASE("Langs getLang", "")
32
{
33
2
    LangVect langs;
34
35
✓✗✓✗
3
    config.setValue("lang", "C");
36
✓✗
2
    langs = getLang();
37
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
    REQUIRE(langs.size() == 1);
38
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
4
    REQUIRE(langs[0] == "C");
39
40
✓✗✓✗
3
    config.setValue("lang", "ru_RU");
41
✓✗
2
    langs = getLang();
42
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
    REQUIRE(langs.size() == 2);
43
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
4
    REQUIRE(langs[0] == "ru_RU");
44
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
    REQUIRE(langs[1] == "ru");
45
46
✓✗✓✗
3
    config.setValue("lang", "ru_RU.UTF-8");
47
✓✗
2
    langs = getLang();
48
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
    REQUIRE(langs.size() == 2);
49
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
4
    REQUIRE(langs[0] == "ru_RU");
50
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
    REQUIRE(langs[1] == "ru");
51
52
✓✗✓✗
3
    config.setValue("lang", "");
53
54
✓✗
1
    setEnv("LANG", "C");
55
✓✗
2
    langs = getLang();
56
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
    REQUIRE(langs.size() == 1);
57
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
4
    REQUIRE(langs[0] == "C");
58
59
✓✗
1
    setEnv("LANG", "ru_RU");
60
✓✗
2
    langs = getLang();
61
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
    REQUIRE(langs.size() == 2);
62
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
4
    REQUIRE(langs[0] == "ru_RU");
63
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
    REQUIRE(langs[1] == "ru");
64
65
✓✗
1
    setEnv("LANG", "ru_RU.UTF-8");
66
✓✗
2
    langs = getLang();
67
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
    REQUIRE(langs.size() == 2);
68
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
4
    REQUIRE(langs[0] == "ru_RU");
69
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
    REQUIRE(langs[1] == "ru");
70
1
}
71
72
✓✗
3
TEST_CASE("Langs getLangSimple", "")
73
{
74
✓✗
3
    config.setValue("lang", "C");
75
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
    REQUIRE(getLangSimple() == "C");
76
77
✓✗
3
    config.setValue("lang", "ru_RU");
78
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
    REQUIRE(getLangSimple() == "ru_RU");
79
80
✓✗
3
    config.setValue("lang", "ru_RU.UTF-8");
81
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
    REQUIRE(getLangSimple() == "ru_RU.UTF-8");
82
83
✓✗
3
    config.setValue("lang", "");
84
85
1
    setEnv("LANG", "C");
86
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
    REQUIRE(getLangSimple() == "C");
87
88
1
    setEnv("LANG", "ru_RU");
89
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
    REQUIRE(getLangSimple() == "ru_RU");
90
91
1
    setEnv("LANG", "ru_RU.UTF-8");
92
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
    REQUIRE(getLangSimple() == "ru_RU.UTF-8");
93
1
}
94
95
✓✗
3
TEST_CASE("Langs getLangShort", "")
96
{
97
✓✗
3
    config.setValue("lang", "C");
98
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
    REQUIRE(getLangShort() == "C");
99
100
✓✗
3
    config.setValue("lang", "ru_RU");
101
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
    REQUIRE(getLangShort() == "ru");
102
103
✓✗
3
    config.setValue("lang", "ru_RU.UTF-8");
104
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
    REQUIRE(getLangShort() == "ru");
105
106
✓✗
3
    config.setValue("lang", "");
107
108
1
    setEnv("LANG", "C");
109
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
    REQUIRE(getLangShort() == "C");
110
111
1
    setEnv("LANG", "ru_RU");
112
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
    REQUIRE(getLangShort() == "ru");
113
114
1
    setEnv("LANG", "ru_RU.UTF-8");
115
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
    REQUIRE(getLangShort() == "ru");
116
✓✗✓✗
4
}