]> git.saurik.com Git - apt.git/blob - test/libapt/parsedepends_test.cc
Merge remote-tracking branch 'upstream/debian/sid' into feature/apt-manpage
[apt.git] / test / libapt / parsedepends_test.cc
1 #include <config.h>
2
3 #include <apt-pkg/deblistparser.h>
4 #include <apt-pkg/configuration.h>
5 #include <apt-pkg/pkgcache.h>
6
7 #include <string.h>
8 #include <string>
9
10 #include "assert.h"
11
12 int main() {
13 std::string Package;
14 std::string Version;
15 unsigned int Op = 5;
16 unsigned int Null = 0;
17 bool StripMultiArch = true;
18 bool ParseArchFlags = false;
19 bool ParseRestrictionsList = false;
20 _config->Set("APT::Architecture","amd64");
21 _config->Set("APT::Build-Profiles","stage1");
22
23 const char* Depends =
24 "debhelper:any (>= 5.0), "
25 "libdb-dev:any, "
26 "gettext:native (<= 0.12), "
27 "libcurl4-gnutls-dev:native | libcurl3-gnutls-dev (>> 7.15.5), "
28 "debiandoc-sgml, "
29 "apt (>= 0.7.25), "
30 "not-for-me [ !amd64 ], "
31 "only-for-me [ amd64 ], "
32 "any-for-me [ any ], "
33 "not-for-darwin [ !darwin-any ], "
34 "cpu-for-me [ any-amd64 ], "
35 "os-for-me [ linux-any ], "
36 "cpu-not-for-me [ any-armel ], "
37 "os-not-for-me [ kfreebsd-any ], "
38 "not-in-stage1 <!profile.stage1>, "
39 "not-in-stage1-or-nodoc <!profile.nodoc !profile.stage1>, "
40 "only-in-stage1 <unknown.unknown profile.stage1>, "
41 "overlord-dev:any (= 7.15.3~) | overlord-dev:native (>> 7.15.5), "
42 ;
43
44 unsigned short runner = 0;
45 test:
46 // std::clog << (StripMultiArch ? "NO-Multi" : "Multi") << " " << (ParseArchFlags ? "Flags" : "NO-Flags") << std::endl;
47
48 // Stripping MultiArch is currently the default setting to not confuse
49 // non-MultiArch capable users of the library with "strange" extensions.
50 const char* Start = Depends;
51 const char* End = Depends + strlen(Depends);
52
53 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
54 if (StripMultiArch == true)
55 equals("debhelper", Package);
56 else
57 equals("debhelper:any", Package);
58 equals("5.0", Version);
59 equals(Null | pkgCache::Dep::GreaterEq, Op);
60
61 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
62 if (StripMultiArch == true)
63 equals("libdb-dev", Package);
64 else
65 equals("libdb-dev:any", Package);
66 equals("", Version);
67 equals(Null | pkgCache::Dep::NoOp, Op);
68
69 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
70 if (StripMultiArch == true)
71 equals("gettext", Package);
72 else
73 equals("gettext:native", Package);
74 equals("0.12", Version);
75 equals(Null | pkgCache::Dep::LessEq, Op);
76
77 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
78 if (StripMultiArch == true)
79 equals("libcurl4-gnutls-dev", Package);
80 else
81 equals("libcurl4-gnutls-dev:native", Package);
82 equals("", Version);
83 equals(Null | pkgCache::Dep::Or, Op);
84
85 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
86 equals("libcurl3-gnutls-dev", Package);
87 equals("7.15.5", Version);
88 equals(Null | pkgCache::Dep::Greater, Op);
89
90 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
91 equals("debiandoc-sgml", Package);
92 equals("", Version);
93 equals(Null | pkgCache::Dep::NoOp, Op);
94
95 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
96 equals("apt", Package);
97 equals("0.7.25", Version);
98 equals(Null | pkgCache::Dep::GreaterEq, Op);
99
100 if (ParseArchFlags == true) {
101 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
102 equals("", Package); // not-for-me
103 } else {
104 equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
105 Start = strstr(Start, ",");
106 Start++;
107 }
108
109 if (ParseArchFlags == true) {
110 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
111 equals("only-for-me", Package);
112 equals("", Version);
113 equals(Null | pkgCache::Dep::NoOp, Op);
114 } else {
115 equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
116 Start = strstr(Start, ",");
117 Start++;
118 }
119
120 if (ParseArchFlags == true) {
121 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
122 equals("any-for-me", Package);
123 equals("", Version);
124 equals(Null | pkgCache::Dep::NoOp, Op);
125 } else {
126 equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
127 Start = strstr(Start, ",");
128 Start++;
129 }
130
131 if (ParseArchFlags == true) {
132 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
133 equals("not-for-darwin", Package);
134 equals("", Version);
135 equals(Null | pkgCache::Dep::NoOp, Op);
136 } else {
137 equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
138 Start = strstr(Start, ",");
139 Start++;
140 }
141
142 if (ParseArchFlags == true) {
143 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
144 equals("cpu-for-me", Package);
145 equals("", Version);
146 equals(Null | pkgCache::Dep::NoOp, Op);
147 } else {
148 equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
149 Start = strstr(Start, ",");
150 Start++;
151 }
152
153 if (ParseArchFlags == true) {
154 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
155 equals("os-for-me", Package);
156 equals("", Version);
157 equals(Null | pkgCache::Dep::NoOp, Op);
158 } else {
159 equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
160 Start = strstr(Start, ",");
161 Start++;
162 }
163
164 if (ParseArchFlags == true) {
165 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
166 equals("", Package); // cpu-not-for-me
167 } else {
168 equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
169 Start = strstr(Start, ",");
170 Start++;
171 }
172
173 if (ParseArchFlags == true) {
174 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
175 equals("", Package); // os-not-for-me
176 } else {
177 equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
178 Start = strstr(Start, ",");
179 Start++;
180 }
181
182 if (ParseRestrictionsList == true) {
183 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
184 equals("", Package); // not-in-stage1
185 } else {
186 equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
187 Start = strstr(Start, ",");
188 Start++;
189 }
190
191 if (ParseRestrictionsList == true) {
192 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
193 equals("", Package); // not-in-stage1-or-in-nodoc
194 } else {
195 equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
196 Start = strstr(Start, ",");
197 Start++;
198 }
199
200 if (ParseRestrictionsList == true) {
201 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
202 equals("only-in-stage1", Package);
203 } else {
204 equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
205 Start = strstr(Start, ",");
206 Start++;
207 }
208
209 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
210 if (StripMultiArch == true)
211 equals("overlord-dev", Package);
212 else
213 equals("overlord-dev:any", Package);
214 equals("7.15.3~", Version);
215 equals(Null | pkgCache::Dep::Equals | pkgCache::Dep::Or, Op);
216
217 debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
218 if (StripMultiArch == true)
219 equals("overlord-dev", Package);
220 else
221 equals("overlord-dev:native", Package);
222 equals("7.15.5", Version);
223 equals(Null | pkgCache::Dep::Greater, Op);
224
225 if (StripMultiArch == false)
226 if (ParseArchFlags == false)
227 ParseRestrictionsList = !ParseRestrictionsList;
228 ParseArchFlags = !ParseArchFlags;
229 StripMultiArch = !StripMultiArch;
230
231 runner++;
232 if (runner < 8)
233 goto test; // this is the prove: tests are really evil ;)
234
235 return 0;
236 }