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