diff options
author | Hugo Parente Lima <hugo.pl@gmail.com> | 2011-05-17 16:34:08 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:54:23 -0300 |
commit | 952f9f0bda958afa36421c6af828f55f643a3deb (patch) | |
tree | 73ea5825f48defad774d8e87c75c087a4bc0ae83 /tests/QtCore/bug_686.py | |
parent | c27dceaaab0d35aa0227157d6901ab96faf78e93 (diff) |
Fix bug 686 - "Request to make Q[Mutex|Read|Write]Locker context managers"
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>
Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'tests/QtCore/bug_686.py')
-rw-r--r-- | tests/QtCore/bug_686.py | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/QtCore/bug_686.py b/tests/QtCore/bug_686.py new file mode 100644 index 000000000..97ead98f5 --- /dev/null +++ b/tests/QtCore/bug_686.py @@ -0,0 +1,85 @@ +import unittest +from PySide.QtCore import * + +class MyWriteThread(QThread): + def __init__(self, lock): + QThread.__init__(self) + self.lock = lock + self.started = False + self.canQuit = False + + def run(self): + self.started = True + while not self.lock.tryLockForWrite(): + pass + self.canQuit = True + +class MyReadThread(QThread): + def __init__(self, lock): + QThread.__init__(self) + self.lock = lock + self.started = False + self.canQuit = False + + def run(self): + self.started = True + while not self.lock.tryLockForRead(): + pass + self.canQuit = True + +class MyMutexedThread(QThread): + def __init__(self, mutex): + QThread.__init__(self) + self.mutex = mutex + self.started = False + self.canQuit = False + + def run(self): + self.started = True + while not self.mutex.tryLock(): + pass + self.canQuit = True + +class TestQMutex (unittest.TestCase): + + def testReadLocker(self): + lock = QReadWriteLock() + thread = MyWriteThread(lock) + + with QReadLocker(lock): + thread.start() + while not thread.started: + pass + self.assertFalse(thread.canQuit) + + thread.wait() + self.assertTrue(thread.canQuit) + + def testWriteLocker(self): + lock = QReadWriteLock() + thread = MyReadThread(lock) + + with QWriteLocker(lock): + thread.start() + while not thread.started: + pass + self.assertFalse(thread.canQuit) + + thread.wait() + self.assertTrue(thread.canQuit) + + def testMutexLocker(self): + mutex = QMutex() + thread = MyMutexedThread(mutex) + + with QMutexLocker(mutex): + thread.start() + while not thread.started: + pass + self.assertFalse(thread.canQuit) + + thread.wait() + self.assertTrue(thread.canQuit) + +if __name__ == '__main__': + unittest.main() |