From a37115f55d2ad71489c495b150bd08f0f45809e0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 4 Apr 2008 23:26:54 +0000 Subject: [PATCH] Correct test for global shared_ptr variable git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10343 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../test-suite/csharp/li_boost_shared_ptr_runme.cs | 4 ++-- .../test-suite/java/li_boost_shared_ptr_runme.java | 4 ++-- Examples/test-suite/li_boost_shared_ptr.i | 11 +++-------- .../test-suite/python/li_boost_shared_ptr_runme.py | 7 ++++--- Examples/test-suite/shared_ptr_wrapper.h | 4 ++-- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs b/Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs index 575435ceb..27bc4628f 100644 --- a/Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs +++ b/Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs @@ -42,8 +42,8 @@ public class runme int wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count(); if (wrapper_count != li_boost_shared_ptr.NOT_COUNTING) - if (wrapper_count != 0) - throw new ApplicationException("shared_ptr wrapper count not zero: " + wrapper_count); + if (wrapper_count != 1) // Expect 1 instance - the one global variable (GlobalSmartValue) + throw new ApplicationException("shared_ptr wrapper count=" + wrapper_count); if (debug) Console.WriteLine("Finished"); diff --git a/Examples/test-suite/java/li_boost_shared_ptr_runme.java b/Examples/test-suite/java/li_boost_shared_ptr_runme.java index b4bf3dc61..a699222e5 100644 --- a/Examples/test-suite/java/li_boost_shared_ptr_runme.java +++ b/Examples/test-suite/java/li_boost_shared_ptr_runme.java @@ -55,8 +55,8 @@ public class li_boost_shared_ptr_runme { int wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count(); if (wrapper_count != li_boost_shared_ptr.getNOT_COUNTING()) - if (wrapper_count != 0) - throw new RuntimeException("shared_ptr wrapper count not zero: " + wrapper_count); + if (wrapper_count != 1) // Expect 1 instance - the one global variable (GlobalSmartValue) + throw new RuntimeException("shared_ptr wrapper count=" + wrapper_count); if (debug) System.out.println("Finished"); diff --git a/Examples/test-suite/li_boost_shared_ptr.i b/Examples/test-suite/li_boost_shared_ptr.i index 437d7d2de..5dced8be1 100644 --- a/Examples/test-suite/li_boost_shared_ptr.i +++ b/Examples/test-suite/li_boost_shared_ptr.i @@ -4,6 +4,8 @@ // the runtime tests can be run for a long time to monitor memory leaks using memory monitor tools // like 'top'. There is a wrapper for shared_ptr in shared_ptr_wrapper.h which enables one to // count the instances of shared_ptr. Uncomment the SHARED_PTR_WRAPPER macro to turn this on. +// +// Also note the debug_shared flag which can be set from the target language. %module li_boost_shared_ptr @@ -36,7 +38,7 @@ #if defined(SHARED_PTR_WRAPPERS_IMPLEMENTED) -%include "boost_shared_ptr.i" +%include SWIG_SHARED_PTR(Klass, Space::Klass) SWIG_SHARED_PTR_DERIVED(KlassDerived, Space::Klass, Space::KlassDerived) @@ -212,13 +214,6 @@ Klass *pointerownertest() { SwigBoost::shared_ptr* smartpointerpointerownertest() { return new SwigBoost::shared_ptr(new Klass("smartpointerpointerownertest")); } -/* -Klass* arraytest(Klass k[]) { - k[0].append(" arraytest"); - return k; -} -*/ - // Provide overloads for Klass and KlassDerived as some language modules, eg Python, create an extra reference in // the marshalling if an upcast to a base class is required. diff --git a/Examples/test-suite/python/li_boost_shared_ptr_runme.py b/Examples/test-suite/python/li_boost_shared_ptr_runme.py index 0b966ce6e..5f6cbd211 100644 --- a/Examples/test-suite/python/li_boost_shared_ptr_runme.py +++ b/Examples/test-suite/python/li_boost_shared_ptr_runme.py @@ -18,12 +18,13 @@ class li_boost_shared_ptr_runme: # 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()) + raise RuntimeError("Klass.total_count=%s" % li_boost_shared_ptr.Klass.getTotal_count()) wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count() if (wrapper_count != li_boost_shared_ptr.NOT_COUNTING): - if (wrapper_count != 0): - raise RuntimeError("shared_ptr wrapper count not zero: ", wrapper_count) + # Expect 1 instance - the one global variable (GlobalSmartValue) + if (wrapper_count != 1): + raise RuntimeError("shared_ptr wrapper count=%s" % wrapper_count) if (debug): print "Finished" diff --git a/Examples/test-suite/shared_ptr_wrapper.h b/Examples/test-suite/shared_ptr_wrapper.h index f6d039899..ef7b261b2 100644 --- a/Examples/test-suite/shared_ptr_wrapper.h +++ b/Examples/test-suite/shared_ptr_wrapper.h @@ -24,12 +24,12 @@ namespace SharedPtrWrapper { template void increment(boost::shared_ptr* ptr) { SwigExamples::Lock lock(critical_section); - std::cout << ptr << " " << show_message(ptr) << " " << " +" << std::endl << std::flush; + std::cout << "====SharedPtrWrapper==== + " << ptr << " " << show_message(ptr) << " " << std::endl << std::flush; total_count++; } template void decrement(boost::shared_ptr* ptr) { SwigExamples::Lock lock(critical_section); - std::cout << ptr << " " << show_message(ptr) << " " << " -" << std::endl << std::flush; + std::cout << "====SharedPtrWrapper==== - " << ptr << " " << show_message(ptr) << " " << std::endl << std::flush; total_count--; } static int getTotalCount() { return total_count; }