7 #include <boost/test/unit_test.hpp>
9 #include "zypp/base/Logger.h"
10 #include "zypp/base/Exception.h"
11 #include "zypp/RepoManager.h"
12 #include "zypp/ResPool.h"
13 #include "zypp/sat/Pool.h"
14 #include "zypp/PoolQuery.h"
16 #include "KeyRingTestReceiver.h"
17 #include "TestSetup.h"
19 using boost::unit_test::test_case;
23 using namespace zypp::repo;
24 using namespace zypp::filesystem;
26 #define TEST_DIR TESTS_SRC_DIR "/repo/susetags/data/dudata"
28 PoolItem piFind( const std::string & name_r, const std::string & ver_r, bool installed_r = false )
31 q.addDependency( sat::SolvAttr::name, name_r, Rel::EQ, Edition(ver_r) );
32 q.setStatusFilterFlags( installed_r ? PoolQuery::INSTALLED_ONLY : PoolQuery::UNINSTALLED_ONLY );
34 ZYPP_THROW(Exception(q.size()?"Ambiguous!":"Missing!"));
35 return PoolItem( *q.begin() );
38 typedef std::pair<ByteCount,ByteCount> ByteSet;
41 inline std::ostream & operator<<( std::ostream & str, const ByteSet & obj )
42 { return str << "<" << obj.first << "," << obj.second << ">"; }
45 inline ByteSet mkByteSet( const DiskUsageCounter::MountPointSet & mps_r )
46 { return ByteSet( mps_r.begin()->commitDiff(), (++mps_r.begin())->commitDiff() ); }
48 inline ByteSet mkByteSet( int grow_r , int norm_r )
49 { return ByteSet( ByteCount( grow_r, ByteCount::K ), ByteCount( norm_r, ByteCount::K ) ); }
51 inline ByteSet getSize( const DiskUsageCounter & duc_r, const PoolItem & pi_r )
52 { return mkByteSet( duc_r.disk_usage( pi_r ) ); }
54 inline ByteSet getSize( const DiskUsageCounter & duc_r, const ResPool & pool_r )
55 { return mkByteSet( duc_r.disk_usage( pool_r ) ); }
57 inline void XLOG( const DiskUsageCounter & duc_r, const ResPool & pool_r )
59 for( const auto & pi : pool_r )
63 WAR << duc_r.disk_usage( pool_r ) << endl;
66 BOOST_AUTO_TEST_CASE(dudata)
68 //KeyRingTestReceiver rec;
69 // rec.answerAcceptUnknownKey(true);
70 //rec.answerAcceptUnsignedFile(true);
71 // rec.answerImportKey(true);
73 Pathname repodir( TEST_DIR );
74 TestSetup test( Arch_x86_64 );
75 test.loadTargetRepo( repodir/"system" );
76 test.loadRepo( repodir/"repo", "repo" );
78 ResPool pool( ResPool::instance() );
79 PoolItem ins( piFind( "dutest", "1.0", true ) );
80 PoolItem up1( piFind( "dutest", "1.0" ) );
81 PoolItem up2( piFind( "dutest", "2.0" ) );
82 PoolItem up3( piFind( "dutest", "3.0" ) );
84 DiskUsageCounter duc( { DiskUsageCounter::MountPoint( "/grow", DiskUsageCounter::MountPoint::Hint_growonly ),
85 DiskUsageCounter::MountPoint( "/norm" ) } );
88 BOOST_CHECK_EQUAL( getSize( duc, ins ), mkByteSet( 5, 5 ) );
89 BOOST_CHECK_EQUAL( getSize( duc, up1 ), mkByteSet( 15, 15 ) );
90 BOOST_CHECK_EQUAL( getSize( duc, up2 ), mkByteSet( 45, 45 ) );
91 BOOST_CHECK_EQUAL( getSize( duc, up3 ), mkByteSet( 0, 0 ) );
93 // delete installed size 5 g n
94 ins.status().setTransact( true, ResStatus::USER );
95 BOOST_CHECK_EQUAL( getSize( duc, pool ), mkByteSet( 0, -5 ) );
96 ins.status().setTransact( false, ResStatus::USER );
98 // install known DU size 15 g n
99 up1.status().setTransact( true, ResStatus::USER );
100 BOOST_CHECK_EQUAL( getSize( duc, pool ), mkByteSet( 15, 15 ) ); // (multi)install (old stays)
101 ins.status().setTransact( true, ResStatus::USER );
102 BOOST_CHECK_EQUAL( getSize( duc, pool ), mkByteSet( 15, 10 ) ); // update (old goes)
103 ins.status().setTransact( false, ResStatus::USER );
104 up1.status().setTransact( false, ResStatus::USER );
106 // install unknown DU size 0/installed g n
107 up3.status().setTransact( true, ResStatus::USER );
108 BOOST_CHECK_EQUAL( getSize( duc, pool ), mkByteSet( 5, 0 ) ); // (multi)install (n could be 5 too, but satsolver does not know about multinstall)
109 ins.status().setTransact( true, ResStatus::USER );
110 BOOST_CHECK_EQUAL( getSize( duc, pool ), mkByteSet( 5, 0 ) ); // update (old goes)
111 ins.status().setTransact( false, ResStatus::USER );
112 up3.status().setTransact( false, ResStatus::USER );