]> git.saurik.com Git - apt.git/blame - test/libapt/configuration_test.cc
Use _apt as our unprivileged user name
[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}
115TEST(ConfigurationTest,Vector)
116{
117 Configuration Cnf;
a5414e56
DK
118
119 std::vector<std::string> vec = Cnf.FindVector("Test::Vector", "");
f00832cc 120 EXPECT_EQ(0, vec.size());
a5414e56 121 vec = Cnf.FindVector("Test::Vector", "foo");
f00832cc
DK
122 ASSERT_EQ(1, vec.size());
123 EXPECT_EQ("foo", vec[0]);
a5414e56 124 vec = Cnf.FindVector("Test::Vector", "foo,bar");
f00832cc
DK
125 EXPECT_EQ(2, vec.size());
126 EXPECT_EQ("foo", vec[0]);
127 EXPECT_EQ("bar", vec[1]);
a5414e56
DK
128 Cnf.Set("Test::Vector::", "baz");
129 Cnf.Set("Test::Vector::", "bob");
130 Cnf.Set("Test::Vector::", "dob");
131 vec = Cnf.FindVector("Test::Vector");
f00832cc
DK
132 ASSERT_EQ(3, vec.size());
133 EXPECT_EQ("baz", vec[0]);
134 EXPECT_EQ("bob", vec[1]);
135 EXPECT_EQ("dob", vec[2]);
a5414e56 136 vec = Cnf.FindVector("Test::Vector", "foo,bar");
f00832cc
DK
137 ASSERT_EQ(3, vec.size());
138 EXPECT_EQ("baz", vec[0]);
139 EXPECT_EQ("bob", vec[1]);
140 EXPECT_EQ("dob", vec[2]);
a5414e56
DK
141 Cnf.Set("Test::Vector", "abel,bravo");
142 vec = Cnf.FindVector("Test::Vector", "foo,bar");
f00832cc
DK
143 ASSERT_EQ(2, vec.size());
144 EXPECT_EQ("abel", vec[0]);
145 EXPECT_EQ("bravo", vec[1]);
213b8805 146}