]> git.saurik.com Git - apt.git/blame - test/libapt/getlanguages_test.cc
merged lp:~mvo/apt/apt-get-changelog
[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);
9c562bc9
DK
29 equals(vec.size(), 2);
30 equals(vec[0], "de");
31 equals(vec[1], "en");
45df0ad2
DK
32
33 // Special: Check if the cache is actually in use
d7cf5923
DK
34 env[0] = "en_GB.UTF-8";
35 vec = APT::Configuration::getLanguages(false, true, env);
9c562bc9
DK
36 equals(vec.size(), 2);
37 equals(vec[0], "de");
38 equals(vec[1], "en");
45df0ad2 39
d7cf5923
DK
40 env[0] = "en_GB.UTF-8";
41 vec = APT::Configuration::getLanguages(false, false, env);
9c562bc9
DK
42 equals(vec.size(), 2);
43 equals(vec[0], "en_GB");
44 equals(vec[1], "en");
45df0ad2 45
52d9d000
MV
46 // esperanto
47 env[0] = "eo.UTF-8";
48 vec = APT::Configuration::getLanguages(false, false, env);
49 equals(vec.size(), 2);
50 equals(vec[0], "eo");
51 equals(vec[1], "en");
52
d7cf5923
DK
53 env[0] = "tr_DE@euro";
54 vec = APT::Configuration::getLanguages(false, false, env);
55 equals(vec.size(), 2);
56 equals(vec[0], "tr");
57 equals(vec[1], "en");
58
59 env[0] = "de_NO";
60 env[1] = "se_NO:en_GB:nb_NO:nb:no_NO:no:nn_NO:nn:da:sv:en";
61 vec = APT::Configuration::getLanguages(false, false, env);
62 equals(vec.size(), 5);
63 equals(vec[0], "de");
64 equals(vec[1], "en_GB");
65 equals(vec[2], "nb");
66 equals(vec[3], "no");
67 equals(vec[4], "en");
68
69 env[0] = "pt_PR.UTF-8";
70 env[1] = "";
71 vec = APT::Configuration::getLanguages(false, false, env);
9c562bc9
DK
72 equals(vec.size(), 3);
73 equals(vec[0], "pt_PR");
74 equals(vec[1], "pt");
75 equals(vec[2], "en");
45df0ad2 76
d7cf5923
DK
77 env[0] = "ast_DE.UTF-8";
78 vec = APT::Configuration::getLanguages(false, false, env); // bogus, but syntactical correct
9c562bc9
DK
79 equals(vec.size(), 2);
80 equals(vec[0], "ast");
81 equals(vec[1], "en");
45df0ad2 82
d7cf5923
DK
83 env[0] = "C";
84 vec = APT::Configuration::getLanguages(false, false, env);
9c562bc9
DK
85 equals(vec.size(), 1);
86 equals(vec[0], "en");
45df0ad2 87
03745479
DK
88 _config->Set("Acquire::Languages", "none");
89 env[0] = "C";
90 vec = APT::Configuration::getLanguages(false, false, env);
91 equals(vec.size(), 0);
eb3947c6
DK
92
93 _config->Set("Acquire::Languages", "environment");
94 env[0] = "C";
95 vec = APT::Configuration::getLanguages(false, false, env);
96 equals(vec.size(), 1);
97 equals(vec[0], "en");
98
99 _config->Set("Acquire::Languages", "de");
100 env[0] = "C";
101 vec = APT::Configuration::getLanguages(false, false, env);
102 equals(vec.size(), 1);
103 equals(vec[0], "de");
104
105 _config->Set("Acquire::Languages", "fr");
106 env[0] = "ast_DE.UTF-8";
107 vec = APT::Configuration::getLanguages(false, false, env);
108 equals(vec.size(), 1);
109 equals(vec[0], "fr");
03745479
DK
110 _config->Set("Acquire::Languages", "");
111
45df0ad2
DK
112 _config->Set("Acquire::Languages::1", "environment");
113 _config->Set("Acquire::Languages::2", "en");
d7cf5923
DK
114 env[0] = "de_DE.UTF-8";
115 vec = APT::Configuration::getLanguages(false, false, env);
9c562bc9
DK
116 equals(vec.size(), 2);
117 equals(vec[0], "de");
118 equals(vec[1], "en");
45df0ad2
DK
119
120 _config->Set("Acquire::Languages::3", "de");
d7cf5923
DK
121 env[0] = "de_DE.UTF-8";
122 vec = APT::Configuration::getLanguages(false, false, env);
9c562bc9
DK
123 equals(vec.size(), 2);
124 equals(vec[0], "de");
125 equals(vec[1], "en");
45df0ad2 126
3f2d77b5
DK
127 _config->Set("Dir::State::lists", argv[1]);
128 vec = APT::Configuration::getLanguages(true, false, env);
129 equals(vec.size(), 5);
130 equals(vec[0], "de");
131 equals(vec[1], "en");
132 equals(vec[2], "none");
133 equals(vec[3], "pt");
134 equals(vec[4], "tr");
135
136 _config->Set("Dir::State::lists", "/non-existing-dir");
45df0ad2 137 _config->Set("Acquire::Languages::1", "none");
d7cf5923
DK
138 env[0] = "de_DE.UTF-8";
139 vec = APT::Configuration::getLanguages(false, false, env);
9c562bc9 140 equals(vec.size(), 0);
d7cf5923
DK
141 env[0] = "de_DE.UTF-8";
142 vec = APT::Configuration::getLanguages(true, false, env);
9c562bc9
DK
143 equals(vec[0], "en");
144 equals(vec[1], "de");
45df0ad2
DK
145
146 _config->Set("Acquire::Languages::1", "fr");
147 _config->Set("Acquire::Languages", "de_DE");
d7cf5923
DK
148 env[0] = "de_DE.UTF-8";
149 vec = APT::Configuration::getLanguages(false, false, env);
9c562bc9
DK
150 equals(vec.size(), 1);
151 equals(vec[0], "de_DE");
45df0ad2
DK
152
153 _config->Set("Acquire::Languages", "none");
d7cf5923
DK
154 env[0] = "de_DE.UTF-8";
155 vec = APT::Configuration::getLanguages(true, false, env);
9c562bc9 156 equals(vec.size(), 0);
45df0ad2
DK
157
158 _config->Set("Acquire::Languages", "");
159 //FIXME: Remove support for this deprecated setting
160 _config->Set("APT::Acquire::Translation", "ast_DE");
d7cf5923
DK
161 env[0] = "de_DE.UTF-8";
162 vec = APT::Configuration::getLanguages(true, false, env);
3f2d77b5 163 equals(vec.size(), 2);
9c562bc9 164 equals(vec[0], "ast_DE");
3f2d77b5 165 equals(vec[1], "en");
45df0ad2 166 _config->Set("APT::Acquire::Translation", "none");
d7cf5923
DK
167 env[0] = "de_DE.UTF-8";
168 vec = APT::Configuration::getLanguages(true, false, env);
3f2d77b5
DK
169 equals(vec.size(), 1);
170 equals(vec[0], "en");
45df0ad2
DK
171
172 return 0;
173}