Mailinglist Archive: zypp-commit (606 mails)

< Previous Next >
[zypp-commit] r9475 - in /trunk/libzypp: tests/zypp/PoolQuery_test.cc zypp/PoolQuery.cc zypp/PoolQuery.h
  • From: jkupec@xxxxxxxxxxxxxxxx
  • Date: Tue, 08 Apr 2008 18:23:43 -0000
  • Message-id: <20080408182343.44CF32706C@xxxxxxxxxxxxxxxx>
Author: jkupec
Date: Tue Apr 8 20:23:42 2008
New Revision: 9475

URL: http://svn.opensuse.org/viewcvs/zypp?rev=9475&view=rev
Log:
- multiple repositories filter reenabled
- some cleanup

Modified:
trunk/libzypp/tests/zypp/PoolQuery_test.cc
trunk/libzypp/zypp/PoolQuery.cc
trunk/libzypp/zypp/PoolQuery.h

Modified: trunk/libzypp/tests/zypp/PoolQuery_test.cc
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/zypp/PoolQuery_test.cc?rev=9475&r1=9474&r2=9475&view=diff
==============================================================================
--- trunk/libzypp/tests/zypp/PoolQuery_test.cc (original)
+++ trunk/libzypp/tests/zypp/PoolQuery_test.cc Tue Apr 8 20:23:42 2008
@@ -47,26 +47,31 @@
{
init_pool();
}
-/*
+
+/////////////////////////////////////////////////////////////////////////////
+// 0xx basic queries
+/////////////////////////////////////////////////////////////////////////////
+
// no conditions, default query
// result: all available resolvables
-BOOST_AUTO_TEST_CASE(pool_query_1)
+BOOST_AUTO_TEST_CASE(pool_query_000)
{
- cout << "****1****" << endl;
+ cout << "****000****" << endl;
PoolQuery q;
cout << q.size() << endl;
BOOST_CHECK(q.size() == 11451);
- //!\todo should be 11453 probably according to:
- // dumpsolv factory.solv factory-nonoss.solv zypp_svn.solv \@System.solv | \
- // grep '^name:.*\(noarch\|i386\|i586\|i686\|src\)$' | wc -l
+ /**!\todo should be 11453 probably according to:
+ * dumpsolv factory.solv factory-nonoss.solv zypp_svn.solv \@System.solv | \
+ * grep '^name:.*\(noarch\|i386\|i586\|i686\|src\)$' | wc -l
+ */
}

