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