Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / tests / zypp / PoolQuery_test.cc
index ac321e7..1f9e3a3 100644 (file)
@@ -5,15 +5,14 @@
 #define BOOST_TEST_MODULE PoolQuery
 
 /////////////////////////////////////////////////////////////////////////////
-static TestSetup test( "/tmp/x", Arch_x86_64 );
+static TestSetup test( Arch_x86_64 );
 
 BOOST_AUTO_TEST_CASE(pool_query_init)
 {
-  //test.loadTarget(); // initialize and load target
-  //test.loadRepo( TESTS_SRC_DIR "/data/openSUSE-11.1", "@System" );
+  // Abuse;) vbox as System repo:
+  test.loadTargetRepo( TESTS_SRC_DIR "/data/obs_virtualbox_11_1" );
   test.loadRepo( TESTS_SRC_DIR "/data/openSUSE-11.1", "opensuse" );
   test.loadRepo( TESTS_SRC_DIR "/data/OBS_zypp_svn-11.1", "zyppsvn" );
-  test.loadRepo( TESTS_SRC_DIR "/data/OBS:VirtualBox-11.1", "@system" );
 
   dumpRange( USR, test.pool().knownRepositoriesBegin(),
                   test.pool().knownRepositoriesEnd() );
@@ -21,6 +20,9 @@ BOOST_AUTO_TEST_CASE(pool_query_init)
 }
 /////////////////////////////////////////////////////////////////////////////
 
+static std::ofstream devNull;
+#define COUT devNull
+
 struct PrintAndCount
 {
   PrintAndCount() : _count(0) {}
@@ -28,7 +30,7 @@ struct PrintAndCount
   bool operator()( const sat::Solvable & solvable )
   {
     zypp::PoolItem pi( zypp::ResPool::instance().find( solvable ) );
-    cout << pi.resolvable() << endl;
+    COUT << pi.resolvable() << endl;
     ++_count;
     return true;
   }
@@ -36,6 +38,24 @@ struct PrintAndCount
   unsigned _count;
 };
 
+void dumpQ( std::ostream & str, const PoolQuery & q, bool verbose = true )
+{
+  q.begin();
+  str << q << endl;
+  unsigned nc = 0;
+  if ( 1 )
+  {
+    for_( it, q.begin(), q.end() )
+    {
+      ++nc;
+      if ( verbose )
+        str << it << endl;
+    }
+    str << "--> MATCHES: " << nc << endl;
+  }
+}
+
+
 #if 0
 BOOST_AUTO_TEST_CASE(pool_query_experiment)
 {
@@ -59,7 +79,6 @@ BOOST_AUTO_TEST_CASE(pool_query_experiment)
 }
 #endif
 
-
 /////////////////////////////////////////////////////////////////////////////
 //  0xx basic queries
 /////////////////////////////////////////////////////////////////////////////
@@ -218,18 +237,17 @@ BOOST_AUTO_TEST_CASE(pool_query_007)
   BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 6);
 }
 
-/*
 // match by installed status (basically by system vs. repo)
 BOOST_AUTO_TEST_CASE(pool_query_050)
 {
   cout << "****050****"  << endl;
   PoolQuery q;
-  q.addString("zypper");
+  q.addString("yasm");
   q.addAttribute(sat::SolvAttr::name);
   q.setMatchExact();
   q.setInstalledOnly();
 
-  BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 1);
+  BOOST_CHECK_EQUAL(std::for_each(q.begin(), q.end(), PrintAndCount())._count, 4);
 
   cout << endl;
 
@@ -238,10 +256,8 @@ BOOST_AUTO_TEST_CASE(pool_query_050)
   q1.addAttribute(sat::SolvAttr::name);
   q1.setMatchExact();
   q1.setUninstalledOnly();
-
-  BOOST_CHECK(std::for_each(q1.begin(), q1.end(), PrintAndCount())._count == 5);
+  BOOST_CHECK_EQUAL(std::for_each(q1.begin(), q1.end(), PrintAndCount())._count, 5);
 }
-*/
 
 /////////////////////////////////////////////////////////////////////////////
 //  1xx multiple attribute queries
@@ -266,11 +282,19 @@ BOOST_AUTO_TEST_CASE(pool_query_100)
 
   cout << endl;
 
-  PoolQuery q1;
-  q1.addString("sat");
-  q1.addAttribute(sat::SolvAttr::name);
+  {
+    PoolQuery q1;
+    q1.addAttribute(sat::SolvAttr::name, "zypper");
+    BOOST_CHECK_EQUAL(q1.size(),5);
+
+    PoolQuery q2;
+    q2.addAttribute(sat::SolvAttr::summary,"samba");
+    BOOST_CHECK_EQUAL(q2.size(),13);
 
-  BOOST_CHECK(std::for_each(q1.begin(), q1.end(), PrintAndCount())._count == 15);
+    // now summary and name in one go:
+    q1.addAttribute(sat::SolvAttr::summary,"samba");
+    BOOST_CHECK_EQUAL(q1.size(),18);
+  }
 }
 
 
