]> git.saurik.com Git - apt.git/blob - test/libapt/getlanguages_test.cc
dd support for the LANGUAGE environment variable
[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 char const* env[2];
20 env[0] = "de_DE.UTF-8";
21 env[1] = "";
22 std::vector<std::string> vec = APT::Configuration::getLanguages(false, false, env);
23 equals(vec.size(), 2);
24 equals(vec[0], "de");
25 equals(vec[1], "en");
26
27 // Special: Check if the cache is actually in use
28 env[0] = "en_GB.UTF-8";
29 vec = APT::Configuration::getLanguages(false, true, env);
30 equals(vec.size(), 2);
31 equals(vec[0], "de");
32 equals(vec[1], "en");
33
34 env[0] = "en_GB.UTF-8";
35 vec = APT::Configuration::getLanguages(false, false, env);
36 equals(vec.size(), 2);
37 equals(vec[0], "en_GB");
38 equals(vec[1], "en");
39
40 env[0] = "tr_DE@euro";
41 vec = APT::Configuration::getLanguages(false, false, env);
42 equals(vec.size(), 2);
43 equals(vec[0], "tr");
44 equals(vec[1], "en");
45
46 env[0] = "de_NO";
47 env[1] = "se_NO:en_GB:nb_NO:nb:no_NO:no:nn_NO:nn:da:sv:en";
48 vec = APT::Configuration::getLanguages(false, false, env);
49 equals(vec.size(), 5);
50 equals(vec[0], "de");
51 equals(vec[1], "en_GB");
52 equals(vec[2], "nb");
53 equals(vec[3], "no");
54 equals(vec[4], "en");
55
56 env[0] = "pt_PR.UTF-8";
57 env[1] = "";
58 vec = APT::Configuration::getLanguages(false, false, env);
59 equals(vec.size(), 3);
60 equals(vec[0], "pt_PR");
61 equals(vec[1], "pt");
62 equals(vec[2], "en");
63
64 env[0] = "ast_DE.UTF-8";
65 vec = APT::Configuration::getLanguages(false, false, env); // bogus, but syntactical correct
66 equals(vec.size(), 2);
67 equals(vec[0], "ast");
68 equals(vec[1], "en");
69
70 env[0] = "C";
71 vec = APT::Configuration::getLanguages(false, false, env);
72 equals(vec.size(), 1);
73 equals(vec[0], "en");
74
75 _config->Set("Acquire::Languages::1", "environment");
76 _config->Set("Acquire::Languages::2", "en");
77 env[0] = "de_DE.UTF-8";
78 vec = APT::Configuration::getLanguages(false, false, env);
79 equals(vec.size(), 2);
80 equals(vec[0], "de");
81 equals(vec[1], "en");
82
83 _config->Set("Acquire::Languages::3", "de");
84 env[0] = "de_DE.UTF-8";
85 vec = APT::Configuration::getLanguages(false, false, env);
86 equals(vec.size(), 2);
87 equals(vec[0], "de");
88 equals(vec[1], "en");
89
90 _config->Set("Acquire::Languages::1", "none");
91 env[0] = "de_DE.UTF-8";
92 vec = APT::Configuration::getLanguages(false, false, env);
93 equals(vec.size(), 0);
94 env[0] = "de_DE.UTF-8";
95 vec = APT::Configuration::getLanguages(true, false, env);
96 equals(vec[0], "en");
97 equals(vec[1], "de");
98
99 _config->Set("Acquire::Languages::1", "fr");
100 _config->Set("Acquire::Languages", "de_DE");
101 env[0] = "de_DE.UTF-8";
102 vec = APT::Configuration::getLanguages(false, false, env);
103 equals(vec.size(), 1);
104 equals(vec[0], "de_DE");
105
106 _config->Set("Acquire::Languages", "none");
107 env[0] = "de_DE.UTF-8";
108 vec = APT::Configuration::getLanguages(true, false, env);
109 equals(vec.size(), 0);
110
111 _config->Set("Acquire::Languages", "");
112 //FIXME: Remove support for this deprecated setting
113 _config->Set("APT::Acquire::Translation", "ast_DE");
114 env[0] = "de_DE.UTF-8";
115 vec = APT::Configuration::getLanguages(true, false, env);
116 equals(vec.size(), 1);
117 equals(vec[0], "ast_DE");
118 _config->Set("APT::Acquire::Translation", "none");
119 env[0] = "de_DE.UTF-8";
120 vec = APT::Configuration::getLanguages(true, false, env);
121 equals(vec.size(), 0);
122
123 return 0;
124 }