aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2009-11-17 16:20:43 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2009-11-18 08:47:46 -0300
commit515d3e34046415007027a1749a7a3be2a8b7a534 (patch)
tree601160d7c800345bf2d62161e95b727fa7e4ad7f /tests
parent5a579efa850071ef06345a982611eb19995f8187 (diff)
Added support for the type system "invalidate-after-use" argument modification.
The Python wrapper object produced for an argument received from C++ on a virtual method call is marked as invalid after the call to the Python override. If the Python script keeps the wrapper and try to use it afterwards a RuntimeError exception is raised. Test cases were added using the ObjectType::event method and the new Event class.
Diffstat (limited to 'tests')
-rw-r--r--tests/libsample/objecttype.cpp8
-rw-r--r--tests/libsample/objecttype.h19
-rw-r--r--tests/samplebinding/CMakeLists.txt1
-rwxr-xr-xtests/samplebinding/objecttype_test.py21
-rw-r--r--tests/samplebinding/typesystem_sample.xml8
5 files changed, 53 insertions, 4 deletions
diff --git a/tests/libsample/objecttype.cpp b/tests/libsample/objecttype.cpp
index cc4733040..e6a42d6d8 100644
--- a/tests/libsample/objecttype.cpp
+++ b/tests/libsample/objecttype.cpp
@@ -84,7 +84,13 @@ ObjectType::objectName() const
return *m_objectName;
}
-bool ObjectType::event()
+bool ObjectType::causeEvent(Event::EventType eventType)
+{
+ Event e(eventType);
+ return this->event(&e);
+}
+
+bool ObjectType::event(Event* event)
{
return true;
}
diff --git a/tests/libsample/objecttype.h b/tests/libsample/objecttype.h
index e5383524b..f75bbeb35 100644
--- a/tests/libsample/objecttype.h
+++ b/tests/libsample/objecttype.h
@@ -38,6 +38,20 @@
#include <list>
#include "str.h"
+struct Event
+{
+ enum EventType {
+ NO_EVENT,
+ BASIC_EVENT,
+ SOME_EVENT,
+ ANY_EVENT
+ };
+ Event(EventType eventType) : m_eventType(eventType) {}
+ EventType eventType() { return m_eventType; }
+private:
+ EventType m_eventType;
+};
+
class ObjectType
{
public:
@@ -53,7 +67,10 @@ public:
Str objectName() const;
void setObjectName(const Str& name);
- virtual bool event();
+ bool causeEvent(Event::EventType eventType);
+
+ // Returns true if the event is processed.
+ virtual bool event(Event* event);
private:
ObjectType(const ObjectType&);
diff --git a/tests/samplebinding/CMakeLists.txt b/tests/samplebinding/CMakeLists.txt
index 7e946d5b2..af73a6bdb 100644
--- a/tests/samplebinding/CMakeLists.txt
+++ b/tests/samplebinding/CMakeLists.txt
@@ -10,6 +10,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/abstract_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/collector_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/derived_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/echo_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/event_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/implicitconv_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/intwrapper_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/injectcode_wrapper.cpp
diff --git a/tests/samplebinding/objecttype_test.py b/tests/samplebinding/objecttype_test.py
index 6b310265c..c442ec7e8 100755
--- a/tests/samplebinding/objecttype_test.py
+++ b/tests/samplebinding/objecttype_test.py
@@ -29,7 +29,19 @@
import sys
import unittest
-from sample import ObjectType, Str
+from sample import ObjectType, Event, Str
+
+
+class ExtObjectType(ObjectType):
+ def __init__(self):
+ ObjectType.__init__(self)
+ self.type_of_last_event = None
+ self.last_event = None
+ def event(self, event):
+ self.last_event = event
+ self.type_of_last_event = event.eventType()
+ return True
+
class ObjectTypeTest(unittest.TestCase):
'''Test cases ObjectType class of object-type with privates copy constructor and = operator.'''
@@ -54,6 +66,13 @@ class ObjectTypeTest(unittest.TestCase):
o.setObjectName('object name')
self.assertEqual(str(o.objectName()), 'object name')
+ def testInvalidateAfterUse(self):
+ '''In ObjectType.event(Event*) the wrapper object created for Event must me marked as invalid after the method is called.'''
+ o = ExtObjectType()
+ o.causeEvent(Event.SOME_EVENT)
+ self.assertEqual(o.type_of_last_event, Event.SOME_EVENT)
+ self.assertRaises(RuntimeError, o.last_event.eventType)
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index 56774bd15..9196e0b96 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -50,6 +50,7 @@
<enum-type name="GlobalOverloadFuncEnum"/>
<enum-type name="Overload::FunctionEnum"/>
<enum-type name="Overload::ParamEnum"/>
+ <enum-type name="Event::EventType"/>
<namespace-type name="SampleNamespace"/>
@@ -59,7 +60,12 @@
<object-type name="Derived"/>
- <object-type name="ObjectType"/>
+ <object-type name="ObjectType">
+ <modify-function signature="event(Event*)">
+ <modify-argument index="1" invalidate-after-use="yes"/>
+ </modify-function>
+ </object-type>
+ <value-type name="Event"/>
<template name="boolptr_at_end_fix_beginning">
bool __ok__;