lib_xxxx tests renamed to li_xxxx as a workaround in glib which Mono C# uses - libraries wont be loaded if they start with lib

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6591 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2004-11-01 22:56:31 +00:00
commit c611933db3
16 changed files with 911 additions and 14 deletions

View file

@ -0,0 +1,25 @@
require 'lib_carrays'
include Lib_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,44 @@
require 'lib_std_deque'
include Lib_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,47 @@
require 'lib_std_pair'
include Lib_std_pair
#
# Because of template specializations for pair<int, int>, this should return
# an Array of size 2, where both elements are Fixnums.
#
intPair = makeIntPair(7, 6)
raise RuntimeError unless intPair.instance_of?(Array)
raise RuntimeError unless intPair.size == 2
raise RuntimeError unless (intPair[0] == 7 && intPair[1] == 6)
#
# Each of these should return a reference to a wrapped
# std::pair<int, int> object (i.e. an IntPair instance).
#
intPairPtr = makeIntPairPtr(7, 6)
raise RuntimeError unless intPairPtr.instance_of?(IntPair)
raise RuntimeError unless (intPairPtr.first == 7 && intPairPtr.second == 6)
intPairRef = makeIntPairRef(7, 6)
raise RuntimeError unless intPairRef.instance_of?(IntPair)
raise RuntimeError unless (intPairRef.first == 7 && intPairRef.second == 6)
intPairConstRef = makeIntPairConstRef(7, 6)
raise RuntimeError unless intPairConstRef.instance_of?(IntPair)
raise RuntimeError unless (intPairConstRef.first == 7 && intPairConstRef.second == 6)
#
# Now test various input typemaps. Each of the wrapped C++ functions
# (product1, product2 and product3) is expecting an argument of a
# different type (see lib_std_pair.i). Typemaps should be in place to
# convert this Array into the expected argument type.
#
raise RuntimeError unless product1(intPair) == 42
raise RuntimeError unless product2(intPair) == 42
raise RuntimeError unless product3(intPair) == 42
#
# Similarly, each of the input typemaps should know what to do
# with an IntPair instance.
#
raise RuntimeError unless product1(intPairPtr) == 42
raise RuntimeError unless product2(intPairPtr) == 42
raise RuntimeError unless product3(intPairPtr) == 42

View file

@ -0,0 +1,78 @@
require 'lib_std_string'
include Lib_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

View file

@ -0,0 +1,17 @@
require 'lib_std_vector'
include Lib_std_vector
iv = IntVector.new(4)
0.upto(3) { |i| iv[i] = i }
x = average(iv)
y = average([1, 2, 3, 4])
a = half([10, 10.5, 11, 11.5])
dv = DoubleVector.new(10)
0.upto(9) { |i| dv[i] = i/2.0 }
halve_in_place(dv)