diff options
author | David Boddie <dboddie@trolltech.com> | 2010-06-30 17:06:37 (GMT) |
---|---|---|
committer | David Boddie <dboddie@trolltech.com> | 2010-06-30 17:06:37 (GMT) |
commit | 0713442baa4120050e85c13998797415bb40efce (patch) | |
tree | 2735cae5573363fd5edceae71ae8b7af60518df2 /tests/auto/qsemaphore/tst_qsemaphore.cpp | |
parent | 08478207ee9a6563ae63ebcef833925db6426bd8 (diff) | |
parent | 01648005f1f546dc0281155fecd94b4f47a94584 (diff) | |
download | Qt-0713442baa4120050e85c13998797415bb40efce.zip Qt-0713442baa4120050e85c13998797415bb40efce.tar.gz Qt-0713442baa4120050e85c13998797415bb40efce.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-2 into 4.7
Conflicts:
tools/qdoc3/test/qt-html-templates.qdocconf
Diffstat (limited to 'tests/auto/qsemaphore/tst_qsemaphore.cpp')
-rw-r--r-- | tests/auto/qsemaphore/tst_qsemaphore.cpp | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/tests/auto/qsemaphore/tst_qsemaphore.cpp b/tests/auto/qsemaphore/tst_qsemaphore.cpp index ace33dc..7cede30 100644 --- a/tests/auto/qsemaphore/tst_qsemaphore.cpp +++ b/tests/auto/qsemaphore/tst_qsemaphore.cpp @@ -63,6 +63,7 @@ private slots: void tryAcquire(); void tryAcquireWithTimeout_data(); void tryAcquireWithTimeout(); + void tryAcquireWithTimeoutStarvation(); void release(); void available(); void producerConsumer(); @@ -232,8 +233,8 @@ void tst_QSemaphore::tryAcquireWithTimeout_data() { QTest::addColumn<int>("timeout"); - QTest::newRow("") << 1000; - QTest::newRow("") << 10000; + QTest::newRow("1s") << 1000; + QTest::newRow("10s") << 10000; } void tst_QSemaphore::tryAcquireWithTimeout() @@ -316,6 +317,50 @@ void tst_QSemaphore::tryAcquireWithTimeout() QCOMPARE(semaphore.available(), 0); } +void tst_QSemaphore::tryAcquireWithTimeoutStarvation() +{ + class Thread : public QThread + { + public: + QSemaphore startup; + QSemaphore *semaphore; + int amountToConsume, timeout; + + void run() + { + startup.release(); + forever { + if (!semaphore->tryAcquire(amountToConsume, timeout)) + break; + semaphore->release(amountToConsume); + } + } + }; + + QSemaphore semaphore; + semaphore.release(1); + + Thread consumer; + consumer.semaphore = &semaphore; + consumer.amountToConsume = 1; + consumer.timeout = 1000; + + // start the thread and wait for it to start consuming + consumer.start(); + consumer.startup.acquire(); + + // try to consume more than the thread we started is, and provide a longer + // timeout... we should timeout, not wait indefinitely + QVERIFY(!semaphore.tryAcquire(consumer.amountToConsume * 2, consumer.timeout * 2)); + + // the consumer should still be running + QVERIFY(consumer.isRunning() && !consumer.isFinished()); + + // acquire, and wait for smallConsumer to timeout + semaphore.acquire(); + QVERIFY(consumer.wait()); +} + void tst_QSemaphore::release() { DEPENDS_ON("acquire"); } |