]> git.saurik.com Git - apt.git/blob - test/libapt/configuration_test.cc
merged lp:~mvo/apt/source-hashes
[apt.git] / test / libapt / configuration_test.cc
1 #include <apt-pkg/configuration.h>
2
3 #include <string>
4 #include <vector>
5
6 #include "assert.h"
7
8 int main(int argc,const char *argv[]) {
9 Configuration Cnf;
10 std::vector<std::string> fds;
11
12 Cnf.Set("APT::Keep-Fds::",28);
13 Cnf.Set("APT::Keep-Fds::",17);
14 Cnf.Set("APT::Keep-Fds::2",47);
15 Cnf.Set("APT::Keep-Fds::","broken");
16 fds = Cnf.FindVector("APT::Keep-Fds");
17 equals(fds[0], "28");
18 equals(fds[1], "17");
19 equals(fds[2], "47");
20 equals(fds[3], "broken");
21 equals(fds.size(), 4);
22 equals(Cnf.Exists("APT::Keep-Fds::2"), true);
23 equals(Cnf.Find("APT::Keep-Fds::2"), "47");
24 equals(Cnf.FindI("APT::Keep-Fds::2"), 47);
25 equals(Cnf.Exists("APT::Keep-Fds::3"), false);
26 equals(Cnf.Find("APT::Keep-Fds::3"), "");
27 equals(Cnf.FindI("APT::Keep-Fds::3", 56), 56);
28 equals(Cnf.Find("APT::Keep-Fds::3", "not-set"), "not-set");
29
30 Cnf.Clear("APT::Keep-Fds::2");
31 fds = Cnf.FindVector("APT::Keep-Fds");
32 equals(fds[0], "28");
33 equals(fds[1], "17");
34 equals(fds[2], "");
35 equals(fds[3], "broken");
36 equals(fds.size(), 4);
37 equals(Cnf.Exists("APT::Keep-Fds::2"), true);
38
39 Cnf.Clear("APT::Keep-Fds",28);
40 fds = Cnf.FindVector("APT::Keep-Fds");
41 equals(fds[0], "17");
42 equals(fds[1], "");
43 equals(fds[2], "broken");
44 equals(fds.size(), 3);
45
46 Cnf.Clear("APT::Keep-Fds","");
47 equals(Cnf.Exists("APT::Keep-Fds::2"), false);
48
49 Cnf.Clear("APT::Keep-Fds",17);
50 Cnf.Clear("APT::Keep-Fds","broken");
51 fds = Cnf.FindVector("APT::Keep-Fds");
52 equals(fds.empty(), true);
53
54 Cnf.Set("APT::Keep-Fds::",21);
55 Cnf.Set("APT::Keep-Fds::",42);
56 fds = Cnf.FindVector("APT::Keep-Fds");
57 equals(fds[0], "21");
58 equals(fds[1], "42");
59 equals(fds.size(), 2);
60
61 Cnf.Clear("APT::Keep-Fds");
62 fds = Cnf.FindVector("APT::Keep-Fds");
63 equals(fds.empty(), true);
64
65 Cnf.CndSet("APT::Version", 42);
66 Cnf.CndSet("APT::Version", "66");
67 equals(Cnf.Find("APT::Version"), "42");
68 equals(Cnf.FindI("APT::Version"), 42);
69 equals(Cnf.Find("APT::Version", "33"), "42");
70 equals(Cnf.FindI("APT::Version", 33), 42);
71 equals(Cnf.Find("APT2::Version", "33"), "33");
72 equals(Cnf.FindI("APT2::Version", 33), 33);
73
74 equals(Cnf.FindFile("Dir::State"), "");
75 equals(Cnf.FindFile("Dir::Aptitude::State"), "");
76 Cnf.Set("Dir", "/srv/sid");
77 equals(Cnf.FindFile("Dir::State"), "");
78 Cnf.Set("Dir::State", "var/lib/apt");
79 Cnf.Set("Dir::Aptitude::State", "var/lib/aptitude");
80 equals(Cnf.FindFile("Dir::State"), "/srv/sid/var/lib/apt");
81 equals(Cnf.FindFile("Dir::Aptitude::State"), "/srv/sid/var/lib/aptitude");
82
83 Cnf.Set("RootDir", "/");
84 equals(Cnf.FindFile("Dir::State"), "/srv/sid/var/lib/apt");
85 equals(Cnf.FindFile("Dir::Aptitude::State"), "/srv/sid/var/lib/aptitude");
86 Cnf.Set("RootDir", "//./////.////");
87 equals(Cnf.FindFile("Dir::State"), "/srv/sid/var/lib/apt");
88 equals(Cnf.FindFile("Dir::Aptitude::State"), "/srv/sid/var/lib/aptitude");
89 Cnf.Set("RootDir", "/rootdir");
90 equals(Cnf.FindFile("Dir::State"), "/rootdir/srv/sid/var/lib/apt");
91 equals(Cnf.FindFile("Dir::Aptitude::State"), "/rootdir/srv/sid/var/lib/aptitude");
92 Cnf.Set("RootDir", "/rootdir/");
93 equals(Cnf.FindFile("Dir::State"), "/rootdir/srv/sid/var/lib/apt");
94 equals(Cnf.FindFile("Dir::Aptitude::State"), "/rootdir/srv/sid/var/lib/aptitude");
95
96 Cnf.Set("Dir::State", "/dev/null");
97 Cnf.Set("Dir::State::lists", "lists/");
98 equals(Cnf.FindDir("Dir::State"), "/rootdir/dev/null");
99 equals(Cnf.FindDir("Dir::State::lists"), "/rootdir/dev/null");
100
101 Cnf.Set("Moo::Bar", "1");
102 Cnf.Clear();
103 equals(Cnf.Find("Moo::Bar"), "");
104
105 //FIXME: Test for configuration file parsing;
106 // currently only integration/ tests test them implicitly
107
108 return 0;
109 }