201958014b04aaebaf9446b9efbb74eb10330420
[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 BOOST_AUTO_TEST_CASE(pool_query_X1)
566 {
567   cout << "****601.****"  << endl;
568   PoolQuery q;
569   q.addString("zypper");
570   q.addAttribute(sat::SolvAttr::name );
571   BOOST_CHECK_EQUAL(std::for_each(q.begin(), q.end(), PrintAndCount())._count, 5);
572
573   q.setEdition(Edition("0.12.8"), Rel::GE);
574   BOOST_CHECK_EQUAL(std::for_each(q.begin(), q.end(), PrintAndCount())._count, 4);
575 }
576
577 BOOST_AUTO_TEST_CASE(pool_query_X2)
578 {
579   cout << "****X****"  << endl;
580   PoolQuery q;
581   q.setMatchGlob();
582   q.addString("zypp*");
583   q.addAttribute(sat::SolvAttr::name);
584
585   BOOST_CHECK_EQUAL(std::for_each(q.begin(), q.end(), PrintAndCount())._count, 5);
586 }
587
588
589 BOOST_AUTO_TEST_CASE(pool_query_recovery)
590 {
591   Pathname testfile(TESTS_SRC_DIR);
592     testfile += "/zypp/data/PoolQuery/savedqueries";
593   cout << "****recovery****"  << endl;
594
595   std::vector<PoolQuery> queries;
596   std::insert_iterator<std::vector<PoolQuery> > ii( queries,queries.begin());
597   readPoolQueriesFromFile(testfile,ii);
598   BOOST_REQUIRE_MESSAGE(queries.size() == 2, "Bad count of read queries.");
599
600   BOOST_CHECK_EQUAL(queries[0].size(), 8);
601
602   PoolQuery q;
603   q.addString("ma*");
604   q.addRepo("opensuse");
605   q.addKind(ResKind::patch);
606   q.setMatchRegex();
607   q.setRequireAll();
608   q.setCaseSensitive();
609   q.setUninstalledOnly();
610   q.setEdition(Edition("0.8.3"),Rel::NE);
611   BOOST_CHECK(q == queries[1]);
612 }
613
614 BOOST_AUTO_TEST_CASE(pool_predicated_matcher)
615 {
616   cout << "****predicated_matcher****"  << endl;
617   {
618     PoolQuery q;
619     q.setMatchExact();
620
621     q.addDependency( sat::SolvAttr::name, "zy*", Rel::ANY, Edition(), Arch_empty );
622     BOOST_CHECK_EQUAL( q.size(), 0 );
623
624     q.addDependency( sat::SolvAttr::name, "zy*", Rel::ANY, Edition(), Arch_empty, Match::GLOB );
625     BOOST_CHECK_EQUAL( q.size(), 5 ); // 5 more
626
627     q.addDependency( sat::SolvAttr::name, "^kde.*-zh", Rel::ANY, Edition(), Arch_noarch, Match::REGEX );
628     BOOST_CHECK_EQUAL( q.size(), 9 ); // 4 more
629
630     q.addDependency( sat::SolvAttr::name,     "kde.*-zh", Rel::ANY, Edition(), Arch_noarch, Match::REGEX );
631     BOOST_CHECK_EQUAL( q.size(), 10 ); // 1 more
632   }
633 }
634
635 BOOST_AUTO_TEST_CASE(pool_query_serialize)
636 {
637   std::vector<PoolQuery> queries;
638   {
639     PoolQuery q;
640     q.addString( "ma" );
641     q.addAttribute( sat::SolvAttr::name );
642     q.addRepo( "factory-nonoss" );
643     q.addRepo( "zypp_svn" );
644     queries.push_back( q );
645   }
646   {
647     PoolQuery q;
648     q.addAttribute( sat::SolvAttr::name, "ma" );
649     q.addRepo( "factory-nonoss" );
650     q.addRepo( "zypp_svn" );
651     queries.push_back( q );
652   }
653   {
654     PoolQuery q;
655     q.setMatchExact();
656     q.addAttribute( sat::SolvAttr::name,      "ma" );
657     q.addDependency( sat::SolvAttr::name,     "nn", Rel::EQ, Edition("nne-nnr"), Arch_noarch );
658     q.addDependency( sat::SolvAttr::name,     "nx", Rel::EQ, Edition("nxe-nxr"), Arch_noarch, Match::REGEX );
659     q.addDependency( sat::SolvAttr::requires, "rn", Rel::EQ, Edition("rne-rnr"), Arch_noarch );
660     q.addDependency( sat::SolvAttr::requires, "rx", Rel::EQ, Edition("rxe-rxr"), Arch_noarch, Match::GLOB );
661     queries.push_back( q );
662   }
663
664   cout << "****serialize****"  << endl;
665   //   filesystem::TmpFile testfile;
666   Pathname testfile( "/tmp/testfile" );
667   writePoolQueriesToFile( testfile, queries.begin(), queries.end() );
668
669   std::vector<PoolQuery> recovered;
670   std::insert_iterator<std::vector<PoolQuery>> ii( recovered, recovered.end() );
671   readPoolQueriesFromFile( testfile, ii );
672
673   BOOST_REQUIRE_EQUAL( queries.size(), recovered.size() );
674   for ( unsigned i = 0U; i < queries.size(); ++i )
675   {
676     BOOST_CHECK_EQUAL( queries[i], recovered[i] );
677   }
678 }
679 // test matching
680 BOOST_AUTO_TEST_CASE(pool_query_equal)
681 {
682   cout << "****equal****"  << endl;
683   std::vector<PoolQuery> v;
684   {
685     PoolQuery q;
686     v.push_back( q );
687   }
688   {
689     PoolQuery q;
690     q.addAttribute( sat::SolvAttr::name, "zypper" );
691     q.setMatchExact();
692     q.setCaseSensitive(true);
693     v.push_back( q );
694   }
695   {
696     PoolQuery q;
697     q.addAttribute( sat::SolvAttr::name, "libzypp" );   // different
698     q.setMatchExact();
699     q.setCaseSensitive(true);
700     v.push_back( q );
701   }
702   {
703     PoolQuery q;
704     q.addAttribute( sat::SolvAttr::vendor, "zypper" );  // different
705     q.setMatchExact();
706     q.setCaseSensitive(true);
707     v.push_back( q );
708   }
709   {
710     PoolQuery q;
711     q.addAttribute( sat::SolvAttr::name, "zypper" );
712     q.setMatchExact();
713     q.setCaseSensitive(false);  // different
714     v.push_back( q );
715   }
716   {
717     PoolQuery q;
718     q.addAttribute( sat::SolvAttr::name, "zypper" );
719     q.setMatchSubstring();      // different
720     q.setCaseSensitive(true);
721     v.push_back( q );
722   }
723   {
724     PoolQuery q;
725     q.addDependency( sat::SolvAttr::provides, "zypper" );
726     v.push_back( q );
727   }
728   {
729     PoolQuery q;
730     q.addDependency( sat::SolvAttr::provides, "zypper", Rel::GT, Edition("1.0")  );
731     v.push_back( q );
732   }
733   {
734     PoolQuery q;
735     q.addDependency( sat::SolvAttr::provides, "zypper", Rel::GT, Edition("2.0")  );
736     v.push_back( q );
737   }
738
739   for (size_t li = 0; li < v.size(); ++li)
740   {
741     for (size_t ri = 0; ri < v.size(); ++ri)
742     {
743       COUT << li << " <> " << ri << endl;
744       bool equal( v[li] == v[ri] );
745       bool nequal( v[li] != v[ri] );
746       BOOST_CHECK_EQUAL( equal, li==ri );
747       BOOST_CHECK_EQUAL( equal, !nequal );
748     }
749   }
750 }
751
752 /////////////////////////////////////////////////////////////////////////////
753 //  Dependency Query
754 /////////////////////////////////////////////////////////////////////////////
755
756 BOOST_AUTO_TEST_CASE(addDependency)
757 {
758   {
759     cout << "****addDependency1****"  << endl;
760     PoolQuery q;
761     q.setCaseSensitive( false );
762     q.setMatchSubstring();
763     q.addString( "libzypp" );
764     q.addDependency( sat::SolvAttr::provides, "FOO" ); // ! finds 'perl(CPAN::InfoObj)' 'foO'
765     std::for_each(q.begin(), q.end(), PrintAndCount());
766     //dumpQ( std::cout, q );
767     BOOST_CHECK_EQUAL( q.size(), 13 );
768   }
769   {
770     cout << "****addDependency2****"  << endl;
771     PoolQuery q;
772     q.setCaseSensitive( false );
773     q.setMatchSubstring();
774     q.addString( "libzypp" );
775     q.addDependency( sat::SolvAttr::provides, "FOO", Rel::GT, Edition("5.0") );
776     std::for_each(q.begin(), q.end(), PrintAndCount());
777     //dumpQ( std::cout, q );
778     BOOST_CHECK_EQUAL( q.size(), 7 );
779   }
780   {
781     cout << "****addDependency2a****"  << endl;
782     PoolQuery q;
783     q.setCaseSensitive( false );
784     q.setMatchSubstring();
785     q.addDependency( sat::SolvAttr::provides, "libzypp", Rel::GT, Edition("5.0") );
786     q.addAttribute( sat::SolvAttr::arch, Arch_i586.asString() ); // OR with arch i585
787     std::for_each(q.begin(), q.end(), PrintAndCount());
788     //dumpQ( std::cout, q );
789     BOOST_CHECK_EQUAL( q.size(), 66 );
790   }
791   {
792     cout << "****addDependency2b****"  << endl;
793     PoolQuery q;
794     q.setCaseSensitive( false );
795     q.setMatchSubstring();
796     // libzypp provides yast2-packagemanager...
797     q.addDependency( sat::SolvAttr::provides, "yast2-packagemanager", Rel::GT, Edition("5.0"), Arch_i586 ); // AND with arch i585
798     std::for_each(q.begin(), q.end(), PrintAndCount());
799     //dumpQ( std::cout, q );
800     BOOST_CHECK_EQUAL( q.size(), 2 );
801   }
802   {
803     cout << "****addDependency2c****"  << endl;
804     PoolQuery q;
805     q.setCaseSensitive( false );
806     q.setMatchSubstring();
807     // but no package named yast2-packagemanager
808     q.addDependency( sat::SolvAttr::name, "yast2-packagemanager", Rel::GT, Edition("5.0"), Arch_i586 ); // AND with arch i585
809     std::for_each(q.begin(), q.end(), PrintAndCount());
810     //dumpQ( std::cout, q );
811     BOOST_CHECK_EQUAL( q.size(), 0 );
812   }
813   {
814     cout << "****addDependency2d****"  << endl;
815     PoolQuery q;
816     q.setCaseSensitive( false );
817     q.setMatchSubstring();
818     // libzypp provides yast2-packagemanager...
819     q.addDependency( sat::SolvAttr::provides, "yast2-packagemanager", Arch_i586 ); // AND with arch i585
820     std::for_each(q.begin(), q.end(), PrintAndCount());
821     //dumpQ( std::cout, q );
822     BOOST_CHECK_EQUAL( q.size(), 2 );
823   }
824   {
825     cout << "****addDependency2e****"  << endl;
826     PoolQuery q;
827     q.setCaseSensitive( false );
828     q.setMatchSubstring();
829     // but no package named yast2-packagemanager
830     q.addDependency( sat::SolvAttr::name, "yast2-packagemanager", Arch_i586 ); // AND with arch i585
831     std::for_each(q.begin(), q.end(), PrintAndCount());
832     //dumpQ( std::cout, q );
833     BOOST_CHECK_EQUAL( q.size(), 0 );
834   }
835
836   {
837     cout << "****addDependency3****"  << endl;
838     PoolQuery q;
839     // includes wine
840     q.addDependency( sat::SolvAttr::provides, "kernel" );
841     std::for_each(q.begin(), q.end(), PrintAndCount());
842     //dumpQ( std::cout, q );
843     BOOST_CHECK_EQUAL( q.size(), 12 );
844   }
845   {
846     cout << "****addDependency4****"  << endl;
847     PoolQuery q;
848     // no wine
849     q.addDependency( sat::SolvAttr::name, "kernel" );
850     std::for_each(q.begin(), q.end(), PrintAndCount());
851     //dumpQ( std::cout, q );
852     BOOST_CHECK_EQUAL( q.size(), 11 );
853   }
854   {
855     cout << "****addDependency5****"  << endl;
856     PoolQuery q;
857     // Capability always matches exact
858     q.addDependency( sat::SolvAttr::provides, Capability("kernel") );
859     std::for_each(q.begin(), q.end(), PrintAndCount());
860     //dumpQ( std::cout, q );
861     BOOST_CHECK_EQUAL( q.size(), 2 );
862   }
863   {
864     cout << "****addDependency6****"  << endl;
865     PoolQuery q;
866     // non dependecy + Capability matches solvable name!
867     q.addDependency( sat::SolvAttr::summary, Capability("kernel") );
868     std::for_each(q.begin(), q.end(), PrintAndCount());
869     //dumpQ( std::cout, q );
870     BOOST_CHECK_EQUAL( q.size(), 0 ); // non dependecy
871   }
872 }
873
874