Author: kkaempf Date: Fri Dec 21 20:21:39 2007 New Revision: 8138 URL: http://svn.opensuse.org/viewcvs/zypp?rev=8138&view=rev Log: Add public constructor, compare and match for Relation with testcase Added: trunk/sat-solver/bindings/ruby/tests/relation.rb Modified: trunk/sat-solver/bindings/ruby/tests/solvable.rb trunk/sat-solver/bindings/satsolver.i Added: trunk/sat-solver/bindings/ruby/tests/relation.rb URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/relation.rb?rev=8138&view=auto ============================================================================== --- trunk/sat-solver/bindings/ruby/tests/relation.rb (added) +++ trunk/sat-solver/bindings/ruby/tests/relation.rb Fri Dec 21 20:21:39 2007 @@ -0,0 +1,28 @@ +$: << "../../../build/bindings/ruby" +# test Relation +require 'test/unit' +require 'SatSolver' + +class SolvableTest < Test::Unit::TestCase + def setup + @pool = SatSolver::Pool.new + assert @pool + @repo = SatSolver::Repo.new( @pool, "test" ) + assert @repo + @pool.arch = "i686" + @repo.add_solv( "../../../testsuite/data.libzypp/basic-exercises/exercise-1-packages.solv" ) + assert @repo.size > 0 + end + def test_relation + rel = SatSolver::Relation.new( @pool, "A", SatSolver::REL_EQ, "1.0-0" ) + puts "Relation: #{rel}" + @repo.each_solvable{ |s| + s.provides.each { |p| + res1 = (p <=> rel) + puts "#{p} cmp #{rel} => #{res1}" + res2 = (p =~ rel) + puts "#{p} match #{rel} => #{res1}" + } + } + end +end Modified: trunk/sat-solver/bindings/ruby/tests/solvable.rb URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/solvable.rb?rev=8138&r1=8137&r2=8138&view=diff ============================================================================== --- trunk/sat-solver/bindings/ruby/tests/solvable.rb (original) +++ trunk/sat-solver/bindings/ruby/tests/solvable.rb Fri Dec 21 20:21:39 2007 @@ -13,7 +13,9 @@ i += 1 end # does not work yet - deps.each { |d| puts d } + deps.each { |d| + puts "#{d.name} #{d.op} #{d.evr}" + } end class SolvableTest < Test::Unit::TestCase Modified: trunk/sat-solver/bindings/satsolver.i URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/satsolver.i?rev=8138&r1=8137&r2=8138&view=diff ============================================================================== --- trunk/sat-solver/bindings/satsolver.i (original) +++ trunk/sat-solver/bindings/satsolver.i Fri Dec 21 20:21:39 2007 @@ -256,8 +256,24 @@ /* Relation */ %extend Relation { + %constant int REL_GT = 1; + %constant int REL_EQ = 2; + %constant int REL_LT = 4; + %constant int REL_AND = 16; + %constant int REL_OR = 17; + %constant int REL_WITH = 18; + %constant int REL_NAMESPACE = 18; Relation( Id id, Pool *pool) { return relation_new( id, pool ); } + Relation( Pool *pool, const char *name, int op = 0, const char *evr = NULL ) + { + Id name_id = str2id( pool, name, 1 ); + Id evr_id = 0; + if (evr) + evr_id = str2id( pool, evr, 1 ); + Id rel = rel2id( pool, name_id, evr_id, op, 1 ); + return relation_new( rel, pool ); + } ~Relation() { free( $self ); } %rename("to_s") asString(); @@ -266,7 +282,30 @@ return dep2str( $self->pool, $self->id ); } const char *name() - { return id2str( $self->pool, $self->id ); } + { + Reldep *rd = GETRELDEP( $self->pool, $self->id ); + return id2str( $self->pool, rd->name ); + } + const char *evr() + { + Reldep *rd = GETRELDEP( $self->pool, $self->id ); + return id2str( $self->pool, rd->evr ); + } + int op() + { + Reldep *rd = GETRELDEP( $self->pool, $self->id ); + return rd->flags; + } +#if defined(SWIGRUBY) + %alias cmp "<=>"; +#endif + int cmp( const Relation *r ) + { return evrcmp( $self->pool, $self->id, r->id, EVRCMP_COMPARE ); } +#if defined(SWIGRUBY) + %alias match "=~"; +#endif + int match( const Relation *r ) + { return evrcmp( $self->pool, $self->id, r->id, EVRCMP_MATCH_RELEASE ) == 0; } } /*-------------------------------------------------------------*/ -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org