aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-08-04 16:10:34 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:17:13 -0300
commit784a4bbb707d132b26bcb177521745575dc0823f (patch)
treef637ef4134445b1cfdd0c33878b7a1ce46f02145 /tests
parent8b1ddcd3ef711bab70bb7cdebc26558a26f42df9 (diff)
Implements PSEP-0106 and fixes bug 902 - "Expose Shiboken functionality through a Python module".
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt12
-rw-r--r--tests/libsample/objecttype.cpp6
-rw-r--r--tests/libsample/objecttype.h1
-rw-r--r--tests/samplebinding/typesystem_sample.xml6
-rw-r--r--tests/shibokenmodule/module_test.py70
5 files changed, 89 insertions, 6 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 6d8e41489..1c728dd98 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -23,7 +23,8 @@ if(DEFINED MINIMAL_TESTS)
else()
file(GLOB TEST_FILES minimalbinding/*_test.py
samplebinding/*_test.py
- otherbinding/*_test.py)
+ otherbinding/*_test.py
+ shibokenmodule/*_test.py)
endif()
list(SORT TEST_FILES)
@@ -38,7 +39,7 @@ if(CMAKE_VERSION VERSION_LESS 2.8)
message("CMake version greater than 2.8 necessary to run tests")
else()
if(WIN32)
- set(TEST_PYTHONPATH "${minimal_BINARY_DIR};${sample_BINARY_DIR};${other_BINARY_DIR}")
+ set(TEST_PYTHONPATH "${minimal_BINARY_DIR};${sample_BINARY_DIR};${other_BINARY_DIR};${shibokenmodule_BINARY_DIR}")
set(TEST_LIBRARY_PATH "$ENV{PATH};${libminimal_BINARY_DIR};${libsample_BINARY_DIR};${libother_BINARY_DIR};${libshiboken_BINARY_DIR}")
set(LIBRARY_PATH_VAR "PATH")
string(REPLACE "\\" "/" TEST_PYTHONPATH "${TEST_PYTHONPATH}")
@@ -46,14 +47,13 @@ else()
string(REPLACE ";" "\\;" TEST_PYTHONPATH "${TEST_PYTHONPATH}")
string(REPLACE ";" "\\;" TEST_LIBRARY_PATH "${TEST_LIBRARY_PATH}")
else()
- set(TEST_PYTHONPATH "${minimal_BINARY_DIR}:${sample_BINARY_DIR}:${other_BINARY_DIR}")
+ set(TEST_PYTHONPATH "${minimal_BINARY_DIR}:${sample_BINARY_DIR}:${other_BINARY_DIR}:${shibokenmodule_BINARY_DIR}")
set(TEST_LIBRARY_PATH "$ENV{LD_LIBRARY_PATH}:${libminimal_BINARY_DIR}:${libsample_BINARY_DIR}:${libother_BINARY_DIR}:${libshiboken_BINARY_DIR}")
set(LIBRARY_PATH_VAR "LD_LIBRARY_PATH")
endif()
-
foreach(test_file ${TEST_FILES})
- string(REGEX MATCH "/([^/]+)binding/([^/]+)_test.py" tmp ${test_file})
- set(test_name "${CMAKE_MATCH_1}_${CMAKE_MATCH_2}")
+ string(REGEX MATCH "/([^/]+)(binding|module)/([^/]+)_test.py" tmp ${test_file})
+ set(test_name "${CMAKE_MATCH_1}_${CMAKE_MATCH_3}")
list(FIND test_blacklist ${test_name} expect_fail)
add_test(${test_name} ${PYTHON_EXECUTABLE} ${test_file})
set_tests_properties(${test_name} PROPERTIES ENVIRONMENT "PYTHONPATH=${TEST_PYTHONPATH};${LIBRARY_PATH_VAR}=${TEST_LIBRARY_PATH}")
diff --git a/tests/libsample/objecttype.cpp b/tests/libsample/objecttype.cpp
index e4fce71e3..c253c610f 100644
--- a/tests/libsample/objecttype.cpp
+++ b/tests/libsample/objecttype.cpp
@@ -283,3 +283,9 @@ ObjectType* ObjectType::createChild(ObjectType* parent)
{
return new ObjectType(parent);
}
+
+std::size_t ObjectType::createObjectType()
+{
+ void* addr = new ObjectType();
+ return (std::size_t) addr;
+}
diff --git a/tests/libsample/objecttype.h b/tests/libsample/objecttype.h
index f032a09f8..84812a8d6 100644
--- a/tests/libsample/objecttype.h
+++ b/tests/libsample/objecttype.h
@@ -106,6 +106,7 @@ public:
virtual bool isPython() { return false; }
void callVirtualCreateChild();
virtual ObjectType* createChild(ObjectType* parent);
+ static std::size_t createObjectType();
//return a parent from C++
ObjectType* getCppParent() {
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index 2fef355fc..09de7b948 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -16,6 +16,7 @@
<primitive-type name="unsigned char"/>
<primitive-type name="long"/>
<primitive-type name="unsigned long"/>
+ <primitive-type name="std::size_t" target-lang-api-name="PyLong"/>
<primitive-type name="std::string"/>
<primitive-type name="Complex" target-lang-api-name="PyComplex">
@@ -303,6 +304,11 @@
</object-type>
<object-type name="ObjectView">
+ <modify-function signature="ObjectView(ObjectModel*, ObjectType*)">
+ <modify-argument index="1">
+ <reference-count action="set" variable-name="setModel(ObjectModel*)1"/>
+ </modify-argument>
+ </modify-function>
<modify-function signature="setModel(ObjectModel*)">
<modify-argument index="1">
<reference-count action="set"/>
diff --git a/tests/shibokenmodule/module_test.py b/tests/shibokenmodule/module_test.py
new file mode 100644
index 000000000..565e985aa
--- /dev/null
+++ b/tests/shibokenmodule/module_test.py
@@ -0,0 +1,70 @@
+import shiboken
+import unittest
+from sample import *
+
+class MultipleInherited (ObjectType, Point):
+ def __init__(self):
+ ObjectType.__init__(self)
+ Point.__init__(self)
+
+class TestShiboken(unittest.TestCase):
+ def testIsValid(self):
+ self.assertTrue(shiboken.isValid(object()))
+ self.assertTrue(shiboken.isValid(None))
+
+ bb = BlackBox()
+ item = ObjectType()
+ ticket = bb.keepObjectType(item)
+ bb.disposeObjectType(ticket)
+ self.assertFalse(shiboken.isValid(item))
+
+ def testWrapInstance(self):
+ addr = ObjectType.createObjectType()
+ obj = shiboken.wrapInstance(addr, ObjectType)
+ self.assertFalse(shiboken.wasCreatedByPython(obj))
+ obj.setObjectName("obj")
+ self.assertEqual(obj.objectName(), "obj")
+ self.assertEqual(addr, obj.identifier())
+ self.assertFalse(shiboken.wasCreatedByPython(obj))
+
+ # avoid mem leak =]
+ bb = BlackBox()
+ self.assertTrue(shiboken.wasCreatedByPython(bb))
+ bb.disposeObjectType(bb.keepObjectType(obj))
+
+ def testIsOwnedByPython(self):
+ obj = ObjectType()
+ self.assertTrue(shiboken.isOwnedByPython(obj))
+ p = ObjectType()
+ obj.setParent(p)
+ self.assertFalse(shiboken.isOwnedByPython(obj))
+
+ def testDump(self):
+ """Just check if dump doesn't crash on certain use cases"""
+ p = ObjectType()
+ obj = ObjectType(p)
+ obj2 = ObjectType(obj)
+ obj3 = ObjectType(obj)
+ self.assertEqual(shiboken.dump(None), "Ordinary Python type.")
+ shiboken.dump(obj)
+
+ model = ObjectModel(p)
+ v = ObjectView(model, p)
+ shiboken.dump(v)
+
+ m = MultipleInherited()
+ shiboken.dump(m)
+ self.assertEqual(len(shiboken.getCppPointer(m)), 2)
+
+ def testDelete(self):
+ obj = ObjectType()
+ child = ObjectType(obj)
+ self.assertTrue(shiboken.isValid(obj))
+ self.assertTrue(shiboken.isValid(child))
+ # Note: this test doesn't assure that the object dtor was really called
+ shiboken.delete(obj)
+ self.assertFalse(shiboken.isValid(obj))
+ self.assertFalse(shiboken.isValid(child))
+
+if __name__ == '__main__':
+ unittest.main()