aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/tests
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2018-02-28 10:30:27 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2018-02-28 14:01:37 +0000
commit44cb6c51e6c3b43376f284941454dc8c13b81c3f (patch)
tree7e9fda1ba3788a3b9ed051e853b08926d325df6f /sources/shiboken2/tests
parent7c83f2ebc1ac55c6e2556c8c852716502dcdba5a (diff)
Type system: Add attribute indicating C++ 11 enum classes
Introduce enumeration for the type to EnumTypeEntry which can be specified by the boolean "class" attribute. For the enum classes, the value names need to be qualified by the enum name to match the C++ API. For the C++ generator, add an overload to Shiboken::createScopedEnumItem() that takes a PyTypeObject and add the enum items to the enum so that the name is in the enum scope. Change-Id: Ia0e469d13b08c196b9ddd965b9cf3cc62a38630b Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'sources/shiboken2/tests')
-rw-r--r--sources/shiboken2/tests/libsample/objecttype.h6
-rw-r--r--sources/shiboken2/tests/samplebinding/enum_test.py5
-rw-r--r--sources/shiboken2/tests/samplebinding/typesystem_sample.xml1
3 files changed, 12 insertions, 0 deletions
diff --git a/sources/shiboken2/tests/libsample/objecttype.h b/sources/shiboken2/tests/libsample/objecttype.h
index 752659488..91fb45515 100644
--- a/sources/shiboken2/tests/libsample/objecttype.h
+++ b/sources/shiboken2/tests/libsample/objecttype.h
@@ -45,6 +45,12 @@ struct Event
SOME_EVENT,
ANY_EVENT
};
+
+ enum class EventTypeClass {
+ Value1,
+ Value2
+ };
+
Event(EventType eventType) : m_eventType(eventType) {}
EventType eventType() { return m_eventType; }
private:
diff --git a/sources/shiboken2/tests/samplebinding/enum_test.py b/sources/shiboken2/tests/samplebinding/enum_test.py
index 6468d3cc4..711215c35 100644
--- a/sources/shiboken2/tests/samplebinding/enum_test.py
+++ b/sources/shiboken2/tests/samplebinding/enum_test.py
@@ -110,6 +110,11 @@ class EnumTest(unittest.TestCase):
self.assertEqual(SampleNamespace.AnonymousClassEnum_Value0, 0)
self.assertEqual(SampleNamespace.AnonymousClassEnum_Value1, 1)
+ def testEnumClasses(self):
+ # C++ 11: values of enum classes need to be fully qualified to match C++
+ sum = Event.EventTypeClass.Value1 + Event.EventTypeClass.Value2
+ self.assertEqual(sum, 1)
+
def testEnumTpPrintImplementation(self):
'''Without SbkEnum.tp_print 'print' returns the enum represented as an int.'''
tmpfile = createTempFile()
diff --git a/sources/shiboken2/tests/samplebinding/typesystem_sample.xml b/sources/shiboken2/tests/samplebinding/typesystem_sample.xml
index ffb5c976f..5a12eeccd 100644
--- a/sources/shiboken2/tests/samplebinding/typesystem_sample.xml
+++ b/sources/shiboken2/tests/samplebinding/typesystem_sample.xml
@@ -798,6 +798,7 @@
<value-type name="Event">
<enum-type name="EventType"/>
+ <enum-type name="EventTypeClass" class="yes"/>
</value-type>
<value-type name="BlackBox">