]>
Commit | Line | Data |
---|---|---|
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 | ||
12 | static 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 ], " | |
ac81c0f9 | 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>, " | |
f00832cc DK |
40 | "overlord-dev:any (= 7.15.3~) | overlord-dev:native (>> 7.15.5), " |
41 | ; | |
42 | ||
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); | |
47 | ||
48 | Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList); | |
49 | if (StripMultiArch == true) | |
50 | EXPECT_EQ("debhelper", Package); | |
51 | else | |
52 | EXPECT_EQ("debhelper:any", Package); | |
53 | EXPECT_EQ("5.0", Version); | |
54 | EXPECT_EQ(Null | pkgCache::Dep::GreaterEq, Op); | |
55 | ||
56 | Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList); | |
57 | if (StripMultiArch == true) | |
58 | EXPECT_EQ("libdb-dev", Package); | |
59 | else | |
60 | EXPECT_EQ("libdb-dev:any", Package); | |
61 | EXPECT_EQ("", Version); | |
62 | EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op); | |
63 | ||
64 | Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList); | |
65 | if (StripMultiArch == true) | |
66 | EXPECT_EQ("gettext", Package); | |
67 | else | |
68 | EXPECT_EQ("gettext:native", Package); | |
69 | EXPECT_EQ("0.12", Version); | |
70 | EXPECT_EQ(Null | pkgCache::Dep::LessEq, Op); | |
71 | ||
72 | Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList); | |
73 | if (StripMultiArch == true) | |
74 | EXPECT_EQ("libcurl4-gnutls-dev", Package); | |
75 | else | |
76 | EXPECT_EQ("libcurl4-gnutls-dev:native", Package); | |
77 | EXPECT_EQ("", Version); | |
78 | EXPECT_EQ(Null | pkgCache::Dep::Or, Op); | |
79 | ||
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); | |
84 | ||
85 | Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList); | |
a034d852 | 86 | EXPECT_EQ("docbook-xml", Package); |
f00832cc DK |
87 | EXPECT_EQ("", Version); |
88 | EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op); | |
89 | ||
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); | |
94 | ||
95 | if (ParseArchFlags == true) { | |
96 | Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList); | |
97 | EXPECT_EQ("", Package); // not-for-me | |
98 | } else { | |
99 | EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList)); | |
100 | Start = strstr(Start, ","); | |
101 | Start++; | |
102 | } | |
103 | ||
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); | |
109 | } else { | |
110 | EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList)); | |
111 | Start = strstr(Start, ","); | |
112 | Start++; | |
113 | } | |
114 | ||
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); | |
120 | } else { | |
121 | EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList)); | |
122 | Start = strstr(Start, ","); | |
123 | Start++; | |
124 | } | |
125 | ||
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); | |
131 | } else { | |
132 | EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList)); | |
133 | Start = strstr(Start, ","); | |
134 | Start++; | |
135 | } | |
136 | ||
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); | |
142 | } else { | |
143 | EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList)); | |
144 | Start = strstr(Start, ","); | |
145 | Start++; | |
146 | } | |
147 | ||
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); | |
153 | } else { | |
154 | EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList)); | |
155 | Start = strstr(Start, ","); | |
156 | Start++; | |
157 | } | |
158 | ||
159 | if (ParseArchFlags == true) { | |
160 | Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList); | |
161 | EXPECT_EQ("", Package); // cpu-not-for-me | |
162 | } else { | |
163 | EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList)); | |
164 | Start = strstr(Start, ","); | |
165 | Start++; | |
166 | } | |
167 | ||
168 | if (ParseArchFlags == true) { | |
169 | Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList); | |
170 | EXPECT_EQ("", Package); // os-not-for-me | |
171 | } else { | |
172 | EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList)); | |
173 | Start = strstr(Start, ","); | |
174 | Start++; | |
175 | } | |
176 | ||
177 | if (ParseRestrictionsList == true) { | |
178 | Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList); | |
179 | EXPECT_EQ("", Package); // not-in-stage1 | |
180 | } else { | |
181 | EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList)); | |
182 | Start = strstr(Start, ","); | |
183 | Start++; | |
184 | } | |
185 | ||
186 | if (ParseRestrictionsList == true) { | |
187 | Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList); | |
ac81c0f9 | 188 | EXPECT_EQ("", Package); // not-stage1-and-not-nodoc |
f00832cc DK |
189 | } else { |
190 | EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList)); | |
191 | Start = strstr(Start, ","); | |
192 | Start++; | |
193 | } | |
194 | ||
195 | if (ParseRestrictionsList == true) { | |
196 | Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList); | |
ac81c0f9 | 197 | EXPECT_EQ("not-stage1-or-not-nodoc", Package); |
198 | } else { | |
199 | EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList)); | |
200 | Start = strstr(Start, ","); | |
201 | Start++; | |
202 | } | |
203 | ||
204 | if (ParseRestrictionsList == true) { | |
205 | Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList); | |
206 | EXPECT_EQ("", Package); // unknown-profile | |
f00832cc DK |
207 | } else { |
208 | EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList)); | |
209 | Start = strstr(Start, ","); | |
210 | Start++; | |
211 | } | |
212 | ||
213 | Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList); | |
214 | if (StripMultiArch == true) | |
215 | EXPECT_EQ("overlord-dev", Package); | |
216 | else | |
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); | |
220 | ||
221 | debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList); | |
222 | if (StripMultiArch == true) | |
223 | EXPECT_EQ("overlord-dev", Package); | |
224 | else | |
225 | EXPECT_EQ("overlord-dev:native", Package); | |
226 | EXPECT_EQ("7.15.5", Version); | |
227 | EXPECT_EQ(Null | pkgCache::Dep::Greater, Op); | |
228 | } | |
229 | ||
230 | // FIXME: This testcase is too big/complex | |
231 | TEST(ParseDependsTest, Everything) | |
232 | { | |
233 | bool StripMultiArch = true; | |
234 | bool ParseArchFlags = false; | |
235 | bool ParseRestrictionsList = false; | |
236 | unsigned short runner = 0; | |
237 | ||
41c81fd8 | 238 | test: |
f00832cc DK |
239 | { |
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); | |
244 | } | |
ac81c0f9 | 245 | if (StripMultiArch == false) { |
246 | if (ParseArchFlags == false) | |
247 | ParseRestrictionsList = !ParseRestrictionsList; | |
248 | ParseArchFlags = !ParseArchFlags; | |
249 | } | |
f00832cc DK |
250 | StripMultiArch = !StripMultiArch; |
251 | ||
252 | runner++; | |
253 | if (runner < 8) | |
254 | goto test; // this is the prove: tests are really evil ;) | |
41c81fd8 | 255 | } |