global variables test and shared_ptr varin/varout typemaps
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10285 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
03ac417e7f
commit
1a560e3866
6 changed files with 337 additions and 22 deletions
|
|
@ -34,12 +34,10 @@ public class runme
|
|||
System.Threading.Thread.Sleep(10);
|
||||
if (--countdown == 0)
|
||||
break;
|
||||
if (Klass.getTotal_count() == 0)
|
||||
if (Klass.getTotal_count() == 1) // Expect 1 instance - the one global variable (GlobalValue)
|
||||
break;
|
||||
else
|
||||
Console.WriteLine("Count: {0}", Klass.getTotal_count());
|
||||
};
|
||||
if (Klass.getTotal_count() != 0)
|
||||
if (Klass.getTotal_count() != 1)
|
||||
throw new ApplicationException("Klass.total_count=" + Klass.getTotal_count());
|
||||
|
||||
int wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count();
|
||||
|
|
@ -490,7 +488,77 @@ public class runme
|
|||
try { m.MemberValue = null; throw new ApplicationException("Failed to catch null pointer"); } catch (ArgumentNullException) {}
|
||||
}
|
||||
|
||||
// templates
|
||||
////////////////////////////////// Global variables ////////////////////////////////////////
|
||||
// smart pointer
|
||||
{
|
||||
Klass kglobal = li_boost_shared_ptr.GlobalSmartValue;
|
||||
if (kglobal != null)
|
||||
throw new ApplicationException("expected null");
|
||||
|
||||
Klass k = new Klass("smart global value");
|
||||
li_boost_shared_ptr.GlobalSmartValue = k;
|
||||
verifyCount(2, k);
|
||||
|
||||
kglobal = li_boost_shared_ptr.GlobalSmartValue;
|
||||
String val = kglobal.getValue();
|
||||
verifyValue("smart global value", val);
|
||||
verifyCount(3, kglobal);
|
||||
verifyCount(3, k);
|
||||
verifyValue("smart global value", li_boost_shared_ptr.GlobalSmartValue.getValue());
|
||||
li_boost_shared_ptr.GlobalSmartValue = null;
|
||||
}
|
||||
// plain value
|
||||
{
|
||||
Klass kglobal;
|
||||
|
||||
Klass k = new Klass("global value");
|
||||
li_boost_shared_ptr.GlobalValue = k;
|
||||
verifyCount(1, k);
|
||||
|
||||
kglobal = li_boost_shared_ptr.GlobalValue;
|
||||
String val = kglobal.getValue();
|
||||
verifyValue("global value", val);
|
||||
verifyCount(1, kglobal);
|
||||
verifyCount(1, k);
|
||||
verifyValue("global value", li_boost_shared_ptr.GlobalValue.getValue());
|
||||
|
||||
try { li_boost_shared_ptr.GlobalValue = null; throw new ApplicationException("Failed to catch null pointer"); } catch (ArgumentNullException) {}
|
||||
}
|
||||
// plain pointer
|
||||
{
|
||||
Klass kglobal = li_boost_shared_ptr.GlobalPointer;
|
||||
if (kglobal != null)
|
||||
throw new ApplicationException("expected null");
|
||||
|
||||
Klass k = new Klass("global pointer");
|
||||
li_boost_shared_ptr.GlobalPointer = k;
|
||||
verifyCount(1, k);
|
||||
|
||||
kglobal = li_boost_shared_ptr.GlobalPointer;
|
||||
String val = kglobal.getValue();
|
||||
verifyValue("global pointer", val);
|
||||
verifyCount(1, kglobal);
|
||||
verifyCount(1, k);
|
||||
li_boost_shared_ptr.GlobalPointer = null;
|
||||
}
|
||||
// plain reference
|
||||
{
|
||||
Klass kglobal;
|
||||
|
||||
Klass k = new Klass("global reference");
|
||||
li_boost_shared_ptr.GlobalReference = k;
|
||||
verifyCount(1, k);
|
||||
|
||||
kglobal = li_boost_shared_ptr.GlobalReference;
|
||||
String val = kglobal.getValue();
|
||||
verifyValue("global reference", val);
|
||||
verifyCount(1, kglobal);
|
||||
verifyCount(1, k);
|
||||
|
||||
try { li_boost_shared_ptr.GlobalReference = null; throw new ApplicationException("Failed to catch null pointer"); } catch (ArgumentNullException) {}
|
||||
}
|
||||
|
||||
////////////////////////////////// Templates ////////////////////////////////////////
|
||||
{
|
||||
PairIntDouble pid = new PairIntDouble(10, 20.2);
|
||||
if (pid.baseVal1 != 20 || pid.baseVal2 != 40.4)
|
||||
|
|
|
|||
|
|
@ -47,10 +47,10 @@ public class li_boost_shared_ptr_runme {
|
|||
}
|
||||
if (--countdown == 0)
|
||||
break;
|
||||
if (Klass.getTotal_count() == 0)
|
||||
if (Klass.getTotal_count() == 1) // Expect 1 instance - the one global variable (GlobalValue)
|
||||
break;
|
||||
};
|
||||
if (Klass.getTotal_count() != 0)
|
||||
if (Klass.getTotal_count() != 1)
|
||||
throw new RuntimeException("Klass.total_count=" + Klass.getTotal_count());
|
||||
|
||||
int wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count();
|
||||
|
|
@ -501,7 +501,78 @@ public class li_boost_shared_ptr_runme {
|
|||
try { m.setMemberValue(null); throw new RuntimeException("Failed to catch null pointer"); } catch (NullPointerException e) {}
|
||||
}
|
||||
|
||||
// templates
|
||||
////////////////////////////////// Global variables ////////////////////////////////////////
|
||||
// smart pointer
|
||||
{
|
||||
Klass kglobal = li_boost_shared_ptr.getGlobalSmartValue();
|
||||
if (kglobal != null)
|
||||
throw new RuntimeException("expected null");
|
||||
|
||||
Klass k = new Klass("smart global value");
|
||||
li_boost_shared_ptr.setGlobalSmartValue(k);
|
||||
verifyCount(2, k);
|
||||
|
||||
kglobal = li_boost_shared_ptr.getGlobalSmartValue();
|
||||
String val = kglobal.getValue();
|
||||
verifyValue("smart global value", val);
|
||||
verifyCount(3, kglobal);
|
||||
verifyCount(3, k);
|
||||
verifyValue("smart global value", li_boost_shared_ptr.getGlobalSmartValue().getValue());
|
||||
li_boost_shared_ptr.setGlobalSmartValue(null);
|
||||
}
|
||||
// plain value
|
||||
{
|
||||
Klass kglobal;
|
||||
|
||||
Klass k = new Klass("global value");
|
||||
li_boost_shared_ptr.setGlobalValue(k);
|
||||
verifyCount(1, k);
|
||||
|
||||
kglobal = li_boost_shared_ptr.getGlobalValue();
|
||||
String val = kglobal.getValue();
|
||||
verifyValue("global value", val);
|
||||
verifyCount(1, kglobal);
|
||||
verifyCount(1, k);
|
||||
verifyValue("global value", li_boost_shared_ptr.getGlobalValue().getValue());
|
||||
|
||||
try { li_boost_shared_ptr.setGlobalValue(null); throw new RuntimeException("Failed to catch null pointer"); } catch (NullPointerException e) {}
|
||||
}
|
||||
// plain pointer
|
||||
{
|
||||
Klass kglobal = li_boost_shared_ptr.getGlobalPointer();
|
||||
if (kglobal != null)
|
||||
throw new RuntimeException("expected null");
|
||||
|
||||
Klass k = new Klass("global pointer");
|
||||
li_boost_shared_ptr.setGlobalPointer(k);
|
||||
verifyCount(1, k);
|
||||
|
||||
kglobal = li_boost_shared_ptr.getGlobalPointer();
|
||||
String val = kglobal.getValue();
|
||||
verifyValue("global pointer", val);
|
||||
verifyCount(1, kglobal);
|
||||
verifyCount(1, k);
|
||||
li_boost_shared_ptr.setGlobalPointer(null);
|
||||
}
|
||||
|
||||
// plain reference
|
||||
{
|
||||
Klass kglobal;
|
||||
|
||||
Klass k = new Klass("global reference");
|
||||
li_boost_shared_ptr.setGlobalReference(k);
|
||||
verifyCount(1, k);
|
||||
|
||||
kglobal = li_boost_shared_ptr.getGlobalReference();
|
||||
String val = kglobal.getValue();
|
||||
verifyValue("global reference", val);
|
||||
verifyCount(1, kglobal);
|
||||
verifyCount(1, k);
|
||||
|
||||
try { li_boost_shared_ptr.setGlobalReference(null); throw new RuntimeException("Failed to catch null pointer"); } catch (NullPointerException e) {}
|
||||
}
|
||||
|
||||
////////////////////////////////// Templates ////////////////////////////////////////
|
||||
{
|
||||
PairIntDouble pid = new PairIntDouble(10, 20.2);
|
||||
if (pid.getBaseVal1() != 20 || pid.getBaseVal2() != 40.4)
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ SWIG_SHARED_PTR_DERIVED(KlassDerived, Space::Klass, Space::KlassDerived)
|
|||
// const shared_ptr
|
||||
// std::vector
|
||||
// Add in generic %extend for the Upcast function for derived classes
|
||||
// Can probably remove the pgcpp for shared_ptr, unless wrapping shared_ptr<>* shared_ptr<>& and use IntPtr instead of HandleRef for C# ???
|
||||
// Remove proxy upcast method - implement %feature("shadow") ??? which replaces the proxy method
|
||||
|
||||
%exception {
|
||||
|
|
@ -281,6 +280,13 @@ struct MemberVariables {
|
|||
Space::Klass * MemberPointer;
|
||||
Space::Klass & MemberReference;
|
||||
};
|
||||
|
||||
// Global variables
|
||||
SwigBoost::shared_ptr<Space::Klass> GlobalSmartValue;
|
||||
Space::Klass GlobalValue;
|
||||
Space::Klass * GlobalPointer = 0;
|
||||
Space::Klass & GlobalReference = GlobalValue;
|
||||
|
||||
%}
|
||||
|
||||
#if defined(SHARED_PTR_WRAPPERS_IMPLEMENTED)
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ class li_boost_shared_ptr_runme:
|
|||
for i in range (0,loopCount):
|
||||
self.runtest()
|
||||
|
||||
if (li_boost_shared_ptr.Klass.getTotal_count() != 0):
|
||||
# Expect 1 instance - the one global variable (GlobalValue)
|
||||
if (li_boost_shared_ptr.Klass.getTotal_count() != 1):
|
||||
raise RuntimeError("Klass.total_count=", li_boost_shared_ptr.Klass.getTotal_count())
|
||||
|
||||
wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count()
|
||||
|
|
@ -440,7 +441,78 @@ class li_boost_shared_ptr_runme:
|
|||
except ValueError:
|
||||
pass
|
||||
|
||||
# templates
|
||||
# ////////////////////////////////// Global variables ////////////////////////////////////////
|
||||
# smart pointer
|
||||
kglobal = li_boost_shared_ptr.cvar.GlobalSmartValue
|
||||
if (kglobal != None):
|
||||
raise RuntimeError("expected null")
|
||||
|
||||
k = li_boost_shared_ptr.Klass("smart global value")
|
||||
li_boost_shared_ptr.cvar.GlobalSmartValue = k
|
||||
self.verifyCount(2, k)
|
||||
|
||||
kglobal = li_boost_shared_ptr.cvar.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.cvar.GlobalSmartValue.getValue())
|
||||
li_boost_shared_ptr.cvar.GlobalSmartValue = None
|
||||
|
||||
# plain value
|
||||
k = li_boost_shared_ptr.Klass("global value")
|
||||
li_boost_shared_ptr.cvar.GlobalValue = k
|
||||
self.verifyCount(1, k)
|
||||
|
||||
kglobal = li_boost_shared_ptr.cvar.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.cvar.GlobalValue.getValue())
|
||||
|
||||
try:
|
||||
li_boost_shared_ptr.cvar.GlobalValue = None
|
||||
raise RuntimeError("Failed to catch null pointer")
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# plain pointer
|
||||
kglobal = li_boost_shared_ptr.cvar.GlobalPointer
|
||||
if (kglobal != None):
|
||||
raise RuntimeError("expected null")
|
||||
|
||||
k = li_boost_shared_ptr.Klass("global pointer")
|
||||
li_boost_shared_ptr.cvar.GlobalPointer = k
|
||||
self.verifyCount(1, k)
|
||||
|
||||
kglobal = li_boost_shared_ptr.cvar.GlobalPointer
|
||||
val = kglobal.getValue()
|
||||
self.verifyValue("global pointer", val)
|
||||
self.verifyCount(1, kglobal)
|
||||
self.verifyCount(1, k)
|
||||
li_boost_shared_ptr.cvar.GlobalPointer = None
|
||||
|
||||
# plain reference
|
||||
kglobal
|
||||
|
||||
k = li_boost_shared_ptr.Klass("global reference")
|
||||
li_boost_shared_ptr.cvar.GlobalReference = k
|
||||
self.verifyCount(1, k)
|
||||
|
||||
kglobal = li_boost_shared_ptr.cvar.GlobalReference
|
||||
val = kglobal.getValue()
|
||||
self.verifyValue("global reference", val)
|
||||
self.verifyCount(1, kglobal)
|
||||
self.verifyCount(1, k)
|
||||
|
||||
try:
|
||||
li_boost_shared_ptr.cvar.GlobalReference = None
|
||||
raise RuntimeError("Failed to catch null pointer")
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# ////////////////////////////////// Templates ////////////////////////////////////////
|
||||
pid = li_boost_shared_ptr.PairIntDouble(10, 20.2)
|
||||
if (pid.baseVal1 != 20 or pid.baseVal2 != 40.4):
|
||||
raise RuntimeError("Base values wrong")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue