Imported Upstream version 15.17.2 81/94681/1
authorDongHun Kwak <dh0128.kwak@samsung.com>
Tue, 1 Nov 2016 02:06:10 +0000 (11:06 +0900)
committerDongHun Kwak <dh0128.kwak@samsung.com>
Tue, 1 Nov 2016 02:06:11 +0000 (11:06 +0900)
Change-Id: I44c3cc4a97cf2f85642f141e3a630275d94e3715
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
VERSION.cmake
package/libzypp.changes
tests/zypp/CMakeLists.txt
tests/zypp/SetTracker_test.cc [new file with mode: 0644]
zypp/base/SetTracker.h

index 3b209d9..32e7afc 100644 (file)
@@ -61,8 +61,8 @@
 SET(LIBZYPP_MAJOR "15")
 SET(LIBZYPP_COMPATMINOR "14")
 SET(LIBZYPP_MINOR "17")
-SET(LIBZYPP_PATCH "1")
+SET(LIBZYPP_PATCH "2")
 #
-# LAST RELEASED: 15.17.1 (14)
+# LAST RELEASED: 15.17.2 (14)
 # (The number in parenthesis is LIBZYPP_COMPATMINOR)
 #=======
index a86c59b..b9ba18d 100644 (file)
@@ -1,4 +1,10 @@
 -------------------------------------------------------------------
