Imported Upstream version 17.25.4
[platform/upstream/libzypp.git] / devel / devel.ma / Test.cc
1 #include "Tools.h"
2 #include <zypp/ResObjects.h>
3
4 #include <zypp/sat/LookupAttr.h>
5 #include <zypp/PoolQuery.h>
6
7 static const Pathname sysRoot( "/tmp/ToolScanRepos" );
8
9 void addInstall( const std::string & pkgspec_r )
10 {
11   bool rewrote( false );
12   Capability pkgspec( Capability::guessPackageSpec( pkgspec_r, rewrote ) );
13   MIL << "Add '" << pkgspec << "' for '" << pkgspec_r << "'" << endl;
14   ResPool::instance().resolver().addRequire( pkgspec );
15 }
16
17 void addConflict( const std::string & pkgspec_r )
18 {
19   bool rewrote( false );
20   Capability pkgspec( Capability::guessPackageSpec( pkgspec_r, rewrote ) );
21   MIL << "Con '" << pkgspec << "' for '" << pkgspec_r << "'" << endl;
22   ResPool::instance().resolver().addConflict( pkgspec );
23 }
24
25 bool solve()
26 {
27   bool rres = false;
28   {
29     //zypp::base::LogControl::TmpLineWriter shutUp;
30     //ResPool::instance().resolver().setOnlyRequires( true );
31     rres = ResPool::instance().resolver().resolvePool();
32   }
33   if ( ! rres )
34   {
35     ERR << "resolve " << rres << endl;
36     ResPool::instance().resolver().problems();
37     return false;
38   }
39   MIL << "resolve " << rres << endl;
40   vdumpPoolStats( USR << "Transacting:"<< endl,
41                   make_filter_begin<resfilter::ByTransact>(ResPool::instance()),
42                   make_filter_end<resfilter::ByTransact>(ResPool::instance()) ) << endl;
43
44   return true;
45 }
46
47 bool install()
48 {
49   ZYppCommitPolicy pol;
50   pol.dryRun( true );
51   pol.rpmInstFlags( pol.rpmInstFlags().setFlag( target::rpm::RPMINST_JUSTDB ) );
52   SEC << getZYpp()->commit( pol ) << endl;
53   return true;
54 }
55
56
57 /******************************************************************
58 **
59 **      FUNCTION NAME : main
60 **      FUNCTION TYPE : int
61 */
62 int main( int argc, char * argv[] )
63 {
64   INT << "===[START]==========================================" << endl;
65   ///////////////////////////////////////////////////////////////////
66   if ( sysRoot == "/" )
67     ::unsetenv( "ZYPP_CONF" );
68   TestSetup::LoadSystemAt( sysRoot, Arch_x86_64 );
69   ///////////////////////////////////////////////////////////////////
70   ResPool   pool( ResPool::instance() );
71   sat::Pool satpool( sat::Pool::instance() );
72   ///////////////////////////////////////////////////////////////////
73
74 //   addConflict( "kernel-default" );
75 //   addConflict( "kernel-default-base" );
76   addInstall( "test");
77   solve();
78
79   INT << "===[END]============================================" << endl << endl;
80   return 0;
81 }
82