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