]>
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 <!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), "
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
);
47 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
48 if (StripMultiArch
== true)
49 EXPECT_EQ("debhelper", Package
);
51 EXPECT_EQ("debhelper:any", Package
);
52 EXPECT_EQ("5.0", Version
);
53 EXPECT_EQ(Null
| pkgCache::Dep::GreaterEq
, Op
);
55 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
56 if (StripMultiArch
== true)
57 EXPECT_EQ("libdb-dev", Package
);
59 EXPECT_EQ("libdb-dev:any", Package
);
60 EXPECT_EQ("", Version
);
61 EXPECT_EQ(Null
| pkgCache::Dep::NoOp
, Op
);
63 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
64 if (StripMultiArch
== true)
65 EXPECT_EQ("gettext", Package
);
67 EXPECT_EQ("gettext:native", Package
);
68 EXPECT_EQ("0.12", Version
);
69 EXPECT_EQ(Null
| pkgCache::Dep::LessEq
, Op
);
71 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
72 if (StripMultiArch
== true)
73 EXPECT_EQ("libcurl4-gnutls-dev", Package
);
75 EXPECT_EQ("libcurl4-gnutls-dev:native", Package
);
76 EXPECT_EQ("", Version
);
77 EXPECT_EQ(Null
| pkgCache::Dep::Or
, Op
);
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
);
84 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
85 EXPECT_EQ("debiandoc-sgml", Package
);
86 EXPECT_EQ("", Version
);
87 EXPECT_EQ(Null
| pkgCache::Dep::NoOp
, Op
);
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
);
94 if (ParseArchFlags
== true) {
95 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
96 EXPECT_EQ("", Package
); // not-for-me
98 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
99 Start
= strstr(Start
, ",");
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
);
109 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
110 Start
= strstr(Start
, ",");
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
);
120 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
121 Start
= strstr(Start
, ",");
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
);
131 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
132 Start
= strstr(Start
, ",");
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
);
142 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
143 Start
= strstr(Start
, ",");
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
);
153 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
154 Start
= strstr(Start
, ",");
158 if (ParseArchFlags
== true) {
159 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
160 EXPECT_EQ("", Package
); // cpu-not-for-me
162 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
163 Start
= strstr(Start
, ",");
167 if (ParseArchFlags
== true) {
168 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
169 EXPECT_EQ("", Package
); // os-not-for-me
171 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
172 Start
= strstr(Start
, ",");
176 if (ParseRestrictionsList
== true) {
177 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
178 EXPECT_EQ("", Package
); // not-in-stage1
180 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
181 Start
= strstr(Start
, ",");
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
189 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
190 Start
= strstr(Start
, ",");
194 if (ParseRestrictionsList
== true) {
195 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
196 EXPECT_EQ("only-in-stage1", Package
);
198 EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
));
199 Start
= strstr(Start
, ",");
203 Start
= debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
204 if (StripMultiArch
== true)
205 EXPECT_EQ("overlord-dev", Package
);
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
);
211 debListParser::ParseDepends(Start
, End
, Package
, Version
, Op
, ParseArchFlags
, StripMultiArch
, ParseRestrictionsList
);
212 if (StripMultiArch
== true)
213 EXPECT_EQ("overlord-dev", Package
);
215 EXPECT_EQ("overlord-dev:native", Package
);
216 EXPECT_EQ("7.15.5", Version
);
217 EXPECT_EQ(Null
| pkgCache::Dep::Greater
, Op
);
220 // FIXME: This testcase is too big/complex
221 TEST(ParseDependsTest
, Everything
)
223 bool StripMultiArch
= true;
224 bool ParseArchFlags
= false;
225 bool ParseRestrictionsList
= false;
226 unsigned short runner
= 0;
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
);
235 if (StripMultiArch
== false)
236 if (ParseArchFlags
== false)
237 ParseRestrictionsList
= !ParseRestrictionsList
;
238 ParseArchFlags
= !ParseArchFlags
;
239 StripMultiArch
= !StripMultiArch
;
243 goto test
; // this is the prove: tests are really evil ;)