[Aptitude-svn-commit] r3944 - in branches/aptitude-0.3/aptitude: . src/generic/problemresolver tests

Daniel Burrows dburrows at costa.debian.org
Wed Aug 24 23:52:24 UTC 2005


Author: dburrows
Date: Wed Aug 24 23:52:21 2005
New Revision: 3944

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/generic/problemresolver/solution.h
   branches/aptitude-0.3/aptitude/tests/test_resolver.cc
Log:
Don't die in the resolver test with an assertion failure.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Wed Aug 24 23:52:21 2005
@@ -1,5 +1,11 @@
 2005-08-24  Daniel Burrows  <dburrows at debian.org>
 
+	* src/generic/problemresolver/solution.h, tests/test_resolver.h:
+
+	  Avoid crashing in test code by making the tester a friend of the
+	  solution and directly constructing solutions for the solution
+	  test (bypassing the sanity-checking public constructors).
+
 	* src/generic/problemresolver/problemresolver.h, src/generic/problemresolver/solution.h, tests/test_resolver.h:
 
 	  Massive refactoring of the problem resolver.  The solution

Modified: branches/aptitude-0.3/aptitude/src/generic/problemresolver/solution.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/problemresolver/solution.h	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/problemresolver/solution.h	Wed Aug 24 23:52:21 2005
@@ -79,6 +79,9 @@
 class generic_solution
 {
 public:
+  // Let the resolver tester poke around in our internals.
+  friend class ResolverTest;
+
   typedef typename PackageUniverse::package package;
   typedef typename PackageUniverse::version version;
   typedef typename PackageUniverse::dep dep;

Modified: branches/aptitude-0.3/aptitude/tests/test_resolver.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/tests/test_resolver.cc	(original)
+++ branches/aptitude-0.3/aptitude/tests/test_resolver.cc	Wed Aug 24 23:52:21 2005
@@ -132,6 +132,32 @@
     assertEqInequivalent(a3, a4);
   }
 
+  /** Generate a successor solution that just contains the given
+   *  information by using internal constructors of the solution
+   *  class.  Used when testing the solution class itself.
+   */
+  template<class a_iter, class u_iter>
+  dummy_solution unsafe_successor(const dummy_solution &parent,
+				  a_iter abegin, a_iter aend,
+				  u_iter ubegin, u_iter uend)
+  {
+    std::map<dummy_universe::package, dummy_solution::action> actions = parent.get_actions();
+    std::set<dummy_universe::dep> unresolved = parent.get_unresolved_soft_deps();
+
+    for(a_iter ai = abegin; ai != aend; ++ai)
+      actions[(*ai).ver.get_package()] = *ai;
+
+    for(u_iter ui = ubegin; ui != uend; ++ui)
+      unresolved.insert(*ui);
+
+    return dummy_solution(new dummy_solution::solution_rep(actions,
+							   parent.get_broken(),
+							   unresolved,
+							   parent.get_forbidden_versions(),
+							   parent.get_score(),
+							   parent.get_action_score()));
+  }
+
   /** Tests that the comparison operations on solutions work. */
   void testSolutionCompare()
   {
@@ -169,44 +195,38 @@
     dummy_solution s0 = dummy_solution::root_node(u_broken,
 						  u, weights);
     dummy_solution s1
-      = dummy_solution::successor(s0, &a1, &a1+1,
-				  (dummy_universe::dep *) 0,
-				  (dummy_universe::dep *) 0,
-				  u, weights);
+      = unsafe_successor(s0, &a1, &a1+1,
+			 (dummy_universe::dep *) 0,
+			 (dummy_universe::dep *) 0);
     dummy_solution s2
-      = dummy_solution::successor(s0, &a2, &a2+1,
-				  (dummy_universe::dep *) 0,
-				  (dummy_universe::dep *) 0,
-				  u, weights);
+      = unsafe_successor(s0, &a2, &a2+1,
+			 (dummy_universe::dep *) 0,
+			 (dummy_universe::dep *) 0);
     dummy_solution s3
-      = dummy_solution::successor(s0, &a3, &a3+1,
-				  (dummy_universe::dep *) 0,
-				  (dummy_universe::dep *) 0,
-				  u, weights);
+      = unsafe_successor(s0, &a3, &a3+1,
+			 (dummy_universe::dep *) 0,
+			 (dummy_universe::dep *) 0);
     dummy_solution s4
-      = dummy_solution::successor(s0, &a4, &a4+1,
-				  (dummy_universe::dep *) 0,
-				  (dummy_universe::dep *) 0,
-				  u, weights);
+      = unsafe_successor(s0, &a4, &a4+1,
+			 (dummy_universe::dep *) 0,
+			 (dummy_universe::dep *) 0);
 
     // the following two should be equal.
     dummy_solution s5
-      = dummy_solution::successor(s1, &a4, &a4+1,
-				  (dummy_universe::dep *) 0,
-				  (dummy_universe::dep *) 0,
-				  u, weights);
+      = unsafe_successor(s1, &a4, &a4+1,
+			 (dummy_universe::dep *) 0,
+			 (dummy_universe::dep *) 0);
     dummy_solution s6
-      = dummy_solution::successor(s4, &a1, &a1+1,
-				  (dummy_universe::dep *) 0,
-				  (dummy_universe::dep *) 0,
-				  u, weights);
+      = unsafe_successor(s4, &a1, &a1+1,
+			 (dummy_universe::dep *) 0,
+			 (dummy_universe::dep *) 0);
 
     // and this should not equal any other solution.
     dummy_solution s7
-      = dummy_solution::successor(s0,
-				  (dummy_solution::action *) 0,
-				  (dummy_solution::action *) 0,
-				  &d1, &d1+1, u, weights);
+      = unsafe_successor(s0,
+			 (dummy_solution::action *) 0,
+			 (dummy_solution::action *) 0,
+			 &d1, &d1+1);
 
     dummy_resolver::solution_contents_compare solcmp;
 



More information about the Aptitude-svn-commit mailing list