+Mon Sep 28 12:19:26 CEST 2015 - ma@suse.de
+
+- SetTracker: fix computation of change sets (bsc#946898)
+- version 15.17.2 (14)
+
+-------------------------------------------------------------------
 Fri Sep 25 11:42:28 CEST 2015 - ma@suse.de
 
 - Pattern: support dynamic computation of pattern visibility (bsc#900769)
index b3ceb6f..2a1f137 100644 (file)
@@ -39,6 +39,7 @@ ADD_TESTS(
   ResStatus
   Selectable
   SetRelationMixin
+  SetTracker
   StrMatcher
   Target
   Url
diff --git a/tests/zypp/SetTracker_test.cc b/tests/zypp/SetTracker_test.cc
new file mode 100644 (file)
index 0000000..c52ed72
--- /dev/null
@@ -0,0 +1,103 @@
+#include <set>
+#include <boost/test/auto_unit_test.hpp>
+#include "zypp/base/LogTools.h"
+#include "zypp/base/SetTracker.h"
+
+typedef std::set<int> SetType;
+namespace std
+{
+  inline ostream & operator<<( ostream & str, const SetType & obj )
+  { return zypp::dumpRangeLine( str, obj.begin(), obj.end() );  }
+}
+typedef zypp::base::SetTracker<SetType> Tracker;
+
+std::set<int> s;
+std::set<int> s1       ({1});
+std::set<int> s2       ({2});
+std::set<int> s3       ({3});
+std::set<int> s12      ({1,2});
+std::set<int> s13      ({1,3});
+std::set<int> s23      ({2,3});
+std::set<int> s123     ({1,2,3});
+
+
+BOOST_AUTO_TEST_CASE(basic)
+{
+  Tracker t;
+  BOOST_CHECK_EQUAL( t.current(),      s       );
+  BOOST_CHECK_EQUAL( t.added(),                s       );
+  BOOST_CHECK_EQUAL( t.removed(),      s       );
+
+  BOOST_CHECK( t.add( 1 ) );
+  BOOST_CHECK_EQUAL( t.current(),      s1      );
+  BOOST_CHECK_EQUAL( t.added(),                s1      );
+  BOOST_CHECK_EQUAL( t.removed(),      s       );
+
+  BOOST_CHECK( !t.add( 1 ) );
+  BOOST_CHECK_EQUAL( t.current(),      s1      );
+  BOOST_CHECK_EQUAL( t.added(),                s1      );
+  BOOST_CHECK_EQUAL( t.removed(),      s       );
+
+  BOOST_CHECK( t.add( 2 ) );
+  BOOST_CHECK_EQUAL( t.current(),      s12     );
+  BOOST_CHECK_EQUAL( t.added(),                s12     );
+  BOOST_CHECK_EQUAL( t.removed(),      s       );
+
+  BOOST_CHECK( t.remove( 1 ) );
+  BOOST_CHECK_EQUAL( t.current(),      s2      );
+  BOOST_CHECK_EQUAL( t.added(),                s2      );
+  BOOST_CHECK_EQUAL( t.removed(),      s       );
+
+  BOOST_CHECK( t.set( s3 ) );
+  BOOST_CHECK_EQUAL( t.current(),      s3      );
+  BOOST_CHECK_EQUAL( t.added(),                s3      );
+  BOOST_CHECK_EQUAL( t.removed(),      s       );
+
+  BOOST_CHECK( t.add( 2 ) );
+  BOOST_CHECK_EQUAL( t.current(),      s23     );
+  BOOST_CHECK_EQUAL( t.added(),                s23     );
+  BOOST_CHECK_EQUAL( t.removed(),      s       );
+
+  BOOST_CHECK( t.remove( 2 ) );
+  BOOST_CHECK_EQUAL( t.current(),      s3      );
+  BOOST_CHECK_EQUAL( t.added(),                s3      );
+  BOOST_CHECK_EQUAL( t.removed(),      s       );
+
+  BOOST_CHECK( ! t.remove( 2 ) );
+  BOOST_CHECK_EQUAL( t.current(),      s3      );
+  BOOST_CHECK_EQUAL( t.added(),                s3      );
+  BOOST_CHECK_EQUAL( t.removed(),      s       );
+
+  BOOST_CHECK( t.set( s ) );
+  BOOST_CHECK_EQUAL( t.current(),      s       );
+  BOOST_CHECK_EQUAL( t.added(),                s       );
+  BOOST_CHECK_EQUAL( t.removed(),      s       );
+
+  //----------------------------------------------------------------------
+
+  BOOST_CHECK( t.setInitial( s2 ) );
+  BOOST_CHECK_EQUAL( t.current(),      s2      );
+  BOOST_CHECK_EQUAL( t.added(),                s       );
+  BOOST_CHECK_EQUAL( t.removed(),      s       );
+
+  BOOST_CHECK( t.set( s13 ) );
+  BOOST_CHECK_EQUAL( t.current(),      s13     );
+  BOOST_CHECK_EQUAL( t.added(),                s13     );
+  BOOST_CHECK_EQUAL( t.removed(),      s2      );
+
+  BOOST_CHECK( t.set( s123 ) );
+  BOOST_CHECK_EQUAL( t.current(),      s123    );
+  BOOST_CHECK_EQUAL( t.added(),                s13     );
+  BOOST_CHECK_EQUAL( t.removed(),      s       );
+
+  BOOST_CHECK( t.set( s ) );
+  BOOST_CHECK_EQUAL( t.current(),      s       );
+  BOOST_CHECK_EQUAL( t.added(),                s       );
+  BOOST_CHECK_EQUAL( t.removed(),      s2      );
+
+  BOOST_CHECK( t.set( s2 ) );
+  BOOST_CHECK_EQUAL( t.current(),      s2      );
+  BOOST_CHECK_EQUAL( t.added(),                s       );
+  BOOST_CHECK_EQUAL( t.removed(),      s       );
+
+}
index 373cde8..6aa3f45 100644 (file)
@@ -80,21 +80,16 @@ namespace zypp
        bool changed = ( new_r != _current );
        if ( changed )
        {
-         setInitial(); // clear added/removed
-         if ( new_r.empty() )
-         {
-           _removed.swap( _current );
-         }
-         else if ( _current.empty() )
-         {
-           _added.swap( _current );
-         }
-         else
-         {
-           setDifference( new_r, _current, _added );
-           setDifference( _current, new_r, _removed );
-           _current = std::move(new_r);
-         }
+         // build the initial (cur-add+rem) set in _current
+         setDifference( _current, _added, _removed );
+         _current.swap( _removed );
+         _added.clear();
+         _removed.clear();
+
+         const set_type & initial( _current );
+         setDifference( initial, new_r, _removed );
+         setDifference( new_r, initial, _added );
+         _current.swap( new_r );
        }
        return changed;
       }
@@ -107,8 +102,8 @@ namespace zypp
        bool done = _current.insert( val_r ).second;
        if ( done )
        {
-         _added.insert( val_r );
-         _removed.erase( val_r );
+         if ( ! _removed.erase( val_r ) )
+           _added.insert( val_r );
        }
        return done;
       }
@@ -121,8 +116,8 @@ namespace zypp
        bool done = _current.erase( val_r );
        if ( done )
        {
-         _added.erase( val_r );
-         _removed.insert( val_r );
+         if ( ! _added.erase( val_r ) )
+           _removed.insert( val_r );
        }
        return done;
       }
@@ -163,6 +158,7 @@ namespace zypp
       //@}
 
     private:
+
       static bool find( const set_type & set_r, const key_type & key_r )
       { return set_r.find( key_r ) != set_r.end(); }