Added some more tests for c file wraps.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9928 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
d1defceb95
commit
8682f0cbaf
6 changed files with 252 additions and 0 deletions
14
Examples/test-suite/ruby/const_const_runme.rb
Executable file
14
Examples/test-suite/ruby/const_const_runme.rb
Executable file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
require 'swig_assert'
|
||||||
|
|
||||||
|
require 'const_const'
|
||||||
|
include Const_const
|
||||||
|
|
||||||
|
swig_assert_each_line <<EOF
|
||||||
|
foo(1) # 1 is unused
|
||||||
|
EOF
|
||||||
|
|
||||||
|
|
||||||
11
Examples/test-suite/ruby/function_typedef_runme.rb
Executable file
11
Examples/test-suite/ruby/function_typedef_runme.rb
Executable file
|
|
@ -0,0 +1,11 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
#
|
||||||
|
# Tests for function_typedef.i
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
require 'swig_assert'
|
||||||
|
require 'function_typedef'
|
||||||
|
include Function_typedef
|
||||||
|
|
||||||
|
# Hmm... not sure how to test this.
|
||||||
21
Examples/test-suite/ruby/integers_runme.rb
Executable file
21
Examples/test-suite/ruby/integers_runme.rb
Executable file
|
|
@ -0,0 +1,21 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
#
|
||||||
|
# Put script description here.
|
||||||
|
#
|
||||||
|
|
||||||
|
require 'swig_assert'
|
||||||
|
require 'integers'
|
||||||
|
include Integers
|
||||||
|
|
||||||
|
swig_assert_each_line <<EOF
|
||||||
|
signed_char_identity(-3) == -3
|
||||||
|
unsigned_char_identity(5) == 5
|
||||||
|
signed_short_identity(-3) == -3
|
||||||
|
unsigned_short_identity(5) == 5
|
||||||
|
signed_int_identity(-3) == -3
|
||||||
|
unsigned_int_identity(5) == 5
|
||||||
|
signed_long_identity(-3) == -3
|
||||||
|
unsigned_long_identity(5) == 5
|
||||||
|
signed_long_long_identity(-3) == -3
|
||||||
|
unsigned_long_long_identity(5) == 5
|
||||||
|
EOF
|
||||||
22
Examples/test-suite/ruby/li_cstring_runme.rb
Executable file
22
Examples/test-suite/ruby/li_cstring_runme.rb
Executable file
|
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
#
|
||||||
|
# Test for li_cstring.i
|
||||||
|
#
|
||||||
|
|
||||||
|
require 'swig_assert'
|
||||||
|
require 'li_cstring'
|
||||||
|
|
||||||
|
include Li_cstring
|
||||||
|
|
||||||
|
swig_assert_each_line <<EOF
|
||||||
|
count("hello", 'l'[0]) == 2
|
||||||
|
test1 == 'Hello World'
|
||||||
|
test2
|
||||||
|
test3('hello') == 'hello-suffix'
|
||||||
|
test4('hello') == 'hello-suffix'
|
||||||
|
test5(5) == 'xxxxx'
|
||||||
|
test6(6) == 'xxx'
|
||||||
|
test7 == 'Hello world!'
|
||||||
|
test8 == (32..32+63).map {|x| x.chr }.join
|
||||||
|
EOF
|
||||||
|
|
||||||
67
Examples/test-suite/ruby/li_std_speed2_runme.rb
Executable file
67
Examples/test-suite/ruby/li_std_speed2_runme.rb
Executable file
|
|
@ -0,0 +1,67 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
require 'benchmark'
|
||||||
|
require 'li_std_speed'
|
||||||
|
include Li_std_speed
|
||||||
|
|
||||||
|
def benchmark(f, phigh, sequences)
|
||||||
|
print f.class
|
||||||
|
puts '%10s ' % 'n' + sequences.inject('') { |a,s| a << '%10s' % s.class }
|
||||||
|
0.upto(phigh-1) do |p|
|
||||||
|
n = 2**p
|
||||||
|
print "%10d"%n
|
||||||
|
$stdout.flush
|
||||||
|
for s in sequences
|
||||||
|
cont = s.new((0..n).to_a)
|
||||||
|
Benchmark.benchmark { f.call(cont) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def iterate(cont)
|
||||||
|
# expected: O(n)
|
||||||
|
# got: O(n**2) for set/list (vector/deque fine)
|
||||||
|
it = cont.begin
|
||||||
|
last = cont.end
|
||||||
|
while it != last
|
||||||
|
it.next
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def erase(cont)
|
||||||
|
# expected: O(n)
|
||||||
|
# got: O(n**2) for vector/deque and O(n**3) for set/list
|
||||||
|
it = cont.end
|
||||||
|
# can't reuse begin since it might get invalidated
|
||||||
|
while it != cont.begin
|
||||||
|
it.previous
|
||||||
|
# set returns None, so need to reobtain end
|
||||||
|
it = cont.erase(it) or cont.end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def insert(cont)
|
||||||
|
it = cont.end
|
||||||
|
size = cont.size
|
||||||
|
if cont.kind_of? RbSet
|
||||||
|
# swig stl missing hint version of insert for set
|
||||||
|
# expected would be O(n) with iterator hint version
|
||||||
|
# expected: O(n*log(n))
|
||||||
|
# got: O(n**3*log(n))
|
||||||
|
size.upto(size<<1) { |x| cont.insert(x) }
|
||||||
|
else
|
||||||
|
# expected: O(n)
|
||||||
|
# got: O(n**3) for list (vector/deque fine)
|
||||||
|
size.upto(size<<1) { |x| cont.push(x) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if $0 == __FILE__
|
||||||
|
sequences = [RbVector,RbDeque,RbSet,RbList]
|
||||||
|
for f,phigh in [[method(:iterate),15], [method(:insert),15],
|
||||||
|
[method(:erase),11]]
|
||||||
|
benchmark(f, phigh, sequences)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
117
Examples/test-suite/ruby/stl_new_runme.rb
Executable file
117
Examples/test-suite/ruby/stl_new_runme.rb
Executable file
|
|
@ -0,0 +1,117 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
#
|
||||||
|
# This is a test of STL containers, iterators and using proc
|
||||||
|
# objects to change the sorting function used in them. Same as a
|
||||||
|
# std::binary_predicate in C++.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
require 'swig_assert'
|
||||||
|
require 'stl_new'
|
||||||
|
|
||||||
|
|
||||||
|
def _sequence(container)
|
||||||
|
swig_assert_each_line(<<'EOF', binding)
|
||||||
|
cont = container.new([9,1,8,2,7,3,6,4,5])
|
||||||
|
cont.to_a == [9,1,8,2,7,3,6,4,5]
|
||||||
|
cont.size == 9
|
||||||
|
i = cont.begin
|
||||||
|
i.class == Stl_new::Iterator
|
||||||
|
cont.end - cont.begin == cont.size
|
||||||
|
cont.begin.value == 9
|
||||||
|
(cont.end-1).value == 5
|
||||||
|
cont[0],cont[1] = cont[1],cont[0]
|
||||||
|
cont.to_a == [1,9,8,2,7,3,6,4,5]
|
||||||
|
i0 = cont.begin
|
||||||
|
i1 = i0+1
|
||||||
|
tmp = i0.value # tmp = 1
|
||||||
|
tmp == 1
|
||||||
|
i0.value = i1.value # elem[0] = 9
|
||||||
|
i1.value = tmp # elem[1] = 1
|
||||||
|
cont.to_a == [9,1,8,2,7,3,6,4,5]
|
||||||
|
i0 += 8
|
||||||
|
prev = i0.value
|
||||||
|
i0 -= 8
|
||||||
|
cur = i0.value
|
||||||
|
i0.value = prev
|
||||||
|
prev = cur
|
||||||
|
i0 += 8
|
||||||
|
cur = i0.value
|
||||||
|
i0.value = prev
|
||||||
|
cont.to_a == [5,1,8,2,7,3,6,4,9]
|
||||||
|
i0 == cont.end-1
|
||||||
|
i0 != cont.end
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
|
||||||
|
def _random_iterator(container)
|
||||||
|
swig_assert_each_line(<<EOF, binding)
|
||||||
|
cont = #{container}.new([9,1,8,2,7,3,6,4,5])
|
||||||
|
Stl_new.nth_element(cont.begin,cont.begin+cont.size/2,cont.end)
|
||||||
|
cont.to_a == [3, 1, 2, 4, 5, 6, 7, 8, 9]
|
||||||
|
Stl_new.nth_element(cont.begin,cont.begin+1,cont.end, proc { |a,b| b<a } )
|
||||||
|
cont.to_a == [9, 8, 7, 6, 5, 4, 2, 1, 3]
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
|
||||||
|
def _set(container)
|
||||||
|
swig_assert_each_line(<<EOF, binding)
|
||||||
|
cont = #{container}.new
|
||||||
|
[9,1,8,2,7,3,6,4,5].each { |x| cont.insert(x) }
|
||||||
|
i0 = cont.begin()
|
||||||
|
cont.to_a == [1,2,3,4,5,6,7,8,9]
|
||||||
|
cont = #{container}.new( proc { |a,b| b < a } )
|
||||||
|
[9,1,8,2,7,3,6,4,5].each { |x| cont.insert(x) }
|
||||||
|
cont.to_a == [9, 8, 7, 6, 5, 4, 3, 2, 1]
|
||||||
|
cont = #{container}.new( proc { |a,b| b > a } )
|
||||||
|
[9,1,8,2,7,3,6,4,5].each { |x| cont.insert(x) }
|
||||||
|
cont.to_a == [1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||||
|
cont = #{container}.new(proc { |a,b| b < a } )
|
||||||
|
cont.insert(1)
|
||||||
|
cont.to_a == [1]
|
||||||
|
i0 = cont.begin()
|
||||||
|
cont.erase(i0) # don't use i0 anymore, it is invalid now
|
||||||
|
cont.to_a == []
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
|
||||||
|
def _map(container)
|
||||||
|
swig_assert_each_line(<<EOF, binding)
|
||||||
|
cont = #{container}.new
|
||||||
|
cont['z'] = 9
|
||||||
|
cont['y'] = 1
|
||||||
|
cont['x'] = 8
|
||||||
|
cont['w'] = 2
|
||||||
|
cont.to_a == [['w',2],['x',8],['y',1],['z',9]]
|
||||||
|
|
||||||
|
cont = #{container}.new(proc { |a,b| b < a } )
|
||||||
|
cont['z'] = 9
|
||||||
|
cont['y'] = 1
|
||||||
|
cont['x'] = 8
|
||||||
|
cont['w'] = 2
|
||||||
|
cont.to_a == [['z',9],['y',1],['x',8],['w',2]]
|
||||||
|
|
||||||
|
#cont.iterator.to_a == [['w',2],['x',8],['y',1],['z',9]]
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
|
||||||
|
def test
|
||||||
|
for container in [Stl_new::Vector, Stl_new::Deque, Stl_new::List]
|
||||||
|
yield method(:_sequence), container
|
||||||
|
end
|
||||||
|
yield method(:_set), Stl_new::Set
|
||||||
|
yield method(:_map), Stl_new::Map
|
||||||
|
# for container in [Stl_new::Vector, Stl_new::Deque]
|
||||||
|
# yield method(:_random_iterator), container
|
||||||
|
# end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
test do |proc, container|
|
||||||
|
proc.call(container)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue