]>
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 "cpu-not-for-me [ any-armel ], "
35 "os-not-for-me [ kfreebsd-any ], "
36 "not-in-stage1 <!stage1>, "
37 "not-stage1-and-not-nodoc <!nodoc !stage1>, "
38 "not-stage1-or-not-nodoc <!nodoc> <!stage1>, "
39 "unknown-profile <unknown stage1>, "
40 "overlord-dev:any (= 7.15.3~) | overlord-dev:native (>> 7.15.5), "
43 // Stripping MultiArch is currently the default setting to not confuse
44 // non-MultiArch capable users of the library with "strange" extensions.
45 const char* Start
= Depends
;
46 const char* End
= Depends
+ strlen(Depends
);
48 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
49 if (StripMultiArch
== true)
50 EXPECT_EQ("debhelper", Package
);
52 EXPECT_EQ("debhelper:any", Package
);
53 EXPECT_EQ("5.0", Version
);
54 EXPECT_EQ(Null
| pkgCache::Dep::GreaterEq
, Op
);
56 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
57 if (StripMultiArch
== true)
58 EXPECT_EQ("libdb-dev", Package
);
60 EXPECT_EQ("libdb-dev:any", Package
);
61 EXPECT_EQ("", Version
);
62 EXPECT_EQ(Null
| pkgCache::Dep::NoOp
, Op
);
64 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
65 if (StripMultiArch
== true)
66 EXPECT_EQ("gettext", Package
);
68 EXPECT_EQ("gettext:native", Package
);
69 EXPECT_EQ("0.12", Version
);
70 EXPECT_EQ(Null
| pkgCache::Dep::LessEq
, Op
);
72 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
73 if (StripMultiArch
== true)
74 EXPECT_EQ("libcurl4-gnutls-dev", Package
);
76 EXPECT_EQ("libcurl4-gnutls-dev:native", Package
);
77 EXPECT_EQ("", Version
);
78 EXPECT_EQ(Null
| pkgCache::Dep::Or
, Op
);
80 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
81 EXPECT_EQ("libcurl3-gnutls-dev", Package
);
82 EXPECT_EQ("7.15.5", Version
);
83 EXPECT_EQ(Null
| pkgCache::Dep::Greater
, Op
);
85 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
86 EXPECT_EQ("docbook-xml", Package
);
87 EXPECT_EQ("", Version
);
88 EXPECT_EQ(Null
| pkgCache::Dep::NoOp
, Op
);
90 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
91 EXPECT_EQ("apt", Package
);
92 EXPECT_EQ("0.7.25", Version
);
93 EXPECT_EQ(Null
| pkgCache::Dep::GreaterEq
, Op
);
95 if (ParseArchFlags
== true) {
96 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
97 EXPECT_EQ("", Package
); // not-for-me
99 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
100 Start
= strstr(Start
, ",");
104 if (ParseArchFlags
== true) {
105 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
106 EXPECT_EQ("only-for-me", Package
);
107 EXPECT_EQ("", Version
);
108 EXPECT_EQ(Null
| pkgCache::Dep::NoOp
, Op
);
110 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
111 Start
= strstr(Start
, ",");
115 if (ParseArchFlags
== true) {
116 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
117 EXPECT_EQ("any-for-me", Package
);
118 EXPECT_EQ("", Version
);
119 EXPECT_EQ(Null
| pkgCache::Dep::NoOp
, Op
);
121 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
122 Start
= strstr(Start
, ",");
126 if (ParseArchFlags
== true) {
127 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
128 EXPECT_EQ("not-for-darwin", Package
);
129 EXPECT_EQ("", Version
);
130 EXPECT_EQ(Null
| pkgCache::Dep::NoOp
, Op
);
132 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
133 Start
= strstr(Start
, ",");
137 if (ParseArchFlags
== true) {
138 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
139 EXPECT_EQ("cpu-for-me", Package
);
140 EXPECT_EQ("", Version
);
141 EXPECT_EQ(Null
| pkgCache::Dep::NoOp
, Op
);
143 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
144 Start
= strstr(Start
, ",");
148 if (ParseArchFlags
== true) {
149 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
150 EXPECT_EQ("os-for-me", Package
);
151 EXPECT_EQ("", Version
);
152 EXPECT_EQ(Null
| pkgCache::Dep::NoOp
, Op
);
154 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
155 Start
= strstr(Start
, ",");
159 if (ParseArchFlags
== true) {
160 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
161 EXPECT_EQ("", Package
); // cpu-not-for-me
163 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
164 Start
= strstr(Start
, ",");
168 if (ParseArchFlags
== true) {
169 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
170 EXPECT_EQ("", Package
); // os-not-for-me
172 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
173 Start
= strstr(Start
, ",");
177 if (ParseRestrictionsList
== true) {
178 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
179 EXPECT_EQ("", Package
); // not-in-stage1
181 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
182 Start
= strstr(Start
, ",");
186 if (ParseRestrictionsList
== true) {
187 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
188 EXPECT_EQ("", Package
); // not-stage1-and-not-nodoc
190 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
191 Start
= strstr(Start
, ",");
195 if (ParseRestrictionsList
== true) {
196 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
197 EXPECT_EQ("not-stage1-or-not-nodoc", Package
);
199 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
200 Start
= strstr(Start
, ",");
204 if (ParseRestrictionsList
== true) {
205 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
206 EXPECT_EQ("", Package
); // unknown-profile
208 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
209 Start
= strstr(Start
, ",");
213 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
214 if (StripMultiArch
== true)
215 EXPECT_EQ("overlord-dev", Package
);
217 EXPECT_EQ("overlord-dev:any", Package
);
218 EXPECT_EQ("7.15.3~", Version
);
219 EXPECT_EQ(Null
| pkgCache::Dep::Equals
| pkgCache::Dep::Or
, Op
);
221 debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
222 if (StripMultiArch
== true)
223 EXPECT_EQ("overlord-dev", Package
);
225 EXPECT_EQ("overlord-dev:native", Package
);
226 EXPECT_EQ("7.15.5", Version
);
227 EXPECT_EQ(Null
| pkgCache::Dep::Greater
, Op
);
230 // FIXME: This testcase is too big/complex
231 TEST(ParseDependsTest
, Everything
)
233 bool StripMultiArch
= true;
234 bool ParseArchFlags
= false;
235 bool ParseRestrictionsList
= false;
236 unsigned short runner
= 0;
240 SCOPED_TRACE(std::string("StripMultiArch: ") + (StripMultiArch
? "true" : "false"));
241 SCOPED_TRACE(std::string("ParseArchFlags: ") + (ParseArchFlags
? "true" : "false"));
242 SCOPED_TRACE(std::string("ParseRestrictionsList: ") + (ParseRestrictionsList
? "true" : "false"));
243 parseDependency(StripMultiArch
, ParseArchFlags
, ParseRestrictionsList
);
245 if (StripMultiArch
== false) {
246 if (ParseArchFlags
== false)
247 ParseRestrictionsList
= !ParseRestrictionsList
;
248 ParseArchFlags
= !ParseArchFlags
;
250 StripMultiArch
= !StripMultiArch
;
254 goto test
; // this is the prove: tests are really evil ;)