]>
Commit | Line | Data |
---|---|---|
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(), 2); | |
30 | equals(vec[0], "de"); | |
31 | equals(vec[1], "en"); | |
32 | ||
33 | // Special: Check if the cache is actually in use | |
34 | env[0] = "en_GB.UTF-8"; | |
35 | vec = APT::Configuration::getLanguages(false, true, env); | |
36 | equals(vec.size(), 2); | |
37 | equals(vec[0], "de"); | |
38 | equals(vec[1], "en"); | |
39 | ||
40 | env[0] = "en_GB.UTF-8"; | |
41 | vec = APT::Configuration::getLanguages(false, false, env); | |
42 | equals(vec.size(), 2); | |
43 | equals(vec[0], "en_GB"); | |
44 | equals(vec[1], "en"); | |
45 | ||
46 | env[0] = "tr_DE@euro"; | |
47 | vec = APT::Configuration::getLanguages(false, false, env); | |
48 | equals(vec.size(), 2); | |
49 | equals(vec[0], "tr"); | |
50 | equals(vec[1], "en"); | |
51 | ||
52 | env[0] = "de_NO"; | |
53 | env[1] = "se_NO:en_GB:nb_NO:nb:no_NO:no:nn_NO:nn:da:sv:en"; | |
54 | vec = APT::Configuration::getLanguages(false, false, env); | |
55 | equals(vec.size(), 5); | |
56 | equals(vec[0], "de"); | |
57 | equals(vec[1], "en_GB"); | |
58 | equals(vec[2], "nb"); | |
59 | equals(vec[3], "no"); | |
60 | equals(vec[4], "en"); | |
61 | ||
62 | env[0] = "pt_PR.UTF-8"; | |
63 | env[1] = ""; | |
64 | vec = APT::Configuration::getLanguages(false, false, env); | |
65 | equals(vec.size(), 3); | |
66 | equals(vec[0], "pt_PR"); | |
67 | equals(vec[1], "pt"); | |
68 | equals(vec[2], "en"); | |
69 | ||
70 | env[0] = "ast_DE.UTF-8"; | |
71 | vec = APT::Configuration::getLanguages(false, false, env); // bogus, but syntactical correct | |
72 | equals(vec.size(), 2); | |
73 | equals(vec[0], "ast"); | |
74 | equals(vec[1], "en"); | |
75 | ||
76 | env[0] = "C"; | |
77 | vec = APT::Configuration::getLanguages(false, false, env); | |
78 | equals(vec.size(), 1); | |
79 | equals(vec[0], "en"); | |
80 | ||
81 | _config->Set("Acquire::Languages::1", "environment"); | |
82 | _config->Set("Acquire::Languages::2", "en"); | |
83 | env[0] = "de_DE.UTF-8"; | |
84 | vec = APT::Configuration::getLanguages(false, false, env); | |
85 | equals(vec.size(), 2); | |
86 | equals(vec[0], "de"); | |
87 | equals(vec[1], "en"); | |
88 | ||
89 | _config->Set("Acquire::Languages::3", "de"); | |
90 | env[0] = "de_DE.UTF-8"; | |
91 | vec = APT::Configuration::getLanguages(false, false, env); | |
92 | equals(vec.size(), 2); | |
93 | equals(vec[0], "de"); | |
94 | equals(vec[1], "en"); | |
95 | ||
96 | _config->Set("Dir::State::lists", argv[1]); | |
97 | vec = APT::Configuration::getLanguages(true, false, env); | |
98 | equals(vec.size(), 5); | |
99 | equals(vec[0], "de"); | |
100 | equals(vec[1], "en"); | |
101 | equals(vec[2], "none"); | |
102 | equals(vec[3], "pt"); | |
103 | equals(vec[4], "tr"); | |
104 | ||
105 | _config->Set("Dir::State::lists", "/non-existing-dir"); | |
106 | _config->Set("Acquire::Languages::1", "none"); | |
107 | env[0] = "de_DE.UTF-8"; | |
108 | vec = APT::Configuration::getLanguages(false, false, env); | |
109 | equals(vec.size(), 0); | |
110 | env[0] = "de_DE.UTF-8"; | |
111 | vec = APT::Configuration::getLanguages(true, false, env); | |
112 | equals(vec[0], "en"); | |
113 | equals(vec[1], "de"); | |
114 | ||
115 | _config->Set("Acquire::Languages::1", "fr"); | |
116 | _config->Set("Acquire::Languages", "de_DE"); | |
117 | env[0] = "de_DE.UTF-8"; | |
118 | vec = APT::Configuration::getLanguages(false, false, env); | |
119 | equals(vec.size(), 1); | |
120 | equals(vec[0], "de_DE"); | |
121 | ||
122 | _config->Set("Acquire::Languages", "none"); | |
123 | env[0] = "de_DE.UTF-8"; | |
124 | vec = APT::Configuration::getLanguages(true, false, env); | |
125 | equals(vec.size(), 0); | |
126 | ||
127 | _config->Set("Acquire::Languages", ""); | |
128 | //FIXME: Remove support for this deprecated setting | |
129 | _config->Set("APT::Acquire::Translation", "ast_DE"); | |
130 | env[0] = "de_DE.UTF-8"; | |
131 | vec = APT::Configuration::getLanguages(true, false, env); | |
132 | equals(vec.size(), 2); | |
133 | equals(vec[0], "ast_DE"); | |
134 | equals(vec[1], "en"); | |
135 | _config->Set("APT::Acquire::Translation", "none"); | |
136 | env[0] = "de_DE.UTF-8"; | |
137 | vec = APT::Configuration::getLanguages(true, false, env); | |
138 | equals(vec.size(), 1); | |
139 | equals(vec[0], "en"); | |
140 | ||
141 | return 0; | |
142 | } |