]> git.saurik.com Git - apt.git/blob - test/libapt/configuration_test.cc
pass Target/MetaIndexParser around into pkgAcqDiffIndex so that this can be used...
[apt.git] / test / libapt / configuration_test.cc
1 #include <config.h>
2
3 #include <apt-pkg/configuration.h>
4
5 #include <string>
6 #include <vector>
7
8 #include "assert.h"
9
10 int main() {
11 Configuration Cnf;
12 std::vector<std::string> fds;
13
14 Cnf.Set("APT::Keep-Fds::",28);
15 Cnf.Set("APT::Keep-Fds::",17);
16 Cnf.Set("APT::Keep-Fds::2",47);
17 Cnf.Set("APT::Keep-Fds::","broken");
18 fds = Cnf.FindVector("APT::Keep-Fds");
19 equals(fds[0], "28");
20 equals(fds[1], "17");
21 equals(fds[2], "47");
22 equals(fds[3], "broken");
23 equals(fds.size(), 4);
24 equals(Cnf.Exists("APT::Keep-Fds::2"), true);
25 equals(Cnf.Find("APT::Keep-Fds::2"), "47");
26 equals(Cnf.FindI("APT::Keep-Fds::2"), 47);
27 equals(Cnf.Exists("APT::Keep-Fds::3"), false);
28 equals(Cnf.Find("APT::Keep-Fds::3"), "");
29 equals(Cnf.FindI("APT::Keep-Fds::3", 56), 56);
30 equals(Cnf.Find("APT::Keep-Fds::3", "not-set"), "not-set");
31
32 Cnf.Clear("APT::Keep-Fds::2");
33 fds = Cnf.FindVector("APT::Keep-Fds");
34 equals(fds[0], "28");
35 equals(fds[1], "17");
36 equals(fds[2], "");
37 equals(fds[3], "broken");
38 equals(fds.size(), 4);
39 equals(Cnf.Exists("APT::Keep-Fds::2"), true);
40
41 Cnf.Clear("APT::Keep-Fds",28);
42 fds = Cnf.FindVector("APT::Keep-Fds");
43 equals(fds[0], "17");
44 equals(fds[1], "");
45 equals(fds[2], "broken");
46 equals(fds.size(), 3);
47
48 Cnf.Clear("APT::Keep-Fds","");
49 equals(Cnf.Exists("APT::Keep-Fds::2"), false);
50
51 Cnf.Clear("APT::Keep-Fds",17);
52 Cnf.Clear("APT::Keep-Fds","broken");
53 fds = Cnf.FindVector("APT::Keep-Fds");
54 equals(fds.empty(), true);
55
56 Cnf.Set("APT::Keep-Fds::",21);
57 Cnf.Set("APT::Keep-Fds::",42);
58 fds = Cnf.FindVector("APT::Keep-Fds");
59 equals(fds[0], "21");
60 equals(fds[1], "42");
61 equals(fds.size(), 2);
62
63 Cnf.Clear("APT::Keep-Fds");
64 fds = Cnf.FindVector("APT::Keep-Fds");
65 equals(fds.empty(), true);
66
67 Cnf.CndSet("APT::Version", 42);
68 Cnf.CndSet("APT::Version", "66");
69 equals(Cnf.Find("APT::Version"), "42");
70 equals(Cnf.FindI("APT::Version"), 42);
71 equals(Cnf.Find("APT::Version", "33"), "42");
72 equals(Cnf.FindI("APT::Version", 33), 42);
73 equals(Cnf.Find("APT2::Version", "33"), "33");
74 equals(Cnf.FindI("APT2::Version", 33), 33);
75
76 equals(Cnf.FindFile("Dir::State"), "");
77 equals(Cnf.FindFile("Dir::Aptitude::State"), "");
78 Cnf.Set("Dir", "/srv/sid");
79 equals(Cnf.FindFile("Dir::State"), "");
80 Cnf.Set("Dir::State", "var/lib/apt");
81 Cnf.Set("Dir::Aptitude::State", "var/lib/aptitude");
82 equals(Cnf.FindFile("Dir::State"), "/srv/sid/var/lib/apt");
83 equals(Cnf.FindFile("Dir::Aptitude::State"), "/srv/sid/var/lib/aptitude");
84
85 Cnf.Set("RootDir", "/");
86 equals(Cnf.FindFile("Dir::State"), "/srv/sid/var/lib/apt");
87 equals(Cnf.FindFile("Dir::Aptitude::State"), "/srv/sid/var/lib/aptitude");
88 Cnf.Set("RootDir", "//./////.////");
89 equals(Cnf.FindFile("Dir::State"), "/srv/sid/var/lib/apt");
90 equals(Cnf.FindFile("Dir::Aptitude::State"), "/srv/sid/var/lib/aptitude");
91 Cnf.Set("RootDir", "/rootdir");
92 equals(Cnf.FindFile("Dir::State"), "/rootdir/srv/sid/var/lib/apt");
93 equals(Cnf.FindFile("Dir::Aptitude::State"), "/rootdir/srv/sid/var/lib/aptitude");
94 Cnf.Set("RootDir", "/rootdir/");
95 equals(Cnf.FindFile("Dir::State"), "/rootdir/srv/sid/var/lib/apt");
96 equals(Cnf.FindFile("Dir::Aptitude::State"), "/rootdir/srv/sid/var/lib/aptitude");
97
98 Cnf.Set("Dir::State", "/dev/null");
99 Cnf.Set("Dir::State::lists", "lists/");
100 equals(Cnf.FindDir("Dir::State"), "/rootdir/dev/null");
101 equals(Cnf.FindDir("Dir::State::lists"), "/rootdir/dev/null");
102
103 Cnf.Set("Moo::Bar", "1");
104 Cnf.Clear();
105 equals(Cnf.Find("Moo::Bar"), "");
106
107 std::vector<std::string> vec = Cnf.FindVector("Test::Vector", "");
108 equals(vec.size(), 0);
109 vec = Cnf.FindVector("Test::Vector", "foo");
110 equals(vec.size(), 1);
111 equals(vec[0], "foo");
112 vec = Cnf.FindVector("Test::Vector", "foo,bar");
113 equals(vec.size(), 2);
114 equals(vec[0], "foo");
115 equals(vec[1], "bar");
116 Cnf.Set("Test::Vector::", "baz");
117 Cnf.Set("Test::Vector::", "bob");
118 Cnf.Set("Test::Vector::", "dob");
119 vec = Cnf.FindVector("Test::Vector");
120 equals(vec.size(), 3);
121 equals(vec[0], "baz");
122 equals(vec[1], "bob");
123 equals(vec[2], "dob");
124 vec = Cnf.FindVector("Test::Vector", "foo,bar");
125 equals(vec.size(), 3);
126 equals(vec[0], "baz");
127 equals(vec[1], "bob");
128 equals(vec[2], "dob");
129 Cnf.Set("Test::Vector", "abel,bravo");
130 vec = Cnf.FindVector("Test::Vector", "foo,bar");
131 equals(vec.size(), 2);
132 equals(vec[0], "abel");
133 equals(vec[1], "bravo");
134
135 //FIXME: Test for configuration file parsing;
136 // currently only integration/ tests test them implicitly
137
138 return 0;
139 }