Selectable status computation testcases added.
authorMichael Andres <ma@suse.de>
Thu, 4 Feb 2010 13:41:40 +0000 (14:41 +0100)
committerMichael Andres <ma@suse.de>
Thu, 4 Feb 2010 13:41:40 +0000 (14:41 +0100)
devel/devel.ma/Main.cc
tests/data/TCSelectable/RepoLOW.xml
tests/data/TCSelectable/solver-system.xml
tests/zypp/Selectable_test.cc

index 1cbdfee..57b989d 100644 (file)
@@ -2,6 +2,9 @@
 
 #include <zypp/PoolQuery.h>
 #include <zypp/target/rpm/librpmDb.h>
+#include <zypp/parser/ProductFileReader.h>
+#include "zypp/pool/GetResolvablesToInsDel.h"
+#include "zypp/sat/WhatObsoletes.h"
 
 ///////////////////////////////////////////////////////////////////
 
@@ -61,28 +64,67 @@ try {
   ++argv;
   zypp::base::LogControl::instance().logToStdErr();
   INT << "===[START]==========================================" << endl;
+  ///////////////////////////////////////////////////////////////////
+
+
+  DBG << Pathname("a\\b") << endl;
+  DBG << Pathname(".\\a/") << endl;
+  DBG << Pathname("/a\\b/c") << endl;
+
+  INT << "===[END]============================================" << endl << endl;
+  zypp::base::LogControl::instance().logNothing();
+  return 0;
+
   ::unsetenv( "ZYPP_CONF" );
   ZConfig::instance();
-  TestSetup::LoadSystemAt( sysRoot, Arch_i586 );
-  ///////////////////////////////////////////////////////////////////
   ResPool   pool( ResPool::instance() );
   sat::Pool satpool( sat::Pool::instance() );
   ///////////////////////////////////////////////////////////////////
+  dumpRange( WAR, satpool.multiversionBegin(), satpool.multiversionEnd() ) << endl;
+  TestSetup::LoadSystemAt( sysRoot, Arch_i586 );
+  ///////////////////////////////////////////////////////////////////
+
   dumpRange( USR, satpool.reposBegin(), satpool.reposEnd() ) << endl;
   USR << "pool: " << pool << endl;
 
-  {
-    PoolQuery q;
-    q.addAttribute( sat::SolvAttr::name, "yast2-samba-server" );
-    MIL << dump(q) << endl;
-  }
+  dumpRange( WAR, satpool.multiversionBegin(), satpool.multiversionEnd() ) << endl;
+
+  ui::Selectable::Ptr sel( getSel<Package>( "test" ) );
+  WAR << dump( sel ) << endl;
+
+  DBG << sel->setStatus( ui::S_Update, ResStatus::USER ) << endl;
+  WAR << dump( sel ) << endl;
+
+  DBG << sel->setStatus( ui::S_Del, ResStatus::USER ) << endl;
+  WAR << dump( sel ) << endl;
+
+  DBG << sel->setStatus( ui::S_KeepInstalled, ResStatus::USER ) << endl;
+  WAR << dump( sel ) << endl;
+
+  DBG << sel->pickInstall( *(++++sel->availableBegin()) ) << endl;
+  WAR << dump( sel ) << endl;
+
+  DBG << sel->pickDelete( *(++sel->installedBegin()) ) << endl;
+  WAR << dump( sel ) << endl;
+
+  DBG << sel->pickInstall( *(sel->installedBegin()) ) << endl;
+  WAR << dump( sel ) << endl;
+
+  solve();
+  WAR << dump( sel ) << endl;
+  pool::GetResolvablesToInsDel collect( pool, pool::GetResolvablesToInsDel::ORDER_BY_MEDIANR );
+
+  ///////////////////////////////////////////////////////////////////
+  INT << "===[END]============================================" << endl << endl;
+  zypp::base::LogControl::instance().logNothing();
+       return 0;
    {
     PoolQuery q;
-    q.addAttribute( sat::SolvAttr::name, "yast2-samba-server" );
+    q.addAttribute( sat::SolvAttr::name, "open" );
     q.addKind( ResKind::patch );
     MIL << dump(q) << endl;
   }
- {
 {
     PoolQuery q;
     q.addAttribute( sat::SolvAttr::name, "patch:yast2-samba-server" );
     MIL << dump(q) << endl;
index 71f335a..2248672 100644 (file)
                <release>1</release>
        </update></history>
 </package>
+
+<package>
+       <name>installed_and_available</name>
+       <history><update>
+               <arch>i586</arch>
+               <version>1</version>
+               <release>1</release>
+       </update></history>
+</package>
+<package>
+       <name>installed_and_available</name>
+       <history><update>
+               <arch>i586</arch>
+               <version>2</version>
+               <release>1</release>
+       </update></history>
+</package>
+<package>
+       <name>installed_and_available</name>
+       <history><update>
+               <arch>i586</arch>
+               <version>3</version>
+               <release>1</release>
+       </update></history>
+</package>
+
+<package>
+       <name>available_only</name>
+       <history><update>
+               <arch>i586</arch>
+               <version>1</version>
+               <release>1</release>
+       </update></history>
+</package>
+<package>
+       <name>available_only</name>
+       <history><update>
+               <arch>i586</arch>
+               <version>2</version>
+               <release>1</release>
+       </update></history>
+</package>
+<package>
+       <name>available_only</name>
+       <history><update>
+               <arch>i586</arch>
+               <version>3</version>
+               <release>1</release>
+       </update></history>
+</package>
+
 </subchannel></channel>
index 7e1a908..9cac186 100644 (file)
                <release>1</release>
        </update></history>
 </package>
+
+<package>
+       <name>installed_only</name>
+       <history><update>
+               <arch>i586</arch>
+               <version>1</version>
+               <release>1</release>
+       </update></history>
+</package>
+<package>
+       <name>installed_only</name>
+       <history><update>
+               <arch>i586</arch>
+               <version>1</version>
+               <release>0</release>
+       </update></history>
+</package>
+
+<package>
+       <name>installed_and_available</name>
+       <history><update>
+               <arch>i586</arch>
+               <version>1</version>
+               <release>1</release>
+       </update></history>
+</package>
+<package>
+       <name>installed_and_available</name>
+       <history><update>
+               <arch>i586</arch>
+               <version>1</version>
+               <release>0</release>
+       </update></history>
+</package>
+
 </subchannel></channel>
index 8d49f80..22dbbd6 100644 (file)
@@ -57,10 +57,265 @@ BOOST_AUTO_TEST_CASE(candiadatenoarch)
    U__s_(14)candidatenoarch-0-1.i586(RepoMID)
    U__s_(15)candidatenoarch-0-1.noarch(RepoMID)
 }  */
-  std::cout << dump(s) << endl;
   BOOST_CHECK_EQUAL( s->candidateObj()->repoInfo().alias(), "RepoHIGH" );
   BOOST_CHECK_EQUAL( s->candidateObj()->edition(), Edition("5-1") );
   BOOST_CHECK_EQUAL( s->candidateObj()->arch(), Arch_noarch );
   // no updateCandidate due to low version
   BOOST_CHECK_EQUAL( s->updateCandidateObj(), s->candidateObj() );
 }
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Status change tests
+//
+/////////////////////////////////////////////////////////////////////////////
+
+// build ResStatus and return whether the comination is supported. (e.g currently no LOCKED state below APPL_HIGH)
+inline bool initStatus( ResStatus::TransactValue fromState, ResStatus::TransactByValue fromBy, ResStatus & from )
+{
+  from = ResStatus();
+  if ( fromState == ResStatus::KEEP_STATE )
+  {
+    from.setSoftLock( fromBy );
+  }
+  else
+  {
+    from.setTransactValue( fromState, fromBy );
+    if ( fromState == ResStatus::LOCKED && ! from.isLocked() )
+      return false; // no lock at this level (by now just USER APPL_HIGH)
+  }
+  return true;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+// status verification helper
+/////////////////////////////////////////////////////////////////////////////
+//     enum TransactValue
+//       {
+//         KEEP_STATE = bit::RangeValue<TransactField,0>::value,
+//         LOCKED     = bit::RangeValue<TransactField,1>::value, // locked, must not transact
+//         TRANSACT   = bit::RangeValue<TransactField,2>::value  // transact according to state
+//       };
+
+template <class _Iter>
+inline bool _all( _Iter begin_r, _Iter end_r, ResStatus::TransactValue val_r )
+{
+  for_( it, begin_r, end_r )
+  {
+    if ( it->status().getTransactValue() != val_r )
+      return false;
+  }
+  return true;
+}
+
+template <class _Iter>
+inline bool _none( _Iter begin_r, _Iter end_r, ResStatus::TransactValue val_r )
+{
+  for_( it, begin_r, end_r )
+  {
+    if ( it->status().getTransactValue() == val_r )
+      return false;
+  }
+  return true;
+}
+
+template <class _Iter>
+inline bool _atLeastOne( _Iter begin_r, _Iter end_r, ResStatus::TransactValue val_r )
+{ return ! _none( begin_r, end_r, val_r ); }
+
+inline bool _allBySolver( ui::Selectable::Ptr sel )
+{
+  for_( it, sel->installedBegin(), sel->installedEnd() )
+  {
+    if ( it->status().transacts() && ! it->status().isBySolver() )
+      return false;
+  }
+  for_( it, sel->availableBegin(), sel->availableEnd() )
+  {
+    if ( it->status().transacts() && ! it->status().isBySolver() )
+      return false;
+  }
+  return true;
+}
+
+inline bool _allInstalled( ui::Selectable::Ptr sel, ResStatus::TransactValue val_r )           { return _all( sel->installedBegin(), sel->installedEnd(), val_r ); }
+inline bool _noneInstalled( ui::Selectable::Ptr sel, ResStatus::TransactValue val_r )          { return _none( sel->installedBegin(), sel->installedEnd(), val_r ); }
+inline bool _atLeastOneInstalled( ui::Selectable::Ptr sel, ResStatus::TransactValue val_r )    { return _atLeastOne( sel->installedBegin(), sel->installedEnd(), val_r ); }
+
+inline bool _allAvailable( ui::Selectable::Ptr sel, ResStatus::TransactValue val_r )           { return _all( sel->availableBegin(), sel->availableEnd(), val_r ); }
+inline bool _noneAvailable( ui::Selectable::Ptr sel, ResStatus::TransactValue val_r )          { return _none( sel->availableBegin(), sel->availableEnd(), val_r ); }
+inline bool _atLeastOneAvailable( ui::Selectable::Ptr sel, ResStatus::TransactValue val_r )    { return _atLeastOne( sel->availableBegin(), sel->availableEnd(), val_r ); }
+
+inline bool _haveInstalled( ui::Selectable::Ptr sel )                                          { return ! sel->installedEmpty(); }
+inline bool _haveAvailable( ui::Selectable::Ptr sel )                                          { return ! sel->availableEmpty(); }
+
+inline bool _noInstalled( ui::Selectable::Ptr sel )                                            { return sel->installedEmpty(); }
+inline bool _noAvailable( ui::Selectable::Ptr sel )                                            { return sel->availableEmpty(); }
+
+#define allInstalled(V)                        _allInstalled(sel,ResStatus::V)
+#define noneInstalled(V)               _noneInstalled(sel,ResStatus::V)
+#define atLeastOneInstalled(V)         _atLeastOneInstalled(sel,ResStatus::V)
+
+#define allAvailable(V)                        _allAvailable(sel,ResStatus::V)
+#define noneAvailable(V)               _noneAvailable(sel,ResStatus::V)
+#define atLeastOneAvailable(V)         _atLeastOneAvailable(sel,ResStatus::V)
+
+#define haveInstalled                  _haveInstalled(sel)
+#define haveAvailable                  _haveAvailable(sel)
+#define noInstalled                    _noInstalled(sel)
+#define noAvailable                    _noAvailable(sel)
+
+#define allBySolver                    _allBySolver(sel)
+
+// Verify Selectable::status computes the right value.
+//
+//       S_Protected,           // Keep this unmodified ( have installedObj && S_Protected )
+//       S_Taboo,               // Keep this unmodified ( have no installedObj && S_Taboo)
+//       // requested by user:
+//       S_Del,                 // delete  installedObj ( clears S_Protected if set )
+//       S_Update,              // install candidateObj ( have installedObj, clears S_Protected if set )
+//       S_Install,             // install candidateObj ( have no installedObj, clears S_Taboo if set )
+//       // not requested by user:
+//       S_AutoDel,             // delete  installedObj
+//       S_AutoUpdate,          // install candidateObj ( have installedObj )
+//       S_AutoInstall,         // install candidateObj ( have no installedObj )
+//       // no modification:
+//       S_KeepInstalled,       // no modification      ( have installedObj && !S_Protected, clears S_Protected if set )
+//       S_NoInst,              // no modification      ( have no installedObj && !S_Taboo, clears S_Taboo if set )
+void verifyState( ui::Selectable::Ptr sel )
+{
+  ui::Status status( sel->status() );
+  SEC << dump(sel) << endl;
+  switch ( status )
+  {
+    case ui::S_Update:
+    case ui::S_AutoUpdate:
+      BOOST_CHECK( haveInstalled );
+      BOOST_CHECK( atLeastOneAvailable(TRANSACT) );
+      BOOST_CHECK_EQUAL( allBySolver, status==ui::S_AutoUpdate );
+      break;
+
+    case ui::S_Del:
+    case ui::S_AutoDel:
+      BOOST_CHECK( haveInstalled );
+      BOOST_CHECK( noneAvailable(TRANSACT) );  // else would be UPDATE
+      BOOST_CHECK( atLeastOneInstalled(TRANSACT) );
+      BOOST_CHECK_EQUAL( allBySolver, status==ui::S_AutoDel );
+      break;
+
+    case ui::S_Protected:
+      BOOST_CHECK( haveInstalled );
+      BOOST_CHECK( noneAvailable(TRANSACT) );  // else would be UPDATE
+      BOOST_CHECK( noneInstalled(TRANSACT) );  // else would be DEL
+      BOOST_CHECK( allInstalled(LOCKED) );     // implies noneInstalled(TRANSACT)
+      break;
+
+    case ui::S_KeepInstalled:
+      BOOST_CHECK( haveInstalled );
+      BOOST_CHECK( noneAvailable(TRANSACT) );  // else would be UPDATE
+      BOOST_CHECK( noneInstalled(TRANSACT) );  // else would be DEL
+      BOOST_CHECK( ! allInstalled(LOCKED) );   // else would be PROTECTED
+      break;
+
+
+    case ui::S_Install:
+    case ui::S_AutoInstall:
+      BOOST_CHECK( noInstalled );
+      BOOST_CHECK( atLeastOneAvailable(TRANSACT) );
+      BOOST_CHECK_EQUAL( allBySolver, status==ui::S_AutoInstall );
+      break;
+
+    case ui::S_Taboo:
+      BOOST_CHECK( noInstalled );
+      BOOST_CHECK( noneAvailable(TRANSACT) );  // else would be INSTALL
+      BOOST_CHECK( allAvailable(LOCKED) );     // implies noneAvailable(TRANSACT)
+      break;
+
+
+    case ui::S_NoInst:
+      BOOST_CHECK( noInstalled );
+      BOOST_CHECK( noneAvailable(TRANSACT) );  // else would be INSTALL
+      BOOST_CHECK( ! allAvailable(LOCKED) );   // else would be TABOO
+      break;
+  }
+}
+
+// Create all ResStatus combinations over a Selectables PoolItems
+struct StatusCombination
+{
+  StatusCombination()
+  {}
+  StatusCombination( ui::Selectable::Ptr sel_r )
+  {
+   _items.insert( _items.end(), sel_r->installedBegin(), sel_r->installedEnd() );
+   _items.insert( _items.end(), sel_r->availableBegin(), sel_r->availableEnd() );
+  }
+  bool next()
+  {
+    for_( i, 0U, _items.size() )
+    {
+      switch ( _items[i].status().getTransactValue() )
+      {
+        case ResStatus::KEEP_STATE:
+          _items[i].status().setTransactValue( ResStatus::LOCKED, ResStatus::USER );
+          return true;
+          break;
+        case ResStatus::LOCKED:
+          _items[i].status().setTransactValue( ResStatus::TRANSACT, ResStatus::USER );
+          return true;
+          break;
+        case ResStatus::TRANSACT:
+          _items[i].status().setTransactValue( ResStatus::KEEP_STATE, ResStatus::USER );
+          // increment next i
+          break;
+      }
+    }
+    return false; // back at the beginning
+  }
+
+  std::vector<PoolItem> _items;
+};
+
+// Create all ResStatus combinations over the Selectables PoolItems and verify the result.
+void testStatusTable( ui::Selectable::Ptr sel )
+{
+  StatusCombination comb( sel );
+  do {
+    verifyState( sel );
+  } while ( comb.next() );
+}
+
+BOOST_AUTO_TEST_CASE(status_change)
+{
+  // this verifies the Selectables computes ui::Status
+  ResPoolProxy poolProxy( test.poolProxy() );
+  poolProxy.saveState();
+  {
+    ui::Selectable::Ptr sel( poolProxy.lookup( ResKind::package, "installed_only" ) );
+    BOOST_REQUIRE( !sel->installedEmpty() );
+    BOOST_REQUIRE( sel->availableEmpty() );
+    BOOST_CHECK_EQUAL( sel->status(), ui::S_KeepInstalled );
+    testStatusTable( sel );
+  }
+  {
+    ui::Selectable::Ptr sel( poolProxy.lookup( ResKind::package, "installed_and_available" ) );
+    BOOST_REQUIRE( !sel->installedEmpty() );
+    BOOST_REQUIRE( !sel->availableEmpty() );
+    BOOST_CHECK_EQUAL( sel->status(), ui::S_KeepInstalled );
+    testStatusTable( sel );
+  }
+  {
+    ui::Selectable::Ptr sel( poolProxy.lookup( ResKind::package, "available_only" ) );
+    BOOST_REQUIRE( sel->installedEmpty() );
+    BOOST_REQUIRE( !sel->availableEmpty() );
+    BOOST_CHECK_EQUAL( sel->status(), ui::S_NoInst );
+    testStatusTable( sel );
+  }
+
+  // TODO: Test the pickStatus computation (w./w.o. multiinstall)
+  // TODO: Test status/pickStatus transactions (w./w.o. multiinstall)
+}
+
+/////////////////////////////////////////////////////////////////////////////
+