From 47d4a1f545eb7f348e46d39230a73a1b465e57a4 Mon Sep 17 00:00:00 2001 From: Marcelo Lira Date: Mon, 31 May 2010 15:25:12 -0300 Subject: Generator improved to handle protected enums without the protected hack. --- tests/libsample/protected.h | 6 ++++++ tests/samplebinding/protected_test.py | 36 +++++++++++++++++++++++++++---- tests/samplebinding/typesystem_sample.xml | 2 +- 3 files changed, 39 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/libsample/protected.h b/tests/libsample/protected.h index abbbf2930..d8d55a40f 100644 --- a/tests/libsample/protected.h +++ b/tests/libsample/protected.h @@ -111,6 +111,10 @@ class LIBSAMPLE_API ProtectedEnumClass public: ProtectedEnumClass() {} virtual ~ProtectedEnumClass() {} + enum PublicEnum { + PublicItem0, + PublicItem1 + }; protected: enum ProtectedEnum { ProtectedItem0, @@ -118,6 +122,8 @@ protected: }; ProtectedEnum callProtectedEnumMethod(ProtectedEnum in) { return protectedEnumMethod(in); } virtual ProtectedEnum protectedEnumMethod(ProtectedEnum in) { return in; } + PublicEnum callPublicEnumMethod(PublicEnum in) { return publicEnumMethod(in); } + virtual PublicEnum publicEnumMethod(PublicEnum in) { return in; } }; #endif // PROTECTED_H diff --git a/tests/samplebinding/protected_test.py b/tests/samplebinding/protected_test.py index 6a5f732c9..efb0bedbf 100755 --- a/tests/samplebinding/protected_test.py +++ b/tests/samplebinding/protected_test.py @@ -185,12 +185,16 @@ class ExtendedProtectedEnumClass(ProtectedEnumClass): if value == ProtectedEnumClass.ProtectedItem0: return ProtectedEnumClass.ProtectedItem1 return ProtectedEnumClass.ProtectedItem0 + def publicEnumMethod(self, value): + if value == ProtectedEnumClass.PublicItem0: + return ProtectedEnumClass.PublicItem1 + return ProtectedEnumClass.PublicItem0 class ProtectedEnumTest(unittest.TestCase): '''Test cases for protected enum.''' - def testProtectedEnum(self): - '''Original protected method is being called.''' + def testProtectedMethodWithProtectedEnumArgument(self): + '''Calls protected method with protected enum argument.''' obj = ProtectedEnumClass() self.assertEqual(type(ProtectedEnumClass.ProtectedItem0), ProtectedEnumClass.ProtectedEnum) @@ -201,8 +205,18 @@ class ProtectedEnumTest(unittest.TestCase): self.assertEqual(obj.callProtectedEnumMethod(ProtectedEnumClass.ProtectedItem0), ProtectedEnumClass.ProtectedItem0) self.assertEqual(obj.callProtectedEnumMethod(ProtectedEnumClass.ProtectedItem1), ProtectedEnumClass.ProtectedItem1) - def testProtectedEnumWithMethodOverride(self): - '''Overridden protected method is being called.''' + def testProtectedMethodWithPublicEnumArgument(self): + '''Calls protected method with public enum argument.''' + obj = ProtectedEnumClass() + + self.assertEqual(obj.publicEnumMethod(ProtectedEnumClass.PublicItem0), ProtectedEnumClass.PublicItem0) + self.assertEqual(obj.publicEnumMethod(ProtectedEnumClass.PublicItem1), ProtectedEnumClass.PublicItem1) + + self.assertEqual(obj.callPublicEnumMethod(ProtectedEnumClass.PublicItem0), ProtectedEnumClass.PublicItem0) + self.assertEqual(obj.callPublicEnumMethod(ProtectedEnumClass.PublicItem1), ProtectedEnumClass.PublicItem1) + + def testOverriddenProtectedMethodWithProtectedEnumArgument(self): + '''Calls overridden protected method with protected enum argument.''' obj = ExtendedProtectedEnumClass() self.assertEqual(obj.protectedEnumMethod(ProtectedEnumClass.ProtectedItem0), ProtectedEnumClass.ProtectedItem1) @@ -214,6 +228,20 @@ class ProtectedEnumTest(unittest.TestCase): self.assertEqual(obj.callProtectedEnumMethod(ProtectedEnumClass.ProtectedItem0), ProtectedEnumClass.ProtectedItem1) self.assertEqual(obj.callProtectedEnumMethod(ProtectedEnumClass.ProtectedItem1), ProtectedEnumClass.ProtectedItem0) + def testOverriddenProtectedMethodWithPublicEnumArgument(self): + '''Calls overridden protected method with public enum argument.''' + obj = ExtendedProtectedEnumClass() + + self.assertEqual(obj.publicEnumMethod(ProtectedEnumClass.PublicItem0), ProtectedEnumClass.PublicItem1) + self.assertEqual(obj.publicEnumMethod(ProtectedEnumClass.PublicItem1), ProtectedEnumClass.PublicItem0) + + self.assertEqual(ProtectedEnumClass.publicEnumMethod(obj, ProtectedEnumClass.PublicItem0), ProtectedEnumClass.PublicItem0) + self.assertEqual(ProtectedEnumClass.publicEnumMethod(obj, ProtectedEnumClass.PublicItem1), ProtectedEnumClass.PublicItem1) + + self.assertEqual(obj.callPublicEnumMethod(ProtectedEnumClass.PublicItem0), ProtectedEnumClass.PublicItem1) + self.assertEqual(obj.callPublicEnumMethod(ProtectedEnumClass.PublicItem1), ProtectedEnumClass.PublicItem0) + + if __name__ == '__main__': unittest.main() diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index 2a905f234..e53486fcc 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -280,9 +280,9 @@ - // Receives and returns the same protected enum item. +