]> git.saurik.com Git - apt.git/blame - test/libapt/getlanguages_test.cc
Merge remote-tracking branch 'upstream/debian/sid' into feature/apt-manpage
[apt.git] / test / libapt / getlanguages_test.cc
CommitLineData
453b82a3
DK
1#include <config.h>
2
45df0ad2
DK
3#include <apt-pkg/aptconfiguration.h>
4#include <apt-pkg/configuration.h>
5
9c562bc9 6#include "assert.h"
45df0ad2
DK
7#include <string>
8#include <vector>
9
10#include <iostream>
11
45df0ad2
DK
12int main(int argc,char *argv[])
13{
3f2d77b5
DK
14 if (argc != 2) {
15 std::cout << "One parameter expected - given " << argc << std::endl;
16 return 100;
17 }
18
d7cf5923
DK
19 char const* env[2];
20 env[0] = "de_DE.UTF-8";
21 env[1] = "";
3f2d77b5 22
d7cf5923 23 std::vector<std::string> vec = APT::Configuration::getLanguages(false, false, env);
ab53c018
DK
24 equals(vec.size(), 3);
25 equals(vec[0], "de_DE");
26 equals(vec[1], "de");
27 equals(vec[2], "en");
45df0ad2
DK
28
29 // Special: Check if the cache is actually in use
d7cf5923
DK
30 env[0] = "en_GB.UTF-8";
31 vec = APT::Configuration::getLanguages(false, true, env);
ab53c018
DK
32 equals(vec.size(), 3);
33 equals(vec[0], "de_DE");
34 equals(vec[1], "de");
35 equals(vec[2], "en");
45df0ad2 36
d7cf5923
DK
37 env[0] = "en_GB.UTF-8";
38 vec = APT::Configuration::getLanguages(false, false, env);
9c562bc9
DK
39 equals(vec.size(), 2);
40 equals(vec[0], "en_GB");
41 equals(vec[1], "en");
45df0ad2 42
52d9d000
MV
43 // esperanto
44 env[0] = "eo.UTF-8";
45 vec = APT::Configuration::getLanguages(false, false, env);
46 equals(vec.size(), 2);
47 equals(vec[0], "eo");
48 equals(vec[1], "en");
49
d7cf5923
DK
50 env[0] = "tr_DE@euro";
51 vec = APT::Configuration::getLanguages(false, false, env);
ab53c018
DK
52 equals(vec.size(), 3);
53 equals(vec[0], "tr_DE");
54 equals(vec[1], "tr");
55 equals(vec[2], "en");
d7cf5923
DK
56
57 env[0] = "de_NO";
ab53c018 58 env[1] = "de_NO:en_GB:nb_NO:nb:no_NO:no:nn_NO:nn:da:sv:en";
d7cf5923 59 vec = APT::Configuration::getLanguages(false, false, env);
ab53c018
DK
60 equals(vec.size(), 6);
61 equals(vec[0], "de_NO");
62 equals(vec[1], "de");
63 equals(vec[2], "en_GB");
64 equals(vec[3], "nb_NO");
65 equals(vec[4], "nb");
66 equals(vec[5], "en");
d7cf5923
DK
67
68 env[0] = "pt_PR.UTF-8";
69 env[1] = "";
70 vec = APT::Configuration::getLanguages(false, false, env);
9c562bc9
DK
71 equals(vec.size(), 3);
72 equals(vec[0], "pt_PR");
73 equals(vec[1], "pt");
74 equals(vec[2], "en");
45df0ad2 75
d7cf5923
DK
76 env[0] = "ast_DE.UTF-8";
77 vec = APT::Configuration::getLanguages(false, false, env); // bogus, but syntactical correct
ab53c018
DK
78 equals(vec.size(), 3);
79 equals(vec[0], "ast_DE");
80 equals(vec[1], "ast");
81 equals(vec[2], "en");
45df0ad2 82
d7cf5923
DK
83 env[0] = "C";
84 vec = APT::Configuration::getLanguages(false, false, env);
9c562bc9
DK
85 equals(vec.size(), 1);
86 equals(vec[0], "en");
45df0ad2 87
03745479
DK
88 _config->Set("Acquire::Languages", "none");
89 env[0] = "C";
90 vec = APT::Configuration::getLanguages(false, false, env);
91 equals(vec.size(), 0);
eb3947c6
DK
92
93 _config->Set("Acquire::Languages", "environment");
94 env[0] = "C";
95 vec = APT::Configuration::getLanguages(false, false, env);
96 equals(vec.size(), 1);
97 equals(vec[0], "en");
98
99 _config->Set("Acquire::Languages", "de");
100 env[0] = "C";
101 vec = APT::Configuration::getLanguages(false, false, env);
102 equals(vec.size(), 1);
103 equals(vec[0], "de");
104
105 _config->Set("Acquire::Languages", "fr");
106 env[0] = "ast_DE.UTF-8";
107 vec = APT::Configuration::getLanguages(false, false, env);
108 equals(vec.size(), 1);
109 equals(vec[0], "fr");
a5414e56
DK
110
111 _config->Set("Acquire::Languages", "environment,en");
112 env[0] = "de_DE.UTF-8";
113 vec = APT::Configuration::getLanguages(false, false, env);
114 equals(vec.size(), 3);
115 equals(vec[0], "de_DE");
116 equals(vec[1], "de");
117 equals(vec[2], "en");
03745479
DK
118 _config->Set("Acquire::Languages", "");
119
45df0ad2
DK
120 _config->Set("Acquire::Languages::1", "environment");
121 _config->Set("Acquire::Languages::2", "en");
d7cf5923
DK
122 env[0] = "de_DE.UTF-8";
123 vec = APT::Configuration::getLanguages(false, false, env);
ab53c018
DK
124 equals(vec.size(), 3);
125 equals(vec[0], "de_DE");
126 equals(vec[1], "de");
127 equals(vec[2], "en");
45df0ad2
DK
128
129 _config->Set("Acquire::Languages::3", "de");
d7cf5923
DK
130 env[0] = "de_DE.UTF-8";
131 vec = APT::Configuration::getLanguages(false, false, env);
ab53c018
DK
132 equals(vec.size(), 3);
133 equals(vec[0], "de_DE");
134 equals(vec[1], "de");
135 equals(vec[2], "en");
45df0ad2 136
3f2d77b5
DK
137 _config->Set("Dir::State::lists", argv[1]);
138 vec = APT::Configuration::getLanguages(true, false, env);
527df5a2 139 equals(vec.size(), 8);
ab53c018
DK
140 equals(vec[0], "de_DE");
141 equals(vec[1], "de");
142 equals(vec[2], "en");
143 equals(vec[3], "none");
527df5a2
DK
144 equalsOr4(vec[4], "pt", "tr", "ast_DE", "tlh_DE");
145 equalsOr4(vec[5], "tr", "pt", "ast_DE", "tlh_DE");
146 equalsOr4(vec[6], "tr", "pt", "ast_DE", "tlh_DE");
147 equalsOr4(vec[7], "tr", "pt", "ast_DE", "tlh_DE");
148 equalsNot(vec[4], vec[5]);
149 equalsNot(vec[4], vec[6]);
150 equalsNot(vec[4], vec[7]);
151 equalsNot(vec[5], vec[6]);
152 equalsNot(vec[5], vec[7]);
153 equalsNot(vec[6], vec[7]);
d073d7db
DK
154
155 _config->Set("Acquire::Languages", "none");
156 vec = APT::Configuration::getLanguages(true, false, env);
f87fab03
DK
157 equals(vec.size(), 1);
158 equals(vec[0], "none");
d073d7db 159 _config->Set("Acquire::Languages", "");
3f2d77b5
DK
160
161 _config->Set("Dir::State::lists", "/non-existing-dir");
45df0ad2 162 _config->Set("Acquire::Languages::1", "none");
d7cf5923
DK
163 env[0] = "de_DE.UTF-8";
164 vec = APT::Configuration::getLanguages(false, false, env);
9c562bc9 165 equals(vec.size(), 0);
d7cf5923
DK
166 env[0] = "de_DE.UTF-8";
167 vec = APT::Configuration::getLanguages(true, false, env);
ab53c018 168 equals(vec.size(), 2);
9c562bc9
DK
169 equals(vec[0], "en");
170 equals(vec[1], "de");
45df0ad2
DK
171
172 _config->Set("Acquire::Languages::1", "fr");
173 _config->Set("Acquire::Languages", "de_DE");
d7cf5923
DK
174 env[0] = "de_DE.UTF-8";
175 vec = APT::Configuration::getLanguages(false, false, env);
9c562bc9
DK
176 equals(vec.size(), 1);
177 equals(vec[0], "de_DE");
45df0ad2
DK
178
179 _config->Set("Acquire::Languages", "none");
d7cf5923
DK
180 env[0] = "de_DE.UTF-8";
181 vec = APT::Configuration::getLanguages(true, false, env);
f87fab03
DK
182 equals(vec.size(), 1);
183 equals(vec[0], "none");
45df0ad2
DK
184
185 _config->Set("Acquire::Languages", "");
186 //FIXME: Remove support for this deprecated setting
187 _config->Set("APT::Acquire::Translation", "ast_DE");
d7cf5923
DK
188 env[0] = "de_DE.UTF-8";
189 vec = APT::Configuration::getLanguages(true, false, env);
3f2d77b5 190 equals(vec.size(), 2);
9c562bc9 191 equals(vec[0], "ast_DE");
3f2d77b5 192 equals(vec[1], "en");
45df0ad2 193 _config->Set("APT::Acquire::Translation", "none");
d7cf5923
DK
194 env[0] = "de_DE.UTF-8";
195 vec = APT::Configuration::getLanguages(true, false, env);
3f2d77b5
DK
196 equals(vec.size(), 1);
197 equals(vec[0], "en");
45df0ad2
DK
198
199 return 0;
200}