a776ea1cd13764133aed0d8cf18f41e8eab1970f
[platform/upstream/libzypp.git] / tests / zypp / Resolver_test.cc
1 #include <boost/test/auto_unit_test.hpp>
2 #define BOOST_CHECK_MODULE Resolver
3 using namespace boost::unit_test;
4
5 #include "TestSetup.h"
6 #include "zypp/ResPool.h"
7 #include "zypp/ResPoolProxy.h"
8 #include "zypp/pool/PoolStats.h"
9 #include "zypp/ui/Selectable.h"
10
11 static TestSetup test( TestSetup::initLater );
12
13 struct BAD_TESTCASE {};
14
15 typedef std::set<PoolItem> PoolItemSet;
16
17 constexpr const unsigned onlyRequires   = 0x1;
18 constexpr const unsigned inrMode        = 0x2;
19
20 PoolItemSet resolve( unsigned flags_r = 0 )
21 {
22   test.resolver().setOnlyRequires            ( flags_r & onlyRequires );
23   test.resolver().setIgnoreAlreadyRecommended( ! ( flags_r & inrMode ) );
24   if ( ! test.resolver().resolvePool() )
25     throw BAD_TESTCASE();
26
27   return { make_filter_begin<resfilter::ByTransact>(test.pool()), make_filter_end<resfilter::ByTransact>(test.pool()) };
28 }
29
30 inline PoolItem getPi( const std::string & name_r, bool installed_r )
31 {
32   for ( const auto & pi : test.pool().byName( name_r ) )
33   { if ( pi.isSystem() == installed_r ) return pi; }
34   throw BAD_TESTCASE();
35 }
36 inline PoolItem getIPi( const std::string & name_r )
37 { return getPi( name_r, true ); }
38 inline PoolItem getAPi( const std::string & name_r )
39 { return getPi( name_r, false ); }
40
41 /////////////////////////////////////////////////////////////////////////////
42 // Pool content:
43 PoolItem Ip;    // IA: aspell
44 PoolItem Ap;
45 PoolItem Ipen;  // IA: aspell-en        (wanted locale)
46 PoolItem Apen;
47 PoolItem Apde;  //  A: aspell-de        (wanted locale)
48 PoolItem Apfr;  //  A: aspell-fr        (unwanted locale)
49 PoolItem Aprec; //  A: recommended-pkg  (by aspell)
50
51 struct TestInit {
52   TestInit() {
53     test = TestSetup( );
54
55     test.loadTestcaseRepos( TESTS_SRC_DIR"/data/TCNamespaceRecommends" );
56     Ip  = getIPi( "aspell" );
57     Ap  = getAPi( "aspell" );
58     Ipen        = getIPi( "aspell-en" );
59     Apen        = getAPi( "aspell-en" );
60     Apde        = getAPi( "aspell-de" );
61     Apfr        = getAPi( "aspell-fr" );
62     Aprec       = getAPi( "recommended-pkg" );
63   }
64   ~TestInit() { test.reset(); }
65 };
66 BOOST_GLOBAL_FIXTURE( TestInit );
67
68 /////////////////////////////////////////////////////////////////////////////
69
70 inline void BOOST_checkresult( const PoolItemSet & resolved_r, const PoolItemSet & expected_r )
71 { BOOST_CHECK_EQUAL( resolved_r, expected_r ); }
72
73
74 BOOST_AUTO_TEST_CASE(install)
75 {
76   Ap.status().setTransact( true, ResStatus::USER );
77   // Upadte aspell, add all recommends
78   BOOST_checkresult( resolve(), { Ap, Ip, Apde, Aprec } );
79   Ap.status().setTransact( false, ResStatus::USER );
80 }
81
82 BOOST_AUTO_TEST_CASE(installOnlyRequires)
83 {
84   Ap.status().setTransact( true, ResStatus::USER );
85   // Upadte aspell, add only namespace recommends
86   BOOST_checkresult( resolve( onlyRequires ), { Ap, Ip, Apde } );
87   Ap.status().setTransact( false, ResStatus::USER );
88 }
89
90 BOOST_AUTO_TEST_CASE(inr)
91 {
92   // Fillup all recommends
93   BOOST_checkresult( resolve( inrMode ), { Apde, Aprec } );
94 }
95
96 BOOST_AUTO_TEST_CASE(inrOnlyRequires)
97 {
98   // Fillup only namespace recommends
99   BOOST_checkresult( resolve( inrMode|onlyRequires ), { Apde } );
100 }