]> git.saurik.com Git - apt.git/blob - test/libapt/getlanguages_test.cc
merged from lp:~donkult/apt/sid
[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 // 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();
13 v != vec.end(); v++)
14 std::cout << *v << std::endl;
15 }
16
17 int main(int argc,char *argv[])
18 {
19 if (argc != 2) {
20 std::cout << "One parameter expected - given " << argc << std::endl;
21 return 100;
22 }
23
24 char const* env[2];
25 env[0] = "de_DE.UTF-8";
26 env[1] = "";
27
28 std::vector<std::string> vec = APT::Configuration::getLanguages(false, false, env);
29 equals(vec.size(), 3);
30 equals(vec[0], "de_DE");
31 equals(vec[1], "de");
32 equals(vec[2], "en");
33
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");
39 equals(vec[1], "de");
40 equals(vec[2], "en");
41
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");
46 equals(vec[1], "en");
47
48 // esperanto
49 env[0] = "eo.UTF-8";
50 vec = APT::Configuration::getLanguages(false, false, env);
51 equals(vec.size(), 2);
52 equals(vec[0], "eo");
53 equals(vec[1], "en");
54
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");
59 equals(vec[1], "tr");
60 equals(vec[2], "en");
61
62 env[0] = "de_NO";
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");
67 equals(vec[1], "de");
68 equals(vec[2], "en_GB");
69 equals(vec[3], "nb_NO");
70 equals(vec[4], "nb");
71 equals(vec[5], "en");
72
73 env[0] = "pt_PR.UTF-8";
74 env[1] = "";
75 vec = APT::Configuration::getLanguages(false, false, env);
76 equals(vec.size(), 3);
77 equals(vec[0], "pt_PR");
78 equals(vec[1], "pt");
79 equals(vec[2], "en");
80
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");
86 equals(vec[2], "en");
87
88 env[0] = "C";
89 vec = APT::Configuration::getLanguages(false, false, env);
90 equals(vec.size(), 1);
91 equals(vec[0], "en");
92
93 _config->Set("Acquire::Languages", "none");
94 env[0] = "C";
95 vec = APT::Configuration::getLanguages(false, false, env);
96 equals(vec.size(), 0);
97
98 _config->Set("Acquire::Languages", "environment");
99 env[0] = "C";
100 vec = APT::Configuration::getLanguages(false, false, env);
101 equals(vec.size(), 1);
102 equals(vec[0], "en");
103
104 _config->Set("Acquire::Languages", "de");
105 env[0] = "C";
106 vec = APT::Configuration::getLanguages(false, false, env);
107 equals(vec.size(), 1);
108 equals(vec[0], "de");
109
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", "");
116
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");
125
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");
133
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");
143
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");
154
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");
161
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);
166
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");
180
181 return 0;
182 }