]> git.saurik.com Git - apt.git/blob - test/libapt/getlanguages_test.cc
Merge remote-tracking branch 'upstream/debian/sid' into feature/apt-manpage
[apt.git] / test / libapt / getlanguages_test.cc
1 #include <config.h>
2
3 #include <apt-pkg/aptconfiguration.h>
4 #include <apt-pkg/configuration.h>
5
6 #include "assert.h"
7 #include <string>
8 #include <vector>
9
10 #include <iostream>
11
12 int main(int argc,char *argv[])
13 {
14 if (argc != 2) {
15 std::cout << "One parameter expected - given " << argc << std::endl;
16 return 100;
17 }
18
19 char const* env[2];
20 env[0] = "de_DE.UTF-8";
21 env[1] = "";
22
23 std::vector<std::string> vec = APT::Configuration::getLanguages(false, false, env);
24 equals(vec.size(), 3);
25 equals(vec[0], "de_DE");
26 equals(vec[1], "de");
27 equals(vec[2], "en");
28
29 // Special: Check if the cache is actually in use
30 env[0] = "en_GB.UTF-8";
31 vec = APT::Configuration::getLanguages(false, true, env);
32 equals(vec.size(), 3);
33 equals(vec[0], "de_DE");
34 equals(vec[1], "de");
35 equals(vec[2], "en");
36
37 env[0] = "en_GB.UTF-8";
38 vec = APT::Configuration::getLanguages(false, false, env);
39 equals(vec.size(), 2);
40 equals(vec[0], "en_GB");
41 equals(vec[1], "en");
42
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
50 env[0] = "tr_DE@euro";
51 vec = APT::Configuration::getLanguages(false, false, env);
52 equals(vec.size(), 3);
53 equals(vec[0], "tr_DE");
54 equals(vec[1], "tr");
55 equals(vec[2], "en");
56
57 env[0] = "de_NO";
58 env[1] = "de_NO:en_GB:nb_NO:nb:no_NO:no:nn_NO:nn:da:sv:en";
59 vec = APT::Configuration::getLanguages(false, false, env);
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");
67
68 env[0] = "pt_PR.UTF-8";
69 env[1] = "";
70 vec = APT::Configuration::getLanguages(false, false, env);
71 equals(vec.size(), 3);
72 equals(vec[0], "pt_PR");
73 equals(vec[1], "pt");
74 equals(vec[2], "en");
75
76 env[0] = "ast_DE.UTF-8";
77 vec = APT::Configuration::getLanguages(false, false, env); // bogus, but syntactical correct
78 equals(vec.size(), 3);
79 equals(vec[0], "ast_DE");
80 equals(vec[1], "ast");
81 equals(vec[2], "en");
82
83 env[0] = "C";
84 vec = APT::Configuration::getLanguages(false, false, env);
85 equals(vec.size(), 1);
86 equals(vec[0], "en");
87
88 _config->Set("Acquire::Languages", "none");
89 env[0] = "C";
90 vec = APT::Configuration::getLanguages(false, false, env);
91 equals(vec.size(), 0);
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");
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");
118 _config->Set("Acquire::Languages", "");
119
120 _config->Set("Acquire::Languages::1", "environment");
121 _config->Set("Acquire::Languages::2", "en");
122 env[0] = "de_DE.UTF-8";
123 vec = APT::Configuration::getLanguages(false, false, env);
124 equals(vec.size(), 3);
125 equals(vec[0], "de_DE");
126 equals(vec[1], "de");
127 equals(vec[2], "en");
128
129 _config->Set("Acquire::Languages::3", "de");
130 env[0] = "de_DE.UTF-8";
131 vec = APT::Configuration::getLanguages(false, false, env);
132 equals(vec.size(), 3);
133 equals(vec[0], "de_DE");
134 equals(vec[1], "de");
135 equals(vec[2], "en");
136
137 _config->Set("Dir::State::lists", argv[1]);
138 vec = APT::Configuration::getLanguages(true, false, env);
139 equals(vec.size(), 8);
140 equals(vec[0], "de_DE");
141 equals(vec[1], "de");
142 equals(vec[2], "en");
143 equals(vec[3], "none");
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]);
154
155 _config->Set("Acquire::Languages", "none");
156 vec = APT::Configuration::getLanguages(true, false, env);
157 equals(vec.size(), 1);
158 equals(vec[0], "none");
159 _config->Set("Acquire::Languages", "");
160
161 _config->Set("Dir::State::lists", "/non-existing-dir");
162 _config->Set("Acquire::Languages::1", "none");
163 env[0] = "de_DE.UTF-8";
164 vec = APT::Configuration::getLanguages(false, false, env);
165 equals(vec.size(), 0);
166 env[0] = "de_DE.UTF-8";
167 vec = APT::Configuration::getLanguages(true, false, env);
168 equals(vec.size(), 2);
169 equals(vec[0], "en");
170 equals(vec[1], "de");
171
172 _config->Set("Acquire::Languages::1", "fr");
173 _config->Set("Acquire::Languages", "de_DE");
174 env[0] = "de_DE.UTF-8";
175 vec = APT::Configuration::getLanguages(false, false, env);
176 equals(vec.size(), 1);
177 equals(vec[0], "de_DE");
178
179 _config->Set("Acquire::Languages", "none");
180 env[0] = "de_DE.UTF-8";
181 vec = APT::Configuration::getLanguages(true, false, env);
182 equals(vec.size(), 1);
183 equals(vec[0], "none");
184
185 _config->Set("Acquire::Languages", "");
186 //FIXME: Remove support for this deprecated setting
187 _config->Set("APT::Acquire::Translation", "ast_DE");
188 env[0] = "de_DE.UTF-8";
189 vec = APT::Configuration::getLanguages(true, false, env);
190 equals(vec.size(), 2);
191 equals(vec[0], "ast_DE");
192 equals(vec[1], "en");
193 _config->Set("APT::Acquire::Translation", "none");
194 env[0] = "de_DE.UTF-8";
195 vec = APT::Configuration::getLanguages(true, false, env);
196 equals(vec.size(), 1);
197 equals(vec[0], "en");
198
199 return 0;
200 }