Author: jkupec
Date: Mon May 5 14:08:08 2008
New Revision: 9945
URL: http://svn.opensuse.org/viewcvs/zypp?rev=9945&view=rev
Log:
- support multiple search strings (ORed)
Modified:
trunk/libzypp/devel/devel.jkupec/poolquery.cc
trunk/libzypp/tests/zypp/PoolQuery_test.cc
trunk/libzypp/zypp/PoolQuery.cc
Modified: trunk/libzypp/devel/devel.jkupec/poolquery.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.jkupec/poolquery.cc?rev=9945&r1=9944&r2=9945&view=diff
==============================================================================
--- trunk/libzypp/devel/devel.jkupec/poolquery.cc (original)
+++ trunk/libzypp/devel/devel.jkupec/poolquery.cc Mon May 5 14:08:08 2008
@@ -9,6 +9,7 @@
#include "zypp/RepoInfo.h"
#include "zypp/Arch.h"
#include "zypp/Pathname.h"
+#include "zypp/base/Regex.h"
using std::cout;
using std::endl;
@@ -46,14 +47,23 @@
int main (int argc, const char ** argv)
{
+ // ./poolquery regex string
+ if (argc == 3)
+ {
+ str::regex regex(argv[1], REG_EXTENDED | REG_NOSUB | REG_NEWLINE | REG_ICASE);
+ cout << (str::regex_match(argv[2], regex) ? "" : "no") << "match" << endl;
+ }
+
init_pool();
PoolQuery q;
- q.addAttribute(sat::SolvAttr::name, "novell");
- q.addAttribute(sat::SolvAttr::summary, "package management");
+ q.addString("weather");
+ q.addAttribute(sat::SolvAttr::name, "thunder");
+ q.addAttribute(sat::SolvAttr::description, "storm");
+ q.addKind(ResKind::package);
+ q.addRepo("factory");
std::for_each(q.begin(), q.end(), &result_cb);
-
- cout << q.size() << endl;
+// cout << q.size() << endl;
cout << q << endl;
}
Modified: trunk/libzypp/tests/zypp/PoolQuery_test.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/zypp/PoolQuery_test.cc?rev=9945&r1=9944&r2=9945&view=diff
==============================================================================
--- trunk/libzypp/tests/zypp/PoolQuery_test.cc (original)
+++ trunk/libzypp/tests/zypp/PoolQuery_test.cc Mon May 5 14:08:08 2008
@@ -226,6 +226,20 @@
}
+// match whole words
+BOOST_AUTO_TEST_CASE(pool_query_007)
+{
+ cout << "****007***" << endl;
+
+ PoolQuery q;
+ q.addString("zypp");
+ q.addAttribute(sat::SolvAttr::name);
+ q.setMatchWord();
+
+ BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 2);
+}
+
+
// match by installed status (basically by system vs. repo)
BOOST_AUTO_TEST_CASE(pool_query_050)
{
@@ -407,7 +421,7 @@
}
/////////////////////////////////////////////////////////////////////////////
-// 4xx repo kind queries (addKind(ResKind))
+// 4xx kind queries (addKind(ResKind))
/////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE(pool_query_400)
@@ -434,6 +448,88 @@
BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 8);
}
+
+/////////////////////////////////////////////////////////////////////////////
+// 5xx multiple string/attribute queries
+/////////////////////////////////////////////////////////////////////////////
+
+// multiple strings for one attribute
+BOOST_AUTO_TEST_CASE(pool_query_500)
+{
+ cout << "****500.1****" << endl;
+ PoolQuery q;
+ q.addString("zypper");
+ q.addString("apt");
+ q.addAttribute(sat::SolvAttr::name);
+ q.setMatchExact();
+ // creates: ^(apt|zypper)$
+ BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 8);
+
+ cout << "****500.2****" << endl;
+ q.addString("*zy?p");
+ q.setMatchGlob();
+ // creates: ^(.*zy.p|apt|zypper)$
+ BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 16);
+
+ cout << "****500.3****" << endl;
+ PoolQuery q1;
+ q1.addString("^libsm[a-z]*[0-9]$");
+ q1.addAttribute(sat::SolvAttr::name, "os.libs$");
+ q1.addKind(ResKind::package);
+ q1.setMatchRegex();
+ // creates: (^libsm[a-z]*[0-9]$|os.libs$)
+ BOOST_CHECK(std::for_each(q1.begin(), q1.end(), PrintAndCount())._count == 3);
+
+ cout << "****500.4****" << endl;
+ PoolQuery q2;
+ q2.addString("thunder");
+ q2.addAttribute(sat::SolvAttr::name, "sun");
+ q2.addKind(ResKind::package);
+ q2.addRepo("factory");
+ q2.setCaseSensitive();
+ // creates: (sun|thunder)
+ BOOST_CHECK(std::for_each(q2.begin(), q2.end(), PrintAndCount())._count == 2);
+
+ cout << "****500.5****" << endl;
+ PoolQuery q3;
+ q3.addString("zypp");
+ q3.addAttribute(sat::SolvAttr::name, "zip");
+ q3.addKind(ResKind::package);
+ q3.addRepo("factory");
+ q3.setMatchWord();
+ // creates: \b(zip|zypp)\b
+ BOOST_CHECK(std::for_each(q3.begin(), q3.end(), PrintAndCount())._count == 4);
+}
+
+// multiple strings, multiple attributes, same strings
+BOOST_AUTO_TEST_CASE(pool_query_501)
+{
+ cout << "****501****" << endl;
+ PoolQuery q;
+ q.addString("thunder");
+ q.addString("storm");
+ q.addAttribute(sat::SolvAttr::name);
+ q.addAttribute(sat::SolvAttr::description);
+ q.addKind(ResKind::package);
+ q.addRepo("factory");
+
+ BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 14);
+}
+
+// multiple strings, multiple attributes, same strings
+BOOST_AUTO_TEST_CASE(pool_query_502)
+{
+ cout << "****502****" << endl;
+ PoolQuery q;
+ q.addString("weather");
+ q.addAttribute(sat::SolvAttr::name, "thunder");
+ q.addAttribute(sat::SolvAttr::description, "storm");
+ q.addKind(ResKind::package);
+ q.addRepo("factory");
+
+ BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 14);
+}
+
/*
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=9945&r1=9944&r2=9945&view=diff
==============================================================================
--- trunk/libzypp/zypp/PoolQuery.cc (original)
+++ trunk/libzypp/zypp/PoolQuery.cc Mon May 5 14:08:08 2008
@@ -161,6 +161,12 @@
invokeOnEach(_attrs.begin()->second.begin(), _attrs.begin()->second.end(), EmptyFilter(), MyInserter(joined));
_rcstrings = createRegex(joined);
_rcattrs.insert(pair