Initial commit

This commit is contained in:
Bassem Girgis
2018-12-20 17:34:07 -06:00
parent 7a2d899662
commit 81b4b9e273
34743 changed files with 5940233 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
#######################################################################
# Makefile for ruby test-suite
#######################################################################
LANGUAGE = ruby
RUBY = @RUBY@
SCRIPTSUFFIX = _runme.rb
srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
CPP_TEST_CASES = \
li_cstring \
li_factory \
li_std_functors \
li_std_multimap \
li_std_pair_lang_object \
li_std_queue \
li_std_set \
li_std_stack \
primitive_types \
ruby_keywords \
ruby_minherit_shared_ptr \
ruby_naming \
ruby_track_objects \
ruby_track_objects_directors \
std_containers
# ruby_li_std_speed
# stl_new
C_TEST_CASES += \
li_cstring \
ruby_manual_proxy \
include $(srcdir)/../common.mk
# Overridden variables here
SWIGOPT += -w801 -noautorename -features autodoc=4
# Custom tests - tests with additional commandline options
ruby_naming.cpptest: SWIGOPT += -autorename
# Rules for the different types of tests
%.cpptest:
$(setup)
+$(swig_and_compile_cpp)
$(run_testcase)
%.ctest:
$(setup)
+$(swig_and_compile_c)
$(run_testcase)
%.multicpptest:
$(setup)
+$(swig_and_compile_multi_cpp)
$(run_testcase)
# Runs the testcase. A testcase is only run if
# a file is found which has _runme.rb appended after the testcase name.
run_testcase = \
if [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(RUBY) $(RUBYFLAGS) -I$(srcdir):. $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \
fi
# Clean
%.clean:
@exit 0
clean:
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' ruby_clean

View File

@@ -0,0 +1,4 @@
See ../README for common README file.
Any testcases which have _runme.rb appended after the testcase name will be detected and run.

View File

@@ -0,0 +1,34 @@
#!/usr/bin/env ruby
#
# Put script description here.
#
#
#
#
#
require 'swig_assert'
require 'abstract_access'
include Abstract_access
begin
a = A.new
rescue TypeError
swig_assert(true, binding, 'A.new')
end
begin
b = B.new
rescue TypeError
swig_assert(true, binding, 'B.new')
end
begin
c = C.new
rescue TypeError
swig_assert(true, binding, 'C.new')
end
swig_assert( 'D.new' )

View File

@@ -0,0 +1,48 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'abstract_inherit_ok'
include Abstract_inherit_ok
#
# Shouldn't be able to instantiate Foo, because it declares
# a pure virtual function.
#
exceptionRaised = false
begin
Foo.new
rescue NameError
exceptionRaised = true
rescue TypeError
# In Ruby 1.8 the exception raised is:
# TypeError: allocator undefined for Abstract_inherit_ok::Foo
exceptionRaised = true
ensure
swig_assert( "exceptionRaised", binding )
end
#
# This one's OK since we cleared it with a %feature("notabstract")
# declaration in the interface file.
#
exceptionRaised = false
begin
spam = Spam.new
raise RuntimeError unless spam.blah == 0
rescue NameError
exceptionRaised = true
ensure
swig_assert( "!exceptionRaised", binding )
end

View File

@@ -0,0 +1,61 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'abstract_inherit'
include Abstract_inherit
#
# Shouldn't be able to instantiate any of these classes
# since none of them implements the pure virtual function
# declared in the base class (Foo).
#
exceptionRaised = false
begin
Foo.new
rescue NameError
exceptionRaised = true
rescue TypeError
# In Ruby 1.8 the exception raised is:
# TypeError: allocator undefined for Abstract_inherit::Foo
exceptionRaised = true
ensure
swig_assert( "exceptionRaised", binding )
end
exceptionRaised = false
begin
Bar.new
rescue NameError
exceptionRaised = true
rescue TypeError
# In Ruby 1.8 the exception raised is:
# TypeError: allocator undefined for Abstract_inherit::Bar
exceptionRaised = true
ensure
swig_assert( "exceptionRaised", binding )
end
exceptionRaised = false
begin
Spam.new
rescue NameError
exceptionRaised = true
rescue TypeError
# In Ruby 1.8 the exception raised is:
# TypeError: allocator undefined for Abstract_inherit::Spam
exceptionRaised = true
ensure
swig_assert( "exceptionRaised", binding )
end

View File

@@ -0,0 +1,62 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'abstract_signature'
include Abstract_signature
#
# Shouldn't be able to instantiate Abstract_foo, because it declares
# a pure virtual function.
#
exceptionRaised = false
begin
foo = Abstract_foo.new
begin
foo.meth(1)
rescue RuntimeError
# here we are using directors
exceptionRaised = true
end
rescue NameError
exceptionRaised = true
rescue TypeError
# In Ruby 1.8 the exception raised is:
# TypeError: allocator undefined for Abstract_signature::Abstract_foo
exceptionRaised = true
ensure
swig_assert( "exceptionRaised", binding)
end
#
# Shouldn't be able to instantiate an Abstract_bar either, because it doesn't
# implement the pure virtual function with the correct signature.
#
exceptionRaised = false
begin
bar = Abstract_bar.new
begin
bar.meth(1)
rescue RuntimeError
# here we are using directors
exceptionRaised = true
end
rescue NameError
exceptionRaised = true
rescue TypeError
# In Ruby 1.8 the exception raised is:
# TypeError: allocator undefined for Abstract_signature::Abstract_bar
exceptionRaised = true
ensure
swig_assert( "exceptionRaised", binding)
end

View File

@@ -0,0 +1,17 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'abstract_typedef2'
include Abstract_typedef2
swig_assert( 'a = A_UF.new' )

View File

@@ -0,0 +1,23 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'abstract_typedef'
include Abstract_typedef
swig_assert_each_line(<<'EOF', binding)
e = Engine.new
a = A.new
a.write(e)
EOF

View File

@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'abstract_virtual'
include Abstract_virtual
swig_assert('d = D.new')
swig_assert('e = E.new')

View File

@@ -0,0 +1,46 @@
#!/usr/bin/env ruby
#
# Put script description here.
#
#
#
#
#
require 'swig_assert'
require 'access_change'
#
# this test will currently fail, as it exposes functions that were
# made protected from public. swig limitation for now.
#
exit(0)
include Access_change
klass = BaseInt.new
public = ['PublicProtectedPublic1', 'PublicProtectedPublic2',
'PublicProtectedPublic3', 'PublicProtectedPublic4']
methods = (klass.public_methods - Object.methods).sort
pmethods = (klass.protected_methods - Object.methods).sort
swig_assert( methods == public,
" incorrect public methods for BaseInt\n" +
"#{methods.inspect} !=\n#{public.inspect}" )
klass = DerivedInt.new
public = ['PublicProtectedPublic3', 'PublicProtectedPublic4',
'WasProtected1', 'WasProtected2', 'WasProtected3', 'WasProtected4']
methods = (klass.public_methods - Object.methods).sort
swig_assert( methods == public,
" incorrect public methods for DerivedInt\n" +
"#{methods.inspect} !=\n#{public.inspect}" )
klass = BottomInt.new
public = ['PublicProtectedPublic1', 'PublicProtectedPublic2',
'PublicProtectedPublic3', 'PublicProtectedPublic4',
'WasProtected1', 'WasProtected2']
methods = (klass.public_methods - Object.methods).sort
swig_assert( methods == public,
" incorrect public methods for BottomInt\n" +
"#{methods.inspect} !=\n#{public.inspect}" )

View File

@@ -0,0 +1,20 @@
#!/usr/bin/env ruby
#
# Put script description here.
#
#
#
#
#
require 'swig_assert'
require 'add_link'
include Add_link
#
# This test currently fails due to swig
#
exit(0)
swig_assert( 'Foo.new' )
swig_assert( 'Foo.blah' )

View File

@@ -0,0 +1,37 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'aggregate'
include Aggregate
# Confirm that move() returns correct results under normal use
result = move(UP)
raise RuntimeError unless (result == UP)
result = move(DOWN)
raise RuntimeError unless (result == DOWN)
result = move(LEFT)
raise RuntimeError unless (result == LEFT)
result = move(RIGHT)
raise RuntimeError unless (result == RIGHT)
# Confirm that it raises an exception when the contract is violated
failed = false
begin
move(0)
rescue RuntimeError
failed = true
end
raise RuntimeError unless failed

View File

@@ -0,0 +1,35 @@
#!/usr/bin/env ruby
#
# Put script description here.
#
#
#
#
#
require 'swig_assert'
require 'anonymous_bitfield'
include Anonymous_bitfield
foo = Foo.new
{'x' => 4,
'y' => 3,
'f' => 1,
'z' => 8,
'seq' => 3 }.each do |m, v|
foo.send("#{m}=", v)
val = foo.send(m)
swig_assert("val == v", binding)
end
{'x' => (1 << 4),
'y' => (1 << 4),
'f' => (1 << 1),
'z' => (1 << 16),
'seq' => (1 << (4*8-6)) }.each do |m, v|
foo.send("#{m}=", v)
val = foo.send(m)
swig_assert("val != v", binding)
end

View File

@@ -0,0 +1,45 @@
#!/usr/bin/env ruby
#
# Put script description here.
#
#
#
#
#
require 'swig_assert'
require 'apply_signed_char'
include Apply_signed_char
['CharValFunction', 'CCharValFunction', 'CCharRefFunction'].each do |m|
[ 3, -3 ].each do |v|
val = send( m, v )
swig_assert( "v == val", binding, "for #{m}")
end
end
{ 'globalchar' => -109,
'globalconstchar' => -110,
}.each do |k,v|
val = Apply_signed_char.send( k )
swig_assert( "v == val", binding, "for #{k}")
end
a = DirectorTest.new
['CharValFunction', 'CCharValFunction', 'CCharRefFunction'].each do |m|
[ 3, -3 ].each do |v|
val = a.send( m, v )
swig_assert( "v == val", binding, "for DirectorTest.#{m}")
end
end
{ 'memberchar' => -111,
'memberconstchar' => -112,
}.each do |k,v|
val = a.send( k )
swig_assert( "v == val", binding, "for #{k}")
end

View File

@@ -0,0 +1,61 @@
#!/usr/bin/env ruby
#
# Put script description here.
#
#
#
#
#
require 'swig_assert'
require 'apply_strings'
include Apply_strings
begin
x = UcharPtr.new
swig_assert( fail, "UcharPtr should not be defined")
rescue NameError
end
ptr = 'a'
['UCharFunction', 'SCharFunction', 'CUCharFunction',
'CSCharFunction'].each do |m|
val = Apply_strings.send(m, ptr)
swig_assert( "val == ptr", binding )
end
['CharFunction', 'CCharFunction'].each do |m|
begin
val = Apply_strings.send(m, ptr)
swig_assert( false, nil, "Apply_strings.#{m} should raise TypeError" )
rescue TypeError
end
end
ptr = 'a'
foo = DirectorTest.new
['UCharFunction', 'SCharFunction', 'CUCharFunction',
'CSCharFunction'].each do |m|
val = foo.send(m, ptr)
swig_assert( "val == ptr", binding, "DirectorTest.#{m}" )
end
['CharFunction', 'CCharFunction'].each do |m|
begin
val = foo.send(m, ptr)
swig_assert( false, nil, "DirectorTest.#{m} should raise TypeError" )
rescue TypeError
end
end
# ary = Apply_strings.DigitsGlobalB
# { 0 => 'A',
# 1 => 'B',
# 2 => 'B' }.each do |k,v|
# val = ary[k]
# swig_assert( val == v, "Apply_strings.DigitsGlobalB[#{k}] #{val} != #{v}")
# end

View File

@@ -0,0 +1,42 @@
#!/usr/bin/env ruby
#
# Put script description here.
#
#
#
#
#
require 'swig_assert'
require 'argout'
include Argout
swig_assert_each_line(<<'EOF', binding)
t = new_intp
intp_assign(t, 5)
v = incp(t)
val = intp_value(t)
val == 6
t = new_intp
intp_assign(t, 5)
v = incr(t)
v == 5
val = intp_value(t)
val == 6
t = new_intp
intp_assign(t, 5)
v = inctr(t)
v == 5
val = intp_value(t)
val == 6
EOF
#
# @todo: how to use voidhandle and handle?
#

View File

@@ -0,0 +1,36 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'array_member'
include Array_member
f = Foo.new
f.data = Array_member.global_data
0.upto(7) { |i|
unless get_value(f.data, i) == get_value(Array_member.global_data, i)
raise RuntimeError, "Bad array assignment"
end
}
0.upto(7) { |i|
set_value(f.data, i, -i)
}
Array_member.global_data = f.data
0.upto(7) { |i|
unless get_value(f.data, i) == get_value(Array_member.global_data, i)
raise RuntimeError, "Bad array assignment"
end
}

View File

@@ -0,0 +1,15 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'arrays_global'
Arrays_global.array_i = Arrays_global.array_const_i

View File

@@ -0,0 +1,25 @@
#!/usr/bin/env ruby
#
# Test run of arrays.i
#
#
require 'swig_assert'
require 'arrays'
include Arrays
a = SimpleStruct.new
a.double_field = 2.0
b = SimpleStruct.new
b.double_field = 1.0
# @bug: this is broken
#
# c = [a,b]
# fn_taking_arrays(c)
#
# a = ArrayStruct.new
# a.array_i[0] = 0
#

View File

@@ -0,0 +1,82 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'bools'
# bool constant check
if (Bools::Constbool != false)
print "Runtime test 1 failed\n"
exit 1
end
# bool variables check
if (Bools.bool1 != true)
print "Runtime test 2 failed\n"
exit 1
end
if (Bools.bool2 != false)
print "Runtime test 3 failed\n"
exit 1
end
if (Bools.value(Bools.pbool) != Bools.bool1)
print "Runtime test 4 failed\n"
exit 1
end
if (Bools.value(Bools.rbool) != Bools.bool2)
print "Runtime test 5 failed\n"
exit 1
end
if (Bools.value(Bools.const_pbool) != Bools.bool1)
print "Runtime test 6 failed\n"
exit 1
end
if (Bools.const_rbool != Bools.bool2)
print "Runtime test 7 failed\n"
exit 1
end
# bool functions check
if (Bools.bo(false) != false)
print "Runtime test 8 failed\n"
exit 1
end
if (Bools.bo(true) != true)
print "Runtime test 9 failed\n"
exit 1
end
if (Bools.value(Bools.rbo(Bools.rbool)) != Bools.value(Bools.rbool))
print "Runtime test 10 failed\n"
exit 1
end
if (Bools.value(Bools.pbo(Bools.pbool)) != Bools.value(Bools.pbool))
print "Runtime test 11 failed\n"
exit 1
end
if (Bools.const_rbo(Bools.const_rbool) != Bools.const_rbool)
print "Runtime test 12 failed\n"
exit 1
end
if (Bools.value(Bools.const_pbo(Bools.const_pbool)) != Bools.value(Bools.const_pbool))
print "Runtime test 13 failed\n"
exit 1
end

View File

@@ -0,0 +1,17 @@
#!/usr/bin/env ruby
#
# Put script description here.
#
#
#
#
#
require 'swig_assert'
require 'cast_operator'
include Cast_operator
a = A.new
t = a.tochar
swig_assert( t == 'hi' )

View File

@@ -0,0 +1,23 @@
#!/usr/bin/env ruby
#
# Put script description here.
#
#
#
#
#
require 'swig_assert'
require 'casts'
include Casts
swig_assert( B.ancestors.include?(A), 'B.ancestors.include? A' )
a = A.new
a.hello
b = B.new
b.hello
swig_assert( b.kind_of?( A ), ' B.kind_of? A' )

View File

@@ -0,0 +1,34 @@
#!/usr/bin/env ruby
#Encoding: ASCII-8BIT
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'char_constant'
if Char_constant::CHAR_CONSTANT != 'x'
raise RuntimeError, "Invalid value for CHAR_CONSTANT."
end
if Char_constant::STRING_CONSTANT != 'xyzzy'
raise RuntimeError, "Invalid value for STRING_CONSTANT."
end
if Char_constant::ESC_CONST != "\001"
raise RuntimeError, "Invalid value for ESC_CONST."
end
if Char_constant::NULL_CONST != "\000"
raise RuntimeError, "Invalid value for NULL_CONST."
end
if Char_constant::SPECIALCHAR != "\341" #'á'
raise RuntimeError, "Invalid value for SPECIALCHAR."
end

View File

@@ -0,0 +1,53 @@
#!/usr/bin/env ruby
#
# This script allows you to compare the tests in the current directory
# (Ruby) against the tests of other languages to see which ones are missing
#
#
#
#
#
ignore = ['ruby','std','typemaps']
curr = Dir.pwd.sub(/.*\//, '')
langs = Dir.glob('../*').select { |x| File.directory?("../#{x}") }
langs.map! { |x| x.sub(/^\.\.\/*/, '') }
langs -= ignore
# Add generic test directory, too
langs << ''
testsB = Dir.glob("*runme*").map { |x| x.sub(/\.\w+$/, '') }
all_tests = []
langs.each do |lang|
testsA = Dir.glob("../#{lang}/*runme*")
testsA.map! { |x| x.sub(/.*\/(\w+)\.\w+$/, '\1') }
testsA.delete_if { |x| x =~ /~$/ } # ignore emacs backups
diff = testsA - testsB
unless diff.empty?
puts '-'*70
title = !lang.empty? ? "#{lang[0,1].upcase}#{lang[1..-1]}" : 'Generic'
title = "Missing #{title} tests"
puts title
puts '='*title.size
puts diff.join(', ')
all_tests += diff
end
end
all_tests.uniq!
puts '-'*70
puts 'All missing tests'
puts '================='
puts all_tests.join(', ')

View File

@@ -0,0 +1,21 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'class_ignore'
a = Class_ignore::Bar.new
# Even though we didn't wrap the Foo class, this call
# to do_blah() should succeed.
if Class_ignore.do_blah(a) != "Bar::blah"
raise RuntimeError
end

View 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

View File

@@ -0,0 +1,55 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'constover'
error = 0
p = Constover.test("test")
if p != "test"
puts "test failed!"
error = 1
end
p = Constover.test_pconst("test")
if p != "test_pconst"
puts "test_pconst failed!"
error = 1
end
f = Constover::Foo.new
p = f.test("test")
if p != "test"
print "member-test failed!"
error = 1
end
p = f.test_pconst("test")
if p != "test_pconst"
print "member-test_pconst failed!"
error = 1
end
p = f.test_constm("test")
if p != "test_constmethod"
print "member-test_constm failed!"
error = 1
end
p = f.test_pconstm("test")
if p != "test_pconstmethod"
print "member-test_pconstm failed!"
error = 1
end
exit(error)

View File

@@ -0,0 +1,134 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'cpp11_li_std_array'
include Cpp11_li_std_array
def failed(a, b, msg)
raise RuntimeError, "#{msg} #{a} #{b}"
end
def compare_sequences(a, b)
if a.size != b.size
failed(a, b, "different sizes")
end
for i in 0..a.size-1
failed(a, b, "elements are different:") if a[i] != b[i]
end
end
def compare_containers(rubyarray, swigarray)
compare_sequences(rubyarray, swigarray)
end
def setslice_exception(swigarray, newval)
begin
swigarray[0..swigarray.size] = newval
raise RuntimeError, "swigarray[] = #{newval} missed set exception for swigarray: #{swigarray}"
rescue ArgumentError => e
# print "exception: #{e}"
end
end
# Check std::array has similar behaviour to a Ruby array
# except it is not resizable
ps = [0, 1, 2, 3, 4, 5]
ai = ArrayInt6.new(ps)
compare_containers(ps, ai)
# slices
compare_containers(ps[0..5], ai[0..5])
compare_containers(ps[-6..-1], ai[-6..-1])
compare_containers(ps[0..10], ai[0..10])
# Reverse (.reverse is not provided)
rev = []
ai.reverse_each { |i| rev.push i }
compare_containers(ps.reverse, rev)
# Modify content
for i in 0..ps.size-1
ps[i] = ps[i] * 10
ai[i] = ai[i] * 10
end
compare_containers(ps, ai)
# Empty
ai = ArrayInt6.new()
compare_containers([0, 0, 0, 0, 0, 0], ai)
# Set slice
newvals = [10, 20, 30, 40, 50, 60]
ai[0, 6] = newvals
compare_containers(ai, newvals)
ai[-6, 6] = newvals
compare_containers(ai, newvals)
setslice_exception(ai, [1, 2, 3, 4, 5, 6, 7])
setslice_exception(ai, [1, 2, 3, 4, 5])
setslice_exception(ai, [1, 2, 3, 4])
setslice_exception(ai, [1, 2, 3])
setslice_exception(ai, [1, 2])
setslice_exception(ai, [1])
setslice_exception(ai, [])
# Check return
compare_containers(arrayOutVal(), [-2, -1, 0, 0, 1, 2])
compare_containers(arrayOutConstRef(), [-2, -1, 0, 0, 1, 2])
compare_containers(arrayOutRef(), [-2, -1, 0, 0, 1, 2])
compare_containers(arrayOutPtr(), [-2, -1, 0, 0, 1, 2])
# Check passing arguments
ai = arrayInVal([9, 8, 7, 6, 5, 4])
compare_containers(ai, [90, 80, 70, 60, 50, 40])
ai = arrayInConstRef([9, 8, 7, 6, 5, 4])
compare_containers(ai, [90, 80, 70, 60, 50, 40])
ai = ArrayInt6.new([9, 8, 7, 6, 5, 4])
arrayInRef(ai)
compare_containers(ai, [90, 80, 70, 60, 50, 40])
ai = ArrayInt6.new([9, 8, 7, 6, 5, 4])
arrayInPtr(ai)
compare_containers(ai, [90, 80, 70, 60, 50, 40])
# indexing
ai = ArrayInt6.new([9, 8, 7, 6, 5, 4])
swig_assert_equal(ai[0], 9, binding)
swig_assert_equal(ai[5], 4, binding)
swig_assert_equal(ai[6], nil, binding)
swig_assert_equal(ai[-7], nil, binding)
# fill
ai.fill(111)
compare_containers(ai, [111, 111, 111, 111, 111, 111])
# various
ai = ArrayInt6.new([9, 8, 7, 6, 5, 4])
swig_assert(ai.include? 9)
swig_assert(!ai.include?(99))
swig_assert(ai.kind_of? ArrayInt6)
swig_assert(ai.find {|x| x == 6 } == 6)
swig_assert(ai.find {|x| x == 66 } == nil)
swig_assert(ai.respond_to?(:each))
swig_assert(ai.respond_to?(:each_with_index))
ai = [0, 10, 20, 30, 40, 50]
ai.each_with_index { |e,i| swig_assert(e/10 == i) }

View File

@@ -0,0 +1,177 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'cpp11_strongly_typed_enumerations'
include Cpp11_strongly_typed_enumerations
def enumCheck(actual, expected)
raise RuntimeError,"Enum value mismatch. Expected #{expected} Actual: #{actual}" if actual != expected
return expected + 1
end
val = 0
val = enumCheck(Enum1_Val1, val)
val = enumCheck(Enum1_Val2, val)
val = enumCheck(Enum1_Val3, 13)
val = enumCheck(Enum1_Val4, val)
val = enumCheck(Enum1_Val5a, 13)
val = enumCheck(Enum1_Val6a, val)
val = 0
val = enumCheck(Enum2_Val1, val)
val = enumCheck(Enum2_Val2, val)
val = enumCheck(Enum2_Val3, 23)
val = enumCheck(Enum2_Val4, val)
val = enumCheck(Enum2_Val5b, 23)
val = enumCheck(Enum2_Val6b, val)
val = 0
val = enumCheck(Val1, val)
val = enumCheck(Val2, val)
val = enumCheck(Val3, 43)
val = enumCheck(Val4, val)
val = 0
val = enumCheck(Enum5_Val1, val)
val = enumCheck(Enum5_Val2, val)
val = enumCheck(Enum5_Val3, 53)
val = enumCheck(Enum5_Val4, val)
val = 0
val = enumCheck(Enum6_Val1, val)
val = enumCheck(Enum6_Val2, val)
val = enumCheck(Enum6_Val3, 63)
val = enumCheck(Enum6_Val4, val)
val = 0
val = enumCheck(Enum7td_Val1, val)
val = enumCheck(Enum7td_Val2, val)
val = enumCheck(Enum7td_Val3, 73)
val = enumCheck(Enum7td_Val4, val)
val = 0
val = enumCheck(Enum8_Val1, val)
val = enumCheck(Enum8_Val2, val)
val = enumCheck(Enum8_Val3, 83)
val = enumCheck(Enum8_Val4, val)
val = 0
val = enumCheck(Enum10_Val1, val)
val = enumCheck(Enum10_Val2, val)
val = enumCheck(Enum10_Val3, 103)
val = enumCheck(Enum10_Val4, val)
val = 0
val = enumCheck(Class1::Enum12_Val1, 1121)
val = enumCheck(Class1::Enum12_Val2, 1122)
val = enumCheck(Class1::Enum12_Val3, val)
val = enumCheck(Class1::Enum12_Val4, val)
val = enumCheck(Class1::Enum12_Val5c, 1121)
val = enumCheck(Class1::Enum12_Val6c, val)
val = 0
val = enumCheck(Class1::Val1, 1131)
val = enumCheck(Class1::Val2, 1132)
val = enumCheck(Class1::Val3, val)
val = enumCheck(Class1::Val4, val)
val = enumCheck(Class1::Val5d, 1131)
val = enumCheck(Class1::Val6d, val)
val = 0
val = enumCheck(Class1::Enum14_Val1, 1141)
val = enumCheck(Class1::Enum14_Val2, 1142)
val = enumCheck(Class1::Enum14_Val3, val)
val = enumCheck(Class1::Enum14_Val4, val)
val = enumCheck(Class1::Enum14_Val5e, 1141)
val = enumCheck(Class1::Enum14_Val6e, val)
# Requires nested class support to work
#val = 0
#val = enumCheck(Class1::Struct1.Enum12_Val1, 3121)
#val = enumCheck(Class1::Struct1.Enum12_Val2, 3122)
#val = enumCheck(Class1::Struct1.Enum12_Val3, val)
#val = enumCheck(Class1::Struct1.Enum12_Val4, val)
#val = enumCheck(Class1::Struct1.Enum12_Val5f, 3121)
#val = enumCheck(Class1::Struct1.Enum12_Val6f, val)
#
#val = 0
#val = enumCheck(Class1::Struct1.Val1, 3131)
#val = enumCheck(Class1::Struct1.Val2, 3132)
#val = enumCheck(Class1::Struct1.Val3, val)
#val = enumCheck(Class1::Struct1.Val4, val)
#
#val = 0
#val = enumCheck(Class1::Struct1.Enum14_Val1, 3141)
#val = enumCheck(Class1::Struct1.Enum14_Val2, 3142)
#val = enumCheck(Class1::Struct1.Enum14_Val3, val)
#val = enumCheck(Class1::Struct1.Enum14_Val4, val)
#val = enumCheck(Class1::Struct1.Enum14_Val5g, 3141)
#val = enumCheck(Class1::Struct1.Enum14_Val6g, val)
val = 0
val = enumCheck(Class2::Enum12_Val1, 2121)
val = enumCheck(Class2::Enum12_Val2, 2122)
val = enumCheck(Class2::Enum12_Val3, val)
val = enumCheck(Class2::Enum12_Val4, val)
val = enumCheck(Class2::Enum12_Val5h, 2121)
val = enumCheck(Class2::Enum12_Val6h, val)
val = 0
val = enumCheck(Class2::Val1, 2131)
val = enumCheck(Class2::Val2, 2132)
val = enumCheck(Class2::Val3, val)
val = enumCheck(Class2::Val4, val)
val = enumCheck(Class2::Val5i, 2131)
val = enumCheck(Class2::Val6i, val)
val = 0
val = enumCheck(Class2::Enum14_Val1, 2141)
val = enumCheck(Class2::Enum14_Val2, 2142)
val = enumCheck(Class2::Enum14_Val3, val)
val = enumCheck(Class2::Enum14_Val4, val)
val = enumCheck(Class2::Enum14_Val5j, 2141)
val = enumCheck(Class2::Enum14_Val6j, val)
# Requires nested class support to work
#val = 0
#val = enumCheck(Class2::Struct1.Enum12_Val1, 4121)
#val = enumCheck(Class2::Struct1.Enum12_Val2, 4122)
#val = enumCheck(Class2::Struct1.Enum12_Val3, val)
#val = enumCheck(Class2::Struct1.Enum12_Val4, val)
#val = enumCheck(Class2::Struct1.Enum12_Val5k, 4121)
#val = enumCheck(Class2::Struct1.Enum12_Val6k, val)
#
#val = 0
#val = enumCheck(Class2::Struct1.Val1, 4131)
#val = enumCheck(Class2::Struct1.Val2, 4132)
#val = enumCheck(Class2::Struct1.Val3, val)
#val = enumCheck(Class2::Struct1.Val4, val)
#val = enumCheck(Class2::Struct1.Val5l, 4131)
#val = enumCheck(Class2::Struct1.Val6l, val)
#
#val = 0
#val = enumCheck(Class2::Struct1.Enum14_Val1, 4141)
#val = enumCheck(Class2::Struct1.Enum14_Val2, 4142)
#val = enumCheck(Class2::Struct1.Enum14_Val3, val)
#val = enumCheck(Class2::Struct1.Enum14_Val4, val)
#val = enumCheck(Class2::Struct1.Enum14_Val5m, 4141)
#val = enumCheck(Class2::Struct1.Enum14_Val6m, val)
class1 = Class1.new
enumCheck(class1.class1Test1(Enum1_Val5a), 13)
enumCheck(class1.class1Test2(Class1::Enum12_Val5c), 1121)
#enumCheck(class1.class1Test3(Class1::Struct1.Enum12_Val5f), 3121)
enumCheck(globalTest1(Enum1_Val5a), 13)
enumCheck(globalTest2(Class1::Enum12_Val5c), 1121)
#enumCheck(globalTest3(Class1::Struct1.Enum12_Val5f), 3121)

View File

@@ -0,0 +1,62 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
# Note: This example assumes that namespaces are flattened
require 'cpp_namespace'
n = Cpp_namespace.fact(4)
if n != 24
raise "Bad return value!"
end
if Cpp_namespace.Foo != 42
raise "Bad variable value!"
end
t = Cpp_namespace::Test.new
if t.method() != "Test::method"
raise "Bad method return value!"
end
if Cpp_namespace.do_method(t) != "Test::method"
raise "Bad return value!"
end
if Cpp_namespace.do_method2(t) != "Test::method"
raise "Bad return value!"
end
Cpp_namespace.weird("hello", 4)
t2 = Cpp_namespace::Test2.new
t3 = Cpp_namespace::Test3.new
t4 = Cpp_namespace::Test4.new
t5 = Cpp_namespace::Test5.new
if Cpp_namespace.foo3(42) != 42
raise "Bad return value!"
end
if Cpp_namespace.do_method3(t2, 40) != "Test2::method"
raise "Bad return value!"
end
if Cpp_namespace.do_method3(t3, 40) != "Test3::method"
raise "Bad return value!"
end
if Cpp_namespace.do_method3(t4, 40) != "Test4::method"
raise "Bad return value!"
end
if Cpp_namespace.do_method3(t5, 40) != "Test5::method"
raise "Bad return value!"
end

View File

@@ -0,0 +1,150 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'default_constructor'
include Default_constructor
# Ruby 1.6 raises NameError if you try to call Class.new where no constructor
# is defined; Ruby 1.7 changed this to NoMethodError
NoConstructorError = Kernel.const_defined?("NoMethodError") ? NoMethodError : NameError
# This should be no problem
a = A.new
# Nor should this
aa = AA.new
# The default constructor for B is private, so this should raise an exception
begin
b = B.new
rescue ArgumentError
# pass
rescue TypeError
# In Ruby 1.8 the exception raised is:
# TypeError: allocator undefined for Default_constructor::BB
exceptionRaised = true
end
# The two-argument constructor for B should work
b = B.new(3, 4)
# BB shouldn't inherit B's default constructor, so this should raise an exception
begin
bb = BB.new
puts "Whoa. new BB created."
rescue NoConstructorError
# pass
rescue TypeError
# In Ruby 1.8 the exception raised is:
# TypeError: allocator undefined for Default_constructor::BB
exceptionRaised = true
end
# C's constructor is protected, so this should raise an exception
begin
c = C.new
print "Whoa. new C created."
rescue NoConstructorError
# pass
rescue TypeError
# In Ruby 1.8 the exception raised is:
# TypeError: allocator undefined for Default_constructor::C
# pass
rescue TypeError
# In Ruby 1.8 the exception raised is:
# TypeError: allocator undefined for Default_constructor::C
# pass
end
# CC gets a default constructor, so no problem here
cc = CC.new
# D's constructor is private, so this should fail
begin
d = D.new
puts "Whoa. new D created"
rescue NoConstructorError
# pass
rescue TypeError
# In Ruby 1.8 the exception raised is:
# TypeError: allocator undefined for Default_constructor::D
# pass
end
# DD shouldn't get a default constructor, so this should fail
begin
dd = DD.new
puts "Whoa. new DD created"
rescue NoConstructorError
# pass
rescue TypeError
# In Ruby 1.8 the exception raised is:
# TypeError: allocator undefined for Default_constructor::DD
# pass
rescue TypeError
# In Ruby 1.8 the exception raised is:
# TypeError: allocator undefined for Default_constructor::D
# pass
rescue TypeError
# In Ruby 1.8 the exception raised is:
# TypeError: allocator undefined for Default_constructor::DD
# pass
end
# AD shouldn't get a default constructor, so this should fail
begin
ad = AD.new
puts "Whoa. new AD created"
rescue NoConstructorError
# pass
rescue TypeError
# In Ruby 1.8 the exception raised is:
# TypeError: allocator undefined for Default_constructor::AD
# pass
rescue TypeError
# In Ruby 1.8 the exception raised is:
# TypeError: allocator undefined for Default_constructor::AD
# pass
end
# Both of the arguments to E's constructor have default values,
# so this should be fine.
e = E.new
# EE should get a default constructor
ee = EE.new
# EB should not get a default constructor (because B doesn't have one)
begin
eb = EB.new
puts "Whoa. new EB created"
rescue NoConstructorError
# pass
rescue TypeError
# In Ruby 1.8 the exception raised is:
# TypeError: allocator undefined for Default_constructor::EB
# pass
rescue TypeError
# In Ruby 1.8 the exception raised is:
# TypeError: allocator undefined for Default_constructor::EB
# pass
end
# This should work fine
f = F.new
# This should work fine
g = G.new
# This should work fine
gg = GG.new

View File

@@ -0,0 +1,42 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'director_abstract'
class MyFoo < Director_abstract::Foo
def ping
"MyFoo::ping()"
end
end
a = MyFoo.new
if a.ping != "MyFoo::ping()"
raise RuntimeError, a.ping
end
if a.pong != "Foo::pong();MyFoo::ping()"
raise RuntimeError, a.pong
end
class MyExample1 < Director_abstract::Example1
def color(r,g,b)
r
end
end
#m1 = MyExample1.new
#
#if m1.color(1,2,3) != 1
# raise RuntimeError, m1.color
#end

View File

@@ -0,0 +1,36 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'director_basic'
class MyFoo < Director_basic::Foo
def ping
"MyFoo::ping()"
end
end
a = MyFoo.new
raise RuntimeError if a.ping != "MyFoo::ping()"
raise RuntimeError if a.pong != "Foo::pong();MyFoo::ping()"
b = Director_basic::Foo.new
raise RuntimeError if b.ping != "Foo::ping()"
raise RuntimeError if b.pong != "Foo::pong();Foo::ping()"
a = Director_basic::MyClass.new
a = Director_basic::MyClassT_i.new
a = Director_basic::MyClass.new 1
a = Director_basic::MyClassT_i.new 1

View File

@@ -0,0 +1,37 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'director_constructor'
include Director_constructor
class Test < Foo
def initialize(i)
super(i)
end
def doubleit()
self.a = (self.a * 2)
end
def test
3
end
end
a = Test.new(5) #dies here
raise RuntimeError if a.getit != 5
raise RuntimeError if a.do_test != 3
a.doubleit
raise RuntimeError if a.getit != 10

View File

@@ -0,0 +1,30 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'director_default'
a = Director_default::Foo.new 1
a = Director_default::Foo.new
a.Msg
a.Msg "hello"
a.GetMsg
a.GetMsg "hello"
a = Director_default::Bar.new 1
a = Director_default::Bar.new
a.Msg
a.Msg "hello"
a.GetMsg
a.GetMsg "hello"

View File

@@ -0,0 +1,54 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'director_detect'
class MyBar < Director_detect::Bar
def initialize(v)
@val = v
end
def get_value
@val = @val + 1
end
def get_class
@val = @val + 1
Director_detect::A
end
def just_do_it
@val = @val + 1
end
def clone
MyBar.new(@val)
end
def val
@val
end
end
b = MyBar.new(2)
f = b
v = f.get_value
a = f.get_class
f.just_do_it
c = b.clone
vc = c.get_value
raise RuntimeError if (v != 3) || (b.val != 5) || (vc != 6)

View File

@@ -0,0 +1,70 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'director_exception'
include Director_exception
class MyFoo < Foo
def ping
raise NotImplementedError, "MyFoo::ping() EXCEPTION"
end
end
class MyFoo2 < Foo
def ping
nil # error: should return a string
end
end
class MyFoo3 < Foo
def ping
5 # error: should return a string
end
end
ok = false
a = MyFoo.new
b = launder(a)
begin
b.pong
rescue NotImplementedError
ok = true
end
raise RuntimeError unless ok
ok = false
a = MyFoo2.new
b = launder(a)
begin
b.pong
rescue TypeError
ok = true
end
a = MyFoo3.new
b = launder(a)
begin
b.pong
rescue TypeError
ok = true
end
raise RuntimeError unless ok

View File

@@ -0,0 +1,17 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'director_frob'
foo = Director_frob::Bravo.new;
s = foo.abs_method;
raise RuntimeError if s != "Bravo::abs_method()"

View File

@@ -0,0 +1,54 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'director_nested'
NoProtectedError = Kernel.const_defined?("NoMethodError") ? NoMethodError : NameError
class A < Director_nested::FooBar_int
protected
def do_step
"A::do_step;"
end
def get_value
"A::get_value"
end
end
a = A.new
begin
a.do_advance
rescue NoProtectedError
end
raise RuntimeError if a.step != "Bar::step;Foo::advance;Bar::do_advance;A::do_step;"
class B < Director_nested::FooBar_int
protected
def do_advance
"B::do_advance;" + do_step
end
def do_step
"B::do_step;"
end
def get_value
"B::get_value"
end
end
b = B.new
raise RuntimeError if b.step != "Bar::step;Foo::advance;B::do_advance;B::do_step;"

View File

@@ -0,0 +1,45 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'director_protected'
NoProtectedError = Kernel.const_defined?("NoMethodError") ? NoMethodError : NameError
class FooBar < Director_protected::Bar
protected
def ping
"FooBar::ping();"
end
end
class Hello < FooBar
public
def pang
ping
end
end
b = Director_protected::Bar.new
fb = FooBar.new
p = 0
begin
b.ping
p = 1
rescue NoProtectedError
end
h = Hello.new
raise RuntimeError if p == 1
raise RuntimeError if b.pong != "Bar::pong();Foo::pong();Bar::ping();"
raise RuntimeError if fb.pong != "Bar::pong();Foo::pong();FooBar::ping();"
raise RuntimeError if h.pang != "FooBar::ping();"

View File

@@ -0,0 +1,54 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'director_smartptr'
include Director_smartptr
class Director_smartptr_MyBarFoo < Foo
def ping()
return "director_smartptr_MyBarFoo.ping()"
end
def pong()
return "director_smartptr_MyBarFoo.pong();" + ping()
end
def upcall(fooBarPtr)
return "override;" + fooBarPtr.FooBarDo()
end
def makeFoo()
return Foo.new()
end
end
def check(got, expected)
if (got != expected)
raise RuntimeError, "Failed, got: #{got} expected: #{expected}"
end
end
fooBar = Director_smartptr::FooBar.new()
myBarFoo = Director_smartptr_MyBarFoo.new()
check(myBarFoo.ping(), "director_smartptr_MyBarFoo.ping()")
check(Foo.callPong(myBarFoo), "director_smartptr_MyBarFoo.pong();director_smartptr_MyBarFoo.ping()")
check(Foo.callUpcall(myBarFoo, fooBar), "override;Bar::Foo2::Foo2Bar()")
myFoo = myBarFoo.makeFoo()
check(myFoo.pong(), "Foo::pong();Foo::ping()")
check(Foo.callPong(myFoo), "Foo::pong();Foo::ping()")
check(myFoo.upcall(FooBar.new()), "Bar::Foo2::Foo2Bar()")
myFoo2 = Foo.new().makeFoo()
check(myFoo2.pong(), "Foo::pong();Foo::ping()")
check(Foo.callPong(myFoo2), "Foo::pong();Foo::ping()")
check(myFoo2.upcall(FooBar.new()), "Bar::Foo2::Foo2Bar()")

View File

@@ -0,0 +1,24 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'director_string'
class B < Director_string::A
def initialize(some_string)
super(some_string)
end
end
b = B.new("hello")
b.get_first
b.get(0)

View File

@@ -0,0 +1,28 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'director_unroll'
class MyFoo < Director_unroll::Foo
def ping
"MyFoo::ping()"
end
end
a = MyFoo.new
b = Director_unroll::Bar.new
b.set(a)
c = b.get()
raise RuntimeError if a != c

View File

@@ -0,0 +1,60 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'director_wombat'
include Director_wombat
# Test base class functionality
barObj = Bar.new
# Bar#meth should return a Foo_integers instance
fooIntsObj = barObj.meth
raise RuntimeError unless fooIntsObj.instance_of?(Foo_integers)
# Foo_integers#meth(n) should return n
raise RuntimeError if fooIntsObj.meth(42) != 42
#
# Now subclass Foo_integers, but override its virtual method
# meth(n) so that it returns the number plus one.
#
class MyFooInts < Foo_integers
def meth(n)
n + 1
end
end
#
# Subclass Bar and override its virtual method meth()
# so that it returns a new MyFooInts instance instead of
# a Foo_integers instance.
#
class MyBar < Bar
def meth
MyFooInts.new
end
end
#
# Now repeat previous tests:
#
# Create a MyBar instance...
#
barObj = MyBar.new
# MyBar#meth should return a MyFooInts instance
fooIntsObj = barObj.meth
raise RuntimeError unless fooIntsObj.instance_of?(MyFooInts)
# MyFooInts#meth(n) should return n+1
raise RuntimeError if fooIntsObj.meth(42) != 43

View File

@@ -0,0 +1,20 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'disown'
include Disown
a = A.new
b = B.new
b.acquire(a)

View File

@@ -0,0 +1,24 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'dynamic_cast'
f = Dynamic_cast::Foo.new
b = Dynamic_cast::Bar.new
x = f.blah
y = b.blah
a = Dynamic_cast.do_test(y)
if a != "Bar::test"
puts "Failed!!"
end

View File

@@ -0,0 +1,19 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'enum_thorough'
include Enum_thorough
# Just test an in and out typemap for enum SWIGTYPE and const enum SWIGTYPE & typemaps
raise RuntimeError if speedTest4(SpeedClass::Slow) != SpeedClass::Slow
raise RuntimeError if speedTest5(SpeedClass::Slow) != SpeedClass::Slow

View File

@@ -0,0 +1,34 @@
#!/usr/bin/env ruby
#
# Runtime tests for enums.i
#
require 'swig_assert'
require 'enums'
swig_assert_each_line( <<EOF )
Enums::CSP_ITERATION_FWD == 0
Enums::CSP_ITERATION_BWD == 11
Enums::ABCDE == 0
Enums::FGHJI == 1
Enums.bar1(1)
Enums.bar2(1)
Enums.bar3(1)
Enums::Boo == 0
Enums::Hoo == 5
Enums::Globalinstance1 == 0
Enums::Globalinstance2 == 1
Enums::Globalinstance3 == 30
Enums::AnonEnum1 == 0
Enums::AnonEnum2 == 100
Enums::BAR1 == 0
Enums::BAR2 == 1
EOF
#
# @bug:
#
# swig_assert_each_line( <<EOF )
# Enums::IFoo::Phoo == 50
# Enums::IFoo::Char == 'a'[0]
# EOF

View File

@@ -0,0 +1,23 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'extend_template_ns'
include Extend_template_ns
f = Foo_One.new
if f.test1(37) != 37
raise RuntimeError
end
if f.test2(42) != 42
raise RuntimeError
end

View File

@@ -0,0 +1,21 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'extend_template'
f = Extend_template::Foo_0.new
if f.test1(37) != 37
raise RuntimeError
end
if f.test2(42) != 42
raise RuntimeError
end

View File

@@ -0,0 +1,19 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'friends'
a = Friends::A.new(2)
raise RuntimeError if Friends::get_val1(a) != 2
raise RuntimeError if Friends::get_val2(a) != 4
raise RuntimeError if Friends::get_val3(a) != 6

View 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.

View File

@@ -0,0 +1,26 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'grouping'
x = Grouping.test1(42)
if x != 42
raise RuntimeError
end
Grouping.test2(42)
x = Grouping.do_unary(37, Grouping::NEGATE)
if x != -37
raise RuntimeError
end
Grouping.test3 = 42

View File

@@ -0,0 +1,34 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'ignore_parameter'
include Ignore_parameter
# Global function tests
raise RuntimeError unless jaguar(0, 1.0) == "hello"
raise RuntimeError unless lotus("foo", 1.0) == 101
raise RuntimeError unless tvr("foo", 0) == 8.8
raise RuntimeError unless ferrari() == 101
# Member function tests
sc = SportsCars.new
raise RuntimeError unless sc.daimler(0, 1.0) == "hello"
raise RuntimeError unless sc.astonmartin("foo", 1.0) == 101
raise RuntimeError unless sc.bugatti("foo", 0) == 8.8
raise RuntimeError unless sc.lamborghini() == 101
# Constructor tests
MiniCooper.new(0, 1.0)
MorrisMinor.new("foo", 1.0)
FordAnglia.new("foo", 0)
AustinAllegro.new()

View File

@@ -0,0 +1,20 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
# This is the import runtime testcase.
require 'imports_a'
require 'imports_b'
x = Imports_b::B.new
x.hello

View File

@@ -0,0 +1,31 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'inherit_missing'
a = Inherit_missing.new_Foo()
b = Inherit_missing::Bar.new
c = Inherit_missing::Spam.new
x = Inherit_missing.do_blah(a)
if x != "Foo::blah"
puts "Whoa! Bad return #{x}"
end
x = Inherit_missing.do_blah(b)
if x != "Bar::blah"
puts "Whoa! Bad return #{x}"
end
x = Inherit_missing.do_blah(c)
if x != "Spam::blah"
puts "Whoa! Bad return #{x}"
end

View 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

View File

@@ -0,0 +1,32 @@
require 'li_boost_shared_ptr_bits'
require 'swig_gc'
v = Li_boost_shared_ptr_bits::VectorIntHolder.new()
v.push(Li_boost_shared_ptr_bits::IntHolder.new(11))
v.push(Li_boost_shared_ptr_bits::IntHolder.new(22))
v.push(Li_boost_shared_ptr_bits::IntHolder.new(33))
sum = Li_boost_shared_ptr_bits::sum(v)
if (sum != 66)
raise RuntimeError, "sum is wrong"
end
hidden = Li_boost_shared_ptr_bits::HiddenDestructor.create()
GC.track_class = Li_boost_shared_ptr_bits::HiddenPrivateDestructor
GC.stats if $VERBOSE
hidden = nil
GC.start
hiddenPrivate = Li_boost_shared_ptr_bits::HiddenPrivateDestructor.create()
if (Li_boost_shared_ptr_bits::HiddenPrivateDestructor.DeleteCount != 0)
# GC doesn't always run
# raise RuntimeError, "Count should be zero"
end
GC.stats if $VERBOSE
hiddenPrivate = nil
GC.start
if (Li_boost_shared_ptr_bits::HiddenPrivateDestructor.DeleteCount != 1)
# GC doesn't always run
# raise RuntimeError, "Count should be one"
end

View File

@@ -0,0 +1,614 @@
require 'li_boost_shared_ptr'
require 'swig_gc'
#debug = $VERBOSE
debug = false
# simple shared_ptr usage - created in C++
class Li_boost_shared_ptr_runme
def main(debug)
if (debug)
puts "Started"
end
Li_boost_shared_ptr::debug_shared = debug
# Change loop count to run for a long time to monitor memory
loopCount = 1 # 5000
1.upto(loopCount) do
self.runtest()
end
# Expect 1 instance - the one global variable (GlobalValue)
GC.track_class = Li_boost_shared_ptr::Klass
invokeGC("Final GC")
# Actual count is 3 due to memory leaks calling rb_raise in the call to Li_boost_shared_ptr::valuetest(nil)
# as setjmp/longjmp are used thereby failing to call destructors of Klass instances on the stack in _wrap_valuetest
# This is a generic problem in Ruby wrappers, not shared_ptr specific
# expectedCount = 1
expectedCount = 3
actualCount = Li_boost_shared_ptr::Klass.getTotal_count()
if (actualCount != expectedCount)
# raise RuntimeError, "GC failed to run (li_boost_shared_ptr). Expected count: #{expectedCount} Actual count: #{actualCount}"
puts "GC failed to run (li_boost_shared_ptr). Expected count: #{expectedCount} Actual count: #{actualCount}"
end
wrapper_count = Li_boost_shared_ptr::shared_ptr_wrapper_count()
if (wrapper_count != Li_boost_shared_ptr.NOT_COUNTING)
# Expect 1 instance - the one global variable (GlobalSmartValue)
if (wrapper_count != 1)
raise RuntimeError, "shared_ptr wrapper count=#{wrapper_count}"
end
end
if (debug)
puts "Finished"
end
end
def invokeGC(debug_msg)
puts "invokeGC #{debug_msg} start" if $VERBOSE
GC.stats if $VERBOSE
GC.start
puts "invokeGC #{debug_msg} end" if $VERBOSE
end
def runtest
# simple shared_ptr usage - created in C++
k = Li_boost_shared_ptr::Klass.new("me oh my")
val = k.getValue()
self.verifyValue("me oh my", val)
self.verifyCount(1, k)
# simple shared_ptr usage - not created in C++
k = Li_boost_shared_ptr::factorycreate()
val = k.getValue()
self.verifyValue("factorycreate", val)
self.verifyCount(1, k)
# pass by shared_ptr
k = Li_boost_shared_ptr::Klass.new("me oh my")
kret = Li_boost_shared_ptr::smartpointertest(k)
val = kret.getValue()
self.verifyValue("me oh my smartpointertest", val)
self.verifyCount(2, k)
self.verifyCount(2, kret)
# pass by shared_ptr pointer
k = Li_boost_shared_ptr::Klass.new("me oh my")
kret = Li_boost_shared_ptr::smartpointerpointertest(k)
val = kret.getValue()
self.verifyValue("me oh my smartpointerpointertest", val)
self.verifyCount(2, k)
self.verifyCount(2, kret)
# pass by shared_ptr reference
k = Li_boost_shared_ptr::Klass.new("me oh my")
kret = Li_boost_shared_ptr::smartpointerreftest(k)
val = kret.getValue()
self.verifyValue("me oh my smartpointerreftest", val)
self.verifyCount(2, k)
self.verifyCount(2, kret)
# pass by shared_ptr pointer reference
k = Li_boost_shared_ptr::Klass.new("me oh my")
kret = Li_boost_shared_ptr::smartpointerpointerreftest(k)
val = kret.getValue()
self.verifyValue("me oh my smartpointerpointerreftest", val)
self.verifyCount(2, k)
self.verifyCount(2, kret)
# const pass by shared_ptr
k = Li_boost_shared_ptr::Klass.new("me oh my")
kret = Li_boost_shared_ptr::constsmartpointertest(k)
val = kret.getValue()
self.verifyValue("me oh my", val)
self.verifyCount(2, k)
self.verifyCount(2, kret)
# const pass by shared_ptr pointer
k = Li_boost_shared_ptr::Klass.new("me oh my")
kret = Li_boost_shared_ptr::constsmartpointerpointertest(k)
val = kret.getValue()
self.verifyValue("me oh my", val)
self.verifyCount(2, k)
self.verifyCount(2, kret)
# const pass by shared_ptr reference
k = Li_boost_shared_ptr::Klass.new("me oh my")
kret = Li_boost_shared_ptr::constsmartpointerreftest(k)
val = kret.getValue()
self.verifyValue("me oh my", val)
self.verifyCount(2, k)
self.verifyCount(2, kret)
# pass by value
k = Li_boost_shared_ptr::Klass.new("me oh my")
kret = Li_boost_shared_ptr::valuetest(k)
val = kret.getValue()
self.verifyValue("me oh my valuetest", val)
self.verifyCount(1, k)
self.verifyCount(1, kret)
# pass by pointer
k = Li_boost_shared_ptr::Klass.new("me oh my")
kret = Li_boost_shared_ptr::pointertest(k)
val = kret.getValue()
self.verifyValue("me oh my pointertest", val)
self.verifyCount(1, k)
self.verifyCount(1, kret)
# pass by reference
k = Li_boost_shared_ptr::Klass.new("me oh my")
kret = Li_boost_shared_ptr::reftest(k)
val = kret.getValue()
self.verifyValue("me oh my reftest", val)
self.verifyCount(1, k)
self.verifyCount(1, kret)
# pass by pointer reference
k = Li_boost_shared_ptr::Klass.new("me oh my")
kret = Li_boost_shared_ptr::pointerreftest(k)
val = kret.getValue()
self.verifyValue("me oh my pointerreftest", val)
self.verifyCount(1, k)
self.verifyCount(1, kret)
# null tests
k = nil
if (Li_boost_shared_ptr::smartpointertest(k) != nil)
raise RuntimeError, "return was not null"
end
if (Li_boost_shared_ptr::smartpointerpointertest(k) != nil)
raise RuntimeError, "return was not null"
end
if (Li_boost_shared_ptr::smartpointerreftest(k) != nil)
raise RuntimeError, "return was not null"
end
if (Li_boost_shared_ptr::smartpointerpointerreftest(k) != nil)
raise RuntimeError, "return was not null"
end
if (Li_boost_shared_ptr::nullsmartpointerpointertest(nil) != "null pointer")
raise RuntimeError, "not null smartpointer pointer"
end
begin
Li_boost_shared_ptr::valuetest(k)
raise RuntimeError, "Failed to catch null pointer"
rescue ArgumentError
end
if (Li_boost_shared_ptr::pointertest(k) != nil)
raise RuntimeError, "return was not null"
end
begin
Li_boost_shared_ptr::reftest(k)
raise RuntimeError, "Failed to catch null pointer"
rescue ArgumentError
end
# $owner
k = Li_boost_shared_ptr::pointerownertest()
val = k.getValue()
self.verifyValue("pointerownertest", val)
self.verifyCount(1, k)
k = Li_boost_shared_ptr::smartpointerpointerownertest()
val = k.getValue()
self.verifyValue("smartpointerpointerownertest", val)
self.verifyCount(1, k)
# //////////////////////////////// Derived class //////////////////////
# derived pass by shared_ptr
k = Li_boost_shared_ptr::KlassDerived.new("me oh my")
kret = Li_boost_shared_ptr::derivedsmartptrtest(k)
val = kret.getValue()
self.verifyValue("me oh my derivedsmartptrtest-Derived", val)
self.verifyCount(2, k)
self.verifyCount(2, kret)
# derived pass by shared_ptr pointer
k = Li_boost_shared_ptr::KlassDerived.new("me oh my")
kret = Li_boost_shared_ptr::derivedsmartptrpointertest(k)
val = kret.getValue()
self.verifyValue("me oh my derivedsmartptrpointertest-Derived", val)
self.verifyCount(2, k)
self.verifyCount(2, kret)
# derived pass by shared_ptr ref
k = Li_boost_shared_ptr::KlassDerived.new("me oh my")
kret = Li_boost_shared_ptr::derivedsmartptrreftest(k)
val = kret.getValue()
self.verifyValue("me oh my derivedsmartptrreftest-Derived", val)
self.verifyCount(2, k)
self.verifyCount(2, kret)
# derived pass by shared_ptr pointer ref
k = Li_boost_shared_ptr::KlassDerived.new("me oh my")
kret = Li_boost_shared_ptr::derivedsmartptrpointerreftest(k)
val = kret.getValue()
self.verifyValue("me oh my derivedsmartptrpointerreftest-Derived", val)
self.verifyCount(2, k)
self.verifyCount(2, kret)
# derived pass by pointer
k = Li_boost_shared_ptr::KlassDerived.new("me oh my")
kret = Li_boost_shared_ptr::derivedpointertest(k)
val = kret.getValue()
self.verifyValue("me oh my derivedpointertest-Derived", val)
self.verifyCount(1, k)
self.verifyCount(1, kret)
# derived pass by ref
k = Li_boost_shared_ptr::KlassDerived.new("me oh my")
kret = Li_boost_shared_ptr::derivedreftest(k)
val = kret.getValue()
self.verifyValue("me oh my derivedreftest-Derived", val)
self.verifyCount(1, k)
self.verifyCount(1, kret)
# //////////////////////////////// Derived and base class mixed ///////
# pass by shared_ptr (mixed)
k = Li_boost_shared_ptr::KlassDerived.new("me oh my")
kret = Li_boost_shared_ptr::smartpointertest(k)
val = kret.getValue()
self.verifyValue("me oh my smartpointertest-Derived", val)
self.verifyCount(2, k)
self.verifyCount(2, kret)
# pass by shared_ptr pointer (mixed)
k = Li_boost_shared_ptr::KlassDerived.new("me oh my")
kret = Li_boost_shared_ptr::smartpointerpointertest(k)
val = kret.getValue()
self.verifyValue("me oh my smartpointerpointertest-Derived", val)
self.verifyCount(2, k)
self.verifyCount(2, kret)
# pass by shared_ptr reference (mixed)
k = Li_boost_shared_ptr::KlassDerived.new("me oh my")
kret = Li_boost_shared_ptr::smartpointerreftest(k)
val = kret.getValue()
self.verifyValue("me oh my smartpointerreftest-Derived", val)
self.verifyCount(2, k)
self.verifyCount(2, kret)
# pass by shared_ptr pointer reference (mixed)
k = Li_boost_shared_ptr::KlassDerived.new("me oh my")
kret = Li_boost_shared_ptr::smartpointerpointerreftest(k)
val = kret.getValue()
self.verifyValue("me oh my smartpointerpointerreftest-Derived", val)
self.verifyCount(2, k)
self.verifyCount(2, kret)
# pass by value (mixed)
k = Li_boost_shared_ptr::KlassDerived.new("me oh my")
kret = Li_boost_shared_ptr::valuetest(k)
val = kret.getValue()
self.verifyValue("me oh my valuetest", val) # note slicing
self.verifyCount(1, k)
self.verifyCount(1, kret)
# pass by pointer (mixed)
k = Li_boost_shared_ptr::KlassDerived.new("me oh my")
kret = Li_boost_shared_ptr::pointertest(k)
val = kret.getValue()
self.verifyValue("me oh my pointertest-Derived", val)
self.verifyCount(1, k)
self.verifyCount(1, kret)
# pass by ref (mixed)
k = Li_boost_shared_ptr::KlassDerived.new("me oh my")
kret = Li_boost_shared_ptr::reftest(k)
val = kret.getValue()
self.verifyValue("me oh my reftest-Derived", val)
self.verifyCount(1, k)
self.verifyCount(1, kret)
# //////////////////////////////// Overloading tests //////////////////
# Base class
k = Li_boost_shared_ptr::Klass.new("me oh my")
self.verifyValue(Li_boost_shared_ptr::overload_rawbyval(k), "rawbyval")
self.verifyValue(Li_boost_shared_ptr::overload_rawbyref(k), "rawbyref")
self.verifyValue(Li_boost_shared_ptr::overload_rawbyptr(k), "rawbyptr")
self.verifyValue(
Li_boost_shared_ptr::overload_rawbyptrref(k), "rawbyptrref")
self.verifyValue(
Li_boost_shared_ptr::overload_smartbyval(k), "smartbyval")
self.verifyValue(
Li_boost_shared_ptr::overload_smartbyref(k), "smartbyref")
self.verifyValue(
Li_boost_shared_ptr::overload_smartbyptr(k), "smartbyptr")
self.verifyValue(
Li_boost_shared_ptr::overload_smartbyptrref(k), "smartbyptrref")
# Derived class
k = Li_boost_shared_ptr::KlassDerived.new("me oh my")
self.verifyValue(Li_boost_shared_ptr::overload_rawbyval(k), "rawbyval")
self.verifyValue(Li_boost_shared_ptr::overload_rawbyref(k), "rawbyref")
self.verifyValue(Li_boost_shared_ptr::overload_rawbyptr(k), "rawbyptr")
self.verifyValue(
Li_boost_shared_ptr::overload_rawbyptrref(k), "rawbyptrref")
self.verifyValue(
Li_boost_shared_ptr::overload_smartbyval(k), "smartbyval")
self.verifyValue(
Li_boost_shared_ptr::overload_smartbyref(k), "smartbyref")
self.verifyValue(
Li_boost_shared_ptr::overload_smartbyptr(k), "smartbyptr")
self.verifyValue(
Li_boost_shared_ptr::overload_smartbyptrref(k), "smartbyptrref")
# 3rd derived class
k = Li_boost_shared_ptr::Klass3rdDerived.new("me oh my")
val = k.getValue()
self.verifyValue("me oh my-3rdDerived", val)
self.verifyCount(1, k)
val = Li_boost_shared_ptr::test3rdupcast(k)
self.verifyValue("me oh my-3rdDerived", val)
self.verifyCount(1, k)
# //////////////////////////////// Member variables ///////////////////
# smart pointer by value
m = Li_boost_shared_ptr::MemberVariables.new()
k = Li_boost_shared_ptr::Klass.new("smart member value")
m.SmartMemberValue = k
val = k.getValue()
self.verifyValue("smart member value", val)
self.verifyCount(2, k)
kmember = m.SmartMemberValue
val = kmember.getValue()
self.verifyValue("smart member value", val)
self.verifyCount(3, kmember)
self.verifyCount(3, k)
GC.track_class = Li_boost_shared_ptr::MemberVariables
m = nil
invokeGC("m = nil (A)")
self.verifyCount(2, kmember)
self.verifyCount(2, k)
# smart pointer by pointer
m = Li_boost_shared_ptr::MemberVariables.new()
k = Li_boost_shared_ptr::Klass.new("smart member pointer")
m.SmartMemberPointer = k
val = k.getValue()
self.verifyValue("smart member pointer", val)
self.verifyCount(1, k)
kmember = m.SmartMemberPointer
val = kmember.getValue()
self.verifyValue("smart member pointer", val)
self.verifyCount(2, kmember)
self.verifyCount(2, k)
m = nil
invokeGC("m = nil (B)")
self.verifyCount(2, kmember)
self.verifyCount(2, k)
# smart pointer by reference
m = Li_boost_shared_ptr::MemberVariables.new()
k = Li_boost_shared_ptr::Klass.new("smart member reference")
m.SmartMemberReference = k
val = k.getValue()
self.verifyValue("smart member reference", val)
self.verifyCount(2, k)
kmember = m.SmartMemberReference
val = kmember.getValue()
self.verifyValue("smart member reference", val)
self.verifyCount(3, kmember)
self.verifyCount(3, k)
# The C++ reference refers to SmartMemberValue...
kmemberVal = m.SmartMemberValue
val = kmember.getValue()
self.verifyValue("smart member reference", val)
self.verifyCount(4, kmemberVal)
self.verifyCount(4, kmember)
self.verifyCount(4, k)
m = nil
invokeGC("m = nil (C)")
self.verifyCount(3, kmemberVal)
self.verifyCount(3, kmember)
self.verifyCount(3, k)
# plain by value
m = Li_boost_shared_ptr::MemberVariables.new()
k = Li_boost_shared_ptr::Klass.new("plain member value")
m.MemberValue = k
val = k.getValue()
self.verifyValue("plain member value", val)
self.verifyCount(1, k)
kmember = m.MemberValue
val = kmember.getValue()
self.verifyValue("plain member value", val)
self.verifyCount(1, kmember)
self.verifyCount(1, k)
m = nil
invokeGC("m = nil (D)")
self.verifyCount(1, kmember)
self.verifyCount(1, k)
# plain by pointer
m = Li_boost_shared_ptr::MemberVariables.new()
k = Li_boost_shared_ptr::Klass.new("plain member pointer")
m.MemberPointer = k
val = k.getValue()
self.verifyValue("plain member pointer", val)
self.verifyCount(1, k)
kmember = m.MemberPointer
val = kmember.getValue()
self.verifyValue("plain member pointer", val)
self.verifyCount(1, kmember)
self.verifyCount(1, k)
m = nil
invokeGC("m = nil (E)")
self.verifyCount(1, kmember)
self.verifyCount(1, k)
# plain by reference
m = Li_boost_shared_ptr::MemberVariables.new()
k = Li_boost_shared_ptr::Klass.new("plain member reference")
m.MemberReference = k
val = k.getValue()
self.verifyValue("plain member reference", val)
self.verifyCount(1, k)
kmember = m.MemberReference
val = kmember.getValue()
self.verifyValue("plain member reference", val)
self.verifyCount(1, kmember)
self.verifyCount(1, k)
m = nil
invokeGC("m = nil (F)")
self.verifyCount(1, kmember)
self.verifyCount(1, k)
# null member variables
m = Li_boost_shared_ptr::MemberVariables.new()
# shared_ptr by value
k = m.SmartMemberValue
if (k != nil)
raise RuntimeError, "expected null"
end
m.SmartMemberValue = nil
k = m.SmartMemberValue
if (k != nil)
raise RuntimeError, "expected null"
end
self.verifyCount(0, k)
# plain by value
begin
m.MemberValue = nil
raise RuntimeError, "Failed to catch null pointer"
rescue ArgumentError
end
# ////////////////////////////////// Global variables /////////////////
# smart pointer
kglobal = Li_boost_shared_ptr.GlobalSmartValue
if (kglobal != nil)
raise RuntimeError, "expected null"
end
k = Li_boost_shared_ptr::Klass.new("smart global value")
Li_boost_shared_ptr.GlobalSmartValue = k
self.verifyCount(2, k)
kglobal = Li_boost_shared_ptr.GlobalSmartValue
val = kglobal.getValue()
self.verifyValue("smart global value", val)
self.verifyCount(3, kglobal)
self.verifyCount(3, k)
self.verifyValue(
"smart global value", Li_boost_shared_ptr.GlobalSmartValue.getValue())
Li_boost_shared_ptr.GlobalSmartValue = nil
# plain value
k = Li_boost_shared_ptr::Klass.new("global value")
Li_boost_shared_ptr.GlobalValue = k
self.verifyCount(1, k)
kglobal = Li_boost_shared_ptr.GlobalValue
val = kglobal.getValue()
self.verifyValue("global value", val)
self.verifyCount(1, kglobal)
self.verifyCount(1, k)
self.verifyValue(
"global value", Li_boost_shared_ptr.GlobalValue.getValue())
begin
Li_boost_shared_ptr.GlobalValue = nil
raise RuntimeError, "Failed to catch null pointer"
rescue ArgumentError
end
# plain pointer
kglobal = Li_boost_shared_ptr.GlobalPointer
if (kglobal != nil)
raise RuntimeError, "expected null"
end
k = Li_boost_shared_ptr::Klass.new("global pointer")
Li_boost_shared_ptr.GlobalPointer = k
self.verifyCount(1, k)
kglobal = Li_boost_shared_ptr.GlobalPointer
val = kglobal.getValue()
self.verifyValue("global pointer", val)
self.verifyCount(1, kglobal)
self.verifyCount(1, k)
Li_boost_shared_ptr.GlobalPointer = nil
# plain reference
k = Li_boost_shared_ptr::Klass.new("global reference")
Li_boost_shared_ptr.GlobalReference = k
self.verifyCount(1, k)
kglobal = Li_boost_shared_ptr.GlobalReference
val = kglobal.getValue()
self.verifyValue("global reference", val)
self.verifyCount(1, kglobal)
self.verifyCount(1, k)
begin
Li_boost_shared_ptr.GlobalReference = nil
raise RuntimeError, "Failed to catch null pointer"
rescue ArgumentError
end
# ////////////////////////////////// Templates ////////////////////////
pid = Li_boost_shared_ptr::PairIntDouble.new(10, 20.2)
if (pid.baseVal1 != 20 or pid.baseVal2 != 40.4)
raise RuntimeError, "Base values wrong"
end
if (pid.val1 != 10 or pid.val2 != 20.2)
raise RuntimeError, "Derived Values wrong"
end
end
def verifyValue(expected, got)
if (expected != got)
raise RuntimeError, "verify value failed. Expected: #{expected} Got: #{got}"
end
end
def verifyCount(expected, k)
got = Li_boost_shared_ptr::use_count(k)
if (expected != got)
puts "skipped verifyCount expect/got: #{expected}/#{got}"
# raise RuntimeError, "verify use_count failed. Expected: #{expected} Got: #{got}"
end
end
end
runme = Li_boost_shared_ptr_runme.new()
runme.main(debug)

View File

@@ -0,0 +1,45 @@
require 'li_boost_shared_ptr_template'
begin
b = Li_boost_shared_ptr_template::BaseINTEGER.new()
d = Li_boost_shared_ptr_template::DerivedINTEGER.new()
if (b.bar() != 1)
raise RuntimeError("test 1")
end
if (d.bar() != 2)
raise RuntimeError("test 2")
end
if (Li_boost_shared_ptr_template.bar_getter(b) != 1)
raise RuntimeError("test 3")
end
# Needs fixing as it does for Python
# if (Li_boost_shared_ptr_template.bar_getter(d) != 2)
# raise RuntimeError("test 4")
# end
end
begin
b = Li_boost_shared_ptr_template::BaseDefaultInt.new()
d = Li_boost_shared_ptr_template::DerivedDefaultInt.new()
d2 = Li_boost_shared_ptr_template::DerivedDefaultInt2.new()
if (b.bar2() != 3)
raise RuntimeError("test 5")
end
if (d.bar2() != 4)
raise RuntimeError("test 6")
end
if (d2.bar2() != 4)
raise RuntimeError("test 6")
end
if (Li_boost_shared_ptr_template.bar2_getter(b) != 3)
raise RuntimeError("test 7")
end
# Needs fixing as it does for Python
# if (Li_boost_shared_ptr_template.bar2_getter(d) != 4)
# raise RuntimeError("test 8")
# end
# if (Li_boost_shared_ptr_template.bar2_getter(d2) != 4)
# raise RuntimeError("test 8")
# end
end

View File

@@ -0,0 +1,36 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'li_carrays_cpp'
include Li_carrays_cpp
#
# Testing for %array_functions(int,intArray)
#
ary = new_intArray(2)
intArray_setitem(ary, 0, 0)
intArray_setitem(ary, 1, 1)
intArray_getitem(ary, 0)
intArray_getitem(ary, 1)
delete_intArray(ary)
#
# Testing for %array_class(double, doubleArray)
#
ary = DoubleArray.new(2)
ary[0] = 0.0
ary[1] = 1.0
ary[0]
ary[1]
ptr = ary.cast
ary2 = DoubleArray.frompointer(ptr)

View File

@@ -0,0 +1,36 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'li_carrays'
include Li_carrays
#
# Testing for %array_functions(int,intArray)
#
ary = new_intArray(2)
intArray_setitem(ary, 0, 0)
intArray_setitem(ary, 1, 1)
intArray_getitem(ary, 0)
intArray_getitem(ary, 1)
delete_intArray(ary)
#
# Testing for %array_class(double, doubleArray)
#
ary = DoubleArray.new(2)
ary[0] = 0.0
ary[1] = 1.0
ary[0]
ary[1]
ptr = ary.cast
ary2 = DoubleArray.frompointer(ptr)

View 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

View File

@@ -0,0 +1,38 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'li_factory'
circle = Li_factory::Geometry.create(Li_factory::Geometry::CIRCLE)
r = circle.radius()
if (r != 1.5)
raise RuntimeError, "Invalid value for r"
end
new_circle = circle.clone()
r = new_circle.radius()
if (r != 1.5)
raise RuntimeError, "Invalid value for r"
end
point = Li_factory::Geometry.create(Li_factory::Geometry::POINT)
w = point.width()
if (w != 1.0)
raise RuntimeError, "Invalid value for w"
end
new_point = point.clone()
w = new_point.width()
if (w != 1.0)
raise RuntimeError, "Invalid value for w"
end

View File

@@ -0,0 +1,13 @@
#!/usr/bin/env ruby
#
# li_math.i tests
#
#
require 'swig_assert'
require 'li_math'
swig_assert_each_line <<EOF
Li_math.cos(-5) == Math.cos(-5)
Li_math.sin(-5) == Math.sin(-5)
EOF

View File

@@ -0,0 +1,55 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'li_std_deque'
include Li_std_deque
# Test constructors for std::deque<int>
intDeque = IntDeque.new
intDeque2 = IntDeque.new(3)
intDeque3 = IntDeque.new(4, 42)
intDeque4 = IntDeque.new(intDeque3)
# Test constructors for std::deque<double>
doubleDeque = DoubleDeque.new
doubleDeque2 = DoubleDeque.new(3)
doubleDeque3 = DoubleDeque.new(4, 42.0)
doubleDeque4 = DoubleDeque.new(doubleDeque3)
# Test constructors for std::deque<Real>
realDeque = RealDeque.new
realDeque2 = RealDeque.new(3)
realDeque3 = RealDeque.new(4, 42.0)
realDeque4 = RealDeque.new(realDeque3)
# average() should return the average of all values in a std::deque<int>
intDeque << 2
intDeque << 4
intDeque << 6
avg = average(intDeque)
raise RuntimeError if avg != 4.0
#
# half() should return a std::deque<float>, where each element is half
# the value of the corresponding element in the input deque<float>.
# The original deque's contents are unchanged.
#
realDeque.clear
realDeque << 2.0
halfDeque = half(realDeque)
raise RuntimeError unless halfDeque[0] == 1.0
#
# halve_in_place() should...
#
halve_in_place(doubleDeque)

View File

@@ -0,0 +1,76 @@
#!/usr/bin/env ruby
#
# This is a test of STL containers using proc
# objects to change the sorting function used in them. Same as a
# std::binary_predicate in C++.
#
#
#
#
#
require 'swig_assert'
require 'li_std_functors'
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 b_lessthan_a(b, a)
res = b < a
# print b, "<", a, "=", res
return res
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_lessthan_a(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]]
EOF
end
def test
yield method(:_set), Li_std_functors::Set
yield method(:_map), Li_std_functors::Map
end
# these should fail and not segfault
begin
Li_std_functors::Set.new('sd')
rescue
end
test do |proc, container|
proc.call(container)
end

View File

@@ -0,0 +1,51 @@
#!/usr/bin/env ruby
#
# Tests for std::map
#
#
#
#
#
require 'swig_assert'
require 'li_std_map'
swig_assert_each_line(<<'EOF', binding)
a1 = Li_std_map::A.new(3)
a2 = Li_std_map::A.new(7)
p0 = Li_std_map::Pairii.new(1,2)
p1 = Li_std_map::PairA.new(1,a1)
m = {}
m[1] = a1
m[2] = a2
pp1 = Li_std_map::p_identa(p1)
mm = Li_std_map::m_identa(m)
m = Li_std_map::MapA.new
m[1] = a1
m[2] = a2
m.respond_to?(:each_key) == true
m.respond_to?(:each_value) == true
pm ={}
m.each_key { |k| pm[k] = m[k] }
m.each_key { |k| swig_assert_equal("pm[k].object_id", "m[k].object_id", binding, 'only true if %trackings is on') }
m = {}
m[1] = [1,2]
m["foo"] = "hello"
pm = Li_std_map::LanguageMap.new
m.each_key { |k| pm[k] = m[k] }
m.each_key { |k| swig_assert_equal("pm[#{k.inspect}]", "m[#{k.inspect}]", binding) }
EOF
mii = Li_std_map::IntIntMap.new
mii[1] = 1
mii[1] = 2
swig_assert( "mii[1] == 2", binding )

View File

@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
#
# Tests for std::multimap
#
#
#
#
#
require 'swig_assert'
require 'li_std_multimap'
swig_assert_each_line(<<'EOF', binding)
a1 = Li_std_multimap::A.new(3)
a2 = Li_std_multimap::A.new(7)
m = Li_std_multimap::MultimapA.new
m[0] = a1
m[0] = a2
m[0].size == 2
m.respond_to?(:each) == true
m.respond_to?(:each_key) == true
m.respond_to?(:each_value) == true
m.values_at(0)[0] == m[0]
EOF

View File

@@ -0,0 +1,19 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'li_std_pair_lang_object'
include Li_std_pair_lang_object
swig_assert_each_line(<<'EOF', binding)
val = ValuePair.new
val.first = 'sd'
val.second = [5,4,3]
EOF

View File

@@ -0,0 +1,57 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'li_std_pair'
include Li_std_pair
swig_assert_each_line(<<'EOF', binding)
#
# 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)
intPair.instance_of?(Array)
intPair.size == 2
intPair[0] == 7 && intPair[1] == 6
intPairConstRef = makeIntPairConstRef(7, 6)
intPairConstRef.instance_of?(Array)
intPairConstRef[0] == 7 && intPairConstRef[1] == 6
#
# Each of these should return a reference to a wrapped
# std::pair<int, int> object (i.e. an IntPair instance).
#
intPairPtr = makeIntPairPtr(7, 6)
intPairPtr.instance_of?(IntPair)
intPairPtr[0] == 7 && intPairPtr[1] == 6
intPairRef = makeIntPairRef(7, 6)
intPairRef.instance_of?(IntPair)
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
# different type (see li_std_pair.i). Typemaps should be in place to
# convert this Array into the expected argument type.
#
product1(intPair) == 42
product2(intPair) == 42
product3(intPair) == 42
#
# Similarly, each of the input typemaps should know what to do
# with an IntPair instance.
#
product1(intPairPtr) == 42
product2(intPairPtr) == 42
product3(intPairPtr) == 42
EOF

View File

@@ -0,0 +1,32 @@
#!/usr/bin/env ruby
#
# A simple std::queue test
#
#
#
#
#
require 'swig_assert'
require 'li_std_queue'
include Li_std_queue
swig_assert_each_line(<<'EOF', binding)
a = IntQueue.new
a << 1
a << 2
a << 3
a.back == 3
a.front == 1
a.pop
a.back == 3
a.front == 2
a.pop
a.back == 3
a.front == 3
a.pop
a.size == 0
a.empty? == true
EOF

View File

@@ -0,0 +1,70 @@
#!/usr/bin/env ruby
#
# Put script description here.
#
#
#
#
#
require 'swig_assert'
require 'li_std_set'
include Li_std_set
swig_assert_each_line(<<'EOF', binding)
s = Set_string.new
s.push("a")
s.push("b")
s << "c"
sum = ''
s.each { |x| sum << x }
sum == 'abc'
b = s.begin # only if swig iterators are on
e = s.end
sum = ''
while b != e; sum << b.value; b.next; end
sum == 'abc'
b = s.rbegin # only if swig iterators are on
e = s.rend
sum = ''
while b != e; sum << b.value; b.next; end
sum == 'cba'
si = Set_int.new
si << 1
si.push(2)
si.push(3)
i = s.begin()
i.next()
s.erase(i)
s.to_s == 'ac'
b = s.begin
e = s.end
e - b == 2
m = b + 1
m.value == 'c'
s = LanguageSet.new
s.insert([1,2])
s.insert(1)
s.insert("hello")
#s.to_a == [1,[1,2],'hello'] # sort order: s.sort {|a,b| a.hash <=> b.hash}
# Test above is flawed as LanguageSet sorts by each element's hash, so the order will change from one invocation to the next. Sort a conversion to array instead.
sa = s.to_a.sort { |x, y| x.to_s <=> y.to_s }
sa == [1,[1,2],'hello']
EOF
iv = Set_int.new([0,1,2,3,4,5,6])
iv.delete_if { |x| x == 0 || x == 3 || x == 6 }
swig_assert_equal(iv.to_s, '1245', binding)

View 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

View File

@@ -0,0 +1,30 @@
#!/usr/bin/env ruby
#
# A simple std::stack test
#
#
#
#
#
require 'swig_assert'
require 'li_std_stack'
include Li_std_stack
swig_assert_each_line(<<'EOF', binding)
a = IntStack.new
a << 1
a << 2
a << 3
a.top == 3
a.pop
a.top == 2
a.pop
a.top == 1
a.pop
a.size == 0
a.empty? == true
# a.top == Qnil
EOF

View File

@@ -0,0 +1,22 @@
#!/usr/bin/env ruby
#
# Simple test of std::ostringstream.
#
#
#
#
#
require 'swig_assert'
require 'li_std_stream'
include Li_std_stream
swig_assert_each_line(<<'EOF', binding)
a = A.new
o = Ostringstream.new
o << a << " " << 2345 << " " << 1.435
o.str == "A class 2345 1.435"
EOF

View File

@@ -0,0 +1,144 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'li_std_string'
include Li_std_string
# Checking expected use of %typemap(in) std::string {}
test_value("Fee")
# Checking expected result of %typemap(out) std::string {}
raise RuntimeError unless test_value("Fi") == "Fi"
# Verify type-checking for %typemap(in) std::string {}
exceptionRaised = false
begin
test_value(0)
rescue TypeError
exceptionRaised = true
ensure
raise RuntimeError unless exceptionRaised
end
# Checking expected use of %typemap(in) const std::string & {}
test_const_reference("Fo")
# Checking expected result of %typemap(out) const std::string& {}
raise RuntimeError unless test_const_reference("Fum") == "Fum"
# Verify type-checking for %typemap(in) const std::string & {}
exceptionRaised = false
begin
test_const_reference(0)
rescue TypeError
exceptionRaised = true
ensure
raise RuntimeError unless exceptionRaised
end
#
# Input and output typemaps for pointers and non-const references to
# std::string are *not* supported; the following tests confirm
# that none of these cases are slipping through.
#
exceptionRaised = false
begin
test_pointer("foo")
rescue TypeError
exceptionRaised = true
ensure
raise RuntimeError unless exceptionRaised
end
result = test_pointer_out()
raise RuntimeError if result.is_a? String
exceptionRaised = false
begin
test_const_pointer("bar")
rescue TypeError
exceptionRaised = true
ensure
raise RuntimeError unless exceptionRaised
end
result = test_const_pointer_out()
raise RuntimeError if result.is_a? String
exceptionRaised = false
begin
test_reference("foo")
rescue TypeError
exceptionRaised = true
ensure
raise RuntimeError unless exceptionRaised
end
result = test_reference_out()
raise RuntimeError if result.is_a? String
# Member Strings
myStructure = Structure.new
if (myStructure.MemberString2 != "member string 2")
raise RuntimeError
end
s = "Hello"
myStructure.MemberString2 = s
if (myStructure.MemberString2 != s)
raise RuntimeError
end
if (myStructure.ConstMemberString != "const member string")
raise RuntimeError
end
if (Structure.StaticMemberString2 != "static member string 2")
raise RuntimeError
end
Structure.StaticMemberString2 = s
if (Structure.StaticMemberString2 != s)
raise RuntimeError
end
if (Structure.ConstStaticMemberString != "const static member string")
raise RuntimeError
end
if (test_reference_input("hello") != "hello")
raise RuntimeError
end
s = test_reference_inout("hello")
if (s != "hellohello")
raise RuntimeError
end
if (stdstring_empty() != "")
raise RuntimeError
end
if (c_empty() != "")
raise RuntimeError
end
if (c_null() != nil)
raise RuntimeError
end
if (get_null(c_null()) != nil)
raise RuntimeError
end

View File

@@ -0,0 +1,25 @@
#!/usr/bin/env ruby
require 'swig_assert'
require 'li_std_vector_enum'
include Li_std_vector_enum
ev = EnumVector.new()
swig_assert(ev.nums[0] == 10)
swig_assert(ev.nums[1] == 20)
swig_assert(ev.nums[2] == 30)
it = ev.nums.begin
v = it.value()
swig_assert(v == 10)
it.next()
v = it.value()
swig_assert(v == 20)
expected = 10
ev.nums.each do|val|
swig_assert(val == expected)
expected += 10
end

View File

@@ -0,0 +1,262 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'li_std_vector'
include Li_std_vector
iv = IntVector.new(4)
swig_assert( "iv.respond_to? :each", binding )
begin
iv.each
swig_assert( false, nil, "iv.each worked with no block!")
rescue ArgumentError
end
swig_assert_each_line(<<'EOF', binding)
iv.respond_to?(:each) == true
iv.respond_to?(:each_with_index) == true
EOF
iv.each_with_index { |e,i|
swig_assert("#{e} == 0", binding, "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" => "0123",
"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].to_s" => '',
}.each do |k,v|
swig_assert( "#{k} == #{v.inspect}", binding )
end
swig_assert_each_line(<<'EOF', binding)
iv << 5
iv.push 5
iv.pop == 5
iv.unshift(7)
iv.shift == 7
iv.unshift(7, 3)
iv.insert(1,5)
iv.insert(0, 3)
iv.unshift(2,3,4)
x = average(iv)
y = average([1, 2, 3, 4])
half([10, 10.5, 11, 11.5])
EOF
iv = IntVector.new([0,1,2,3,4,5,6])
iv.delete_if { |x| x == 0 || x == 3 || x == 6 }
swig_assert_equal(iv.to_s, '1245', binding)
iv[1,2] = [-2, -4]
swig_assert_equal(iv.to_s, '1-2-45', binding)
iv = IntVector.new([0,1,2,3])
iv[0,1] = [-1, -2]
swig_assert_equal(iv.to_s, '-1-2123', binding)
iv = IntVector.new([1,2,3,4])
iv[1,3] = [6,7,8,9]
#__setitem__ needs fixing
#swig_assert_equal(iv.to_s, '16789', binding)
iv = IntVector.new([1,2,3,4])
swig_assert_equal(iv[0], 1, binding)
swig_assert_equal(iv[3], 4, binding)
swig_assert_equal(iv[4], nil, binding)
swig_assert_equal(iv[-5], nil, binding)
iv[-1] = 9
iv[-4] = 6
swig_assert_equal(iv.to_s, '6239', binding)
begin
iv[-5] = 99
raise "exception missed"
rescue IndexError
end
iv[6] = 5
swig_assert_equal(iv.to_s, '6239555', binding)
def failed(a, b, msg)
a = 'nil' if a == nil
b = 'nil' if b == nil
raise RuntimeError, "#{msg}: #{a} ... #{b}"
end
def compare_sequences(a, b)
if a != nil && b != nil
if a.size != b.size
failed(a, b, "different sizes")
end
for i in 0..a.size-1
failed(a, b, "elements are different") if a[i] != b[i]
end
else
unless a == nil && b == nil
failed(a, b, "only one of the sequences is nil")
end
end
end
def compare_expanded_sequences(a, b)
# a can contain nil elements which indicate additional elements
# b won't contain nil for additional elements
if a != nil && b != nil
if a.size != b.size
failed(a, b, "different sizes")
end
for i in 0..a.size-1
failed(a, b, "elements are different") if a[i] != b[i] && a[i] != nil
end
else
unless a == nil && b == nil
failed(a, b, "only one of the sequences is nil")
end
end
end
def check_slice(i, length)
aa = [1,2,3,4]
iv = IntVector.new(aa)
aa_slice = aa[i, length]
iv_slice = iv[i, length]
compare_sequences(aa_slice, iv_slice)
aa_slice = aa.slice(i, length)
iv_slice = iv.slice(i, length)
compare_sequences(aa_slice, iv_slice)
end
def check_range(i, j)
aa = [1,2,3,4]
iv = IntVector.new(aa)
aa_range = aa[i..j]
iv_range = iv[i..j]
compare_sequences(aa_range, iv_range)
aa_range = aa[Range.new(i, j, true)]
iv_range = iv[Range.new(i, j, true)]
compare_sequences(aa_range, iv_range)
end
def set_slice(i, length, expect_nil_expanded_elements)
aa = [1,2,3,4]
iv = IntVector.new(aa)
aa_new = [8, 9]
iv_new = IntVector.new(aa_new)
aa[i, length] = aa_new
iv[i, length] = iv_new
if expect_nil_expanded_elements
compare_expanded_sequences(aa, iv)
else
compare_sequences(aa, iv)
end
end
for i in -5..5
for length in -5..5
check_slice(i, length)
end
end
for i in -5..5
for j in -5..5
check_range(i, j)
end
end
for i in -4..4
for length in 0..4
set_slice(i, length, false)
end
end
for i in [5, 6]
for length in 0..5
set_slice(i, length, true)
end
end
dv = DoubleVector.new(10)
swig_assert( "dv.respond_to? :each_with_index", binding )
dv.each_with_index { |e,i| swig_assert_equal("dv[#{i}]", 0.0, binding) }
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_equal( k, v.inspect, binding )
end
swig_assert_each_line(<<'EOF', binding)
dv.delete_at(2)
dv.delete_if { |x| x == 2.0 }
dv.include? 3.0
dv.find {|x| x == 3.0 }
dv.kind_of? DoubleVector
halved = []
halved = dv.map { |x| x / 2 }
halve_in_place(dv)
halved.to_a == dv.to_a
sv = StructVector.new
sv << Li_std_vector::Struct.new
sv[0].class == Li_std_vector::Struct
sv[1] = Li_std_vector::Struct.new
EOF
bv = BoolVector.new(2)
[true, false, true, true].each { |i| bv.push(i) }
0.upto(bv.size-1) { |i| bv[i] = !bv[i] }
bv_check = [true, true, false, true, false, false]
for i in 0..bv.size-1 do
swig_assert(bv_check[i] == bv[i], binding, "bv[#{i}]")
end
swig_assert_each_line(<<'EOF', binding)
lv = LanguageVector.new
lv << 1
lv << [1,2]
lv << 'asd'
lv[0], lv[1] = lv[1], lv[0]
EOF
# this should assert
begin
lv = LanguageVector.new('crapola')
rescue
end

View File

@@ -0,0 +1,54 @@
#!/usr/bin/env ruby
#
# Example using pointers to member functions
#
#
#
require 'swig_assert'
require 'member_pointer'
include Member_pointer
def check(what, expected, actual)
if not expected == actual
raise RuntimeError, "Failed: #{what} Expected: #{expected} Actual: #{actual}"
end
end
# Get the pointers
area_pt = Member_pointer::areapt
perim_pt = Member_pointer::perimeterpt
# Create some objects
s = Member_pointer::Square.new(10)
# Do some calculations
check "Square area ", 100.0, Member_pointer::do_op(s, area_pt)
check "Square perim", 40.0, Member_pointer::do_op(s, perim_pt)
memberPtr = Member_pointer::areavar
memberPtr = Member_pointer::perimetervar
# Try the variables
check "Square area ", 100.0, Member_pointer::do_op(s, Member_pointer::areavar)
check "Square perim", 40.0, Member_pointer::do_op(s, Member_pointer::perimetervar)
# Modify one of the variables
Member_pointer::areavar = perim_pt
check "Square perimeter", 40.0, Member_pointer::do_op(s, Member_pointer::areavar)
# Try the constants
memberPtr = Member_pointer::AREAPT
memberPtr = Member_pointer::PERIMPT
memberPtr = Member_pointer::NULLPT
check "Square area ", 100.0, Member_pointer::do_op(s, Member_pointer::AREAPT)
check "Square perim", 40.0, Member_pointer::do_op(s, Member_pointer::PERIMPT)

View File

@@ -0,0 +1,89 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'minherit'
a = Minherit::Foo.new
b = Minherit::Bar.new
c = Minherit::FooBar.new
d = Minherit::Spam.new
if a.xget() != 1
raise RuntimeError, "Bad attribute value"
end
if b.yget() != 2
raise RuntimeError, "Bad attribute value"
end
if c.xget() != 1 or c.yget() != 2 or c.zget() != 3
raise RuntimeError, "Bad attribute value"
end
if d.xget() != 1 or d.yget() != 2 or d.zget() != 3 or d.wget() != 4
raise RuntimeError, "Bad attribute value"
end
if Minherit.xget(a) != 1
raise RuntimeError, "Bad attribute value #{Minherit.xget(a)}"
end
if Minherit.yget(b) != 2
raise RuntimeError, "Bad attribute value #{Minherit.yget(b)}"
end
if Minherit.xget(c) != 1 or Minherit.yget(c) != 2 or Minherit.zget(c) != 3
raise RuntimeError, "Bad attribute value #{Minherit.xget(c)} #{Minherit.yget(c)} #{Minherit.zget(c)}"
end
if Minherit.xget(d) != 1 or Minherit.yget(d) != 2 or Minherit.zget(d) != 3 or Minherit.wget(d) != 4
raise RuntimeError, "Bad attribute value #{Minherit.xget(d)} #{Minherit.yget(d)} #{Minherit.zget(d)} #{Minherit.wget(d)}"
end
# Cleanse all of the pointers and see what happens
aa = Minherit.toFooPtr(a)
bb = Minherit.toBarPtr(b)
cc = Minherit.toFooBarPtr(c)
dd = Minherit.toSpamPtr(d)
if aa.xget() != 1
raise RuntimeError, "Bad attribute value"
end
if bb.yget() != 2
raise RuntimeError, "Bad attribute value"
end
if cc.xget() != 1 or cc.yget() != 2 or cc.zget() != 3
raise RuntimeError, "Bad attribute value"
end
if dd.xget() != 1 or dd.yget() != 2 or dd.zget() != 3 or dd.wget() != 4
raise RuntimeError, "Bad attribute value"
end
if Minherit.xget(aa) != 1
raise RuntimeError, "Bad attribute value #{Minherit.xget(aa)}"
end
if Minherit.yget(bb) != 2
raise RuntimeError, "Bad attribute value #{Minherit.yget(bb)}"
end
if Minherit.xget(cc) != 1 or Minherit.yget(cc) != 2 or Minherit.zget(cc) != 3
raise RuntimeError, "Bad attribute value #{Minherit.xget(cc)} #{Minherit.yget(cc)} #{Minherit.zget(cc)}"
end
if Minherit.xget(dd) != 1 or Minherit.yget(dd) != 2 or Minherit.zget(dd) != 3 or Minherit.wget(dd) != 4
raise RuntimeError, "Bad attribute value #{Minherit.xget(dd)} #{Minherit.yget(dd)} #{Minherit.zget(dd)} #{Minherit.wget(dd)}"
end

View File

@@ -0,0 +1,44 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'namespace_typemap'
include Namespace_typemap
raise RuntimeError if stest1("hello") != "hello"
raise RuntimeError if stest2("hello") != "hello"
raise RuntimeError if stest3("hello") != "hello"
raise RuntimeError if stest4("hello") != "hello"
raise RuntimeError if stest5("hello") != "hello"
raise RuntimeError if stest6("hello") != "hello"
raise RuntimeError if stest7("hello") != "hello"
raise RuntimeError if stest8("hello") != "hello"
raise RuntimeError if stest9("hello") != "hello"
raise RuntimeError if stest10("hello") != "hello"
raise RuntimeError if stest11("hello") != "hello"
raise RuntimeError if stest12("hello") != "hello"
begin
ttest1(-14)
raise RuntimeError
rescue RangeError
end

View File

@@ -0,0 +1,33 @@
#!/usr/bin/env ruby
#
# Simple test of %newobject
# * The purpose of this test is to confirm that a language module
# * correctly handles the case when C++ class member functions (of both
# * the static and non-static persuasion) have been tagged with the
# * %newobject directive.
#
# Ruby's GC is somewhat broken in that it will mark some more stack space
# leading to the collection of local objects to be delayed.
# Thus, upon invokation, it sometimes you can wait up to several
# instructions to kick in.
# See: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/7449
#
#
#
#
#
require 'swig_assert'
require 'swig_gc'
require 'newobject1'
include Newobject1
GC.track_class = Foo
GC.start
100.times { foo1 = Foo.makeFoo; foo2 = foo1.makeMore }
GC.stats if $VERBOSE
swig_assert( 'Foo.fooCount == 200', binding, "but is #{Foo.fooCount}" )
GC.start
swig_assert( 'Foo.fooCount <= 2', binding, "but is #{Foo.fooCount}" )

View File

@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
#
# Ruby's GC is somewhat broken in that it will mark some more stack space
# leading to the collection of local objects to be delayed.
# Thus, upon invokation, it sometimes you can wait up to several
# instructions to kick in.
# See: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/7449
#
#
#
#
#
require 'swig_assert'
require 'swig_gc'
require 'newobject2'
include Newobject2
GC.track_class = Foo
GC.stats if $VERBOSE
100.times { foo1 = makeFoo }
GC.stats if $VERBOSE
swig_assert( 'fooCount == 100', nil, "but is #{fooCount}" )
GC.start
swig_assert( 'fooCount <= 1', nil, "but is #{fooCount}" )

View File

@@ -0,0 +1,88 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'overload_bool'
include Overload_bool
# Overloading bool, int, string
if overloaded(true) != "bool"
raise RuntimeError, "wrong!"
end
if overloaded(false) != "bool"
raise RuntimeError, "wrong!"
end
if overloaded(0) != "int"
raise RuntimeError, "wrong!"
end
if overloaded(1) != "int"
raise RuntimeError, "wrong!"
end
if overloaded(2) != "int"
raise RuntimeError, "wrong!"
end
if overloaded("1234") != "string"
raise RuntimeError, "wrong!"
end
# Test bool masquerading as integer
# Not possible
# Test int masquerading as bool
if boolfunction(0) != "false"
raise RuntimeError, "wrong!"
end
if boolfunction(1) != "true"
raise RuntimeError, "wrong!"
end
if boolfunction(2) != "true"
raise RuntimeError, "wrong!"
end
#############################################
# Overloading bool, int, string
if overloaded_ref(true) != "bool"
raise RuntimeError, "wrong!"
end
if overloaded_ref(false) != "bool"
raise RuntimeError, "wrong!"
end
if overloaded_ref(0) != "int"
raise RuntimeError, "wrong!"
end
if overloaded_ref(1) != "int"
raise RuntimeError, "wrong!"
end
if overloaded_ref(2) != "int"
raise RuntimeError, "wrong!"
end
if overloaded_ref("1234") != "string"
raise RuntimeError, "wrong!"
end
# Test bool masquerading as integer
# Not possible
# Test int masquerading as bool
if boolfunction_ref(0) != "false"
raise RuntimeError, "wrong!"
end
if boolfunction_ref(1) != "true"
raise RuntimeError, "wrong!"
end
if boolfunction_ref(2) != "true"
raise RuntimeError, "wrong!"
end

View File

@@ -0,0 +1,17 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'overload_copy'
include Overload_copy
f = Foo.new
g = Foo.new(f)

View File

@@ -0,0 +1,18 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'overload_extend2'
f = Overload_extend2::Foo.new
raise RuntimeError if f.test(3) != 1
raise RuntimeError if f.test("hello") != 2
raise RuntimeError if f.test(3.5,2.5) != 3

View File

@@ -0,0 +1,19 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'overload_extend_c'
f = Overload_extend_c::Foo.new
raise RuntimeError if f.test(3) != 1
raise RuntimeError if f.test("hello") != 2
raise RuntimeError if f.test(3.5,2.5) != 6

View File

@@ -0,0 +1,19 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'overload_extend'
f = Overload_extend::Foo.new
raise RuntimeError if f.test(3) != 1
raise RuntimeError if f.test("hello") != 2
raise RuntimeError if f.test(3.5,2.5) != 6

View File

@@ -0,0 +1,130 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'overload_simple'
include Overload_simple
if foo(3) != "foo:int"
raise RuntimeError, "foo(int)"
end
if foo(3.0) != "foo:double"
raise RuntimeError, "foo(double)"
end
if foo("hello") != "foo:char *"
raise RuntimeError, "foo(char *)"
end
f = Foo.new
b = Bar.new
if foo(f) != "foo:Foo *"
raise RuntimeError, "foo(Foo *)"
end
if foo(b) != "foo:Bar *"
raise RuntimeError, "foo(Bar *)"
end
v = malloc_void(32)
if foo(v) != "foo:void *"
raise RuntimeError, "foo(void *)"
end
s = Spam.new
if s.foo(3) != "foo:int"
raise RuntimeError, "Spam::foo(int)"
end
if s.foo(3.0) != "foo:double"
raise RuntimeError, "Spam::foo(double)"
end
if s.foo("hello") != "foo:char *"
raise RuntimeError, "Spam::foo(char *)"
end
if s.foo(f) != "foo:Foo *"
raise RuntimeError, "Spam::foo(Foo *)"
end
if s.foo(b) != "foo:Bar *"
raise RuntimeError, "Spam::foo(Bar *)"
end
if s.foo(v) != "foo:void *"
raise RuntimeError, "Spam::foo(void *)"
end
if Spam.bar(3) != "bar:int"
raise RuntimeError, "Spam::bar(int)"
end
if Spam.bar(3.0) != "bar:double"
raise RuntimeError, "Spam::bar(double)"
end
if Spam.bar("hello") != "bar:char *"
raise RuntimeError, "Spam::bar(char *)"
end
if Spam.bar(f) != "bar:Foo *"
raise RuntimeError, "Spam::bar(Foo *)"
end
if Spam.bar(b) != "bar:Bar *"
raise RuntimeError, "Spam::bar(Bar *)"
end
if Spam.bar(v) != "bar:void *"
raise RuntimeError, "Spam::bar(void *)"
end
# Test constructors
s = Spam.new
if s.type != "none"
raise RuntimeError, "Spam()"
end
s = Spam.new(3)
if s.type != "int"
raise RuntimeError, "Spam(int)"
end
s = Spam.new(3.4)
if s.type != "double"
raise RuntimeError, "Spam(double)"
end
s = Spam.new("hello")
if s.type != "char *"
raise RuntimeError, "Spam(char *)"
end
s = Spam.new(f)
if s.type != "Foo *"
raise RuntimeError, "Spam(Foo *)"
end
s = Spam.new(b)
if s.type != "Bar *"
raise RuntimeError, "Spam(Bar *)"
end
s = Spam.new(v)
if s.type != "void *"
raise RuntimeError, "Spam(void *)"
end

View File

@@ -0,0 +1,26 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'overload_subtype'
include Overload_subtype
f = Foo.new
b = Bar.new
if spam(f) != 1
raise RuntimeError, "foo"
end
if spam(b) != 2
raise RuntimeError, "bar"
end

View File

@@ -0,0 +1,17 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'overload_template'
f = Overload_template.foo()
a = Overload_template.maximum(3,4)
b = Overload_template.maximum(3.4,5.2)

View File

@@ -0,0 +1,38 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'primitive_ref'
include Primitive_ref
raise RuntimeError if ref_int(3) != 3
raise RuntimeError if ref_uint(3) != 3
raise RuntimeError if ref_short(3) != 3
raise RuntimeError if ref_ushort(3) != 3
raise RuntimeError if ref_long(3) != 3
raise RuntimeError if ref_ulong(3) != 3
raise RuntimeError if ref_schar(3) != 3
raise RuntimeError if ref_uchar(3) != 3
raise RuntimeError if ref_float(3.5) != 3.5
raise RuntimeError if ref_double(3.5) != 3.5
raise RuntimeError if ref_bool(true) != true
raise RuntimeError if ref_char('x') != 'x'

View File

@@ -0,0 +1,98 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'primitive_types'
include Primitive_types
raise RuntimeError if val_uchar(255) != 255
fail = 0
begin
val_uchar(-1)
rescue RangeError
fail = 1
end
fail = 0
begin
val_uchar(256)
rescue RangeError
fail = 1
end
raise RuntimeError if fail != 1
fail = 0
begin
val_uchar(256.0)
rescue TypeError
fail = 1
end
raise RuntimeError if fail != 1
fail = 0
begin
val_uchar("caca")
rescue TypeError
fail = 1
end
raise RuntimeError if fail != 1
# Test a number which won't fit in a 32 bit integer and is represented
# as a FIXNUM by Ruby.
raise RuntimeError if val_double(51767811298) != 51767811298
raise RuntimeError if val_double_2(1.0) != 4.0
raise RuntimeError if val_double_2(1) != 4
raise RuntimeError if val_double_2(1,1) != 2
fail = 0
begin
val_double_2("1.0",1.0)
rescue
fail = 1
end
raise RuntimeError if fail != 1
fail = 0
begin
val_double_2(1.0,"1.0")
rescue
fail = 1
end
raise RuntimeError if fail != 1
raise RuntimeError if val_float_2(1.0) != 4.0
raise RuntimeError if val_float_2(1) != 4
raise RuntimeError if val_float_2(1,1) != 2
fail = 0
begin
val_float_2("1.0",1.0)
rescue
fail = 1
end
raise RuntimeError if fail != 1
fail = 0
begin
val_float_2(1.0,"1.0")
rescue
fail = 1
end
raise RuntimeError if fail != 1

View File

@@ -0,0 +1,20 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'profiletest'
a = Profiletest::A.new()
b = Profiletest::B.new()
for i in 0...1000000
a = b.fn(a)
end

View File

@@ -0,0 +1,21 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'refcount'
a = Refcount::A3.new;
b1 = Refcount::B.new a;
b2 = Refcount::B.new a;
if a.ref_count() != 3
print "This program will crash... now\n"
end

View File

@@ -0,0 +1,104 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'reference_global_vars'
# primitive reference variables
Reference_global_vars.var_bool = Reference_global_vars.createref_bool(true)
if (Reference_global_vars.value_bool(Reference_global_vars.var_bool) != true)
print "Runtime error test 1\n"
exit 1
end
Reference_global_vars.var_bool = Reference_global_vars.createref_bool(false)
if (Reference_global_vars.value_bool(Reference_global_vars.var_bool) != false)
print "Runtime error test 2 \n"
exit 1
end
Reference_global_vars.var_char = Reference_global_vars.createref_char('w')
if (Reference_global_vars.value_char(Reference_global_vars.var_char) != 'w')
print "Runtime error test 3 \n"
exit 1
end
Reference_global_vars.var_unsigned_char = Reference_global_vars.createref_unsigned_char(10)
if (Reference_global_vars.value_unsigned_char(Reference_global_vars.var_unsigned_char) != 10)
print "Runtime error test 4 \n"
exit 1
end
Reference_global_vars.var_signed_char = Reference_global_vars.createref_signed_char(10)
if (Reference_global_vars.value_signed_char(Reference_global_vars.var_signed_char) != 10)
print "Runtime error test 5 \n"
exit 1
end
Reference_global_vars.var_short = Reference_global_vars.createref_short(10)
if (Reference_global_vars.value_short(Reference_global_vars.var_short) != 10)
print "Runtime error test 6 \n"
exit 1
end
Reference_global_vars.var_unsigned_short = Reference_global_vars.createref_unsigned_short(10)
if (Reference_global_vars.value_unsigned_short(Reference_global_vars.var_unsigned_short) != 10)
print "Runtime error test 7 \n"
exit 1
end
Reference_global_vars.var_int = Reference_global_vars.createref_int(10)
if (Reference_global_vars.value_int(Reference_global_vars.var_int) != 10)
print "Runtime error test 8 \n"
exit 1
end
Reference_global_vars.var_unsigned_int = Reference_global_vars.createref_unsigned_int(10)
if (Reference_global_vars.value_unsigned_int(Reference_global_vars.var_unsigned_int) != 10)
print "Runtime error test 9 \n"
exit 1
end
Reference_global_vars.var_long = Reference_global_vars.createref_long(10)
if (Reference_global_vars.value_long(Reference_global_vars.var_long) != 10)
print "Runtime error test 10 \n"
exit 1
end
Reference_global_vars.var_unsigned_long = Reference_global_vars.createref_unsigned_long(10)
if (Reference_global_vars.value_unsigned_long(Reference_global_vars.var_unsigned_long) != 10)
print "Runtime error test 11 \n"
exit 1
end
Reference_global_vars.var_long_long = Reference_global_vars.createref_long_long(10)
if (Reference_global_vars.value_long_long(Reference_global_vars.var_long_long) != 10)
print "Runtime error test 12 \n"
exit 1
end
Reference_global_vars.var_unsigned_long_long = Reference_global_vars.createref_unsigned_long_long(10)
if (Reference_global_vars.value_unsigned_long_long(Reference_global_vars.var_unsigned_long_long) != 10)
print "Runtime error test 13 \n"
exit 1
end
Reference_global_vars.var_float = Reference_global_vars.createref_float(10.5)
if (Reference_global_vars.value_float(Reference_global_vars.var_float) != 10.5)
print "Runtime error test 14 \n"
exit 1
end
Reference_global_vars.var_double = Reference_global_vars.createref_double(10.5)
if (Reference_global_vars.value_double(Reference_global_vars.var_double) != 10.5)
print "Runtime error test 15 \n"
exit 1
end

View File

@@ -0,0 +1,21 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'rename_scope'
include Rename_scope
a = Natural_UP.new
b = Natural_BP.new
raise RuntimeError if a.rtest() != 1
raise RuntimeError if b.rtest() != 1

View File

@@ -0,0 +1,159 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'ruby_keywords'
kw = Ruby_keywords::Keywords.new
if kw.alias != 'alias' then
raise RuntimeError, 'Keyword method did not work: alias'
end
if kw.and != 'and' then
raise RuntimeError, 'Keyword method did not work: and'
end
if kw.begin != 'begin' then
raise RuntimeError, 'Keyword method did not work: begin'
end
if kw.break != 'break' then
raise RuntimeError, 'Keyword method did not work: break'
end
if kw.case != 'case' then
raise RuntimeError, 'Keyword method did not work: case'
end
if kw.class != 'class' then
raise RuntimeError, 'Keyword method did not work: class'
end
if kw.def != 'def' then
raise RuntimeError, 'Keyword method did not work: def'
end
if kw.defined? != 'defined?' then
raise RuntimeError, 'Keyword method did not work: defined?'
end
if kw.do != 'do' then
raise RuntimeError, 'Keyword method did not work: do'
end
if kw.else != 'else' then
raise RuntimeError, 'Keyword method did not work: else'
end
if kw.elsif != 'elsif' then
raise RuntimeError, 'Keyword method did not work: elsif'
end
if kw.end != 'end' then
raise RuntimeError, 'Keyword method did not work: end'
end
if kw.ensure != 'ensure' then
raise RuntimeError, 'Keyword method did not work: ensure'
end
if kw.false != 'false' then
raise RuntimeError, 'Keyword method did not work: false'
end
if kw.for != 'for' then
raise RuntimeError, 'Keyword method did not work: for'
end
if kw.if != 'if' then
raise RuntimeError, 'Keyword method did not work: if'
end
if kw.in != 'in' then
raise RuntimeError, 'Keyword method did not work: in'
end
if kw.module != 'module' then
raise RuntimeError, 'Keyword method did not work: module'
end
if kw.next != 'next' then
raise RuntimeError, 'Keyword method did not work: next'
end
if kw.nil != 'nil' then
raise RuntimeError, 'Keyword method did not work: nil'
end
if kw.not != 'not' then
raise RuntimeError, 'Keyword method did not work: not'
end
if kw.or != 'or' then
raise RuntimeError, 'Keyword method did not work: or'
end
if kw.redo != 'redo' then
raise RuntimeError, 'Keyword method did not work: redo'
end
if kw.rescue != 'rescue' then
raise RuntimeError, 'Keyword method did not work: rescue'
end
if kw.retry != 'retry' then
raise RuntimeError, 'Keyword method did not work: retry'
end
if kw.return != 'return' then
raise RuntimeError, 'Keyword method did not work: return'
end
if kw.self != 'self' then
raise RuntimeError, 'Keyword method did not work: self'
end
if kw.super != 'super' then
raise RuntimeError, 'Keyword method did not work: super'
end
if kw.then != 'then' then
raise RuntimeError, 'Keyword method did not work: then'
end
if kw.true != 'true' then
raise RuntimeError, 'Keyword method did not work: true'
end
if kw.under != 'under' then
raise RuntimeError, 'Keyword method did not work: under'
end
if kw.unless != 'unless' then
raise RuntimeError, 'Keyword method did not work: unless'
end
if kw.until != 'until' then
raise RuntimeError, 'Keyword method did not work: until'
end
if kw.when != 'when' then
raise RuntimeError, 'Keyword method did not work: when'
end
if kw.while != 'while' then
raise RuntimeError, 'Keyword method did not work: while'
end
if kw.yield != 'yield' then
raise RuntimeError, 'Keyword method did not work: yield'
end

View File

@@ -0,0 +1,82 @@
#!/usr/bin/env ruby
#
# This is a simple speed benchmark suite for std containers,
# to verify their O(n) performance.
# It is not part of the standard tests.
require 'benchmark'
require 'mathn'
require 'ruby_li_std_speed'
include Ruby_li_std_speed
def benchmark(f, phigh, sequences)
puts f
print '%10s' % 'n'
maxlen = sequences.max { |a,b| a.to_s.size <=> b.to_s.size }
maxlen = maxlen.to_s.size - 12
sequences.each { |s| print "%#{maxlen}s" % "#{s.to_s.sub(/.*::/,'')}" }
puts
o_perf = Array.new(sequences.size, 0)
last_t = Array.new(sequences.size, nil)
1.upto(phigh) do |p|
n = 2**(p-1)
print "%10d" % n
sequences.each_with_index do |s, i|
cont = s.new((0..n).to_a)
Benchmark.benchmark('',0,"%#{maxlen-2}.6r") { |x|
t = x.report { f.call(cont) }
o_perf[i] += last_t[i] ? (t.real / last_t[i]) : t.real
last_t[i] = t.real
}
end
puts
end
print " avg. O(n)"
base = 1.0 / Math.log(2.0)
sequences.each_with_index do |s, i|
o_perf[i] /= phigh
# o_perf[i] = 1 if o_perf[i] < 1
o_perf[i] = Math.log(o_perf[i]) * base
print "%#{maxlen-1}.2f " % o_perf[i]
end
puts
end
def iterate(cont)
it = cont.begin
last = cont.end
while it != last
it.next
end
end
def erase(cont)
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) || cont.end
end
end
def insert(cont)
size = cont.size
size.upto((size<<1) - 1) { |x| cont.push(x) }
end
if $0 == __FILE__
GC.disable
sequences = [RbVector,RbDeque,RbSet,RbList,
RbFloatVector,RbFloatDeque,RbFloatSet,RbFloatList]
n = 17
for f,phigh in [[method(:iterate),n], [method(:insert),n],
[method(:erase),n-4]]
benchmark(f, phigh, sequences)
end
end

Some files were not shown because too many files have changed in this diff Show More