Updated std::vector, std::pair tests.

Improved swig_gc.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9720 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Gonzalo Garramuno 2007-04-30 06:37:41 +00:00
commit b2a45de097
3 changed files with 102 additions and 25 deletions

View file

@ -10,17 +10,20 @@
require 'swig_assert'
require 'li_std_pair'
include Li_std_pair
#
# Because of template specializations for pair<int, int>, this should return
# Because of template specializations for pair<int, int>, these should return
# an Array of size 2, where both elements are Fixnums.
#
intPair = makeIntPair(7, 6)
raise RuntimeError unless intPair.instance_of?(Array)
raise RuntimeError unless intPair.size == 2
raise RuntimeError unless (intPair[0] == 7 && intPair[1] == 6)
raise RuntimeError unless intPair[0] == 7 && intPair[1] == 6
intPairConstRef = makeIntPairConstRef(7, 6)
raise RuntimeError unless intPairConstRef.instance_of?(Array)
raise RuntimeError unless intPairConstRef[0] == 7 && intPairConstRef[1] == 6
#
# Each of these should return a reference to a wrapped
@ -28,16 +31,11 @@ raise RuntimeError unless (intPair[0] == 7 && intPair[1] == 6)
#
intPairPtr = makeIntPairPtr(7, 6)
raise RuntimeError unless intPairPtr.instance_of?(IntPair)
raise RuntimeError unless (intPairPtr.first == 7 && intPairPtr.second == 6)
raise RuntimeError unless intPairPtr[0] == 7 && intPairPtr[1] == 6
intPairRef = makeIntPairRef(7, 6)
raise RuntimeError unless intPairRef.instance_of?(IntPair)
raise RuntimeError unless (intPairRef.first == 7 && intPairRef.second == 6)
intPairConstRef = makeIntPairConstRef(7, 6)
raise RuntimeError unless intPairConstRef.instance_of?(IntPair)
raise RuntimeError unless (intPairConstRef.first == 7 && intPairConstRef.second == 6)
raise RuntimeError unless intPairRef[0] == 7 && intPairRef[1] == 6
#
# Now test various input typemaps. Each of the wrapped C++ functions
# (product1, product2 and product3) is expecting an argument of a

View file

@ -13,16 +13,76 @@ require 'li_std_vector'
include Li_std_vector
iv = IntVector.new(4)
0.upto(3) { |i| iv[i] = i }
@iv = IntVector.new(4)
x = average(iv)
y = average([1, 2, 3, 4])
swig_assert( "@iv.respond_to? :each" )
a = half([10, 10.5, 11, 11.5])
begin
@iv.each
swig_assert( false, "@iv.each worked with no block!")
rescue ArgumentError
end
dv = DoubleVector.new(10)
0.upto(9) { |i| dv[i] = i/2.0 }
halve_in_place(dv)
@iv.each_with_index { |e,i| swig_assert("#{e} == 0", "for @iv[#{i}] == 0") }
0.upto(3) { |i| @iv[i] = i }
{ "@iv[-1]" => 3,
"@iv.slice(0,2).to_s" => "01",
"@iv.slice(1,2).to_s" => "12",
"@iv[0,-2]" => nil,
"@iv[0,3].to_s" => "012",
"@iv[0,10].to_s" => "012",
"@iv[1..2].to_s" => '12',
"@iv[1..3].to_s" => '123',
"@iv[1..4].to_s" => '123',
"@iv[1..-2].to_s" => '12',
"@iv[2..-3]" => nil,
}.each do |k,v|
swig_assert( "#{k} == #{v.inspect}", "was #{eval(k).inspect}" )
end
swig_assert( "@iv << 5" )
swig_assert( "@iv.push 5" )
swig_assert( "@iv.pop == 5" )
swig_assert( "@iv.insert(1,5)" )
swig_assert( "@iv.unshift(7)" )
swig_assert( "@iv.shift == 7" )
swig_assert( "@iv.insert(0, 3)" )
swig_assert( "@iv.unshift(7, 3)" )
swig_assert( "x = average(@iv)" )
swig_assert( "y = average([1, 2, 3, 4])" )
swig_assert( "half([10, 10.5, 11, 11.5])" )
@dv = DoubleVector.new(10)
swig_assert( "@dv.respond_to? :each_with_index" )
@dv.each_with_index { |e,i| swig_assert("#{e} == 0.0", "for @dv[#{i}] == 0") }
0.upto(9) { |i| @dv[i] = i/2.0 }
{ "@dv[-1]" => 4.5,
"@dv.slice(0,2).to_s" => "0.00.5",
"@dv[0,-2]" => nil,
"@dv[0,3].to_s" => "0.00.51.0",
"@dv[3,3].to_s" => "1.52.02.5",
}.each do |k,v|
swig_assert( "#{k} == #{v.inspect}", "was #{eval(k).inspect}" )
end
swig_assert( "@dv.delete_at(2)" )
swig_assert( "@dv.delete_if() { |x| x == 2.0 }" )
swig_assert( "@dv.include? 3.0" )
swig_assert( "@dv.find {|x| x==3.0 }" )
swig_assert( "halve_in_place(@dv) == nil" )
swig_assert( "@dv = [0.0,0.25,0.75,1.25,1.5,1.75,2.0,2.25]", "#@dv" )
swig_assert( "@sv = StructVector.new" )
swig_assert( "@sv << C_Struct.new" )

View file

@ -1,16 +1,35 @@
#!/usr/bin/env ruby
#
# Put script description here.
#
# Author::
# Copyright::
# License:: Ruby
#
#
# VERY nice function from Robert Klemme to check memory leaks
# and check on what GC has collected since last call.
#
# Usage can be:
#
# require 'swig_gc'
#
# GC.stats
# # do some stuff..
# GC.start # collect and report stats
# # do some more...
# GC.stats # just report stats
#
# or:
#
# require 'swig_gc'
#
# GC.track_class = String # track just String classes
# GC.stats
# # do some stuff..
# GC.start # collect and report stats
# # do some more...
# GC.stats # just report stats
#
# Author:: gga
# Copyright:: 2007
# License:: Ruby
#
if $VERBOSE
module GC