diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 97828f3ce..41be43921 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -140,14 +140,14 @@ CPP_TEST_CASES += \ inline_initializer \ inherit_void_arg \ kind \ - lib_carrays \ - lib_cdata \ - lib_cpointer \ - lib_std_deque \ - lib_std_pair \ - lib_std_string \ - lib_std_vector \ - lib_typemaps \ + li_carrays \ + li_cdata \ + li_cpointer \ + li_std_deque \ + li_std_pair \ + li_std_string \ + li_std_vector \ + li_typemaps \ long_long_apply \ member_template \ minherit \ @@ -296,12 +296,12 @@ C_TEST_CASES += \ function_typedef \ inctest \ lextype \ - lib_carrays \ - lib_cdata \ - lib_cmalloc \ - lib_constraints \ - lib_cpointer \ - lib_math \ + li_carrays \ + li_cdata \ + li_cmalloc \ + li_constraints \ + li_cpointer \ + li_math \ long_long \ name \ nested \ diff --git a/Examples/test-suite/csharp/li_typemaps_runme.cs b/Examples/test-suite/csharp/li_typemaps_runme.cs new file mode 100644 index 000000000..b6a5090ea --- /dev/null +++ b/Examples/test-suite/csharp/li_typemaps_runme.cs @@ -0,0 +1,101 @@ + +// Check a few of the INPUT, OUTPUT and INOUT typemaps. + +using System; +using lib_typemapsNamespace; + +public class runme +{ + static void Main() + { + // Check double INPUT typemaps + if (lib_typemaps.in_double(22.22) != 22.22) exit_test("in_double"); + if (lib_typemaps.inr_double(22.22) != 22.22) exit_test("inr_double"); + + // Check double OUTPUT typemaps + { + double var = 44.44; + lib_typemaps.out_double(22.22, out var); + if (var != 22.22) exit_test("out_double"); + } + { + double var = 44.44; + lib_typemaps.outr_double(22.22, out var); + if (var != 22.22) exit_test("outr_double"); + } + + // Check double INOUT typemaps + { + double var = 44.44; + lib_typemaps.inout_double(ref var); + if (var != 44.44) exit_test("inout_double"); + } + { + double var = 44.44; + lib_typemaps.inoutr_double(ref var); + if (var != 44.44) exit_test("inoutr_double"); + } + + // Check unsigned long long INPUT typemaps + if (lib_typemaps.in_ulonglong(20) != 20) exit_test("in_ulonglong"); + if (lib_typemaps.inr_ulonglong(20) != 20) exit_test("inr_ulonglong"); + + // Check unsigned long long OUTPUT typemaps + { + ulong var = 40; + lib_typemaps.out_ulonglong(20, out var); + if (var != 20) exit_test("out_ulonglong"); + } + { + ulong var = 40; + lib_typemaps.outr_ulonglong(20, out var); + if (var != 20) exit_test("outr_ulonglong"); + } + + // Check unsigned long long INOUT typemaps + { + ulong var = 40; + lib_typemaps.inout_ulonglong(ref var); + if (var != 40) exit_test("inout_ulonglong"); + } + { + ulong var = 40; + lib_typemaps.inoutr_ulonglong(ref var); + if (var != 40) exit_test("inoutr_ulonglong"); + } + + // Check unsigned bool INPUT typemaps + if (lib_typemaps.in_bool(false) != false) exit_test("in_bool"); + if (lib_typemaps.inr_bool(false) != false) exit_test("inr_bool"); + + // Check unsigned bool OUTPUT typemaps + { + bool var = false; + lib_typemaps.out_bool(true, out var); + if (var != true) exit_test("out_bool"); + } + { + bool var = false; + lib_typemaps.outr_bool(true, out var); + if (var != true) exit_test("outr_bool"); + } + + // Check unsigned bool INOUT typemaps + { + bool var = false; + lib_typemaps.inout_bool(ref var); + if (var != false) exit_test("inout_bool"); + } + { + bool var = false; + lib_typemaps.inoutr_bool(ref var); + if (var != false) exit_test("inoutr_bool"); + } + } + + private static void exit_test(String funcName) { + throw new Exception("Test FAILED in function " + funcName); + } + +} + diff --git a/Examples/test-suite/java/li_std_string_runme.java b/Examples/test-suite/java/li_std_string_runme.java new file mode 100644 index 000000000..3f222a61a --- /dev/null +++ b/Examples/test-suite/java/li_std_string_runme.java @@ -0,0 +1,76 @@ +import lib_std_string.*; + +public class lib_std_string_runme { + + static { + try { + System.loadLibrary("lib_std_string"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) throws Throwable + { + // Checking expected use of %typemap(in) std::string {} + lib_std_string.test_value("Fee"); + + // Checking expected result of %typemap(out) std::string {} + if (!lib_std_string.test_value("Fi").equals("Fi")) + throw new RuntimeException("Test 1 failed"); + + // Verify type-checking for %typemap(in) std::string {} + try { + lib_std_string.test_value(null); + throw new RuntimeException("Test 2 failed"); + } catch (NullPointerException e) { + } + + // Checking expected use of %typemap(in) const std::string & {} + lib_std_string.test_const_reference("Fo"); + + // Checking expected result of %typemap(out) const std::string& {} + if (!lib_std_string.test_const_reference("Fum").equals("Fum")) + throw new RuntimeException("Test 3 failed"); + + // Verify type-checking for %typemap(in) const std::string & {} + try { + lib_std_string.test_const_reference(null); + throw new RuntimeException("Test 4 failed"); + } catch (NullPointerException e) { + } + + // + // 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. + // + + SWIGTYPE_p_std__string stringPtr = null; + + stringPtr = lib_std_string.test_pointer_out(); + + lib_std_string.test_pointer(stringPtr); + + stringPtr = lib_std_string.test_const_pointer_out(); + + lib_std_string.test_const_pointer(stringPtr); + + stringPtr = lib_std_string.test_reference_out(); + + lib_std_string.test_reference(stringPtr); + + // Check throw exception specification + try { + lib_std_string.test_throw(); + throw new Throwable("Test 5 failed"); + } catch (RuntimeException e) { + } + try { + lib_std_string.test_const_reference_throw(); + throw new Throwable("Test 6 failed"); + } catch (RuntimeException e) { + } + } +} diff --git a/Examples/test-suite/java/li_typemaps_runme.java b/Examples/test-suite/java/li_typemaps_runme.java new file mode 100644 index 000000000..2caf57b61 --- /dev/null +++ b/Examples/test-suite/java/li_typemaps_runme.java @@ -0,0 +1,125 @@ + +// Check a few of the INPUT, OUTPUT and INOUT typemaps. + +import lib_typemaps.*; +import java.math.*; + +public class lib_typemaps_runme { + + static { + try { + System.loadLibrary("lib_typemaps"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) { + + // Check double INPUT typemaps + if (lib_typemaps.in_double(22.22) != 22.22) exit_test("in_double"); + if (lib_typemaps.inr_double(22.22) != 22.22) exit_test("inr_double"); + + // Check double OUTPUT typemaps + { + double[] var = {44.44}; + lib_typemaps.out_double(22.22, var); + if (var[0] != 22.22) exit_test("out_double"); + } + { + double[] var = {44.44}; + lib_typemaps.outr_double(22.22, var); + if (var[0] != 22.22) exit_test("outr_double"); + } + try { + double[] var = null; + lib_typemaps.out_double(22.22, var); + exit_test("null out_double"); + } catch (NullPointerException e) { + } + + // Check double INOUT typemaps + { + double[] var = {44.44}; + lib_typemaps.inout_double(var); + if (var[0] != 44.44) exit_test("inout_double"); + } + { + double[] var = {44.44}; + lib_typemaps.inoutr_double(var); + if (var[0] != 44.44) exit_test("inoutr_double"); + } + try { + double[] var = null; + lib_typemaps.inout_double(var); + exit_test("null inout_double"); + } catch (NullPointerException e) { + } + + // Check unsigned long long INPUT typemaps + BigInteger forty = new BigInteger("40"); + BigInteger twenty = new BigInteger("20"); + if (!lib_typemaps.in_ulonglong(twenty).equals(twenty)) exit_test("in_ulonglong"); + if (!lib_typemaps.inr_ulonglong(twenty).equals(twenty)) exit_test("inr_ulonglong"); + + try { + lib_typemaps.in_ulonglong(null); + exit_test("null in_ulonglong"); + } catch (NullPointerException e) { + } + + // Check unsigned long long OUTPUT typemaps + { + BigInteger[] var = {new BigInteger("40")}; + lib_typemaps.out_ulonglong(twenty, var); + if (!var[0].equals(twenty)) exit_test("out_ulonglong"); + } + { + BigInteger[] var = {new BigInteger("40")}; + lib_typemaps.outr_ulonglong(twenty, var); + if (!var[0].equals(twenty)) exit_test("outr_ulonglong"); + } + try { + BigInteger[] var = null; + lib_typemaps.out_ulonglong(twenty, var); + exit_test("null out_ulonglong"); + } catch (NullPointerException e) { + } + { + BigInteger[] var = { null }; + lib_typemaps.out_ulonglong(twenty, var); + if (!var[0].equals(twenty)) exit_test("null element out_ulonglong"); + } + + // Check unsigned long long INOUT typemaps + { + BigInteger[] var = {new BigInteger("40")}; + lib_typemaps.inout_ulonglong(var); + if (!var[0].equals(forty)) exit_test("inout_ulonglong"); + } + { + BigInteger[] var = {new BigInteger("40")}; + lib_typemaps.inoutr_ulonglong(var); + if (!var[0].equals(forty)) exit_test("inoutr_ulonglong"); + } + try { + BigInteger[] var = null; + lib_typemaps.inout_ulonglong(var); + exit_test("null inout_ulonglong"); + } catch (NullPointerException e) { + } + try { + BigInteger[] var = { null }; + lib_typemaps.inout_ulonglong(var); + exit_test("null element inout_ulonglong"); + } catch (NullPointerException e) { + } + + } + + private static void exit_test(String funcName) { + throw new RuntimeException("Test FAILED in function " + funcName); + } +} + diff --git a/Examples/test-suite/perl5/li_std_string_runme.pl b/Examples/test-suite/perl5/li_std_string_runme.pl new file mode 100644 index 000000000..0372273a5 --- /dev/null +++ b/Examples/test-suite/perl5/li_std_string_runme.pl @@ -0,0 +1,63 @@ +use lib_std_string; + + +# Checking expected use of %typemap(in) std::string {} +lib_std_string::test_value("Fee"); + +# Checking expected result of %typemap(out) std::string {} +if (lib_std_string::test_value("Fi") != "Fi") { + die "Test 1 failed"; +} + +###### passing undef seems to work - surely it should fail ???? +# Verify type-checking for %typemap(in) std::string {} +#eval { lib_std_string::test_value(undef) }; +#if (!$@) { +# die "Test 2 failed"; +#} + +# Checking expected use of %typemap(in) const std::string & {} +lib_std_string::test_const_reference("Fo"); + +# Checking expected result of %typemap(out) const std::string& {} +if (lib_std_string::test_const_reference("Fum") != "Fum") { + die "Test 3 failed"; +} + +###### passing undef seems to work - surely it should fail ???? +# Verify type-checking for %typemap(in) const std::string & {} +#eval { lib_std_string::test_const_reference(undef) }; +#if (!$@) { +# die "Test 4 failed"; +#} + +# +# 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. +# + +my $stringPtr = undef; + +$stringPtr = lib_std_string::test_pointer_out(); + +lib_std_string::test_pointer($stringPtr); + +$stringPtr = lib_std_string::test_const_pointer_out(); + +lib_std_string::test_const_pointer($stringPtr); + +$stringPtr = lib_std_string::test_reference_out(); + +lib_std_string::test_reference($stringPtr); + +# Check throw exception specification +eval { lib_std_string::test_throw() }; +if (!$@) { + die "Test 5 failed"; +} +eval { lib_std_string::test_const_reference_throw() }; +if (!$@) { + die "Test 6 failed"; +} + diff --git a/Examples/test-suite/php4/li_carrays_runme.php4 b/Examples/test-suite/php4/li_carrays_runme.php4 new file mode 100644 index 000000000..134dbc251 --- /dev/null +++ b/Examples/test-suite/php4/li_carrays_runme.php4 @@ -0,0 +1,15 @@ + diff --git a/Examples/test-suite/python/li_std_map_runme.py b/Examples/test-suite/python/li_std_map_runme.py new file mode 100644 index 000000000..00fe41a89 --- /dev/null +++ b/Examples/test-suite/python/li_std_map_runme.py @@ -0,0 +1,17 @@ +import lib_std_map + +a1 = lib_std_map.A(3) +a2 = lib_std_map.A(7) + + +if 1: + p0 = lib_std_map.pairii(1,2) + p1 = lib_std_map.pairA(1,a1.this) + m = {} + m[1] = a1 + m[2] = a2 + + lib_std_map.p_identa(p1) + lib_std_map.m_identa(m) + + diff --git a/Examples/test-suite/python/li_std_pair_runme.py b/Examples/test-suite/python/li_std_pair_runme.py new file mode 100644 index 000000000..398e2b1d4 --- /dev/null +++ b/Examples/test-suite/python/li_std_pair_runme.py @@ -0,0 +1,49 @@ +import lib_std_pair + +p = (1,2) +p1 = lib_std_pair.p_inout(p) +p2 = lib_std_pair.p_inoutd(p1) + +d1 = lib_std_pair.d_inout(2) + +i,d2 = lib_std_pair.d_inout2(2) + +i,p = lib_std_pair.p_inout2(p) +p3,p4 = lib_std_pair.p_inout3(p1,p1) + +psi = lib_std_pair.SIPair("hello",1) +pci = lib_std_pair.CIPair(1,1) + + +#psi.first = "hi" + + +psi = lib_std_pair.SIPair("hi",1) +if psi != ("hi",1): + raise RuntimeError + +psii = lib_std_pair.SIIPair(psi,1) + +a = lib_std_pair.A() +b = lib_std_pair.B() + +pab = lib_std_pair.ABPair(a,b); + +pab.first = a +pab.first.val = 2 + +if pab.first.val != 2: + raise RuntimeError + + +pci = lib_std_pair.CIntPair(1,0) + +a = lib_std_pair.A(5) +p1 = lib_std_pair.pairP1(1,a.this) +p2 = lib_std_pair.pairP2(a,1) +p3 = lib_std_pair.pairP3(a,a) + + +if a.val != lib_std_pair.p_identa(p1.this)[1].val: + raise RuntimeError + diff --git a/Examples/test-suite/python/li_std_string_runme.py b/Examples/test-suite/python/li_std_string_runme.py new file mode 100644 index 000000000..51f7b46d1 --- /dev/null +++ b/Examples/test-suite/python/li_std_string_runme.py @@ -0,0 +1,74 @@ +import lib_std_string + +x="hello" + + + +if lib_std_string.test_ccvalue(x) != x: + raise RuntimeError, "bad string mapping" + +if lib_std_string.test_cvalue(x) != x: + raise RuntimeError, "bad string mapping" + +if lib_std_string.test_value(x) != x: + raise RuntimeError, "bad string mapping" + +if lib_std_string.test_const_reference(x) != x: + raise RuntimeError, "bad string mapping" + + +s = lib_std_string.string("he") +#s += "ll" +#s.append('o') +s += "llo" + +if s != x: + print s, x + raise RuntimeError, "bad string mapping" + +if s[1:4] != x[1:4]: + raise RuntimeError, "bad string mapping" + +if lib_std_string.test_value(s) != x: + raise RuntimeError, "bad string mapping" + +if lib_std_string.test_const_reference(s) != x: + raise RuntimeError, "bad string mapping" + +a = lib_std_string.A(s) + +if lib_std_string.test_value(a) != x: + raise RuntimeError, "bad string mapping" + +if lib_std_string.test_const_reference(a) != x: + raise RuntimeError, "bad string mapping" + +b = lib_std_string.string(" world") + +if a + b != "hello world": + raise RuntimeError, "bad string mapping" + +if a + " world" != "hello world": + raise RuntimeError, "bad string mapping" + +if "hello" + b != "hello world": + raise RuntimeError, "bad string mapping" + +c = "hello" + b +if c.find_last_of("l") != 9: + raise RuntimeError, "bad string mapping" + +s = "hello world" + +b = lib_std_string.B("hi") + +b.name = lib_std_string.string("hello") +if b.name != "hello": + raise RuntimeError, "bad string mapping" + + +b.a = lib_std_string.A("hello") +if b.a != "hello": + raise RuntimeError, "bad string mapping" + + diff --git a/Examples/test-suite/python/li_std_vector_runme.py b/Examples/test-suite/python/li_std_vector_runme.py new file mode 100644 index 000000000..bf3e4891b --- /dev/null +++ b/Examples/test-suite/python/li_std_vector_runme.py @@ -0,0 +1,91 @@ +from lib_std_vector import * + +iv = IntVector(4) +for i in range(0,4): + iv[i] = i + +x = average(iv) +y = average([1,2,3,4]) + +a = half([10,10.5,11,11.5]) + +dv = DoubleVector(10) +for i in range(0,10): + dv[i] = i/2.0 + +halve_in_place(dv) + + +bv = BoolVector(4) +bv[0]= 1 +bv[1]= 0 +bv[2]= 4 +bv[3]= 0 + +if bv[0] != bv[2]: + raise RuntimeError,"bad std::vector mapping" + +b = B(5) +va = VecA([b,None,b,b]) + +if va[0].f(1) != 6: + raise RuntimeError,"bad std::vector mapping" + +if vecAptr(va) != 6: + raise RuntimeError,"bad std::vector mapping" + +b.val = 7 +if va[3].f(1) != 8: + raise RuntimeError,"bad std::vector mapping" + + +ip = PtrInt() +ap = new_ArrInt(10) + +ArrInt_setitem(ip,0,123) +ArrInt_setitem(ap,2,123) + +vi = IntPtrVector((ip,ap,None)) +if ArrInt_getitem(vi[0],0) != ArrInt_getitem(vi[1],2): + raise RuntimeError,"bad std::vector mapping" + + + +a = halfs([10,8,4,3]) + +v = IntVector() +v[0:2] = [1,2] +if v[0] != 1 or v[1] != 2: + raise RuntimeError,"bad setslice" + +if v[0:-1][0] != 1: + raise RuntimeError,"bad getslice" + +if v[0:-2].size() != 0: + raise RuntimeError,"bad getslice" + +v[0:1] = [2] +if v[0] != 2: + raise RuntimeError,"bad setslice" + +v[1:] = [3] +if v[1] != 3: + raise RuntimeError,"bad setslice" + +v[2:] = [3] +if v[2] != 3: + raise RuntimeError,"bad setslice" + +if v[0:][0] != v[0]: + raise RuntimeError,"bad getslice" + + +del v[:] +if v.size() != 0: + raise RuntimeError,"bad getslice" + +del v[:] +if v.size() != 0: + raise RuntimeError,"bad getslice" + + diff --git a/Examples/test-suite/python/li_std_wstring_runme.py b/Examples/test-suite/python/li_std_wstring_runme.py new file mode 100644 index 000000000..6d088373a --- /dev/null +++ b/Examples/test-suite/python/li_std_wstring_runme.py @@ -0,0 +1,75 @@ +import lib_std_wstring + +x=u"h" + +if lib_std_wstring.test_wcvalue(x) != x: + raise RuntimeError, "bad string mapping" + +x=u"hello" +if lib_std_wstring.test_ccvalue(x) != x: + raise RuntimeError, "bad string mapping" + +if lib_std_wstring.test_cvalue(x) != x: + raise RuntimeError, "bad string mapping" + +if lib_std_wstring.test_value(x) != x: + print x, lib_std_wstring.test_value(x) + raise RuntimeError, "bad string mapping" + +if lib_std_wstring.test_const_reference(x) != x: + raise RuntimeError, "bad string mapping" + + +s = lib_std_wstring.wstring(u"he") +s += u"llo" + +if s != x: + print s, x + raise RuntimeError, "bad string mapping" + +if s[1:4] != x[1:4]: + raise RuntimeError, "bad string mapping" + +if lib_std_wstring.test_value(s) != x: + raise RuntimeError, "bad string mapping" + +if lib_std_wstring.test_const_reference(s) != x: + raise RuntimeError, "bad string mapping" + +a = lib_std_wstring.A(s) + +if lib_std_wstring.test_value(a) != x: + raise RuntimeError, "bad string mapping" + +if lib_std_wstring.test_const_reference(a) != x: + raise RuntimeError, "bad string mapping" + +b = lib_std_wstring.wstring(" world") + +if a + b != "hello world": + raise RuntimeError, "bad string mapping" + +if a + " world" != "hello world": + raise RuntimeError, "bad string mapping" + +if "hello" + b != "hello world": + raise RuntimeError, "bad string mapping" + +c = "hello" + b +if c.find_last_of("l") != 9: + raise RuntimeError, "bad string mapping" + +s = "hello world" + +b = lib_std_wstring.B("hi") + +b.name = lib_std_wstring.wstring(u"hello") +if b.name != "hello": + raise RuntimeError, "bad string mapping" + + +b.a = lib_std_wstring.A("hello") +if b.a != u"hello": + raise RuntimeError, "bad string mapping" + + diff --git a/Examples/test-suite/ruby/li_carrays_runme.rb b/Examples/test-suite/ruby/li_carrays_runme.rb new file mode 100644 index 000000000..dd8a2c6c3 --- /dev/null +++ b/Examples/test-suite/ruby/li_carrays_runme.rb @@ -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) + diff --git a/Examples/test-suite/ruby/li_std_deque_runme.rb b/Examples/test-suite/ruby/li_std_deque_runme.rb new file mode 100644 index 000000000..fc3940341 --- /dev/null +++ b/Examples/test-suite/ruby/li_std_deque_runme.rb @@ -0,0 +1,44 @@ +require 'lib_std_deque' + +include Lib_std_deque + +# Test constructors for std::deque +intDeque = IntDeque.new +intDeque2 = IntDeque.new(3) +intDeque3 = IntDeque.new(4, 42) +intDeque4 = IntDeque.new(intDeque3) + +# Test constructors for std::deque +doubleDeque = DoubleDeque.new +doubleDeque2 = DoubleDeque.new(3) +doubleDeque3 = DoubleDeque.new(4, 42.0) +doubleDeque4 = DoubleDeque.new(doubleDeque3) + +# Test constructors for std::deque +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 +intDeque << 2 +intDeque << 4 +intDeque << 6 +avg = average(intDeque) +raise RuntimeError if avg != 4.0 + +# +# half() should return a std::deque, where each element is half +# the value of the corresponding element in the input deque. +# 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) + diff --git a/Examples/test-suite/ruby/li_std_pair_runme.rb b/Examples/test-suite/ruby/li_std_pair_runme.rb new file mode 100755 index 000000000..3a3427577 --- /dev/null +++ b/Examples/test-suite/ruby/li_std_pair_runme.rb @@ -0,0 +1,47 @@ +require 'lib_std_pair' + +include Lib_std_pair + +# +# Because of template specializations for pair, 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 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 + diff --git a/Examples/test-suite/ruby/li_std_string_runme.rb b/Examples/test-suite/ruby/li_std_string_runme.rb new file mode 100644 index 000000000..dbf96810c --- /dev/null +++ b/Examples/test-suite/ruby/li_std_string_runme.rb @@ -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 + diff --git a/Examples/test-suite/ruby/li_std_vector_runme.rb b/Examples/test-suite/ruby/li_std_vector_runme.rb new file mode 100755 index 000000000..587495f8d --- /dev/null +++ b/Examples/test-suite/ruby/li_std_vector_runme.rb @@ -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) +