@@ -564,7 +588,6 @@ BOOST_AUTO_TEST_CASE(pool_query_X)
 */
 
 
-#if 1
 BOOST_AUTO_TEST_CASE(pool_query_recovery)
 {
   Pathname testfile(TESTS_SRC_DIR);
@@ -575,7 +598,8 @@ BOOST_AUTO_TEST_CASE(pool_query_recovery)
   std::insert_iterator<std::vector<PoolQuery> > ii( queries,queries.begin());
   readPoolQueriesFromFile(testfile,ii);
   BOOST_REQUIRE_MESSAGE(queries.size() == 2, "Bad count of read queries.");
-  BOOST_CHECK(queries[0].size() == 10);
+
+  BOOST_CHECK_EQUAL(queries[0].size(), 8);
 
   PoolQuery q;
   q.addString("ma*");
@@ -589,8 +613,6 @@ BOOST_AUTO_TEST_CASE(pool_query_recovery)
   BOOST_CHECK(q == queries[1]);
 }
 
-#endif
-
 BOOST_AUTO_TEST_CASE(pool_query_serialize)
 {
   PoolQuery q;
@@ -626,25 +648,195 @@ BOOST_AUTO_TEST_CASE(pool_query_serialize)
 BOOST_AUTO_TEST_CASE(pool_query_equal)
 {
   cout << "****equal****"  << endl;
-  PoolQuery q;
-  q.addString("zypp");
-  q.addAttribute(sat::SolvAttr::name);
-  q.setMatchGlob();
-  PoolQuery q2;
-  q2.addString("zypp");
-  q2.addAttribute(sat::SolvAttr::name);
-  q2.setMatchGlob();
-  PoolQuery q3;
-  q3.addString("zypp");
-  q3.addAttribute(sat::SolvAttr::name);
-  q3.setMatchGlob();
-  q3.setRequireAll(true);
-  PoolQuery q4;
-  q4.addAttribute(sat::SolvAttr::name,"zypp");
-  q4.setMatchGlob();
-
-  BOOST_CHECK(q==q2);
-  BOOST_CHECK(q!=q3);
-  BOOST_CHECK(q==q4);
-  BOOST_CHECK(q4!=q3);
+  std::vector<PoolQuery> v;
+  {
+    PoolQuery q;
+    v.push_back( q );
+  }
+  {
+    PoolQuery q;
+    q.addAttribute( sat::SolvAttr::name, "zypper" );
+    q.setMatchExact();
+    q.setCaseSensitive(true);
+    v.push_back( q );
+  }
+  {
+    PoolQuery q;
+    q.addAttribute( sat::SolvAttr::name, "libzypp" );  // different
+    q.setMatchExact();
+    q.setCaseSensitive(true);
+    v.push_back( q );
+  }
+  {
+    PoolQuery q;
+    q.addAttribute( sat::SolvAttr::vendor, "zypper" ); // different
+    q.setMatchExact();
+    q.setCaseSensitive(true);
+    v.push_back( q );
+  }
+  {
+    PoolQuery q;
+    q.addAttribute( sat::SolvAttr::name, "zypper" );
+    q.setMatchExact();
+    q.setCaseSensitive(false); // different
+    v.push_back( q );
+  }
+  {
+    PoolQuery q;
+    q.addAttribute( sat::SolvAttr::name, "zypper" );
+    q.setMatchSubstring();     // different
+    q.setCaseSensitive(true);
+    v.push_back( q );
+  }
+  {
+    PoolQuery q;
+    q.addDependency( sat::SolvAttr::provides, "zypper" );
+    v.push_back( q );
+  }
+  {
+    PoolQuery q;
+    q.addDependency( sat::SolvAttr::provides, "zypper", Rel::GT, Edition("1.0")  );
+    v.push_back( q );
+  }
+  {
+    PoolQuery q;
+    q.addDependency( sat::SolvAttr::provides, "zypper", Rel::GT, Edition("2.0")  );
+    v.push_back( q );
+  }
+
+  for (size_t li = 0; li < v.size(); ++li)
+  {
+    for (size_t ri = 0; ri < v.size(); ++ri)
+    {
+      COUT << li << " <> " << ri << endl;
+      bool equal( v[li] == v[ri] );
+      bool nequal( v[li] != v[ri] );
+      BOOST_CHECK_EQUAL( equal, li==ri );
+      BOOST_CHECK_EQUAL( equal, !nequal );
+    }
+  }
 }
+
+/////////////////////////////////////////////////////////////////////////////
+//  Dependency Query
+/////////////////////////////////////////////////////////////////////////////
+
+BOOST_AUTO_TEST_CASE(addDependency)
+{
+  {
+    cout << "****addDependency1****"  << endl;
+    PoolQuery q;
+    q.setCaseSensitive( false );
+    q.setMatchSubstring();
+    q.addString( "libzypp" );
+    q.addDependency( sat::SolvAttr::provides, "FOO" ); // ! finds 'perl(CPAN::InfoObj)' 'foO'
+    std::for_each(q.begin(), q.end(), PrintAndCount());
+    //dumpQ( std::cout, q );
+    BOOST_CHECK_EQUAL( q.size(), 13 );
+  }
+  {
+    cout << "****addDependency2****"  << endl;
+    PoolQuery q;
+    q.setCaseSensitive( false );
+    q.setMatchSubstring();
+    q.addString( "libzypp" );
+    q.addDependency( sat::SolvAttr::provides, "FOO", Rel::GT, Edition("5.0") );
+    std::for_each(q.begin(), q.end(), PrintAndCount());
+    //dumpQ( std::cout, q );
+    BOOST_CHECK_EQUAL( q.size(), 7 );
+  }
+  {
+    cout << "****addDependency2a****"  << endl;
+    PoolQuery q;
+    q.setCaseSensitive( false );
+    q.setMatchSubstring();
+    q.addDependency( sat::SolvAttr::provides, "libzypp", Rel::GT, Edition("5.0") );
+    q.addAttribute( sat::SolvAttr::arch, Arch_i586.asString() ); // OR with arch i585
+    std::for_each(q.begin(), q.end(), PrintAndCount());
+    //dumpQ( std::cout, q );
+    BOOST_CHECK_EQUAL( q.size(), 66 );
+  }
+  {
+    cout << "****addDependency2b****"  << endl;
+    PoolQuery q;
+    q.setCaseSensitive( false );
+    q.setMatchSubstring();
+    // libzypp provides yast2-packagemanager...
+    q.addDependency( sat::SolvAttr::provides, "yast2-packagemanager", Rel::GT, Edition("5.0"), Arch_i586 ); // AND with arch i585
+    std::for_each(q.begin(), q.end(), PrintAndCount());
+    //dumpQ( std::cout, q );
+    BOOST_CHECK_EQUAL( q.size(), 2 );
+  }
+  {
+    cout << "****addDependency2c****"  << endl;
+    PoolQuery q;
+    q.setCaseSensitive( false );
+    q.setMatchSubstring();
+    // but no package named yast2-packagemanager
+    q.addDependency( sat::SolvAttr::name, "yast2-packagemanager", Rel::GT, Edition("5.0"), Arch_i586 ); // AND with arch i585
+    std::for_each(q.begin(), q.end(), PrintAndCount());
+    //dumpQ( std::cout, q );
+    BOOST_CHECK_EQUAL( q.size(), 0 );
+  }
+  {
+    cout << "****addDependency2d****"  << endl;
+    PoolQuery q;
+    q.setCaseSensitive( false );
+    q.setMatchSubstring();
+    // libzypp provides yast2-packagemanager...
+    q.addDependency( sat::SolvAttr::provides, "yast2-packagemanager", Arch_i586 ); // AND with arch i585
+    std::for_each(q.begin(), q.end(), PrintAndCount());
+    //dumpQ( std::cout, q );
+    BOOST_CHECK_EQUAL( q.size(), 2 );
+  }
+  {
+    cout << "****addDependency2e****"  << endl;
+    PoolQuery q;
+    q.setCaseSensitive( false );
+    q.setMatchSubstring();
+    // but no package named yast2-packagemanager
+    q.addDependency( sat::SolvAttr::name, "yast2-packagemanager", Arch_i586 ); // AND with arch i585
+    std::for_each(q.begin(), q.end(), PrintAndCount());
+    //dumpQ( std::cout, q );
+    BOOST_CHECK_EQUAL( q.size(), 0 );
+  }
+
+  {
+    cout << "****addDependency3****"  << endl;
+    PoolQuery q;
+    // includes wine
+    q.addDependency( sat::SolvAttr::provides, "kernel" );
+    std::for_each(q.begin(), q.end(), PrintAndCount());
+    //dumpQ( std::cout, q );
+    BOOST_CHECK_EQUAL( q.size(), 12 );
+  }
+  {
+    cout << "****addDependency4****"  << endl;
+    PoolQuery q;
+    // no wine
+    q.addDependency( sat::SolvAttr::name, "kernel" );
+    std::for_each(q.begin(), q.end(), PrintAndCount());
+    //dumpQ( std::cout, q );
+    BOOST_CHECK_EQUAL( q.size(), 11 );
+  }
+  {
+    cout << "****addDependency5****"  << endl;
+    PoolQuery q;
+    // Capability always matches exact
+    q.addDependency( sat::SolvAttr::provides, Capability("kernel") );
+    std::for_each(q.begin(), q.end(), PrintAndCount());
+    //dumpQ( std::cout, q );
+    BOOST_CHECK_EQUAL( q.size(), 2 );
+  }
+  {
+    cout << "****addDependency6****"  << endl;
+    PoolQuery q;
+    // non dependecy + Capability matches solvable name!
+    q.addDependency( sat::SolvAttr::summary, Capability("kernel") );
+    std::for_each(q.begin(), q.end(), PrintAndCount());
+    //dumpQ( std::cout, q );
+    BOOST_CHECK_EQUAL( q.size(), 0 ); // non dependecy
+  }
+}
+
+