aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2010-05-31 10:02:21 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2010-06-01 11:14:38 -0300
commitdfdc92fbe5288064987beb097f50a73a63d2546e (patch)
tree1159f3578a5d40c5b3d212906f35a84eddd1c0e3 /tests
parenta7ff3eba6db91b02b64fd3eb188c78c66b282c0b (diff)
Adds protected enum test cases.
Diffstat (limited to 'tests')
-rw-r--r--tests/libsample/protected.h14
-rw-r--r--tests/samplebinding/CMakeLists.txt1
-rwxr-xr-xtests/samplebinding/protected_test.py38
-rw-r--r--tests/samplebinding/typesystem_sample.xml5
4 files changed, 57 insertions, 1 deletions
diff --git a/tests/libsample/protected.h b/tests/libsample/protected.h
index 23b2f5ca..abbbf293 100644
--- a/tests/libsample/protected.h
+++ b/tests/libsample/protected.h
@@ -106,5 +106,19 @@ private:
static int dtor_called;
};
+class LIBSAMPLE_API ProtectedEnumClass
+{
+public:
+ ProtectedEnumClass() {}
+ virtual ~ProtectedEnumClass() {}
+protected:
+ enum ProtectedEnum {
+ ProtectedItem0,
+ ProtectedItem1
+ };
+ ProtectedEnum callProtectedEnumMethod(ProtectedEnum in) { return protectedEnumMethod(in); }
+ virtual ProtectedEnum protectedEnumMethod(ProtectedEnum in) { return in; }
+};
+
#endif // PROTECTED_H
diff --git a/tests/samplebinding/CMakeLists.txt b/tests/samplebinding/CMakeLists.txt
index 46d666fb..8775802b 100644
--- a/tests/samplebinding/CMakeLists.txt
+++ b/tests/samplebinding/CMakeLists.txt
@@ -47,6 +47,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/pointerholder_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/polygon_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/privatector_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/privatedtor_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/protectedenumclass_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/protectednonpolymorphic_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/protectedpolymorphic_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/protectedpolymorphicdaughter_wrapper.cpp
diff --git a/tests/samplebinding/protected_test.py b/tests/samplebinding/protected_test.py
index dd4175d8..6a5f732c 100755
--- a/tests/samplebinding/protected_test.py
+++ b/tests/samplebinding/protected_test.py
@@ -26,11 +26,11 @@
'''Test cases for protected methods.'''
-import os
import unittest
from sample import ProtectedNonPolymorphic, ProtectedVirtualDestructor
from sample import ProtectedPolymorphic, ProtectedPolymorphicDaughter, ProtectedPolymorphicGrandDaughter
+from sample import ProtectedEnumClass
from sample import Point
class ExtendedProtectedPolymorphic(ProtectedPolymorphic):
@@ -178,6 +178,42 @@ class ProtectedVirtualDtorTest(unittest.TestCase):
self.assertEqual(ExtendedProtectedVirtualDestructor.dtorCalled(), dtor_called + i)
+class ExtendedProtectedEnumClass(ProtectedEnumClass):
+ def __init__(self):
+ ProtectedEnumClass.__init__(self)
+ def protectedEnumMethod(self, value):
+ if value == ProtectedEnumClass.ProtectedItem0:
+ return ProtectedEnumClass.ProtectedItem1
+ return ProtectedEnumClass.ProtectedItem0
+
+class ProtectedEnumTest(unittest.TestCase):
+ '''Test cases for protected enum.'''
+
+ def testProtectedEnum(self):
+ '''Original protected method is being called.'''
+ obj = ProtectedEnumClass()
+
+ self.assertEqual(type(ProtectedEnumClass.ProtectedItem0), ProtectedEnumClass.ProtectedEnum)
+
+ self.assertEqual(obj.protectedEnumMethod(ProtectedEnumClass.ProtectedItem0), ProtectedEnumClass.ProtectedItem0)
+ self.assertEqual(obj.protectedEnumMethod(ProtectedEnumClass.ProtectedItem1), ProtectedEnumClass.ProtectedItem1)
+
+ 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.'''
+ obj = ExtendedProtectedEnumClass()
+
+ self.assertEqual(obj.protectedEnumMethod(ProtectedEnumClass.ProtectedItem0), ProtectedEnumClass.ProtectedItem1)
+ self.assertEqual(obj.protectedEnumMethod(ProtectedEnumClass.ProtectedItem1), ProtectedEnumClass.ProtectedItem0)
+
+ self.assertEqual(ProtectedEnumClass.protectedEnumMethod(obj, ProtectedEnumClass.ProtectedItem0), ProtectedEnumClass.ProtectedItem0)
+ self.assertEqual(ProtectedEnumClass.protectedEnumMethod(obj, ProtectedEnumClass.ProtectedItem1), ProtectedEnumClass.ProtectedItem1)
+
+ self.assertEqual(obj.callProtectedEnumMethod(ProtectedEnumClass.ProtectedItem0), ProtectedEnumClass.ProtectedItem1)
+ self.assertEqual(obj.callProtectedEnumMethod(ProtectedEnumClass.ProtectedItem1), ProtectedEnumClass.ProtectedItem0)
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index 3b0eb906..2a905f23 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -279,6 +279,11 @@
</modify-function>
</object-type>
+
+ // Receives and returns the same protected enum item.
+ <object-type name="ProtectedEnumClass" />
+ <enum-type name="ProtectedEnumClass::ProtectedEnum" />
+
<template name="boolptr_at_end_fix_beginning">
bool __ok__;
%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](