]>
git.saurik.com Git - apt.git/blob - test/libapt/getlanguages_test.cc
1 #include <apt-pkg/aptconfiguration.h>
2 #include <apt-pkg/configuration.h>
10 // simple helper to quickly output a vector of strings
11 void dumpVector(std::vector
<std::string
> vec
) {
12 for (std::vector
<std::string
>::const_iterator v
= vec
.begin();
14 std::cout
<< *v
<< std::endl
;
17 int main(int argc
,char *argv
[])
20 std::cout
<< "One parameter expected - given " << argc
<< std::endl
;
25 env
[0] = "de_DE.UTF-8";
28 std::vector
<std::string
> vec
= APT::Configuration::getLanguages(false, false, env
);
29 equals(vec
.size(), 3);
30 equals(vec
[0], "de_DE");
34 // Special: Check if the cache is actually in use
35 env
[0] = "en_GB.UTF-8";
36 vec
= APT::Configuration::getLanguages(false, true, env
);
37 equals(vec
.size(), 3);
38 equals(vec
[0], "de_DE");
42 env
[0] = "en_GB.UTF-8";
43 vec
= APT::Configuration::getLanguages(false, false, env
);
44 equals(vec
.size(), 2);
45 equals(vec
[0], "en_GB");
50 vec
= APT::Configuration::getLanguages(false, false, env
);
51 equals(vec
.size(), 2);
55 env
[0] = "tr_DE@euro";
56 vec
= APT::Configuration::getLanguages(false, false, env
);
57 equals(vec
.size(), 3);
58 equals(vec
[0], "tr_DE");
63 env
[1] = "de_NO:en_GB:nb_NO:nb:no_NO:no:nn_NO:nn:da:sv:en";
64 vec
= APT::Configuration::getLanguages(false, false, env
);
65 equals(vec
.size(), 6);
66 equals(vec
[0], "de_NO");
68 equals(vec
[2], "en_GB");
69 equals(vec
[3], "nb_NO");
73 env
[0] = "pt_PR.UTF-8";
75 vec
= APT::Configuration::getLanguages(false, false, env
);
76 equals(vec
.size(), 3);
77 equals(vec
[0], "pt_PR");
81 env
[0] = "ast_DE.UTF-8";
82 vec
= APT::Configuration::getLanguages(false, false, env
); // bogus, but syntactical correct
83 equals(vec
.size(), 3);
84 equals(vec
[0], "ast_DE");
85 equals(vec
[1], "ast");
89 vec
= APT::Configuration::getLanguages(false, false, env
);
90 equals(vec
.size(), 1);
93 _config
->Set("Acquire::Languages", "none");
95 vec
= APT::Configuration::getLanguages(false, false, env
);
96 equals(vec
.size(), 0);
98 _config
->Set("Acquire::Languages", "environment");
100 vec
= APT::Configuration::getLanguages(false, false, env
);
101 equals(vec
.size(), 1);
102 equals(vec
[0], "en");
104 _config
->Set("Acquire::Languages", "de");
106 vec
= APT::Configuration::getLanguages(false, false, env
);
107 equals(vec
.size(), 1);
108 equals(vec
[0], "de");
110 _config
->Set("Acquire::Languages", "fr");
111 env
[0] = "ast_DE.UTF-8";
112 vec
= APT::Configuration::getLanguages(false, false, env
);
113 equals(vec
.size(), 1);
114 equals(vec
[0], "fr");
115 _config
->Set("Acquire::Languages", "");
117 _config
->Set("Acquire::Languages::1", "environment");
118 _config
->Set("Acquire::Languages::2", "en");
119 env
[0] = "de_DE.UTF-8";
120 vec
= APT::Configuration::getLanguages(false, false, env
);
121 equals(vec
.size(), 3);
122 equals(vec
[0], "de_DE");
123 equals(vec
[1], "de");
124 equals(vec
[2], "en");
126 _config
->Set("Acquire::Languages::3", "de");
127 env
[0] = "de_DE.UTF-8";
128 vec
= APT::Configuration::getLanguages(false, false, env
);
129 equals(vec
.size(), 3);
130 equals(vec
[0], "de_DE");
131 equals(vec
[1], "de");
132 equals(vec
[2], "en");
134 _config
->Set("Dir::State::lists", argv
[1]);
135 vec
= APT::Configuration::getLanguages(true, false, env
);
136 equals(vec
.size(), 6);
137 equals(vec
[0], "de_DE");
138 equals(vec
[1], "de");
139 equals(vec
[2], "en");
140 equals(vec
[3], "none");
141 equalsOr2(vec
[4], "pt", "tr");
142 equalsOr2(vec
[5], "tr", "pt");
144 _config
->Set("Dir::State::lists", "/non-existing-dir");
145 _config
->Set("Acquire::Languages::1", "none");
146 env
[0] = "de_DE.UTF-8";
147 vec
= APT::Configuration::getLanguages(false, false, env
);
148 equals(vec
.size(), 0);
149 env
[0] = "de_DE.UTF-8";
150 vec
= APT::Configuration::getLanguages(true, false, env
);
151 equals(vec
.size(), 2);
152 equals(vec
[0], "en");
153 equals(vec
[1], "de");
155 _config
->Set("Acquire::Languages::1", "fr");
156 _config
->Set("Acquire::Languages", "de_DE");
157 env
[0] = "de_DE.UTF-8";
158 vec
= APT::Configuration::getLanguages(false, false, env
);
159 equals(vec
.size(), 1);
160 equals(vec
[0], "de_DE");
162 _config
->Set("Acquire::Languages", "none");
163 env
[0] = "de_DE.UTF-8";
164 vec
= APT::Configuration::getLanguages(true, false, env
);
165 equals(vec
.size(), 0);
167 _config
->Set("Acquire::Languages", "");
168 //FIXME: Remove support for this deprecated setting
169 _config
->Set("APT::Acquire::Translation", "ast_DE");
170 env
[0] = "de_DE.UTF-8";
171 vec
= APT::Configuration::getLanguages(true, false, env
);
172 equals(vec
.size(), 2);
173 equals(vec
[0], "ast_DE");
174 equals(vec
[1], "en");
175 _config
->Set("APT::Acquire::Translation", "none");
176 env
[0] = "de_DE.UTF-8";
177 vec
= APT::Configuration::getLanguages(true, false, env
);
178 equals(vec
.size(), 1);
179 equals(vec
[0], "en");