]> git.saurik.com Git - apt.git/blame - test/libapt/getlanguages_test.cc
* apt-pkg/deb/deblistparser.cc:
[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
10// simple helper to quickly output a vector of strings
11void 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
17int main(int argc,char *argv[])
18{
3f2d77b5
DK
19 if (argc != 2) {
20 std::cout << "One parameter expected - given " << argc << std::endl;
21 return 100;
22 }
23
d7cf5923
DK
24 char const* env[2];
25 env[0] = "de_DE.UTF-8";
26 env[1] = "";
3f2d77b5 27
d7cf5923 28 std::vector<std::string> vec = APT::Configuration::getLanguages(false, false, env);
ab53c018
DK
29 equals(vec.size(), 3);
30 equals(vec[0], "de_DE");
31 equals(vec[1], "de");
32 equals(vec[2], "en");
45df0ad2
DK
33
34 // Special: Check if the cache is actually in use
d7cf5923
DK
35 env[0] = "en_GB.UTF-8";
36 vec = APT::Configuration::getLanguages(false, true, env);
ab53c018
DK
37 equals(vec.size(), 3);
38 equals(vec[0], "de_DE");
39 equals(vec[1], "de");
40 equals(vec[2], "en");
45df0ad2 41
d7cf5923
DK
42 env[0] = "en_GB.UTF-8";
43 vec = APT::Configuration::getLanguages(false, false, env);
9c562bc9
DK
44 equals(vec.size(), 2);
45 equals(vec[0], "en_GB");
46 equals(vec[1], "en");
45df0ad2 47
52d9d000
MV
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
d7cf5923
DK
55 env[0] = "tr_DE@euro";
56 vec = APT::Configuration::getLanguages(false, false, env);
ab53c018
DK
57 equals(vec.size(), 3);
58 equals(vec[0], "tr_DE");
59 equals(vec[1], "tr");
60 equals(vec[2], "en");
d7cf5923
DK
61
62 env[0] = "de_NO";
ab53c018 63 env[1] = "de_NO:en_GB:nb_NO:nb:no_NO:no:nn_NO:nn:da:sv:en";
d7cf5923 64 vec = APT::Configuration::getLanguages(false, false, env);
ab53c018
DK
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");
d7cf5923
DK
72
73 env[0] = "pt_PR.UTF-8";
74 env[1] = "";
75 vec = APT::Configuration::getLanguages(false, false, env);
9c562bc9
DK
76 equals(vec.size(), 3);
77 equals(vec[0], "pt_PR");
78 equals(vec[1], "pt");
79 equals(vec[2], "en");
45df0ad2 80
d7cf5923
DK
81 env[0] = "ast_DE.UTF-8";
82 vec = APT::Configuration::getLanguages(false, false, env); // bogus, but syntactical correct
ab53c018
DK
83 equals(vec.size(), 3);
84 equals(vec[0], "ast_DE");
85 equals(vec[1], "ast");
86 equals(vec[2], "en");
45df0ad2 87
d7cf5923
DK
88 env[0] = "C";
89 vec = APT::Configuration::getLanguages(false, false, env);
9c562bc9
DK
90 equals(vec.size(), 1);
91 equals(vec[0], "en");
45df0ad2 92
03745479
DK
93 _config->Set("Acquire::Languages", "none");
94 env[0] = "C";
95 vec = APT::Configuration::getLanguages(false, false, env);
96 equals(vec.size(), 0);
eb3947c6
DK
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");
03745479
DK
115 _config->Set("Acquire::Languages", "");
116
45df0ad2
DK
117 _config->Set("Acquire::Languages::1", "environment");
118 _config->Set("Acquire::Languages::2", "en");
d7cf5923
DK
119 env[0] = "de_DE.UTF-8";
120 vec = APT::Configuration::getLanguages(false, false, env);
ab53c018
DK
121 equals(vec.size(), 3);
122 equals(vec[0], "de_DE");
123 equals(vec[1], "de");
124 equals(vec[2], "en");
45df0ad2
DK
125
126 _config->Set("Acquire::Languages::3", "de");
d7cf5923
DK
127 env[0] = "de_DE.UTF-8";
128 vec = APT::Configuration::getLanguages(false, false, env);
ab53c018
DK
129 equals(vec.size(), 3);
130 equals(vec[0], "de_DE");
131 equals(vec[1], "de");
132 equals(vec[2], "en");
45df0ad2 133
3f2d77b5
DK
134 _config->Set("Dir::State::lists", argv[1]);
135 vec = APT::Configuration::getLanguages(true, false, env);
ab53c018
DK
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 equals(vec[4], "pt");
142 equals(vec[5], "tr");
3f2d77b5
DK
143
144 _config->Set("Dir::State::lists", "/non-existing-dir");
45df0ad2 145 _config->Set("Acquire::Languages::1", "none");
d7cf5923
DK
146 env[0] = "de_DE.UTF-8";
147 vec = APT::Configuration::getLanguages(false, false, env);
9c562bc9 148 equals(vec.size(), 0);
d7cf5923
DK
149 env[0] = "de_DE.UTF-8";
150 vec = APT::Configuration::getLanguages(true, false, env);
ab53c018 151 equals(vec.size(), 2);
9c562bc9
DK
152 equals(vec[0], "en");
153 equals(vec[1], "de");
45df0ad2
DK
154
155 _config->Set("Acquire::Languages::1", "fr");
156 _config->Set("Acquire::Languages", "de_DE");
d7cf5923
DK
157 env[0] = "de_DE.UTF-8";
158 vec = APT::Configuration::getLanguages(false, false, env);
9c562bc9
DK
159 equals(vec.size(), 1);
160 equals(vec[0], "de_DE");
45df0ad2
DK
161
162 _config->Set("Acquire::Languages", "none");
d7cf5923
DK
163 env[0] = "de_DE.UTF-8";
164 vec = APT::Configuration::getLanguages(true, false, env);
9c562bc9 165 equals(vec.size(), 0);
45df0ad2
DK
166
167 _config->Set("Acquire::Languages", "");
168 //FIXME: Remove support for this deprecated setting
169 _config->Set("APT::Acquire::Translation", "ast_DE");
d7cf5923
DK
170 env[0] = "de_DE.UTF-8";
171 vec = APT::Configuration::getLanguages(true, false, env);
3f2d77b5 172 equals(vec.size(), 2);
9c562bc9 173 equals(vec[0], "ast_DE");
3f2d77b5 174 equals(vec[1], "en");
45df0ad2 175 _config->Set("APT::Acquire::Translation", "none");
d7cf5923
DK
176 env[0] = "de_DE.UTF-8";
177 vec = APT::Configuration::getLanguages(true, false, env);
3f2d77b5
DK
178 equals(vec.size(), 1);
179 equals(vec[0], "en");
45df0ad2
DK
180
181 return 0;
182}