Author: kkaempf Date: Mon Dec 31 16:34:22 2007 New Revision: 8168 URL: http://svn.opensuse.org/viewcvs/zypp?rev=8168&view=rev Log: refactor problem test case (backup copy, unfinished) add Pool.create_relation make Python compile again Modified: trunk/sat-solver/bindings/ruby/tests/problems.rb trunk/sat-solver/bindings/satsolver.i Modified: trunk/sat-solver/bindings/ruby/tests/problems.rb URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/problems.rb?rev=8168&r1=8167&r2=8168&view=diff ============================================================================== --- trunk/sat-solver/bindings/ruby/tests/problems.rb (original) +++ trunk/sat-solver/bindings/ruby/tests/problems.rb Mon Dec 31 16:34:22 2007 @@ -3,49 +3,18 @@ require 'test/unit' require 'satsolver' -class ProblemTest < Test::Unit::TestCase - def test_problems - pool = SatSolver::Pool.new - assert pool - - installed = pool.create_repo( 'system' ) - assert installed - installed.create_solvable( 'A', '0.0-0' ) - installed.create_solvable( 'B', '1.0-0' ) - solv = installed.create_solvable( 'C', '2.0-0' ) - solv.requires << SatSolver::Relation.new( pool, "D", SatSolver::REL_EQ, "3.0-0" ) - installed.create_solvable( 'D', '3.0-0' ) - - repo = pool.create_repo( 'test' ) - assert repo - - solv1 = repo.create_solvable( 'A', '1.0-0' ) - assert solv1 - solv1.obsoletes << SatSolver::Relation.new( pool, "C" ) - solv1.requires << SatSolver::Relation.new( pool, "B", SatSolver::REL_GT, "2.0-0" ) - - solv2 = repo.create_solvable( 'B', '2.0-0' ) - assert solv2 - - solv3 = repo.create_solvable( 'CC', '3.3-0' ) -# solv3.requires << SatSolver::Relation.new( pool, "Z" ) - repo.create_solvable( 'DD', '4.4-0' ) - - - transaction = pool.create_transaction - transaction.install( solv1 ) - transaction.remove( "Z" ) - - solver = pool.create_solver( installed ) -# solver.allow_uninstall = 1; -# @pool.debug = 255 - solver.solve( transaction ) - assert solver.problems? - puts "Problems found" - i = 0 - solver.each_problem( transaction ) { |p| - i += 1 - case p.reason +def solve_and_check pool, installed, transaction, problem + + solver = pool.create_solver( installed ) + solver.solve( transaction ) + assert solver.problems? + puts "Problems found" + i = 0 + found = false + solver.each_problem( transaction ) { |p| + found = true if p.reason == problem + i += 1 + case p.reason when SatSolver::SOLVER_PROBLEM_UPDATE_RULE reason = "problem with installed" when SatSolver::SOLVER_PROBLEM_JOB_RULE @@ -66,8 +35,69 @@ reason = "source requires rel but no providers are installable" else reason = "**unknown**" - end - puts "#{i}: [#{reason}] Source #{p.source}, Rel #{p.relation}, Target #{p.target}" - } + end + puts "#{i}: [#{reason}] Source #{p.source}, Rel #{p.relation}, Target #{p.target}" + } + return found +end + +class ProblemTest < Test::Unit::TestCase + def setup + @pool = SatSolver::Pool.new + assert @pool + + @installed = @pool.create_repo( 'system' ) + assert @installed + @installed.create_solvable( 'A', '0.0-0' ) + @installed.create_solvable( 'B', '1.0-0' ) + @installed.create_solvable( 'C', '2.0-0' ) + @installed.create_solvable( 'D', '3.0-0' ) + + @repo = @pool.create_repo( 'test' ) + assert @repo + @repo.create_solvable( 'A', '1.0-0' ) + @repo.create_solvable( 'B', '2.0-0' ) + @repo.create_solvable( 'CC', '3.3-0' ) + @repo.create_solvable( 'DD', '4.4-0' ) + + end + + def test_update_rule + transaction = @pool.create_transaction + assert solve_and_check( @pool, @installed, transaction, SatSolver::SOLVER_PROBLEM_UPDATE_RULE ) + end + def test_job_rule + transaction = @pool.create_transaction + assert solve_and_check( @pool, @installed, transaction, SatSolver::SOLVER_PROBLEM_JOB_RULE ) + end + def test_job_nothing_provides + transaction = @pool.create_transaction + solv = @pool.find( "A", @repo ) + solv.requires << @pool.create_relation( "ZZ" ) + assert solve_and_check( @pool, @installed, transaction, SatSolver::SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP ) + end + def test_not_installable + transaction = @pool.create_transaction + assert solve_and_check( @pool, @installed, transaction, SatSolver::SOLVER_PROBLEM_NOT_INSTALLABLE ) + end + def test_nothing_provides + transaction = @pool.create_transaction + assert solve_and_check( @pool, @installed, transaction, SatSolver::SOLVER_PROBLEM_NOTHING_PROVIDES_DEP ) + end + def test_same_name + transaction = @pool.create_transaction + assert solve_and_check( @pool, @installed, transaction, SatSolver::SOLVER_PROBLEM_SAME_NAME ) + end + def test_package_conflict + transaction = @pool.create_transaction + assert solve_and_check( @pool, @installed, transaction, SatSolver::SOLVER_PROBLEM_PACKAGE_CONFLICT ) + end + def test_package_obsoletes + transaction = @pool.create_transaction + assert solve_and_check( @pool, @installed, transaction, SatSolver::SOLVER_PROBLEM_PACKAGE_OBSOLETES ) + end + def test_providers_not_installable + transaction = @pool.create_transaction + assert solve_and_check( @pool, @installed, transaction, SatSolver::SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE ) end end Modified: trunk/sat-solver/bindings/satsolver.i URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/satsolver.i?rev=8168&r1=8167&r2=8168&view=diff ============================================================================== --- trunk/sat-solver/bindings/satsolver.i (original) +++ trunk/sat-solver/bindings/satsolver.i Mon Dec 31 16:34:22 2007 @@ -181,6 +181,7 @@ Id target; /* solvable id */ } Problem; +#if defined(SWIGRUBY) static Problem *problem_new( Solver *s, Transaction *t, Id id ) { Id prule; @@ -193,6 +194,7 @@ p->reason = solver_problemruleinfo( s, &(t->queue), prule, &(p->relation), &(p->source), &(p->target) ); return p; } +#endif #define SOLUTION_UNKNOWN 0 #define SOLUTION_NOKEEP_INSTALLED 1 @@ -219,6 +221,7 @@ Id n2; } Solution; +#if defined(SWIGRUBY) static Solution *solution_new( Pool *pool, int solution, Id s1, Id n1, Id s2, Id n2 ) { Solution *s = (Solution *)malloc( sizeof( Solution )); @@ -230,6 +233,7 @@ s->n2 = n2; return s; } +#endif %} @@ -409,6 +413,20 @@ } /* + * Relation management + */ + + Relation *create_relation( const char *name, int op = 0, const char *evr = NULL ) + { + Id name_id = str2id( $self, name, 1 ); + Id evr_id = 0; + if (evr) + evr_id = str2id( $self, evr, 1 ); + Id rel = rel2id( $self, name_id, evr_id, op, 1 ); + return relation_new( $self, rel ); + } + + /* * Solvable management */ -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org