Add new swigtype_inout.i library containing SWIGTYPE *& OUTPUT typemaps.
This commit is contained in:
parent
87c1e093ee
commit
0383d08444
5 changed files with 158 additions and 0 deletions
|
|
@ -251,6 +251,7 @@ CPP_TEST_CASES += \
|
|||
li_cpointer \
|
||||
li_std_auto_ptr \
|
||||
li_stdint \
|
||||
li_swigtype_inout \
|
||||
li_typemaps \
|
||||
li_typemaps_apply \
|
||||
li_windows \
|
||||
|
|
|
|||
56
Examples/test-suite/csharp/li_swigtype_inout_runme.cs
Normal file
56
Examples/test-suite/csharp/li_swigtype_inout_runme.cs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
|
||||
using System;
|
||||
using li_swigtype_inoutNamespace;
|
||||
|
||||
public class li_swigtype_inout_runme {
|
||||
|
||||
public static void Main() {
|
||||
XXX xxx = new XXX(999);
|
||||
check_count(1);
|
||||
XXX x1 = null;
|
||||
XXX x2 = null;
|
||||
XXX x3 = null;
|
||||
XXX x4 = null;
|
||||
li_swigtype_inout.ptr_ref_out(out x1, out x2, out x3, out x4);
|
||||
check_value(111, x1.value);
|
||||
check_value(222, x2.value);
|
||||
check_value(333, x3.value);
|
||||
check_value(444, x4.value);
|
||||
check_count(5);
|
||||
x1.Dispose();
|
||||
x2.Dispose();
|
||||
x3.Dispose();
|
||||
x4.Dispose();
|
||||
xxx.Dispose();
|
||||
check_count(0);
|
||||
|
||||
x1 = null;
|
||||
x2 = null;
|
||||
x3 = null;
|
||||
x4 = null;
|
||||
new ConstructorTest(out x1, out x2, out x3, out x4);
|
||||
check_count(4);
|
||||
check_value(111, x1.value);
|
||||
check_value(222, x2.value);
|
||||
check_value(333, x3.value);
|
||||
check_value(444, x4.value);
|
||||
x1.Dispose();
|
||||
x2.Dispose();
|
||||
x3.Dispose();
|
||||
x4.Dispose();
|
||||
check_count(0);
|
||||
}
|
||||
|
||||
public static void check_count(int count) {
|
||||
int actual = XXX.count;
|
||||
if( count != actual ) {
|
||||
throw new Exception(String.Format("Count wrong. Expected: {0} Got: {1}", count, actual));
|
||||
}
|
||||
}
|
||||
|
||||
public static void check_value(int expected, int actual) {
|
||||
if( expected != actual ) {
|
||||
throw new Exception(String.Format("Wrong value. Expected: {0} Got: {1}", expected, actual));
|
||||
}
|
||||
}
|
||||
}
|
||||
53
Examples/test-suite/li_swigtype_inout.i
Normal file
53
Examples/test-suite/li_swigtype_inout.i
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
%module li_swigtype_inout
|
||||
|
||||
// Test SWIGTYPE *& typemaps in swigtype_inout.i library
|
||||
|
||||
#ifdef SWIGCSHARP
|
||||
%include <swigtype_inout.i>
|
||||
%apply SWIGTYPE *& OUTPUT { SWIGTYPE *& }
|
||||
#endif
|
||||
|
||||
%ignore XXX::operator=;
|
||||
|
||||
%inline %{
|
||||
#include <iostream>
|
||||
struct XXX {
|
||||
XXX(int value) : value(value) {
|
||||
if (debug) std::cout << "Default Constructor " << value << " " << this << std::endl;
|
||||
count++;
|
||||
}
|
||||
XXX(const XXX &other) {
|
||||
value = other.value;
|
||||
if (debug) std::cout << "Copy Constructor " << value << " " << this << std::endl;
|
||||
count++;
|
||||
}
|
||||
XXX& operator=(const XXX &other) {
|
||||
value = other.value;
|
||||
if (debug) std::cout << "Assignment operator " << value << " " << this << std::endl;
|
||||
return *this;
|
||||
}
|
||||
~XXX() {
|
||||
if (debug) std::cout << "Destructor " << value << " " << this << std::endl;
|
||||
count--;
|
||||
}
|
||||
void showInfo() {
|
||||
if (debug) std::cout << "Info " << value << " " << this << std::endl;
|
||||
}
|
||||
int value;
|
||||
static const bool debug = false;
|
||||
static int count;
|
||||
};
|
||||
int XXX::count = 0;
|
||||
|
||||
void ptr_ref_out(XXX *& x1, XXX *& x2, XXX const*& x3, XXX const*& x4) {
|
||||
x1 = new XXX(111);
|
||||
x2 = new XXX(222);
|
||||
x3 = new XXX(333);
|
||||
x4 = new XXX(444);
|
||||
}
|
||||
struct ConstructorTest {
|
||||
ConstructorTest(XXX *& x1, XXX *& x2, XXX const*& x3, XXX const*& x4) {
|
||||
ptr_ref_out(x1, x2, x3, x4);
|
||||
}
|
||||
};
|
||||
%}
|
||||
Loading…
Add table
Add a link
Reference in a new issue