]> git.saurik.com Git - apt.git/blame - test/libapt/configuration_test.cc
Don't download "optional" files not in Release :/.
[apt.git] / test / libapt / configuration_test.cc
CommitLineData
453b82a3
DK
1#include <config.h>
2
213b8805
DK
3#include <apt-pkg/configuration.h>
4
5#include <string>
6#include <vector>
7
f00832cc 8#include <gtest/gtest.h>
213b8805 9
f00832cc
DK
10//FIXME: Test for configuration file parsing;
11// currently only integration/ tests test them implicitly
12
13TEST(ConfigurationTest,Lists)
14{
213b8805 15 Configuration Cnf;
213b8805
DK
16
17 Cnf.Set("APT::Keep-Fds::",28);
18 Cnf.Set("APT::Keep-Fds::",17);
19 Cnf.Set("APT::Keep-Fds::2",47);
20 Cnf.Set("APT::Keep-Fds::","broken");
f00832cc
DK
21 std::vector<std::string> fds = Cnf.FindVector("APT::Keep-Fds");
22 ASSERT_EQ(4, fds.size());
23 EXPECT_EQ("28", fds[0]);
24 EXPECT_EQ("17", fds[1]);
25 EXPECT_EQ("47", fds[2]);
26 EXPECT_EQ("broken", fds[3]);
27
28 EXPECT_TRUE(Cnf.Exists("APT::Keep-Fds::2"));
29 EXPECT_EQ("47", Cnf.Find("APT::Keep-Fds::2"));
30 EXPECT_EQ(47, Cnf.FindI("APT::Keep-Fds::2"));
31 EXPECT_FALSE(Cnf.Exists("APT::Keep-Fds::3"));
32 EXPECT_EQ("", Cnf.Find("APT::Keep-Fds::3"));
33 EXPECT_EQ(56, Cnf.FindI("APT::Keep-Fds::3", 56));
34 EXPECT_EQ("not-set", Cnf.Find("APT::Keep-Fds::3", "not-set"));
213b8805
DK
35
36 Cnf.Clear("APT::Keep-Fds::2");
f00832cc 37 EXPECT_TRUE(Cnf.Exists("APT::Keep-Fds::2"));
213b8805 38 fds = Cnf.FindVector("APT::Keep-Fds");
f00832cc
DK
39 ASSERT_EQ(4, fds.size());
40 EXPECT_EQ("28", fds[0]);
41 EXPECT_EQ("17", fds[1]);
42 EXPECT_EQ("", fds[2]);
43 EXPECT_EQ("broken", fds[3]);
213b8805
DK
44
45 Cnf.Clear("APT::Keep-Fds",28);
46 fds = Cnf.FindVector("APT::Keep-Fds");
f00832cc
DK
47 ASSERT_EQ(3, fds.size());
48 EXPECT_EQ("17", fds[0]);
49 EXPECT_EQ("", fds[1]);
50 EXPECT_EQ("broken", fds[2]);
213b8805
DK
51
52 Cnf.Clear("APT::Keep-Fds","");
f00832cc 53 EXPECT_FALSE(Cnf.Exists("APT::Keep-Fds::2"));
213b8805
DK
54
55 Cnf.Clear("APT::Keep-Fds",17);
56 Cnf.Clear("APT::Keep-Fds","broken");
57 fds = Cnf.FindVector("APT::Keep-Fds");
f00832cc 58 EXPECT_TRUE(fds.empty());
213b8805
DK
59
60 Cnf.Set("APT::Keep-Fds::",21);
61 Cnf.Set("APT::Keep-Fds::",42);
62 fds = Cnf.FindVector("APT::Keep-Fds");
f00832cc
DK
63 ASSERT_EQ(2, fds.size());
64 EXPECT_EQ("21", fds[0]);
65 EXPECT_EQ("42", fds[1]);
213b8805
DK
66
67 Cnf.Clear("APT::Keep-Fds");
68 fds = Cnf.FindVector("APT::Keep-Fds");
f00832cc
DK
69 EXPECT_TRUE(fds.empty());
70}
71TEST(ConfigurationTest,Integers)
72{
73 Configuration Cnf;
213b8805
DK
74
75 Cnf.CndSet("APT::Version", 42);
76 Cnf.CndSet("APT::Version", "66");
f00832cc
DK
77 EXPECT_EQ("42", Cnf.Find("APT::Version"));
78 EXPECT_EQ(42, Cnf.FindI("APT::Version"));
79 EXPECT_EQ("42", Cnf.Find("APT::Version", "33"));
80 EXPECT_EQ(42, Cnf.FindI("APT::Version", 33));
81 EXPECT_EQ("33", Cnf.Find("APT2::Version", "33"));
82 EXPECT_EQ(33, Cnf.FindI("APT2::Version", 33));
83}
84TEST(ConfigurationTest,DirsAndFiles)
85{
86 Configuration Cnf;
87
88 EXPECT_EQ("", Cnf.FindFile("Dir::State"));
89 EXPECT_EQ("", Cnf.FindFile("Dir::Aptitude::State"));
017f9fd6 90 Cnf.Set("Dir", "/srv/sid");
f00832cc 91 EXPECT_EQ("", Cnf.FindFile("Dir::State"));
017f9fd6
DK
92 Cnf.Set("Dir::State", "var/lib/apt");
93 Cnf.Set("Dir::Aptitude::State", "var/lib/aptitude");
f00832cc
DK
94 EXPECT_EQ("/srv/sid/var/lib/apt", Cnf.FindFile("Dir::State"));
95 EXPECT_EQ("/srv/sid/var/lib/aptitude", Cnf.FindFile("Dir::Aptitude::State"));
017f9fd6 96
ec76891f 97 Cnf.Set("RootDir", "/");
f00832cc
DK
98 EXPECT_EQ("/srv/sid/var/lib/apt", Cnf.FindFile("Dir::State"));
99 EXPECT_EQ("/srv/sid/var/lib/aptitude", Cnf.FindFile("Dir::Aptitude::State"));
ec76891f 100 Cnf.Set("RootDir", "//./////.////");
f00832cc
DK
101 EXPECT_EQ("/srv/sid/var/lib/apt", Cnf.FindFile("Dir::State"));
102 EXPECT_EQ("/srv/sid/var/lib/aptitude", Cnf.FindFile("Dir::Aptitude::State"));
ec76891f 103 Cnf.Set("RootDir", "/rootdir");
f00832cc
DK
104 EXPECT_EQ("/rootdir/srv/sid/var/lib/apt", Cnf.FindFile("Dir::State"));
105 EXPECT_EQ("/rootdir/srv/sid/var/lib/aptitude", Cnf.FindFile("Dir::Aptitude::State"));
ec76891f 106 Cnf.Set("RootDir", "/rootdir/");
f00832cc
DK
107 EXPECT_EQ("/rootdir/srv/sid/var/lib/apt", Cnf.FindFile("Dir::State"));
108 EXPECT_EQ("/rootdir/srv/sid/var/lib/aptitude", Cnf.FindFile("Dir::Aptitude::State"));
ec76891f 109
af13d143
DK
110 Cnf.Set("Dir::State", "/dev/null");
111 Cnf.Set("Dir::State::lists", "lists/");
f00832cc
DK
112 EXPECT_EQ("/rootdir/dev/null", Cnf.FindDir("Dir::State"));
113 EXPECT_EQ("/rootdir/dev/null", Cnf.FindDir("Dir::State::lists"));
114}
bbd8308c
DK
115TEST(ConfigurationTest,DevNullInPaths)
116{
117 Configuration Cnf;
118 EXPECT_EQ("", Cnf.FindFile("Dir"));
119 EXPECT_EQ("", Cnf.FindFile("Dir::State"));
120 EXPECT_EQ("", Cnf.FindFile("Dir::State::status"));
121 Cnf.Set("Dir::State", "/dev/null");
122 EXPECT_EQ("/dev/null", Cnf.FindFile("Dir::State"));
123 Cnf.Set("Dir", "/");
124 Cnf.Set("Dir::State::status", "status");
125 EXPECT_EQ("/dev/null", Cnf.FindFile("Dir::State"));
126 EXPECT_EQ("/dev/null", Cnf.FindFile("Dir::State::status"));
127 Cnf.Set("Dir::State", "");
128 EXPECT_EQ("", Cnf.FindFile("Dir::State"));
129 EXPECT_EQ("/status", Cnf.FindFile("Dir::State::status"));
130 Cnf.Set("Dir", "/dev/null");
131 EXPECT_EQ("/dev/null", Cnf.FindFile("Dir"));
132 EXPECT_EQ("", Cnf.FindFile("Dir::State"));
133 EXPECT_EQ("/dev/null", Cnf.FindFile("Dir::State::status"));
134 Cnf.Set("Dir", "/rootdir");
135 EXPECT_EQ("/rootdir", Cnf.FindFile("Dir"));
136 EXPECT_EQ("", Cnf.FindFile("Dir::State"));
137 EXPECT_EQ("/rootdir/status", Cnf.FindFile("Dir::State::status"));
138 Cnf.Set("Dir::State::status", "/foo/status");
139 EXPECT_EQ("/rootdir", Cnf.FindFile("Dir"));
140 EXPECT_EQ("", Cnf.FindFile("Dir::State"));
141 EXPECT_EQ("/foo/status", Cnf.FindFile("Dir::State::status"));
142}
f00832cc
DK
143TEST(ConfigurationTest,Vector)
144{
145 Configuration Cnf;
a5414e56
DK
146
147 std::vector<std::string> vec = Cnf.FindVector("Test::Vector", "");
f00832cc 148 EXPECT_EQ(0, vec.size());
a5414e56 149 vec = Cnf.FindVector("Test::Vector", "foo");
f00832cc
DK
150 ASSERT_EQ(1, vec.size());
151 EXPECT_EQ("foo", vec[0]);
a5414e56 152 vec = Cnf.FindVector("Test::Vector", "foo,bar");
f00832cc
DK
153 EXPECT_EQ(2, vec.size());
154 EXPECT_EQ("foo", vec[0]);
155 EXPECT_EQ("bar", vec[1]);
a5414e56
DK
156 Cnf.Set("Test::Vector::", "baz");
157 Cnf.Set("Test::Vector::", "bob");
158 Cnf.Set("Test::Vector::", "dob");
159 vec = Cnf.FindVector("Test::Vector");
f00832cc
DK
160 ASSERT_EQ(3, vec.size());
161 EXPECT_EQ("baz", vec[0]);
162 EXPECT_EQ("bob", vec[1]);
163 EXPECT_EQ("dob", vec[2]);
a5414e56 164 vec = Cnf.FindVector("Test::Vector", "foo,bar");
f00832cc
DK
165 ASSERT_EQ(3, vec.size());
166 EXPECT_EQ("baz", vec[0]);
167 EXPECT_EQ("bob", vec[1]);
168 EXPECT_EQ("dob", vec[2]);
a5414e56
DK
169 Cnf.Set("Test::Vector", "abel,bravo");
170 vec = Cnf.FindVector("Test::Vector", "foo,bar");
f00832cc
DK
171 ASSERT_EQ(2, vec.size());
172 EXPECT_EQ("abel", vec[0]);
173 EXPECT_EQ("bravo", vec[1]);
213b8805 174}
c3ded84c
DK
175TEST(ConfigurationTest,Merge)
176{
177 Configuration Cnf;
178 Cnf.Set("Binary::apt::option::foo", "bar");
514a25cb 179 Cnf.Set("Binary::apt::option::empty", "");
c3ded84c
DK
180 Cnf.Set("option::foo", "foo");
181
182 Cnf.MoveSubTree("Binary::apt", "Binary::apt2");
183 EXPECT_FALSE(Cnf.Exists("Binary::apt::option"));
184 EXPECT_TRUE(Cnf.Exists("option"));
185 EXPECT_EQ("foo", Cnf.Find("option::foo"));
186 EXPECT_EQ("bar", Cnf.Find("Binary::apt2::option::foo"));
187
514a25cb
DK
188 EXPECT_FALSE(Cnf.Exists("option::empty"));
189 EXPECT_TRUE(Cnf.Exists("Binary::apt2::option::empty"));
190 Cnf.Set("option::empty", "not");
191
c3ded84c
DK
192 Cnf.MoveSubTree("Binary::apt2", NULL);
193 EXPECT_FALSE(Cnf.Exists("Binary::apt2::option"));
194 EXPECT_TRUE(Cnf.Exists("option"));
195 EXPECT_EQ("bar", Cnf.Find("option::foo"));
514a25cb 196 EXPECT_EQ("", Cnf.Find("option::empty"));
c3ded84c 197}