ref: refs/heads/ma-tmp-pqt
commit addee07b22fe3b3d9dc198cd896c6b7896d08b13
Author: Michael Andres
Date: Fri Apr 10 15:31:04 2009 +0200
AttrMatcher fix matching and add testcase
---
tests/sat/AttrMatcher_test.cc | 38 ++++++++++++++++++++++++++++++++++++++
tests/sat/CMakeLists.txt | 2 +-
zypp/sat/AttrMatcher.cc | 8 ++++++--
zypp/sat/AttrMatcher.h | 14 ++++++++------
4 files changed, 53 insertions(+), 9 deletions(-)
diff --git a/tests/sat/AttrMatcher_test.cc b/tests/sat/AttrMatcher_test.cc
new file mode 100644
index 0000000..17d35a9
--- /dev/null
+++ b/tests/sat/AttrMatcher_test.cc
@@ -0,0 +1,38 @@
+#include "TestSetup.h"
+#include
+#include
+#include
+
+BOOST_AUTO_TEST_CASE(AttrMatcher_defaultconstructed)
+{
+ sat::AttrMatcher m;
+ BOOST_CHECK( !m ); // eval in boolean context
+ BOOST_CHECK( m.searchstring().empty() );
+ BOOST_CHECK_EQUAL( m.flags(), 0 );
+ // matches nothing:
+ BOOST_CHECK( !m( "" ) );
+ BOOST_CHECK( !m( " " ) );
+ BOOST_CHECK( !m( "a" ) );
+ BOOST_CHECK( !m( "default" ) );
+
+ m.setSearchstring( "fau" );
+ BOOST_CHECK( m ); // eval in boolean context
+}
+
+BOOST_AUTO_TEST_CASE(AttrMatcher_STRING)
+{
+ sat::AttrMatcher m( "fau" );
+ BOOST_CHECK_EQUAL( m.flags(), 1 ); // substitute 1 by enum when it is implemented
+ BOOST_CHECK( !m( "" ) );
+ BOOST_CHECK( !m( "a" ) );
+ BOOST_CHECK( m( "fau" ) );
+ BOOST_CHECK( !m( "default" ) );
+}
+
+#if 0
+BOOST_AUTO_TEST_CASE(AttrMatcher_)
+{
+ base::LogControl::TmpLineWriter shutUp( new log::FileLineWriter( "/tmp/YLOG" ) );
+ MIL << "GO" << endl;
+}
+#endif
diff --git a/tests/sat/CMakeLists.txt b/tests/sat/CMakeLists.txt
index 60775d4..1e34860 100644
--- a/tests/sat/CMakeLists.txt
+++ b/tests/sat/CMakeLists.txt
@@ -2,6 +2,6 @@
# to find the KeyRingTest receiver
INCLUDE_DIRECTORIES( ${LIBZYPP_SOURCE_DIR}/tests/zypp )
-ADD_TESTS(Solvable SolvParsing WhatProvides WhatObsoletes LookupAttr)
+ADD_TESTS(Solvable SolvParsing WhatProvides WhatObsoletes LookupAttr AttrMatcher)
diff --git a/zypp/sat/AttrMatcher.cc b/zypp/sat/AttrMatcher.cc
index fd53562..e85e1d2 100644
--- a/zypp/sat/AttrMatcher.cc
+++ b/zypp/sat/AttrMatcher.cc
@@ -54,8 +54,8 @@ namespace zypp
/** Return whether string matches. */
bool doMatch( const char * string_r ) const
{
- if ( ! string_r || ! *string_r )
- return true; // every string matches nothing.
+ if ( ! string_r )
+ return false; // NULL never matches
if ( !_matcher )
{
@@ -122,6 +122,10 @@ namespace zypp
: _pimpl( new Impl )
{}
+ AttrMatcher::AttrMatcher( const std::string & search_r )
+ : _pimpl( new Impl( search_r, SEARCH_STRING ) )
+ {}
+
AttrMatcher::AttrMatcher( const std::string & search_r, int flags_r )
: _pimpl( new Impl( search_r, flags_r ) )
{}
diff --git a/zypp/sat/AttrMatcher.h b/zypp/sat/AttrMatcher.h
index f918f1d..17c9ab9 100644
--- a/zypp/sat/AttrMatcher.h
+++ b/zypp/sat/AttrMatcher.h
@@ -39,8 +39,6 @@ namespace zypp
* Used by e.g. \ref PoolQuery and \ref LookupAttr for queries,
* but it can also be used for matching arbitrary strings.
*
- * Matches \c SUBSTRING per default.
- *
* \code
* AttrMatcher matches( "foo" );
* for_( it, stringlist.begin(), stringlist().end() )
@@ -51,7 +49,7 @@ namespace zypp
* \endcode
*
* \todo Enhance the search flags manip interface; Enums and
- * Flags are missing.
+ * Flags are missing; int flags should not be needed.
*/
class AttrMatcher : private base::SafeBool<AttrMatcher>
{
@@ -62,11 +60,14 @@ namespace zypp
class Impl;
public:
- /** Default ctor matches everything. */
+ /** Default ctor matches nothing. */
AttrMatcher();
+ /** Ctor from string matches in \c STRING mode per default. */
+ AttrMatcher( const std::string & search_r );
+
/** Low level interface. */
- AttrMatcher( const std::string & search_r, int flags_r = 0 );
+ AttrMatcher( const std::string & search_r, int flags_r );
#ifndef SWIG // Swig treats it as syntax error
/** Evaluate in a boolean context <tt>( ! searchstring().empty() )</tt>. */
@@ -76,7 +77,8 @@ namespace zypp
public:
/** Return whether string matches.
* You can use it with any class that impements \c c_str.
- * (\c std::string, \ref Pathname, \ref IdString, ...)
+ * (\c std::string, \ref Pathname, \ref IdString, ...).
+ * \Note \c NULL never matches.
*/
template<class _Tp>
bool operator()( const _Tp & string_r ) const
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org