From 4a5752cab6484be4a2f9700aa5ea86b359043281 Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Thu, 2 Jul 2009 16:38:58 +0200 Subject: [PATCH] Adapt to satsolvers improved dataiterator handling. --- tests/sat/LookupAttr_test.cc | 12 ++++-------- tests/zypp/PoolQuery_test.cc | 5 +++-- zypp/sat/LookupAttr.cc | 45 +++++++++++--------------------------------- 3 files changed, 18 insertions(+), 44 deletions(-) diff --git a/tests/sat/LookupAttr_test.cc b/tests/sat/LookupAttr_test.cc index 8b7ce75..00cc84b 100644 --- a/tests/sat/LookupAttr_test.cc +++ b/tests/sat/LookupAttr_test.cc @@ -160,6 +160,7 @@ BOOST_AUTO_TEST_CASE(LookupAttr_solvable_attribute_substructure) { sat::LookupAttr q( sat::SolvAttr::updateReference ); BOOST_CHECK_EQUAL( q.size(), 303 ); + for_( res, q.begin(), q.end() ) { BOOST_CHECK( ! res.subEmpty() ); @@ -181,17 +182,12 @@ BOOST_AUTO_TEST_CASE(LookupAttr_solvable_attribute_substructure) BOOST_CHECK_EQUAL( res.subFind( sat::SolvAttr::updateReferenceId ), res.subFind( "id" ) ); BOOST_CHECK_EQUAL( res.subFind( sat::SolvAttr::updateReferenceTitle ), res.subFind( "title" ) ); - // NOTE: Unfortunately the satsolver dataiterator loses constect information when - // entering a sub-structure. That's why one can't invoke e.g subBegin on an iterator - // that was retieved by subFind. - // The test below will fail, once libsatsolver fixes the dataiterator. The expected - // result then is, that subBegin brings you to the beginning again. - BOOST_CHECK_EQUAL( res.subFind( sat::SolvAttr::updateReferenceType ).subBegin(), res.subEnd() ); - // BOOST_CHECK_EQUAL( res.subFind( sat::SolvAttr::updateReferenceType ).subBegin(), res.subBegin() ); + // repeatedly calling subBegin() is ok: + BOOST_CHECK_EQUAL( res.subFind( sat::SolvAttr::updateReferenceType ).subBegin(), res.subBegin() ); } // search substructure id without parent-structure works for wellknown structures: - // q = sat::LookupAttr( sat::SolvAttr::updateReferenceId ); + q = sat::LookupAttr( sat::SolvAttr::updateReferenceId ); BOOST_CHECK_EQUAL( q.size(), 303 ); // search id in parent-structure: diff --git a/tests/zypp/PoolQuery_test.cc b/tests/zypp/PoolQuery_test.cc index 96372db..ed92e65 100644 --- a/tests/zypp/PoolQuery_test.cc +++ b/tests/zypp/PoolQuery_test.cc @@ -682,7 +682,8 @@ BOOST_AUTO_TEST_CASE(addDependency) q.addString( "libzypp" ); q.addDependency( sat::SolvAttr::provides, "FOO" ); // ! finds 'perl(CPAN::InfoObj)' 'foO' std::for_each(q.begin(), q.end(), PrintAndCount()); - BOOST_CHECK_EQUAL( q.size(), 12 ); + //dumpQ( std::cout, q ); + BOOST_CHECK_EQUAL( q.size(), 13 ); } { cout << "****addDependency2****" << endl; @@ -693,7 +694,7 @@ BOOST_AUTO_TEST_CASE(addDependency) 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(), 6 ); + BOOST_CHECK_EQUAL( q.size(), 7 ); } { diff --git a/zypp/sat/LookupAttr.cc b/zypp/sat/LookupAttr.cc index 6f4cf80..1cd3ff9 100644 --- a/zypp/sat/LookupAttr.cc +++ b/zypp/sat/LookupAttr.cc @@ -320,33 +320,7 @@ namespace zypp if ( rhs._dip ) { _dip = new ::Dataiterator; - *_dip = *rhs._dip; - if ( _dip->nparents ) - { - for ( int i = 1; i < _dip->nparents; ++i ) - { - _dip->parents[i].kv.parent = &_dip->parents[i-1].kv; - } - _dip->kv.parent = &_dip->parents[_dip->nparents-1].kv; - } - // now we have to manually clone any allocated regex data matcher. - ::Datamatcher & matcher( _dip->matcher ); - if ( matcher.match && ( matcher.flags & SEARCH_STRINGMASK ) == SEARCH_REGEX ) - { - ::datamatcher_init( &matcher, _mstring.c_str(), matcher.flags ); - } - else if ( matcher.match && matcher.match != _mstring.c_str() ) - { - //SEC << "**" << rhs._dip << endl; - SEC << "r " << rhs._dip->matcher.match << endl; - SEC << "r " << rhs._dip->matcher.flags << endl; - SEC << "r " << (const void*)rhs._mstring.c_str() << "'" << rhs._mstring << "'" << endl; - - SEC << "t " << matcher.match << endl; - SEC << "t " << matcher.flags << endl; - SEC << "t " << (const void*)_mstring.c_str() << "'" << _mstring << "'" << endl; - throw( "this cant be!" ); - } + ::dataiterator_init_clone( _dip, rhs._dip ); } } @@ -495,20 +469,23 @@ namespace zypp LookupAttr::iterator LookupAttr::iterator::subBegin() const { - switch ( subType( _dip ) ) + SubType subtype( subType( _dip ) ); + if ( subtype == ST_NONE ) + return subEnd(); + // setup the new sub iterator with the remembered position + detail::DIWrap dip( 0, 0, 0 ); + ::dataiterator_clonepos( dip.get(), _dip.get() ); + switch ( subtype ) { - case ST_NONE: - return subEnd(); + case ST_NONE: // not reached break; case ST_FLEX: - ::dataiterator_setpos( _dip.get() ); + ::dataiterator_seek( dip.get(), DI_SEEK_CHILD|DI_SEEK_STAY ); break; case ST_SUB: - ::dataiterator_setpos_parent( _dip.get() ); + ::dataiterator_seek( dip.get(), DI_SEEK_REWIND|DI_SEEK_STAY ); break; } - // setup the new sub iterator with the remembered position - detail::DIWrap dip( 0, SOLVID_POS, 0, 0, 0 ); return iterator( dip ); // iterator takes over ownership! } -- 2.7.4