From 1b4094837f983d6273a81daffc5bbffedc82cf2c Mon Sep 17 00:00:00 2001 From: Renato Filho Date: Tue, 27 Jul 2010 10:07:18 -0300 Subject: Fix char* converter Fix tests. Created warnning about return last ref of python object. Reviewer: Marcelo Lira Luciano Wolf --- tests/libsample/mapuser.cpp | 16 ++++++++-------- tests/libsample/mapuser.h | 13 +++++++------ tests/libsample/protected.h | 21 +++++++++++---------- tests/samplebinding/protected_test.py | 10 +++++++--- tests/samplebinding/typesystem_sample.xml | 6 +++--- 5 files changed, 36 insertions(+), 30 deletions(-) (limited to 'tests') diff --git a/tests/libsample/mapuser.cpp b/tests/libsample/mapuser.cpp index fa20e0423..eb29bb62c 100644 --- a/tests/libsample/mapuser.cpp +++ b/tests/libsample/mapuser.cpp @@ -37,27 +37,27 @@ using namespace std; -std::map > +std::map > MapUser::callCreateMap() { return createMap(); } -std::map > +std::map > MapUser::createMap() { - std::map > retval; + std::map > retval; - std::pair > + std::pair > item0("zero", std::pair(Complex(1.2, 3.4), 2)); retval.insert(item0); - std::pair > + std::pair > item1("one", std::pair(Complex(5.6, 7.8), 3)); retval.insert(item1); - std::pair > + std::pair > item2("two", std::pair(Complex(9.1, 2.3), 5)); retval.insert(item2); @@ -65,9 +65,9 @@ MapUser::createMap() } void -MapUser::showMap(std::map mapping) +MapUser::showMap(std::map mapping) { - std::map::iterator it; + std::map::iterator it; cout << __FUNCTION__ << endl; for (it = mapping.begin() ; it != mapping.end(); it++) cout << (*it).first << " => " << (*it).second << endl; diff --git a/tests/libsample/mapuser.h b/tests/libsample/mapuser.h index 78cc4f34c..c963743ac 100644 --- a/tests/libsample/mapuser.h +++ b/tests/libsample/mapuser.h @@ -38,6 +38,7 @@ #include #include #include +#include #include "complex.h" #include "libsamplemacros.h" @@ -48,16 +49,16 @@ public: MapUser() {} virtual ~MapUser() {} - virtual std::map > createMap(); - std::map > callCreateMap(); + virtual std::map > createMap(); + std::map > callCreateMap(); - void showMap(std::map mapping); + void showMap(std::map mapping); - void setMap(std::map > map) { m_map = map; } - std::map > getMap() { return m_map; } + void setMap(std::map > map) { m_map = map; } + std::map > getMap() { return m_map; } private: - std::map > m_map; + std::map > m_map; }; #endif // MAPUSER_H diff --git a/tests/libsample/protected.h b/tests/libsample/protected.h index 8ba4914f8..0d1ead61d 100644 --- a/tests/libsample/protected.h +++ b/tests/libsample/protected.h @@ -36,19 +36,20 @@ #define PROTECTED_H #include "libsamplemacros.h" +#include class LIBSAMPLE_API ProtectedNonPolymorphic { public: - explicit ProtectedNonPolymorphic(const char* name) : m_name(name) {} + explicit ProtectedNonPolymorphic(const char *name) : m_name(name) {} ~ProtectedNonPolymorphic() {} - const char* publicName() { return m_name; } + const char* publicName() { return m_name.c_str(); } static ProtectedNonPolymorphic* create() { return new ProtectedNonPolymorphic("created"); } protected: - const char* protectedName() { return m_name; } + const char* protectedName() { return m_name.c_str(); } int protectedSum(int a0, int a1) { return a0 + a1; } int modifiedProtectedSum(int a0, int a1) { return a0 + a1; } static const char* protectedStatic() { return "protectedStatic"; } @@ -57,39 +58,39 @@ protected: inline const char* dataTypeName(int data) const { return "integer"; } private: - const char* m_name; + std::string m_name; }; class LIBSAMPLE_API ProtectedPolymorphic { public: - explicit ProtectedPolymorphic(const char* name) : m_name(name) {} + explicit ProtectedPolymorphic(const char *name) : m_name(name) {} virtual ~ProtectedPolymorphic() {} - const char* publicName() { return m_name; } + const char* publicName() { return m_name.c_str(); } static ProtectedPolymorphic* create() { return new ProtectedPolymorphic("created"); } const char* callProtectedName() { return protectedName(); } protected: - virtual const char* protectedName() { return m_name; } + virtual const char* protectedName() { return m_name.c_str(); } private: - const char* m_name; + std::string m_name; }; class LIBSAMPLE_API ProtectedPolymorphicDaughter : public ProtectedPolymorphic { public: - explicit ProtectedPolymorphicDaughter(const char* name) : ProtectedPolymorphic(name) {} + explicit ProtectedPolymorphicDaughter(const char *name) : ProtectedPolymorphic(name) {} static ProtectedPolymorphicDaughter* create() { return new ProtectedPolymorphicDaughter("created"); } }; class LIBSAMPLE_API ProtectedPolymorphicGrandDaughter: public ProtectedPolymorphicDaughter { public: - explicit ProtectedPolymorphicGrandDaughter(const char* name) : ProtectedPolymorphicDaughter(name) {} + explicit ProtectedPolymorphicGrandDaughter(const char *name) : ProtectedPolymorphicDaughter(name) {} static ProtectedPolymorphicGrandDaughter* create() { return new ProtectedPolymorphicGrandDaughter("created"); } }; diff --git a/tests/samplebinding/protected_test.py b/tests/samplebinding/protected_test.py index 356df1f7c..88ac5b59f 100644 --- a/tests/samplebinding/protected_test.py +++ b/tests/samplebinding/protected_test.py @@ -40,7 +40,8 @@ class ExtendedProtectedPolymorphic(ProtectedPolymorphic): self.protectedName_called = False def protectedName(self): self.protectedName_called = True - return 'Extended' + ProtectedPolymorphic.protectedName(self) + self._name = 'Extended' + ProtectedPolymorphic.protectedName(self) + return self._name class ExtendedProtectedPolymorphicDaughter(ProtectedPolymorphicDaughter): def __init__(self, name): @@ -48,7 +49,8 @@ class ExtendedProtectedPolymorphicDaughter(ProtectedPolymorphicDaughter): ProtectedPolymorphicDaughter.__init__(self, name) def protectedName(self): self.protectedName_called = True - return 'ExtendedDaughter' + ProtectedPolymorphicDaughter.protectedName(self) + self._name = 'ExtendedDaughter' + ProtectedPolymorphicDaughter.protectedName(self) + return self._name class ExtendedProtectedPolymorphicGrandDaughter(ProtectedPolymorphicGrandDaughter): def __init__(self, name): @@ -56,7 +58,8 @@ class ExtendedProtectedPolymorphicGrandDaughter(ProtectedPolymorphicGrandDaughte ProtectedPolymorphicGrandDaughter.__init__(self, name) def protectedName(self): self.protectedName_called = True - return 'ExtendedGrandDaughter' + ProtectedPolymorphicGrandDaughter.protectedName(self) + self._name = 'ExtendedGrandDaughter' + ProtectedPolymorphicGrandDaughter.protectedName(self) + return self._name class ExtendedProtectedVirtualDestructor(ProtectedVirtualDestructor): def __init__(self): @@ -125,6 +128,7 @@ class ProtectedPolymorphicDaugherTest(unittest.TestCase): original_name = 'Poly' p = ExtendedProtectedPolymorphicDaughter(original_name) name = p.callProtectedName() + print "MyName:", name self.assert_(p.protectedName_called) self.assertEqual(p.protectedName(), name) self.assertEqual(ProtectedPolymorphicDaughter.protectedName(p), original_name) diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index 29e9e601d..77e5052e2 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -10,6 +10,7 @@ + @@ -754,11 +755,10 @@ - Shiboken::AutoDecRef __object__(PyList_New(count)); + PyObject *%out = PyList_New(count); for (int i=0; i < count; i++) { - PyList_SET_ITEM(__object__.object(), i, %CONVERTTOPYTHON[int](%in[i])); + PyList_SET_ITEM(%out, i, %CONVERTTOPYTHON[int](%in[i])); } - PyObject *%out = __object__.object(); -- cgit v1.2.3