]>
git.saurik.com Git - apt.git/blob - test/libapt/parsedepends_test.cc
3 #include <apt-pkg/deblistparser.h>
4 #include <apt-pkg/configuration.h>
5 #include <apt-pkg/pkgcache.h>
10 #include <gtest/gtest.h>
12 static void parseDependency(bool const StripMultiArch
, bool const ParseArchFlags
, bool const ParseRestrictionsList
)
17 unsigned int Null
= 0;
18 _config
->Set("APT::Architecture","amd64");
19 _config
->Set("APT::Build-Profiles","stage1");
22 "debhelper:any (>= 5.0), "
24 "gettext:native (<= 0.12), "
25 "libcurl4-gnutls-dev:native | libcurl3-gnutls-dev (>> 7.15.5), "
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 "libc-for-me [ gnu-linux-any ], "
35 "libc-not-for-me [ musl-linux-any ], "
36 "cpu-not-for-me [ any-armel ], "
37 "os-not-for-me [ kfreebsd-any ], "
38 "not-in-stage1 <!stage1>, "
39 "not-stage1-and-not-nodoc <!nodoc !stage1>, "
40 "not-stage1-or-not-nodoc <!nodoc> <!stage1>, "
41 "unknown-profile <unknown stage1>, "
42 "overlord-dev:any (= 7.15.3~) | overlord-dev:native (>> 7.15.5), "
45 // Stripping MultiArch is currently the default setting to not confuse
46 // non-MultiArch capable users of the library with "strange" extensions.
47 const char* Start
= Depends
;
48 const char* End
= Depends
+ strlen(Depends
);
50 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
51 if (StripMultiArch
== true)
52 EXPECT_EQ("debhelper", Package
);
54 EXPECT_EQ("debhelper:any", Package
);
55 EXPECT_EQ("5.0", Version
);
56 EXPECT_EQ(Null
| pkgCache::Dep::GreaterEq
, Op
);
58 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
59 if (StripMultiArch
== true)
60 EXPECT_EQ("libdb-dev", Package
);
62 EXPECT_EQ("libdb-dev:any", Package
);
63 EXPECT_EQ("", Version
);
64 EXPECT_EQ(Null
| pkgCache::Dep::NoOp
, Op
);
66 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
67 if (StripMultiArch
== true)
68 EXPECT_EQ("gettext", Package
);
70 EXPECT_EQ("gettext:native", Package
);
71 EXPECT_EQ("0.12", Version
);
72 EXPECT_EQ(Null
| pkgCache::Dep::LessEq
, Op
);
74 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
75 if (StripMultiArch
== true)
76 EXPECT_EQ("libcurl4-gnutls-dev", Package
);
78 EXPECT_EQ("libcurl4-gnutls-dev:native", Package
);
79 EXPECT_EQ("", Version
);
80 EXPECT_EQ(Null
| pkgCache::Dep::Or
, Op
);
82 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
83 EXPECT_EQ("libcurl3-gnutls-dev", Package
);
84 EXPECT_EQ("7.15.5", Version
);
85 EXPECT_EQ(Null
| pkgCache::Dep::Greater
, Op
);
87 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
88 EXPECT_EQ("docbook-xml", Package
);
89 EXPECT_EQ("", Version
);
90 EXPECT_EQ(Null
| pkgCache::Dep::NoOp
, Op
);
92 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
93 EXPECT_EQ("apt", Package
);
94 EXPECT_EQ("0.7.25", Version
);
95 EXPECT_EQ(Null
| pkgCache::Dep::GreaterEq
, Op
);
97 if (ParseArchFlags
== true) {
98 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
99 EXPECT_EQ("", Package
); // not-for-me
101 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
102 Start
= strstr(Start
, ",");
106 if (ParseArchFlags
== true) {
107 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
108 EXPECT_EQ("only-for-me", Package
);
109 EXPECT_EQ("", Version
);
110 EXPECT_EQ(Null
| pkgCache::Dep::NoOp
, Op
);
112 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
113 Start
= strstr(Start
, ",");
117 if (ParseArchFlags
== true) {
118 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
119 EXPECT_EQ("any-for-me", Package
);
120 EXPECT_EQ("", Version
);
121 EXPECT_EQ(Null
| pkgCache::Dep::NoOp
, Op
);
123 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
124 Start
= strstr(Start
, ",");
128 if (ParseArchFlags
== true) {
129 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
130 EXPECT_EQ("not-for-darwin", Package
);
131 EXPECT_EQ("", Version
);
132 EXPECT_EQ(Null
| pkgCache::Dep::NoOp
, Op
);
134 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
135 Start
= strstr(Start
, ",");
139 if (ParseArchFlags
== true) {
140 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
141 EXPECT_EQ("cpu-for-me", Package
);
142 EXPECT_EQ("", Version
);
143 EXPECT_EQ(Null
| pkgCache::Dep::NoOp
, Op
);
145 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
146 Start
= strstr(Start
, ",");
150 if (ParseArchFlags
== true) {
151 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
152 EXPECT_EQ("os-for-me", Package
);
153 EXPECT_EQ("", Version
);
154 EXPECT_EQ(Null
| pkgCache::Dep::NoOp
, Op
);
156 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
157 Start
= strstr(Start
, ",");
161 if (ParseArchFlags
== true) {
162 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
163 EXPECT_EQ("libc-for-me", Package
);
164 EXPECT_EQ("", Version
);
165 EXPECT_EQ(Null
| pkgCache::Dep::NoOp
, Op
);
167 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
168 Start
= strstr(Start
, ",");
172 if (ParseArchFlags
== true) {
173 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
174 EXPECT_EQ("", Package
); // libc-not-for-me
176 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
177 Start
= strstr(Start
, ",");
181 if (ParseArchFlags
== true) {
182 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
183 EXPECT_EQ("", Package
); // cpu-not-for-me
185 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
186 Start
= strstr(Start
, ",");
190 if (ParseArchFlags
== true) {
191 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
192 EXPECT_EQ("", Package
); // os-not-for-me
194 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
195 Start
= strstr(Start
, ",");
199 if (ParseRestrictionsList
== true) {
200 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
201 EXPECT_EQ("", Package
); // not-in-stage1
203 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
204 Start
= strstr(Start
, ",");
208 if (ParseRestrictionsList
== true) {
209 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
210 EXPECT_EQ("", Package
); // not-stage1-and-not-nodoc
212 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
213 Start
= strstr(Start
, ",");
217 if (ParseRestrictionsList
== true) {
218 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
219 EXPECT_EQ("not-stage1-or-not-nodoc", Package
);
221 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
222 Start
= strstr(Start
, ",");
226 if (ParseRestrictionsList
== true) {
227 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
228 EXPECT_EQ("", Package
); // unknown-profile
230 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
231 Start
= strstr(Start
, ",");
235 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
236 if (StripMultiArch
== true)
237 EXPECT_EQ("overlord-dev", Package
);
239 EXPECT_EQ("overlord-dev:any", Package
);
240 EXPECT_EQ("7.15.3~", Version
);
241 EXPECT_EQ(Null
| pkgCache::Dep::Equals
| pkgCache::Dep::Or
, Op
);
243 debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
244 if (StripMultiArch
== true)
245 EXPECT_EQ("overlord-dev", Package
);
247 EXPECT_EQ("overlord-dev:native", Package
);
248 EXPECT_EQ("7.15.5", Version
);
249 EXPECT_EQ(Null
| pkgCache::Dep::Greater
, Op
);
252 // FIXME: This testcase is too big/complex
253 TEST(ParseDependsTest
, Everything
)
255 bool StripMultiArch
= true;
256 bool ParseArchFlags
= false;
257 bool ParseRestrictionsList
= false;
258 unsigned short runner
= 0;
262 SCOPED_TRACE(std::string("StripMultiArch: ") + (StripMultiArch
? "true" : "false"));
263 SCOPED_TRACE(std::string("ParseArchFlags: ") + (ParseArchFlags
? "true" : "false"));
264 SCOPED_TRACE(std::string("ParseRestrictionsList: ") + (ParseRestrictionsList
? "true" : "false"));
265 parseDependency(StripMultiArch
, ParseArchFlags
, ParseRestrictionsList
);
267 if (StripMultiArch
== false) {
268 if (ParseArchFlags
== false)
269 ParseRestrictionsList
= !ParseRestrictionsList
;
270 ParseArchFlags
= !ParseArchFlags
;
272 StripMultiArch
= !StripMultiArch
;
276 goto test
; // this is the prove: tests are really evil ;)