]> git.saurik.com Git - apt.git/blame - test/libapt/configuration_test.cc
move defines for version to macros.h
[apt.git] / test / libapt / configuration_test.cc
CommitLineData
213b8805
DK
1#include <apt-pkg/configuration.h>
2
3#include <string>
4#include <vector>
5
6#include "assert.h"
7
65512241 8int main() {
213b8805
DK
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
017f9fd6
DK
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
ec76891f
DK
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
af13d143
DK
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
a5414e56
DK
101 Cnf.Set("Moo::Bar", "1");
102 Cnf.Clear();
103 equals(Cnf.Find("Moo::Bar"), "");
104
105 std::vector<std::string> vec = Cnf.FindVector("Test::Vector", "");
106 equals(vec.size(), 0);
107 vec = Cnf.FindVector("Test::Vector", "foo");
108 equals(vec.size(), 1);
109 equals(vec[0], "foo");
110 vec = Cnf.FindVector("Test::Vector", "foo,bar");
111 equals(vec.size(), 2);
112 equals(vec[0], "foo");
113 equals(vec[1], "bar");
114 Cnf.Set("Test::Vector::", "baz");
115 Cnf.Set("Test::Vector::", "bob");
116 Cnf.Set("Test::Vector::", "dob");
117 vec = Cnf.FindVector("Test::Vector");
118 equals(vec.size(), 3);
119 equals(vec[0], "baz");
120 equals(vec[1], "bob");
121 equals(vec[2], "dob");
122 vec = Cnf.FindVector("Test::Vector", "foo,bar");
123 equals(vec.size(), 3);
124 equals(vec[0], "baz");
125 equals(vec[1], "bob");
126 equals(vec[2], "dob");
127 Cnf.Set("Test::Vector", "abel,bravo");
128 vec = Cnf.FindVector("Test::Vector", "foo,bar");
129 equals(vec.size(), 2);
130 equals(vec[0], "abel");
131 equals(vec[1], "bravo");
d8a06f6e 132
213b8805
DK
133 //FIXME: Test for configuration file parsing;
134 // currently only integration/ tests test them implicitly
135
136 return 0;
137}