]> git.saurik.com Git - apt.git/blame - test/libapt/parsedepends_test.cc
Merge branch 'debian/sid' into debian/experimental
[apt.git] / test / libapt / parsedepends_test.cc
CommitLineData
453b82a3
DK
1#include <config.h>
2
41c81fd8
DK
3#include <apt-pkg/deblistparser.h>
4#include <apt-pkg/configuration.h>
453b82a3
DK
5#include <apt-pkg/pkgcache.h>
6
7#include <string.h>
8#include <string>
41c81fd8 9
f00832cc
DK
10#include <gtest/gtest.h>
11
12static void parseDependency(bool const StripMultiArch, bool const ParseArchFlags, bool const ParseRestrictionsList)
13{
14 std::string Package;
15 std::string Version;
16 unsigned int Op = 5;
17 unsigned int Null = 0;
18 _config->Set("APT::Architecture","amd64");
19 _config->Set("APT::Build-Profiles","stage1");
20
21 const char* Depends =
22 "debhelper:any (>= 5.0), "
23 "libdb-dev:any, "
24 "gettext:native (<= 0.12), "
25 "libcurl4-gnutls-dev:native | libcurl3-gnutls-dev (>> 7.15.5), "
a034d852 26 "docbook-xml, "
f00832cc
DK
27 "apt (>= 0.7.25), "
28 "not-for-me [ !amd64 ], "
29 "only-for-me [ amd64 ], "
30 "any-for-me [ any ], "
31 "not-for-darwin [ !darwin-any ], "
32 "cpu-for-me [ any-amd64 ], "
33 "os-for-me [ linux-any ], "
34 "cpu-not-for-me [ any-armel ], "
35 "os-not-for-me [ kfreebsd-any ], "
36 "not-in-stage1 <!profile.stage1>, "
37 "not-in-stage1-or-nodoc <!profile.nodoc !profile.stage1>, "
38 "only-in-stage1 <unknown.unknown profile.stage1>, "
39 "overlord-dev:any (= 7.15.3~) | overlord-dev:native (>> 7.15.5), "
40 ;
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
47 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
48 if (StripMultiArch == true)
49 EXPECT_EQ("debhelper", Package);
50 else
51 EXPECT_EQ("debhelper:any", Package);
52 EXPECT_EQ("5.0", Version);
53 EXPECT_EQ(Null | pkgCache::Dep::GreaterEq, Op);
54
55 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
56 if (StripMultiArch == true)
57 EXPECT_EQ("libdb-dev", Package);
58 else
59 EXPECT_EQ("libdb-dev:any", Package);
60 EXPECT_EQ("", Version);
61 EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op);
62
63 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
64 if (StripMultiArch == true)
65 EXPECT_EQ("gettext", Package);
66 else
67 EXPECT_EQ("gettext:native", Package);
68 EXPECT_EQ("0.12", Version);
69 EXPECT_EQ(Null | pkgCache::Dep::LessEq, Op);
70
71 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
72 if (StripMultiArch == true)
73 EXPECT_EQ("libcurl4-gnutls-dev", Package);
74 else
75 EXPECT_EQ("libcurl4-gnutls-dev:native", Package);
76 EXPECT_EQ("", Version);
77 EXPECT_EQ(Null | pkgCache::Dep::Or, Op);
78
79 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
80 EXPECT_EQ("libcurl3-gnutls-dev", Package);
81 EXPECT_EQ("7.15.5", Version);
82 EXPECT_EQ(Null | pkgCache::Dep::Greater, Op);
83
84 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
a034d852 85 EXPECT_EQ("docbook-xml", Package);
f00832cc
DK
86 EXPECT_EQ("", Version);
87 EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op);
88
89 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
90 EXPECT_EQ("apt", Package);
91 EXPECT_EQ("0.7.25", Version);
92 EXPECT_EQ(Null | pkgCache::Dep::GreaterEq, Op);
93
94 if (ParseArchFlags == true) {
95 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
96 EXPECT_EQ("", Package); // not-for-me
97 } else {
98 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
99 Start = strstr(Start, ",");
100 Start++;
101 }
102
103 if (ParseArchFlags == true) {
104 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
105 EXPECT_EQ("only-for-me", Package);
106 EXPECT_EQ("", Version);
107 EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op);
108 } else {
109 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
110 Start = strstr(Start, ",");
111 Start++;
112 }
113
114 if (ParseArchFlags == true) {
115 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
116 EXPECT_EQ("any-for-me", Package);
117 EXPECT_EQ("", Version);
118 EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op);
119 } else {
120 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
121 Start = strstr(Start, ",");
122 Start++;
123 }
124
125 if (ParseArchFlags == true) {
126 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
127 EXPECT_EQ("not-for-darwin", Package);
128 EXPECT_EQ("", Version);
129 EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op);
130 } else {
131 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
132 Start = strstr(Start, ",");
133 Start++;
134 }
135
136 if (ParseArchFlags == true) {
137 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
138 EXPECT_EQ("cpu-for-me", Package);
139 EXPECT_EQ("", Version);
140 EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op);
141 } else {
142 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
143 Start = strstr(Start, ",");
144 Start++;
145 }
146
147 if (ParseArchFlags == true) {
148 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
149 EXPECT_EQ("os-for-me", Package);
150 EXPECT_EQ("", Version);
151 EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op);
152 } else {
153 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
154 Start = strstr(Start, ",");
155 Start++;
156 }
157
158 if (ParseArchFlags == true) {
159 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
160 EXPECT_EQ("", Package); // cpu-not-for-me
161 } else {
162 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
163 Start = strstr(Start, ",");
164 Start++;
165 }
166
167 if (ParseArchFlags == true) {
168 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
169 EXPECT_EQ("", Package); // os-not-for-me
170 } else {
171 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
172 Start = strstr(Start, ",");
173 Start++;
174 }
175
176 if (ParseRestrictionsList == true) {
177 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
178 EXPECT_EQ("", Package); // not-in-stage1
179 } else {
180 EXPECT_EQ(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 EXPECT_EQ("", Package); // not-in-stage1-or-in-nodoc
188 } else {
189 EXPECT_EQ(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 EXPECT_EQ("only-in-stage1", Package);
197 } else {
198 EXPECT_EQ(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);
204 if (StripMultiArch == true)
205 EXPECT_EQ("overlord-dev", Package);
206 else
207 EXPECT_EQ("overlord-dev:any", Package);
208 EXPECT_EQ("7.15.3~", Version);
209 EXPECT_EQ(Null | pkgCache::Dep::Equals | pkgCache::Dep::Or, Op);
210
211 debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
212 if (StripMultiArch == true)
213 EXPECT_EQ("overlord-dev", Package);
214 else
215 EXPECT_EQ("overlord-dev:native", Package);
216 EXPECT_EQ("7.15.5", Version);
217 EXPECT_EQ(Null | pkgCache::Dep::Greater, Op);
218}
219
220// FIXME: This testcase is too big/complex
221TEST(ParseDependsTest, Everything)
222{
223 bool StripMultiArch = true;
224 bool ParseArchFlags = false;
225 bool ParseRestrictionsList = false;
226 unsigned short runner = 0;
227
41c81fd8 228test:
f00832cc
DK
229 {
230 SCOPED_TRACE(std::string("StripMultiArch: ") + (StripMultiArch ? "true" : "false"));
231 SCOPED_TRACE(std::string("ParseArchFlags: ") + (ParseArchFlags ? "true" : "false"));
232 SCOPED_TRACE(std::string("ParseRestrictionsList: ") + (ParseRestrictionsList ? "true" : "false"));
233 parseDependency(StripMultiArch, ParseArchFlags, ParseRestrictionsList);
234 }
235 if (StripMultiArch == false)
236 if (ParseArchFlags == false)
237 ParseRestrictionsList = !ParseRestrictionsList;
238 ParseArchFlags = !ParseArchFlags;
239 StripMultiArch = !StripMultiArch;
240
241 runner++;
242 if (runner < 8)
243 goto test; // this is the prove: tests are really evil ;)
41c81fd8 244}