add test for optimal attribute in out typemap

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11199 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2009-04-30 06:12:32 +00:00
commit 90b1578d65
5 changed files with 78 additions and 0 deletions

View file

@ -371,6 +371,7 @@ CPP_TEST_CASES += \
typemap_namespace \
typemap_ns_using \
typemap_numinputs \
typemap_out_optimal \
typemap_variables \
typemap_various \
typename \

View file

@ -0,0 +1,13 @@
using System;
using typemap_out_optimalNamespace;
public class typemap_out_optimal_runme {
public static XX x = null;
public static void Main() {
XX.debug = false;
x = XX.create();
}
}

View file

@ -0,0 +1,21 @@
import typemap_out_optimal.*;
public class typemap_out_optimal_runme {
static {
try {
System.loadLibrary("typemap_out_optimal");
} 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 XX x = null;
public static void main(String argv[]) {
XX.setDebug(false);
x = XX.create();
}
}

View file

@ -0,0 +1,5 @@
from typemap_out_optimal import *
cvar.XX_debug = False
x = XX.create()

View file

@ -0,0 +1,38 @@
// Test the optimal attribute in the out typemap
%module typemap_out_optimal
// Just the following languages tested
#if defined (SWIGCSHARP)
%typemap(out, optimal="1") SWIGTYPE %{
$result = new $1_ltype((const $1_ltype &)$1);
%}
#elif defined (SWIGJAVA)
%typemap(out, optimal="1") SWIGTYPE %{
*($&1_ltype*)&$result = new $1_ltype((const $1_ltype &)$1);
%}
#elif defined (SWIGUTL)
%typemap(out,noblock="1", optimal="1") SWIGTYPE {
%set_output(SWIG_NewPointerObj(%new_copy($1, $ltype), $&descriptor, SWIG_POINTER_OWN | %newpointer_flags));
}
#endif
%ignore XX::operator=;
%inline %{
#include <iostream>
using namespace std;
struct XX {
XX() { cout << "XX()" << endl; }
XX(int i) { if (debug) cout << "XX(" << i << ")" << endl; }
XX(const XX &other) { cout << "XX(const XX &)" << endl; }
XX& operator =(const XX &other) { cout << "operator=(const XX &)" << endl; return *this; }
~XX() { if (debug) cout << "~XX()" << endl; }
static XX create() {
return XX(123);
}
static bool debug;
};
bool XX::debug = true;
%}