Author: jkupec Date: Wed Apr 9 16:17:41 2008 New Revision: 9483 URL: http://svn.opensuse.org/viewcvs/zypp?rev=9483&view=rev Log: - check whether regex compiled allright if matchRegex() - fixed setMatch*() methods - few tests for regexes added Modified: trunk/libzypp/libzypp.spec.cmake trunk/libzypp/tests/zypp/PoolQuery_test.cc trunk/libzypp/zypp/PoolQuery.cc Modified: trunk/libzypp/libzypp.spec.cmake URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/libzypp.spec.cmake?rev=94... ============================================================================== --- trunk/libzypp/libzypp.spec.cmake (original) +++ trunk/libzypp/libzypp.spec.cmake Wed Apr 9 16:17:41 2008 @@ -24,7 +24,7 @@ Provides: yast2-packagemanager Obsoletes: yast2-packagemanager BuildRequires: cmake -BuildRequires: libsatsolver-devel openssl-devel +BuildRequires: libsatsolver-devel >= 0.0.26 openssl-devel BuildRequires: boost-devel curl-devel dejagnu doxygen gcc-c++ gettext-devel graphviz hal-devel libxml2-devel %if 0%{?suse_version} Modified: trunk/libzypp/tests/zypp/PoolQuery_test.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/zypp/PoolQuery_test... ============================================================================== --- trunk/libzypp/tests/zypp/PoolQuery_test.cc (original) +++ trunk/libzypp/tests/zypp/PoolQuery_test.cc Wed Apr 9 16:17:41 2008 @@ -140,7 +140,7 @@ // use globs BOOST_AUTO_TEST_CASE(pool_query_005) { - cout << "****005****" << endl; + cout << "****005.1****" << endl; PoolQuery q; q.addString("z?p*"); q.addAttribute(sat::SolvAttr::name); @@ -149,7 +149,7 @@ std::for_each(q.begin(), q.end(), &result_cb); BOOST_CHECK(q.size() == 11); - cout << endl; + cout << "****005.2****" << endl; PoolQuery q1; q1.addString("*zypp*"); @@ -159,6 +159,8 @@ std::for_each(q1.begin(), q1.end(), &result_cb); BOOST_CHECK(q1.size() == 28); + cout << "****005.3****" << endl; + // should be the same as above PoolQuery q2; q2.addString("zypp"); @@ -167,10 +169,44 @@ BOOST_CHECK(q2.size() == 28); } -// match by installed status (basically by system vs. repo) +// use regex BOOST_AUTO_TEST_CASE(pool_query_006) { - cout << "****006****" << endl; + cout << "****006.1***" << endl; + + // should be the same as 005 1 + PoolQuery q; + q.addString("^z.p.*"); + q.addAttribute(sat::SolvAttr::name); + q.setMatchRegex(); + + std::for_each(q.begin(), q.end(), &result_cb); + BOOST_CHECK(q.size() == 11); + + cout << "****006.2***" << endl; + + PoolQuery q1; + q1.addString("zypper|smart"); + q1.addAttribute(sat::SolvAttr::name); + q1.setMatchRegex(); + + std::for_each(q1.begin(), q1.end(), &result_cb); + BOOST_CHECK(q1.size() == 21); + + cout << "****006.3***" << endl; + + // invalid regex + PoolQuery q2; + q2.addString("zypp\"); + q2.setMatchRegex(); + BOOST_CHECK_THROW(q2.size(), Exception); +} + + +// 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.addAttribute(sat::SolvAttr::name); @@ -263,7 +299,6 @@ q.setMatchGlob(); std::for_each(q.begin(), q.end(), &result_cb); - cout << q.size() << endl; BOOST_CHECK(q.size() == 35); } Modified: trunk/libzypp/zypp/PoolQuery.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/PoolQuery.cc?rev=948... ============================================================================== --- trunk/libzypp/zypp/PoolQuery.cc (original) +++ trunk/libzypp/zypp/PoolQuery.cc Wed Apr 9 16:17:41 2008 @@ -16,6 +16,7 @@ #include <algorithm> #include <fnmatch.h> +#include "zypp/base/Gettext.h" #include "zypp/base/Logger.h" #include "zypp/base/PtrTypes.h" #include "zypp/base/DefaultIntegral.h" @@ -418,6 +419,10 @@ _flags); } + if ((_flags & SEARCH_STRINGMASK) == SEARCH_REGEX && _rdit.regex_err != 0) + ZYPP_THROW(Exception( + str::form(_("Invalid regular expression '%s'"), _rcstrings.c_str()))); + PoolQuery::ResultIterator it(this); it.increment(); return it; @@ -701,13 +706,13 @@ void PoolQuery::setMatchSubstring() - { _pimpl->_flags |= (_pimpl->_flags & ~SEARCH_STRINGMASK) | SEARCH_SUBSTRING; } + { _pimpl->_flags = (_pimpl->_flags & ~SEARCH_STRINGMASK) | SEARCH_SUBSTRING; } void PoolQuery::setMatchExact() - { _pimpl->_flags |= (_pimpl->_flags & ~SEARCH_STRINGMASK) | SEARCH_STRING; } + { _pimpl->_flags = (_pimpl->_flags & ~SEARCH_STRINGMASK) | SEARCH_STRING; } void PoolQuery::setMatchRegex() - { _pimpl->_flags |= (_pimpl->_flags & ~SEARCH_STRINGMASK) | SEARCH_REGEX; } + { _pimpl->_flags = (_pimpl->_flags & ~SEARCH_STRINGMASK) | SEARCH_REGEX; } void PoolQuery::setMatchGlob() - { _pimpl->_flags |= (_pimpl->_flags & ~SEARCH_STRINGMASK) | SEARCH_GLOB; } + { _pimpl->_flags = (_pimpl->_flags & ~SEARCH_STRINGMASK) | SEARCH_GLOB; } void PoolQuery::setMatchWord() { _pimpl->_match_word = true; -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org