// default query + one search string
// q.addString("foo");
// result: all resolvables having at least one attribute matching foo
-BOOST_AUTO_TEST_CASE(pool_query_2)
+BOOST_AUTO_TEST_CASE(pool_query_001)
{
- cout << "****2****" << endl;
+ cout << "****001****" << endl;
PoolQuery q;
q.addString("zypper");

@@ -79,9 +84,9 @@
// should be the same as
// q.addAttribute(foo); q.addString(bar);
// result: resolvables with foo containing bar
-BOOST_AUTO_TEST_CASE(pool_query_3)
+BOOST_AUTO_TEST_CASE(pool_query_002)
{
- cout << "****3****" << endl;
+ cout << "****002****" << endl;
PoolQuery q;
q.addString("zypper");
q.addAttribute(sat::SolvAttr::name);
@@ -98,79 +103,74 @@
BOOST_CHECK(q1.size() == 6);
}

-
-// default query + one attribute(one string) + one repo
-// q.addRepo(foorepo);
-// q.addAttribute(solvable:name, foo);
-// FAILS
-BOOST_AUTO_TEST_CASE(pool_query_4)
+// kind filter
+BOOST_AUTO_TEST_CASE(pool_query_003)
{
- cout << "****4****" << endl;
+ cout << "****003****" << endl;
PoolQuery q;
- q.addAttribute(sat::SolvAttr::name, "zypper");
- q.addRepo("zypp_svn");
+ q.addString("zypper");
+ q.addAttribute(sat::SolvAttr::name);
+ q.addKind(ResTraits<Package>::kind);

std::for_each(q.begin(), q.end(), &result_cb);
BOOST_CHECK(q.size() == 3);
}

-BOOST_AUTO_TEST_CASE(pool_query_5)
-{
- cout << "****5****" << endl;
- PoolQuery q;
- q.addRepo("zypp_svn");
-
- std::for_each(q.begin(), q.end(), &result_cb);
- BOOST_CHECK(q.size() == 21);
-}
-
-BOOST_AUTO_TEST_CASE(pool_query_6)
+// match exact
+BOOST_AUTO_TEST_CASE(pool_query_004)
{
- cout << "****6****" << endl;
+ cout << "****004****" << endl;
PoolQuery q;
- q.addString("browser");
+ q.addString("vim");
q.addAttribute(sat::SolvAttr::name);
- q.addAttribute(sat::SolvAttr::summary);
- q.addAttribute(sat::SolvAttr::description);
+ q.setMatchExact();

std::for_each(q.begin(), q.end(), &result_cb);
- BOOST_CHECK(q.size() == 15);
-
- cout << endl;
+ BOOST_CHECK(q.size() == 3);

PoolQuery q1;
- q1.addString("browser");
+ q1.addString("zypp");
q1.addAttribute(sat::SolvAttr::name);
+ q1.setMatchExact();

std::for_each(q1.begin(), q1.end(), &result_cb);
- BOOST_CHECK(q1.size() == 5);
+ BOOST_CHECK(q1.empty());
}

-// match exact
-BOOST_AUTO_TEST_CASE(pool_query_7)
+// use globs
+BOOST_AUTO_TEST_CASE(pool_query_005)
{
- cout << "****7****" << endl;
+ cout << "****005****" << endl;
PoolQuery q;
- q.addString("vim");
+ q.addString("z?p*");
q.addAttribute(sat::SolvAttr::name);
- q.setMatchExact();
+ q.setMatchGlob();

std::for_each(q.begin(), q.end(), &result_cb);
- BOOST_CHECK(q.size() == 3);
+ BOOST_CHECK(q.size() == 11);
+
+ cout << endl;

PoolQuery q1;
- q1.addString("zypp");
+ q1.addString("*zypp*");
q1.addAttribute(sat::SolvAttr::name);
- q1.setMatchExact();
+ q1.setMatchGlob();

std::for_each(q1.begin(), q1.end(), &result_cb);
- BOOST_CHECK(q1.empty());
+ BOOST_CHECK(q1.size() == 28);
+
+ // should be the same as above
+ PoolQuery q2;
+ q2.addString("zypp");
+ q2.addAttribute(sat::SolvAttr::name);
+
+ BOOST_CHECK(q2.size() == 28);
}

// match by installed status (basically by system vs. repo)
-BOOST_AUTO_TEST_CASE(pool_query_8)
+BOOST_AUTO_TEST_CASE(pool_query_006)
{
- cout << "****8****" << endl;
+ cout << "****006****" << endl;
PoolQuery q;
q.addString("zypper");
q.addAttribute(sat::SolvAttr::name);
@@ -192,41 +192,39 @@
BOOST_CHECK(q1.size() == 5);
}

-// use globs
-BOOST_AUTO_TEST_CASE(pool_query_9)
+/////////////////////////////////////////////////////////////////////////////
+// 1xx multiple attribute queries
+/////////////////////////////////////////////////////////////////////////////
+
+/*
+BOOST_AUTO_TEST_CASE(pool_query_100)
{
- cout << "****9****" << endl;
+ cout << "****100****" << endl;
PoolQuery q;
- q.addString("z?p*");
+ q.addString("browser");
q.addAttribute(sat::SolvAttr::name);
- q.setMatchGlob();
+ q.addAttribute(sat::SolvAttr::summary);
+ q.addAttribute(sat::SolvAttr::description);

std::for_each(q.begin(), q.end(), &result_cb);
- BOOST_CHECK(q.size() == 11);
+ BOOST_CHECK(q.size() == 15);

cout << endl;

PoolQuery q1;
- q1.addString("*zypp*");
+ q1.addString("browser");
q1.addAttribute(sat::SolvAttr::name);
- q1.setMatchGlob();

std::for_each(q1.begin(), q1.end(), &result_cb);
- BOOST_CHECK(q1.size() == 28);
-
- // should be the same as above
- PoolQuery q2;
- q2.addString("zypp");
- q2.addAttribute(sat::SolvAttr::name);
-
- BOOST_CHECK(q2.size() == 28);
+ BOOST_CHECK(q1.size() == 5);
}

+
// multi attr (same value) substring matching (case sensitive and insensitive)
BOOST_AUTO_TEST_CASE(pool_query_10)
{
- cout << "****10****" << endl;*/
-/*
+ cout << "****10****" << endl;
+
PoolQuery q;
q.addString("SSH");
q.addAttribute(sat::SolvAttr::name);
@@ -235,9 +233,8 @@

std::for_each(q.begin(), q.end(), &result_cb);
cout << q.size() << endl;
-// BOOST_CHECK(q.size() == 17);
-*/
-/*
+ BOOST_CHECK(q.size() == 17);
+
cout << endl;

PoolQuery q2;
@@ -249,8 +246,9 @@

std::for_each(q2.begin(), q2.end(), &result_cb);
cout << q2.size() << endl;
-}*/
-/*
+}
+
+
// multi attr (same value) glob matching (case sensitive and insensitive)
BOOST_AUTO_TEST_CASE(pool_query_11)
{
@@ -266,20 +264,48 @@
// BOOST_CHECK(q.size() == 11);
}
*/
-/*
-// kind filter
-BOOST_AUTO_TEST_CASE(pool_query_20)
+
+/////////////////////////////////////////////////////////////////////////////
+// 3xx repo filter queries (addRepo(alias_str))
+/////////////////////////////////////////////////////////////////////////////
+
+// default query + one attribute(one string) + one repo
+BOOST_AUTO_TEST_CASE(pool_query_300)
{
- cout << "****20****" << endl;
+ cout << "****300****" << endl;
PoolQuery q;
- q.addString("zypper");
- q.addAttribute(sat::SolvAttr::name);
- q.addKind(ResTraits<Package>::kind);
+ q.addAttribute(sat::SolvAttr::name, "zypper");
+ q.addRepo("zypp_svn");

std::for_each(q.begin(), q.end(), &result_cb);
BOOST_CHECK(q.size() == 3);
}
-*/
+
+// default query + one repo
+BOOST_AUTO_TEST_CASE(pool_query_301)
+{
+ cout << "****301****" << endl;
+ PoolQuery q;
+ q.addRepo("zypp_svn");
+
+ std::for_each(q.begin(), q.end(), &result_cb);
+ BOOST_CHECK(q.size() == 21);
+}
+
+// multiple repos + one attribute
+BOOST_AUTO_TEST_CASE(pool_query_302)
+{
+ cout << "****302****" << endl;
+ PoolQuery q;
+ q.addString("ma");
+ q.addAttribute(sat::SolvAttr::name);
+ q.addRepo("factory-nonoss");
+ q.addRepo("zypp_svn");
+
+ std::for_each(q.begin(), q.end(), &result_cb);
+ BOOST_CHECK(q.size() == 8);
+}
+
/*
BOOST_AUTO_TEST_CASE(pool_query_X)
{

Modified: trunk/libzypp/zypp/PoolQuery.cc
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/PoolQuery.cc?rev=9475&r1=9474&r2=9475&view=diff
==============================================================================
--- trunk/libzypp/zypp/PoolQuery.cc (original)
+++ trunk/libzypp/zypp/PoolQuery.cc Tue Apr 8 20:23:42 2008
@@ -101,7 +101,7 @@

private:
void compile();
- string createRegex(vector<string> & container);
+ string createRegex(StrContainer & container);

public:
/** Raw search strings. */
@@ -190,13 +190,13 @@
// create regex; store in _rcattrs; flag 'one-attr'; if more strings
flag regex;
else if (_attrs.size() == 1)
{
- vector<string> joined;
- for(vector<string>::const_iterator it = _strings.begin(); it !=
_strings.end(); ++it)
+ StrContainer joined;
+ for(StrContainer::const_iterator it = _strings.begin(); it !=
_strings.end(); ++it)
if (!it->empty())
- joined.push_back(*it);
- for(vector<string>::const_iterator it = _attrs.begin()->second.begin();
it != _attrs.begin()->second.end(); ++it)
+ joined.insert(*it);
+ for(StrContainer::const_iterator it = _attrs.begin()->second.begin(); it
!= _attrs.begin()->second.end(); ++it)
if (!it->empty())
- joined.push_back(*it);
+ joined.insert(*it);
_rcstrings = createRegex(joined);
_rcattrs.insert(pair<sat::SolvAttr, string>(_attrs.begin()->first,
string()));
}
@@ -208,7 +208,7 @@
bool attrvals_empty = true;
for (AttrMap::const_iterator ai = _attrs.begin(); ai != _attrs.end();
++ai)
if (!ai->second.empty())
- for(vector<string>::const_iterator it = ai->second.begin();
+ for(StrContainer::const_iterator it = ai->second.begin();
it != ai->second.end(); it++)
if (!it->empty())
{
@@ -233,10 +233,10 @@
if (attrvals_empty)
{
// compile the search string
- vector<string> joined;
- for(vector<string>::const_iterator it = _strings.begin(); it !=
_strings.end(); ++it)
+ StrContainer joined;
+ for(StrContainer::const_iterator it = _strings.begin(); it !=
_strings.end(); ++it)
if (!it->empty())
- joined.push_back(*it);
+ joined.insert(*it);
_rcstrings = createRegex(joined);

// copy the _attrs keys to _rcattrs
@@ -292,7 +292,7 @@
//! macro for word boundary tags for regexes
#define WB (_match_word ? string("\\b") : string())

- string PoolQuery::Impl::createRegex(vector<string> & container)
+ string PoolQuery::Impl::createRegex(StrContainer & container)
{
string rstr;

@@ -310,7 +310,7 @@
// multiple strings

bool _use_wildcards = (_flags & SEARCH_STRINGMASK) == SEARCH_GLOB;
- vector<string>::const_iterator it = container.begin();
+ StrContainer::const_iterator it = container.begin();
string tmp;

if (_use_wildcards)
@@ -435,6 +435,18 @@
ostringstream o;

o << "compiled: " << _compiled << endl;
+
+ o << "kinds: ";
+ for(Kinds::const_iterator it = _kinds.begin();
+ it != _kinds.end(); ++it)
+ o << *it << " ";
+ o << endl;
+
+ o << "repos: ";
+ for(StrContainer::const_iterator it = _repos.begin();
+ it != _repos.end(); ++it)
+ o << *it << " ";
+ o << endl;

o << "string match flags:" << endl;
o << "* string/substring/glob/regex: " << (_flags & SEARCH_STRINGMASK) <<
endl;
@@ -445,7 +457,7 @@
// raw

o << "strings: ";
- for(vector<string>::const_iterator it = _strings.begin();
+ for(StrContainer::const_iterator it = _strings.begin();
it != _strings.end(); ++it)
o << *it << " ";
o << endl;
@@ -454,7 +466,7 @@
for(AttrMap::const_iterator ai = _attrs.begin(); ai != _attrs.end(); ++ai)
{
o << "* " << ai->first << ": ";
- for(vector<string>::const_iterator vi = ai->second.begin();
+ for(StrContainer::const_iterator vi = ai->second.begin();
vi != ai->second.end(); ++vi)
o << *vi << " ";
o << endl;
@@ -528,6 +540,7 @@
bool matches = !_do_matching;
bool in_repo;
bool drop_by_kind_status = false;
+ bool drop_by_repo = false;
do
{
//! \todo FIXME Dataiterator returning resolvables belonging to current
repo?
@@ -537,8 +550,16 @@
{
while(1)
{
+ drop_by_repo = false;
+ if (!_pqimpl->_repos.empty() &&
+ _pqimpl->_repos.find(_rdit->repo->name) == _pqimpl->_repos.end())
+ {
+ drop_by_repo = true;
+ break;
+ }
+
drop_by_kind_status = false;
-
+
// whether to drop an uninstalled (repo) solvable
if ( (_pqimpl->_status_flags & INSTALLED_ONLY) &&
_rdit->repo->name != _pool.systemRepoName() )
@@ -546,7 +567,7 @@
drop_by_kind_status = true;
break;
}
-
+
// whether to drop an installed (target) solvable
if ((_pqimpl->_status_flags & UNINSTALLED_ONLY) &&
_rdit->repo->name == _pool.systemRepoName())
@@ -567,7 +588,7 @@
break;
}

- matches = matches && !drop_by_kind_status;
+ matches = matches && !drop_by_kind_status && !drop_by_repo;
}

if (_do_matching && !drop_by_kind_status)
@@ -583,12 +604,6 @@
const IdString & value =
IdString(_rdit->kv.id);

- //cout << "solvid: " << _sid << " attr: " << attr.asString() << "
val: " << value.asString() << endl;
-
- //string v2(::id2str(_rdit->repo->pool/*_pool.get()*/,
_rdit->kv.id));
- //if (value.asString() != v2)
- // cout << "ha! " << value.asString() << "!=" << v2 << endl;
-
switch(_pqimpl->_flags & SEARCH_STRINGMASK)
{
case SEARCH_STRING:
@@ -612,7 +627,7 @@
break;
default:
matches = false;
- ERR << "ivalid string matching type: "
+ ERR << "invalid string matching type: "
<< (_pqimpl->_flags & SEARCH_STRINGMASK) << endl;
}
if (matches)
@@ -622,18 +637,40 @@
}
}

+ if (drop_by_repo)
+ {
+ Repository nextRepo(Repository(_rdit->repo).nextInPool());
+ ::dataiterator_skip_repo(_rdit);
+ if (nextRepo)
+ ::dataiterator_jump_to_repo(_rdit, nextRepo.get());
+ drop_by_repo = false;
+ }
+ else if (drop_by_kind_status)
+ {
+ ::dataiterator_skip_solvable(_rdit);
+ drop_by_kind_status = false;
+ }
+
if ((_has_next = ::dataiterator_step(_rdit)))
{
new_solvable = _rdit->solvid != _sid;
if (!in_repo)
- {
- INT << "repo start: " << _rdit->repo->start << endl;
_sid = _rdit->solvid;
- }
}
- // no more attributes/solvables, return
+ // no more attributes in this repo, return
else
{
+ // check for more repos to jump to
+ if (!_pqimpl->_repos.empty())
+ {
+ Repository nextRepo(Repository(_rdit->repo).nextInPool());
+ if (nextRepo)
+ {
+ ::dataiterator_jump_to_repo(_rdit, nextRepo.get());
+ _has_next = ::dataiterator_step(_rdit);
+ }
+ }
+
// did the last solvable match conditions?
return matches && in_repo;
}
@@ -660,7 +697,7 @@

void PoolQuery::addRepo(const std::string &repoalias)
{
- _pimpl->_repos.push_back(repoalias);
+ _pimpl->_repos.insert(repoalias);
_pimpl->_flags &= ~SEARCH_ALL_REPOS;
}

@@ -670,11 +707,11 @@


void PoolQuery::addString(const string & value)
- { _pimpl->_strings.push_back(value); }
+ { _pimpl->_strings.insert(value); }


void PoolQuery::addAttribute(const sat::SolvAttr & attr, const std::string &
value)
- { _pimpl->_attrs[attr].push_back(value); }
+ { _pimpl->_attrs[attr].insert(value); }


void PoolQuery::setCaseSensitive(const bool value)

Modified: trunk/libzypp/zypp/PoolQuery.h
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/PoolQuery.h?rev=9475&r1=9474&r2=9475&view=diff
==============================================================================
--- trunk/libzypp/zypp/PoolQuery.h (original)
+++ trunk/libzypp/zypp/PoolQuery.h Tue Apr 8 20:23:42 2008
@@ -39,7 +39,7 @@
class PoolQuery
{
public:
- typedef std::vector<std::string> StrContainer;
+ typedef std::set<std::string> StrContainer;
typedef std::set<Resolvable::Kind> Kinds;
typedef std::map<sat::SolvAttr, StrContainer> AttrMap;
typedef std::map<sat::SolvAttr, std::string> CompiledAttrMap;

--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages