Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / tests / zypp / PoolQuery_test.cc
1 #include "TestSetup.h"
2 #include "zypp/PoolQuery.h"
3 #include "zypp/PoolQueryUtil.tcc"
4
5 #define BOOST_TEST_MODULE PoolQuery
6
7 /////////////////////////////////////////////////////////////////////////////
8 static TestSetup test( Arch_x86_64 );
9
10 BOOST_AUTO_TEST_CASE(pool_query_init)
11 {
12   // Abuse;) vbox as System repo:
13   test.loadTargetRepo( TESTS_SRC_DIR "/data/obs_virtualbox_11_1" );
14   test.loadRepo( TESTS_SRC_DIR "/data/openSUSE-11.1", "opensuse" );
15   test.loadRepo( TESTS_SRC_DIR "/data/OBS_zypp_svn-11.1", "zyppsvn" );
16
17   dumpRange( USR, test.pool().knownRepositoriesBegin(),
18                   test.pool().knownRepositoriesEnd() );
19   USR << "pool: " << test.pool() << endl;
20 }
21 /////////////////////////////////////////////////////////////////////////////
22
23 static std::ofstream devNull;
24 #define COUT devNull
25
26 struct PrintAndCount
27 {
28   PrintAndCount() : _count(0) {}
29
30   bool operator()( const sat::Solvable & solvable )
31   {
32     zypp::PoolItem pi( zypp::ResPool::instance().find( solvable ) );
33     COUT << pi.resolvable() << endl;
34     ++_count;
35     return true;
36   }
37
38   unsigned _count;
39 };
40
41 void dumpQ( std::ostream & str, const PoolQuery & q, bool verbose = true )
42 {
43   q.begin();
44   str << q << endl;
45   unsigned nc = 0;
46   if ( 1 )
47   {
48     for_( it, q.begin(), q.end() )
49     {
50       ++nc;
51       if ( verbose )
52         str << it << endl;
53     }
54     str << "--> MATCHES: " << nc << endl;
55   }
56 }
57
58
59 #if 0
60 BOOST_AUTO_TEST_CASE(pool_query_experiment)
61 {
62   cout << "****experiment****"  << endl;
63
64   PoolQuery q;
65   q.addString("zypper");
66   q.addAttribute(sat::SolvAttr::name);
67
68   // should list 1 selectable?
69   cout << "****selectables****"  << endl;
70   for (PoolQuery::Selectable_iterator it = q.selectableBegin();
71        it != q.selectableEnd(); ++it)
72   {
73     ui::Selectable::Ptr s = *it;
74     cout << s->kind() << ":" << s->name() << " hasinstalled: " << s->installedEmpty() << endl;
75   }
76   cout << "****solvables****" << endl;
77   PrintAndCount cb;
78   std::for_each(q.begin(), q.end(), cb);
79 }
80 #endif
81
82 /////////////////////////////////////////////////////////////////////////////
83 //  0xx basic queries
84 /////////////////////////////////////////////////////////////////////////////
85
86 // no conditions, default query
87 // result: all available resolvables
88 BOOST_AUTO_TEST_CASE(pool_query_000)
89 {
90   cout << "****000****"  << endl;
91   PoolQuery q;
92   cout << q.size() << endl;
93   BOOST_CHECK(q.size() == 3811);
94
95   /* dumpsolv repo1.solv repo2.solv repo3.solv | \
96      grep '^name:.*\(noarch\|x86_64\|i386\|i586\|i686\|src\)$' | wc -l */
97 }
98
99 // default query + one search string
100 // q.addString("foo");
101 // result: all resolvables having at least one attribute matching foo
102 BOOST_AUTO_TEST_CASE(pool_query_001)
103 {
104   cout << "****001****"  << endl;
105   PoolQuery q;
106   q.addString("zypper");
107
108   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 11);
109 }
110
111 // default query + one attribute + one string
112 // q.addAttribute(foo, bar);
113 // should be the same as
114 // q.addAttribute(foo); q.addString(bar);
115 // result: resolvables with foo containing bar
116 BOOST_AUTO_TEST_CASE(pool_query_002)
117 {
118   cout << "****002****"  << endl;
119   PoolQuery q;
120   q.addString("zypper");
121   q.addAttribute(sat::SolvAttr::name);
122
123   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 5);
124
125   cout << endl;
126
127   PoolQuery q1;
128   q1.addAttribute(sat::SolvAttr::name, "zypper");
129
130   BOOST_CHECK(std::for_each(q1.begin(), q1.end(), PrintAndCount())._count == 5);
131 }
132
133 // kind filter
134 BOOST_AUTO_TEST_CASE(pool_query_003)
135 {
136   cout << "****003****"  << endl;
137   PoolQuery q;
138   q.addString("zypper");
139   q.addAttribute(sat::SolvAttr::name);
140   q.addKind(ResKind::package);
141
142   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 3);
143 }
144
145 // match exact
146 BOOST_AUTO_TEST_CASE(pool_query_004)
147 {
148   cout << "****004****"  << endl;
149   PoolQuery q;
150   q.addString("vim");
151   q.addAttribute(sat::SolvAttr::name);
152   q.setMatchExact();
153
154   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 1);
155
156   PoolQuery q1;
157   q1.addString("zypp");
158   q1.addAttribute(sat::SolvAttr::name);
159   q1.setMatchExact();
160
161   std::for_each(q1.begin(), q1.end(), PrintAndCount());
162   BOOST_CHECK(q1.empty());
163 }
164
165 // use globs
166 BOOST_AUTO_TEST_CASE(pool_query_005)
167 {
168   cout << "****005.1****"  << endl;
169   PoolQuery q;
170   q.addString("z?p*");
171   q.addAttribute(sat::SolvAttr::name);
172   q.setMatchGlob();
173
174   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 6);
175
176   cout << "****005.2****"  << endl;
177
178   PoolQuery q1;
179   q1.addString("*zypp*");
180   q1.addAttribute(sat::SolvAttr::name);
181   q1.setMatchGlob();
182
183   BOOST_CHECK(std::for_each(q1.begin(), q1.end(), PrintAndCount())._count == 26);
184
185   cout << "****005.3****"  << endl;
186
187   // should be the same as above
188   PoolQuery q2;
189   q2.addString("zypp");
190   q2.addAttribute(sat::SolvAttr::name);
191
192   BOOST_CHECK(q2.size() == 26);
193 }
194
195 // use regex
196 BOOST_AUTO_TEST_CASE(pool_query_006)
197 {
198   cout << "****006.1***"  << endl;
199
200   // should be the same as 005 1
201   PoolQuery q;
202   q.addString("^z.p.*");
203   q.addAttribute(sat::SolvAttr::name);
204   q.setMatchRegex();
205
206   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 6);
207
208   cout << "****006.2***"  << endl;
209
210   PoolQuery q1;
211   q1.addString("zypper|smart");
212   q1.addAttribute(sat::SolvAttr::name);
213   q1.setMatchRegex();
214
215   BOOST_CHECK(std::for_each(q1.begin(), q1.end(), PrintAndCount())._count == 8);
216
217   cout << "****006.3***"  << endl;
218
219   // invalid regex
220   PoolQuery q2;
221   q2.addString("zypp\\");
222   q2.setMatchRegex();
223   BOOST_CHECK_THROW(q2.begin(), Exception);
224 }
225
226
227 // match whole words
228 BOOST_AUTO_TEST_CASE(pool_query_007)
229 {
230   cout << "****007***"  << endl;
231
232   PoolQuery q;
233   q.addString("zypp");
234   q.addAttribute(sat::SolvAttr::name);
235   q.setMatchWord();
236
237   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 6);
238 }
239
240 // match by installed status (basically by system vs. repo)
241 BOOST_AUTO_TEST_CASE(pool_query_050)
242 {
243   cout << "****050****"  << endl;
244   PoolQuery q;
245   q.addString("yasm");
246   q.addAttribute(sat::SolvAttr::name);
247   q.setMatchExact();
248   q.setInstalledOnly();
249
250   BOOST_CHECK_EQUAL(std::for_each(q.begin(), q.end(), PrintAndCount())._count, 4);
251
252   cout << endl;
253
254   PoolQuery q1;
255   q1.addString("zypper");
256   q1.addAttribute(sat::SolvAttr::name);
257   q1.setMatchExact();
258   q1.setUninstalledOnly();
259   BOOST_CHECK_EQUAL(std::for_each(q1.begin(), q1.end(), PrintAndCount())._count, 5);
260 }
261
262 /////////////////////////////////////////////////////////////////////////////
263 //  1xx multiple attribute queries
264 /////////////////////////////////////////////////////////////////////////////
265
266
267 BOOST_AUTO_TEST_CASE(pool_query_100)
268 {
269   cout << "****100****"  << endl;
270   PoolQuery q;
271   /* This string is found sometimes only in only in summary (e.g. pgcalc)
272      and sometimes only in description (e.g. bc, lftp). We don't have
273      any package with 'revers' only in package name, but let's ignore this.
274      I didn't find a string with the same characteristics giving fewer matches
275      :-/ */
276   q.addString("revers");
277   q.addAttribute(sat::SolvAttr::name);
278   q.addAttribute(sat::SolvAttr::summary);
279   q.addAttribute(sat::SolvAttr::description);
280
281   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 5);
282
283   cout << endl;
284
285   {
286     PoolQuery q1;
287     q1.addAttribute(sat::SolvAttr::name, "zypper");
288     BOOST_CHECK_EQUAL(q1.size(),5);
289
290     PoolQuery q2;
291     q2.addAttribute(sat::SolvAttr::summary,"samba");
292     BOOST_CHECK_EQUAL(q2.size(),13);
293
294     // now summary and name in one go:
295     q1.addAttribute(sat::SolvAttr::summary,"samba");
296     BOOST_CHECK_EQUAL(q1.size(),18);
297   }
298 }
299
300
301 // multi attr (same value) substring matching (case sensitive and insensitive)
302 BOOST_AUTO_TEST_CASE(pool_query_101)
303 {
304   cout << "****101****"  << endl;
305
306   PoolQuery q;
307   q.addString("RELAX");
308   q.addAttribute(sat::SolvAttr::name);
309   q.addAttribute(sat::SolvAttr::summary);
310   q.addAttribute(sat::SolvAttr::description);
311
312   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 7);
313
314   cout << endl;
315
316   PoolQuery q2;
317   q2.addString("RELAX");
318   q2.addAttribute(sat::SolvAttr::name);
319   q2.addAttribute(sat::SolvAttr::summary);
320   q2.addAttribute(sat::SolvAttr::description);
321   q2.setCaseSensitive();
322
323   BOOST_CHECK(std::for_each(q2.begin(), q2.end(), PrintAndCount())._count == 4);
324 }
325
326
327 // multi attr (same value) glob matching (case sensitive and insensitive)
328 BOOST_AUTO_TEST_CASE(pool_query_102)
329 {
330   cout << "****102****"  << endl;
331   PoolQuery q;
332   q.addString("pack*");
333   q.addAttribute(sat::SolvAttr::name);
334   q.addAttribute(sat::SolvAttr::summary);
335   q.setMatchGlob();
336
337   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 23);
338 }
339
340
341 // multi attr (same value via addAttribute())
342 BOOST_AUTO_TEST_CASE(pool_query_103)
343 {
344   cout << "****103.1****"  << endl;
345   PoolQuery q;
346   q.addAttribute(sat::SolvAttr::name, "rest");
347   q.addAttribute(sat::SolvAttr::summary, "rest");
348
349   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 14);
350
351   cout << "****103.2****"  << endl;
352
353   PoolQuery q1;
354   q1.addString("rest");
355   q1.addAttribute(sat::SolvAttr::name);
356   q1.addAttribute(sat::SolvAttr::summary);
357
358   BOOST_CHECK(std::for_each(q1.begin(), q1.end(), PrintAndCount())._count == 14);
359 //  BOOST_CHECK(q1.size() == 42);
360
361   cout << endl;
362 }
363
364 // multiple attributes, different search strings (one string per attrbute)
365 BOOST_AUTO_TEST_CASE(pool_query_104)
366 {
367   cout << "****104****"  << endl;
368   PoolQuery q;
369   q.addAttribute(sat::SolvAttr::name, "zypper");
370   q.addAttribute(sat::SolvAttr::summary, "package management");
371
372   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 8);
373 }
374
375 // multiple attributes, different search strings (one string per attrbute), regex matching
376 BOOST_AUTO_TEST_CASE(pool_query_105)
377 {
378   cout << "****105****"  << endl;
379   PoolQuery q;
380   q.addAttribute(sat::SolvAttr::name, "zy..er");
381   q.addAttribute(sat::SolvAttr::summary, "package management");
382   q.setMatchRegex();
383
384   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 8);
385 }
386
387 /////////////////////////////////////////////////////////////////////////////
388 //  3xx repo filter queries (addRepo(alias_str))
389 /////////////////////////////////////////////////////////////////////////////
390
391 // default query + one attribute(one string) + one repo
392 BOOST_AUTO_TEST_CASE(pool_query_300)
393 {
394   cout << "****300****"  << endl;
395   PoolQuery q;
396   q.addAttribute(sat::SolvAttr::name, "zypper");
397   q.addRepo("zyppsvn");
398
399   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 4);
400 }
401
402 // default query + one repo
403 BOOST_AUTO_TEST_CASE(pool_query_301)
404 {
405   cout << "****301****"  << endl;
406   PoolQuery q;
407   q.addRepo("zyppsvn");
408
409   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 42);
410 }
411
412 // multiple repos + one attribute
413 BOOST_AUTO_TEST_CASE(pool_query_302)
414 {
415   cout << "****302****"  << endl;
416   PoolQuery q;
417   q.addString("zypper");
418   q.addAttribute(sat::SolvAttr::name);
419   q.addRepo("opensuse");
420   q.addRepo("zyppsvn");
421
422   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 5);
423 }
424
425 /////////////////////////////////////////////////////////////////////////////
426 //  4xx kind queries (addKind(ResKind))
427 /////////////////////////////////////////////////////////////////////////////
428
429 BOOST_AUTO_TEST_CASE(pool_query_400)
430 {
431   cout << "****400****"  << endl;
432   PoolQuery q;
433   q.addString("lamp_server");
434   q.addAttribute(sat::SolvAttr::name);
435   q.addKind(ResKind::pattern);
436   q.setMatchExact();
437
438   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 1);
439 }
440
441 // should find packages and patterns
442 BOOST_AUTO_TEST_CASE(pool_query_401)
443 {
444   cout << "****401****"  << endl;
445   PoolQuery q;
446   q.addString("mail*");
447   q.addAttribute(sat::SolvAttr::name);
448   q.setMatchGlob();
449
450   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 4);
451 }
452
453
454 /////////////////////////////////////////////////////////////////////////////
455 //  5xx multiple string/attribute queries
456 /////////////////////////////////////////////////////////////////////////////
457
458 // multiple strings for one attribute
459 BOOST_AUTO_TEST_CASE(pool_query_500)
460 {
461   cout << "****500.1****"  << endl;
462   PoolQuery q;
463   q.addString("zypper");
464   q.addString("yast2-packager");
465   q.addAttribute(sat::SolvAttr::name);
466   q.setMatchExact();
467   // creates: ^(apt|zypper)$
468   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 6);
469
470   cout << "****500.2****"  << endl;
471   q.addString("*bzypp");
472   q.setMatchGlob();
473   // creates: ^(.*zy.p|yast.*package.*|.*bzypp)$
474   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 11);
475
476   cout << "****500.3****"  << endl;
477   PoolQuery q1;
478   q1.addString("^libsm[a-z]*[0-9]$");
479   q1.addAttribute(sat::SolvAttr::name, "bzypp$");
480   q1.addKind(ResKind::package);
481   q1.setMatchRegex();
482   // creates: (^libsm[a-z]*[0-9]$|bzypp$)
483   BOOST_CHECK(std::for_each(q1.begin(), q1.end(), PrintAndCount())._count == 5);
484
485   cout << "****500.4****"  << endl;
486   PoolQuery q2;
487   q2.addString("Thunder");
488   q2.addAttribute(sat::SolvAttr::name, "sun");
489   q2.addKind(ResKind::package);
490   q2.addRepo("opensuse");
491   q2.setCaseSensitive();
492   // creates: (sun|Thunder)
493   BOOST_CHECK(std::for_each(q2.begin(), q2.end(), PrintAndCount())._count == 3);
494
495   cout << "****500.5****"  << endl;
496   PoolQuery q3;
497   q3.addString("audio");
498   q3.addAttribute(sat::SolvAttr::name, "zip");
499   q3.addKind(ResKind::package);
500   q3.addRepo("opensuse");
501   q3.setMatchWord();
502   // creates: \b(zip|audio)\b
503   BOOST_CHECK(std::for_each(q3.begin(), q3.end(), PrintAndCount())._count == 3);
504 }
505
506 // multiple strings, multiple attributes, same strings
507 BOOST_AUTO_TEST_CASE(pool_query_501)
508 {
509   cout << "****501****"  << endl;
510   PoolQuery q;
511   q.addString("Thunder");
512   q.addString("storm");
513   q.addAttribute(sat::SolvAttr::name);
514   q.addAttribute(sat::SolvAttr::description);
515   q.addKind(ResKind::package);
516   q.addRepo("opensuse");
517
518   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 14);
519 }
520
521 // multiple strings, multiple attributes, same strings
522 BOOST_AUTO_TEST_CASE(pool_query_502)
523 {
524   cout << "****502****"  << endl;
525   PoolQuery q;
526   q.addString("weather");
527   q.addAttribute(sat::SolvAttr::name, "thunder");
528   q.addAttribute(sat::SolvAttr::description, "storm");
529   q.addKind(ResKind::package);
530   q.addRepo("opensuse");
531
532   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 13);
533 }
534
535 /////////////////////////////////////////////////////////////////////////////
536 //  6xx queries with edition
537 /////////////////////////////////////////////////////////////////////////////
538
539 BOOST_AUTO_TEST_CASE(pool_query_X)
540 {
541   cout << "****600.1****"  << endl;
542   PoolQuery q;
543   q.addAttribute(sat::SolvAttr::name, "zypper");
544   q.setMatchExact();
545   q.setEdition(Edition("0.12.5"), Rel::GT);
546
547   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 4);
548
549   cout << "****600.2****"  << endl;
550   q.setEdition(Edition("0.12.5"), Rel::LT);
551
552   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 0);
553
554   cout << "****600.3****"  << endl;
555   q.setEdition(Edition("0.12.5"), Rel::LE);
556
557   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 1);
558
559   cout << "****600.4****"  << endl;
560   q.setEdition(Edition("0.12.5-5"), Rel::LT);
561
562   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 1);
563 }
564
565 //! \todo FIXME this segfaults currently - one addString() + (version or kind or installed status condition)
566 /*
567 BOOST_AUTO_TEST_CASE(pool_query_FIXME)
568 {
569   cout << "****FIXME****"  << endl;
570   PoolQuery q;
571   q.addString("zypper");
572   q.setEdition(Edition("0.10.3-4"), Rel::GE);
573
574   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 2);
575 }
576 */
577
578 /*
579 BOOST_AUTO_TEST_CASE(pool_query_X)
580 {
581   cout << "****X****"  << endl;
582   PoolQuery q;
583   q.addString("pack*");
584   q.addAttribute(sat::SolvAttr::name);
585
586   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 28);
587 }
588 */
589
590
591 BOOST_AUTO_TEST_CASE(pool_query_recovery)
592 {
593   Pathname testfile(TESTS_SRC_DIR);
594     testfile += "/zypp/data/PoolQuery/savedqueries";
595   cout << "****recovery****"  << endl;
596
597   std::vector<PoolQuery> queries;
598   std::insert_iterator<std::vector<PoolQuery> > ii( queries,queries.begin());
599   readPoolQueriesFromFile(testfile,ii);
600   BOOST_REQUIRE_MESSAGE(queries.size() == 2, "Bad count of read queries.");
601
602   BOOST_CHECK_EQUAL(queries[0].size(), 8);
603
604   PoolQuery q;
605   q.addString("ma*");
606   q.addRepo("opensuse");
607   q.addKind(ResKind::patch);
608   q.setMatchRegex();
609   q.setRequireAll();
610   q.setCaseSensitive();
611   q.setUninstalledOnly();
612   q.setEdition(Edition("0.8.3"),Rel::NE);
613   BOOST_CHECK(q == queries[1]);
614 }
615
616 BOOST_AUTO_TEST_CASE(pool_query_serialize)
617 {
618   PoolQuery q;
619   q.addString("ma");
620   q.addAttribute(sat::SolvAttr::name);
621   q.addRepo("factory-nonoss");
622   q.addRepo("zypp_svn");
623
624   PoolQuery q2;
625   q2.addAttribute(sat::SolvAttr::name,"ma");
626   q2.addRepo("factory-nonoss");
627   q2.addRepo("zypp_svn");
628
629
630   //  Pathname testfile(TESTS_SRC_DIR);
631   //  testfile += "/zypp/data/PoolQuery/testqueries";
632   filesystem::TmpFile testfile;
633   cout << "****serialize****"  << endl;
634   std::vector<PoolQuery> queries;
635   queries.push_back(q);
636   queries.push_back(q2);
637   writePoolQueriesToFile(testfile,queries.begin(),queries.end());
638   BOOST_REQUIRE_MESSAGE(queries.size()==2,"Bad count of added queries.");
639
640   std::insert_iterator<std::vector<PoolQuery> > ii( queries,queries.end());
641   readPoolQueriesFromFile(testfile,ii);
642   BOOST_REQUIRE_MESSAGE(queries.size()==4,"Bad count of written/readed queries.");
643   BOOST_CHECK(queries[2] == queries[0]);
644   BOOST_CHECK(queries[3] == queries[1]);
645 }
646
647 // test matching
648 BOOST_AUTO_TEST_CASE(pool_query_equal)
649 {
650   cout << "****equal****"  << endl;
651   std::vector<PoolQuery> v;
652   {
653     PoolQuery q;
654     v.push_back( q );
655   }
656   {
657     PoolQuery q;
658     q.addAttribute( sat::SolvAttr::name, "zypper" );
659     q.setMatchExact();
660     q.setCaseSensitive(true);
661     v.push_back( q );
662   }
663   {
664     PoolQuery q;
665     q.addAttribute( sat::SolvAttr::name, "libzypp" );   // different
666     q.setMatchExact();
667     q.setCaseSensitive(true);
668     v.push_back( q );
669   }
670   {
671     PoolQuery q;
672     q.addAttribute( sat::SolvAttr::vendor, "zypper" );  // different
673     q.setMatchExact();
674     q.setCaseSensitive(true);
675     v.push_back( q );
676   }
677   {
678     PoolQuery q;
679     q.addAttribute( sat::SolvAttr::name, "zypper" );
680     q.setMatchExact();
681     q.setCaseSensitive(false);  // different
682     v.push_back( q );
683   }
684   {
685     PoolQuery q;
686     q.addAttribute( sat::SolvAttr::name, "zypper" );
687     q.setMatchSubstring();      // different
688     q.setCaseSensitive(true);
689     v.push_back( q );
690   }
691   {
692     PoolQuery q;
693     q.addDependency( sat::SolvAttr::provides, "zypper" );
694     v.push_back( q );
695   }
696   {
697     PoolQuery q;
698     q.addDependency( sat::SolvAttr::provides, "zypper", Rel::GT, Edition("1.0")  );
699     v.push_back( q );
700   }
701   {
702     PoolQuery q;
703     q.addDependency( sat::SolvAttr::provides, "zypper", Rel::GT, Edition("2.0")  );
704     v.push_back( q );
705   }
706
707   for (size_t li = 0; li < v.size(); ++li)
708   {
709     for (size_t ri = 0; ri < v.size(); ++ri)
710     {
711       COUT << li << " <> " << ri << endl;
712       bool equal( v[li] == v[ri] );
713       bool nequal( v[li] != v[ri] );
714       BOOST_CHECK_EQUAL( equal, li==ri );
715       BOOST_CHECK_EQUAL( equal, !nequal );
716     }
717   }
718 }
719
720 /////////////////////////////////////////////////////////////////////////////
721 //  Dependency Query
722 /////////////////////////////////////////////////////////////////////////////
723
724 BOOST_AUTO_TEST_CASE(addDependency)
725 {
726   {
727     cout << "****addDependency1****"  << endl;
728     PoolQuery q;
729     q.setCaseSensitive( false );
730     q.setMatchSubstring();
731     q.addString( "libzypp" );
732     q.addDependency( sat::SolvAttr::provides, "FOO" ); // ! finds 'perl(CPAN::InfoObj)' 'foO'
733     std::for_each(q.begin(), q.end(), PrintAndCount());
734     //dumpQ( std::cout, q );
735     BOOST_CHECK_EQUAL( q.size(), 13 );
736   }
737   {
738     cout << "****addDependency2****"  << endl;
739     PoolQuery q;
740     q.setCaseSensitive( false );
741     q.setMatchSubstring();
742     q.addString( "libzypp" );
743     q.addDependency( sat::SolvAttr::provides, "FOO", Rel::GT, Edition("5.0") );
744     std::for_each(q.begin(), q.end(), PrintAndCount());
745     //dumpQ( std::cout, q );
746     BOOST_CHECK_EQUAL( q.size(), 7 );
747   }
748   {
749     cout << "****addDependency2a****"  << endl;
750     PoolQuery q;
751     q.setCaseSensitive( false );
752     q.setMatchSubstring();
753     q.addDependency( sat::SolvAttr::provides, "libzypp", Rel::GT, Edition("5.0") );
754     q.addAttribute( sat::SolvAttr::arch, Arch_i586.asString() ); // OR with arch i585
755     std::for_each(q.begin(), q.end(), PrintAndCount());
756     //dumpQ( std::cout, q );
757     BOOST_CHECK_EQUAL( q.size(), 66 );
758   }
759   {
760     cout << "****addDependency2b****"  << endl;
761     PoolQuery q;
762     q.setCaseSensitive( false );
763     q.setMatchSubstring();
764     // libzypp provides yast2-packagemanager...
765     q.addDependency( sat::SolvAttr::provides, "yast2-packagemanager", Rel::GT, Edition("5.0"), Arch_i586 ); // AND with arch i585
766     std::for_each(q.begin(), q.end(), PrintAndCount());
767     //dumpQ( std::cout, q );
768     BOOST_CHECK_EQUAL( q.size(), 2 );
769   }
770   {
771     cout << "****addDependency2c****"  << endl;
772     PoolQuery q;
773     q.setCaseSensitive( false );
774     q.setMatchSubstring();
775     // but no package named yast2-packagemanager
776     q.addDependency( sat::SolvAttr::name, "yast2-packagemanager", Rel::GT, Edition("5.0"), Arch_i586 ); // AND with arch i585
777     std::for_each(q.begin(), q.end(), PrintAndCount());
778     //dumpQ( std::cout, q );
779     BOOST_CHECK_EQUAL( q.size(), 0 );
780   }
781   {
782     cout << "****addDependency2d****"  << endl;
783     PoolQuery q;
784     q.setCaseSensitive( false );
785     q.setMatchSubstring();
786     // libzypp provides yast2-packagemanager...
787     q.addDependency( sat::SolvAttr::provides, "yast2-packagemanager", Arch_i586 ); // AND with arch i585
788     std::for_each(q.begin(), q.end(), PrintAndCount());
789     //dumpQ( std::cout, q );
790     BOOST_CHECK_EQUAL( q.size(), 2 );
791   }
792   {
793     cout << "****addDependency2e****"  << endl;
794     PoolQuery q;
795     q.setCaseSensitive( false );
796     q.setMatchSubstring();
797     // but no package named yast2-packagemanager
798     q.addDependency( sat::SolvAttr::name, "yast2-packagemanager", Arch_i586 ); // AND with arch i585
799     std::for_each(q.begin(), q.end(), PrintAndCount());
800     //dumpQ( std::cout, q );
801     BOOST_CHECK_EQUAL( q.size(), 0 );
802   }
803
804   {
805     cout << "****addDependency3****"  << endl;
806     PoolQuery q;
807     // includes wine
808     q.addDependency( sat::SolvAttr::provides, "kernel" );
809     std::for_each(q.begin(), q.end(), PrintAndCount());
810     //dumpQ( std::cout, q );
811     BOOST_CHECK_EQUAL( q.size(), 12 );
812   }
813   {
814     cout << "****addDependency4****"  << endl;
815     PoolQuery q;
816     // no wine
817     q.addDependency( sat::SolvAttr::name, "kernel" );
818     std::for_each(q.begin(), q.end(), PrintAndCount());
819     //dumpQ( std::cout, q );
820     BOOST_CHECK_EQUAL( q.size(), 11 );
821   }
822   {
823     cout << "****addDependency5****"  << endl;
824     PoolQuery q;
825     // Capability always matches exact
826     q.addDependency( sat::SolvAttr::provides, Capability("kernel") );
827     std::for_each(q.begin(), q.end(), PrintAndCount());
828     //dumpQ( std::cout, q );
829     BOOST_CHECK_EQUAL( q.size(), 2 );
830   }
831   {
832     cout << "****addDependency6****"  << endl;
833     PoolQuery q;
834     // non dependecy + Capability matches solvable name!
835     q.addDependency( sat::SolvAttr::summary, Capability("kernel") );
836     std::for_each(q.begin(), q.end(), PrintAndCount());
837     //dumpQ( std::cout, q );
838     BOOST_CHECK_EQUAL( q.size(), 0 ); // non dependecy
839   }
840 }
841
842