9d51b931f1e99a64cdbcd78c36769750640fa149
[platform/upstream/libzypp.git] / devel / devel.ma / Test.cc
1 #include <ctime>
2
3 #include <iostream>
4 #include <list>
5 #include <map>
6 #include <set>
7
8 #include "Measure.h"
9 #include "Printing.h"
10 #include "Tools.h"
11
12 #include <zypp/base/String.h>
13 #include <zypp/base/Exception.h>
14 #include <zypp/base/PtrTypes.h>
15 #include <zypp/base/Iterator.h>
16 #include <zypp/base/Algorithm.h>
17 #include <zypp/base/Functional.h>
18 #include <zypp/base/ProvideNumericId.h>
19 #include <zypp/base/ProvideNumericId.h>
20
21 #include "zypp/NVRAD.h"
22 #include "zypp/ResPool.h"
23 #include "zypp/ResFilters.h"
24 #include "zypp/CapFilters.h"
25 #include "zypp/Package.h"
26 #include "zypp/Language.h"
27 #include "zypp/NameKindProxy.h"
28
29 #include <zypp/SourceManager.h>
30 #include <zypp/SourceFactory.h>
31 #include <zypp/source/susetags/SuseTagsImpl.h>
32
33 #include "zypp/ZYppFactory.h"
34 #include "zypp/ResPoolProxy.h"
35 #include "zypp/ResPoolProxy.h"
36 #include "zypp/target/rpm/RpmDb.h"
37
38 using namespace std;
39 using namespace zypp;
40 using namespace zypp::ui;
41 using namespace zypp::functor;
42
43 ///////////////////////////////////////////////////////////////////
44
45 static const Pathname sysRoot( "/Local/ROOT" );
46 static const Url      instSrc( "dir:/Local/SLES10" );
47 //static const Url      instSrc( "dir:/Local/FACTORY" );
48
49 ///////////////////////////////////////////////////////////////////
50
51 namespace container
52 {
53   template<class _Tp>
54     bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
55     { return cont.find( val ) != cont.end(); }
56 }
57
58 ///////////////////////////////////////////////////////////////////
59
60 template<class _Condition>
61   struct SetTrue
62   {
63     SetTrue( _Condition cond_r )
64     : _cond( cond_r )
65     {}
66
67     template<class _Tp>
68       bool operator()( _Tp t ) const
69       {
70         _cond( t );
71         return true;
72       }
73
74     _Condition _cond;
75   };
76
77 template<class _Condition>
78   inline SetTrue<_Condition> setTrue_c( _Condition cond_r )
79   {
80     return SetTrue<_Condition>( cond_r );
81   }
82
83 template <class _Iterator, class _Filter, class _Function>
84   inline _Function for_each_if( _Iterator begin_r, _Iterator end_r,
85                                 _Filter filter_r,
86                                 _Function fnc_r )
87   {
88     for ( _Iterator it = begin_r; it != end_r; ++it )
89       {
90         if ( filter_r( *it ) )
91           {
92             fnc_r( *it );
93           }
94       }
95     return fnc_r;
96   }
97
98 ///////////////////////////////////////////////////////////////////
99
100 template <class _Iterator>
101   std::ostream & vdumpPoolStats( std::ostream & str,
102                                  _Iterator begin_r, _Iterator end_r )
103   {
104     pool::PoolStats stats;
105    // std::for_each( begin_r, end_r,
106 //
107     //               functor::chain( setTrue_c(PrintPoolItem()),
108     //                               setTrue_c(functor::functorRef<void,ResObject::constPtr>(stats)) )
109
110      //            );
111     return str << stats;
112   }
113
114 struct PoolItemSelect
115 {
116   void operator()( const PoolItem & pi ) const
117   {
118     if ( pi->source().numericId() == 2 )
119       pi.status().setTransact( true, ResStatus::USER );
120   }
121 };
122
123 /******************************************************************
124 **
125 **      FUNCTION NAME : main
126 **      FUNCTION TYPE : int
127 */
128 int main( int argc, char * argv[] )
129 {
130   //zypp::base::LogControl::instance().logfile( "xxx" );
131   INT << "===[START]==========================================" << endl;
132
133   ResPool pool( getZYpp()->pool() );
134
135   if ( 0 )
136     {
137       Measure x( "initTarget " + sysRoot.asString() );
138       getZYpp()->initTarget( sysRoot );
139       getZYpp()->addResolvables( getZYpp()->target()->resolvables(), true );
140       INT << "Added target: " << pool << endl;
141     }
142
143   if ( 0 ) {
144     SourceManager::sourceManager()->restore( sysRoot );
145     if ( SourceManager::sourceManager()->allSources().empty() )
146       {
147         Source_Ref src( createSource( instSrc ) );
148         SourceManager::sourceManager()->addSource( src );
149         SourceManager::sourceManager()->store( sysRoot, true );
150       }
151
152     Source_Ref src( *SourceManager::sourceManager()->Source_begin() );
153     getZYpp()->addResolvables( src.resolvables() );
154     INT << "Added source: " << pool << endl;
155   }
156
157   Source_Ref src1( createSource( "dir:/Local/SUSE-Linux-10.1-Build_830-Addon-BiArch/CD1" ) );
158   Source_Ref src2( createSource( "dir:/Local/SUSE-Linux-10.1-Build_830-i386/CD1" ) );
159   INT << "Pool: " << pool << endl;
160   getZYpp()->addResolvables( src1.resolvables() );
161   INT << "Added source1: " << pool << endl;
162   getZYpp()->addResolvables( src2.resolvables() );
163   INT << "Added source2: " << pool << endl;
164
165
166
167
168 #if 0
169   Source_Ref src( *SourceManager::sourceManager()->Source_begin() );
170   const std::list<Pathname> srcKeys( src.publicKeys() );
171   MIL << src << endl;
172   DBG << srcKeys << endl;
173
174   target::rpm::RpmDb rpm;
175   rpm.initDatabase( sysRoot );
176   std::set<Edition> rpmKeys( rpm.pubkeys() );
177   MIL << rpm << endl;
178   DBG << rpmKeys << endl;
179
180   ResPool pool( getZYpp()->pool() );
181   getZYpp()->addResolvables( src.resolvables() );
182   SEC << pool << endl;
183
184   rpm.closeDatabase();
185 #endif
186
187   INT << "===[END]============================================" << endl << endl;
188   return 0;
189 }
190