aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2010-01-18 11:00:39 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2010-01-18 15:02:14 -0300
commitf8e64fa28917dfd7446f8710ec2a1a33ef06cebc (patch)
tree7a368c4f126e7a288894b0a1a4a1ff3814e92d5f
parentcd23ce8002ea34c5baabf060b3065b9cbb7618a3 (diff)
Expanded thread locking tests with two more cases.
Added a virtual method marked to allow threads and tests for C++ calling it and also a Python reimplemented version.
-rw-r--r--tests/libsample/bucket.cpp8
-rw-r--r--tests/libsample/bucket.h5
-rwxr-xr-xtests/samplebinding/lock_test.py30
-rw-r--r--tests/samplebinding/typesystem_sample.xml1
4 files changed, 42 insertions, 2 deletions
diff --git a/tests/libsample/bucket.cpp b/tests/libsample/bucket.cpp
index d9f42a0ac..d0da98a0c 100644
--- a/tests/libsample/bucket.cpp
+++ b/tests/libsample/bucket.cpp
@@ -69,3 +69,11 @@ void Bucket::unlock()
{
m_locked = false;
}
+
+bool Bucket::virtualBlockerMethod()
+{
+ lock();
+ // The return value was added just for diversity sake.
+ return true;
+}
+
diff --git a/tests/libsample/bucket.h b/tests/libsample/bucket.h
index 5da528dd6..d85b92235 100644
--- a/tests/libsample/bucket.h
+++ b/tests/libsample/bucket.h
@@ -48,9 +48,12 @@ public:
int pop();
bool empty();
void lock();
- bool locked() { return m_locked;}
+ bool locked() { return m_locked; }
void unlock();
+ virtual bool virtualBlockerMethod();
+ bool callVirtualBlockerMethodButYouDontKnowThis() { return virtualBlockerMethod(); }
+
private:
std::list<int> m_data;
diff --git a/tests/samplebinding/lock_test.py b/tests/samplebinding/lock_test.py
index 7b84d7429..9e0db9e1b 100755
--- a/tests/samplebinding/lock_test.py
+++ b/tests/samplebinding/lock_test.py
@@ -22,11 +22,20 @@ class Unlocker(threading.Thread):
self.bucket.unlock()
+class MyBucket(Bucket):
+
+ def __init__(self):
+ Bucket.__init__(self)
+
+ def virtualBlockerMethod(self):
+ self.lock()
+ return True
+
+
class TestLockUnlock(unittest.TestCase):
def testBasic(self):
'''Locking in C++ and releasing in a python thread'''
-
bucket = Bucket()
unlocker = Unlocker(bucket)
@@ -34,6 +43,25 @@ class TestLockUnlock(unittest.TestCase):
bucket.lock()
unlocker.join()
+ def testVirtualBlocker(self):
+ '''Same as the basic case but blocker method is a C++ virtual called from C++.'''
+ bucket = Bucket()
+ unlocker = Unlocker(bucket)
+
+ unlocker.start()
+ result = bucket.callVirtualBlockerMethodButYouDontKnowThis()
+ unlocker.join()
+ self.assert_(result)
+
+ def testReimplementedVirtualBlocker(self):
+ '''Same as the basic case but blocker method is a C++ virtual reimplemented in Python and called from C++.'''
+ mybucket = MyBucket()
+ unlocker = Unlocker(mybucket)
+
+ unlocker.start()
+ result = mybucket.callVirtualBlockerMethodButYouDontKnowThis()
+ unlocker.join()
+ self.assert_(result)
if __name__ == '__main__':
unittest.main()
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index e66384fad..ea6e48926 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -833,6 +833,7 @@
<object-type name="Bucket">
<modify-function signature="lock()" allow-thread="yes" />
+ <modify-function signature="virtualBlockerMethod()" allow-thread="yes"/>
</object-type>
<value-type name="Echo">