summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/thread
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/thread')
-rw-r--r--tests/auto/corelib/thread/qfuture/tst_qfuture.cpp2
-rw-r--r--tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp50
-rw-r--r--tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp34
3 files changed, 52 insertions, 34 deletions
diff --git a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp
index a546cad225..37b052bf1d 100644
--- a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp
+++ b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp
@@ -1205,8 +1205,6 @@ void tst_QFuture::pause()
Interface.reportFinished();
}
-const int resultCount = 1000;
-
class ResultObject : public QObject
{
Q_OBJECT
diff --git a/tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp b/tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp
index 2970b2e118..ba470a77c9 100644
--- a/tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp
+++ b/tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp
@@ -42,6 +42,7 @@ private slots:
void tryAcquireWithTimeout();
void tryAcquireWithTimeoutStarvation();
void producerConsumer();
+ void raii();
};
static QSemaphore *semaphore = 0;
@@ -417,5 +418,54 @@ void tst_QSemaphore::producerConsumer()
consumer.wait();
}
+void tst_QSemaphore::raii()
+{
+ QSemaphore sem;
+
+ QCOMPARE(sem.available(), 0);
+
+ // basic operation:
+ {
+ QSemaphoreReleaser r0;
+ const QSemaphoreReleaser r1(sem);
+ const QSemaphoreReleaser r2(sem, 2);
+
+ QCOMPARE(r0.semaphore(), nullptr);
+ QCOMPARE(r1.semaphore(), &sem);
+ QCOMPARE(r2.semaphore(), &sem);
+ }
+
+ QCOMPARE(sem.available(), 3);
+
+ // cancel:
+ {
+ const QSemaphoreReleaser r1(sem);
+ QSemaphoreReleaser r2(sem, 2);
+
+ QCOMPARE(r2.cancel(), &sem);
+ QCOMPARE(r2.semaphore(), nullptr);
+ }
+
+ QCOMPARE(sem.available(), 4);
+
+ // move-assignment:
+ {
+ const QSemaphoreReleaser r1(sem);
+ QSemaphoreReleaser r2(sem, 2);
+
+ QCOMPARE(sem.available(), 4);
+
+ r2 = QSemaphoreReleaser();
+
+ QCOMPARE(sem.available(), 6);
+
+ r2 = QSemaphoreReleaser(sem, 42);
+
+ QCOMPARE(sem.available(), 6);
+ }
+
+ QCOMPARE(sem.available(), 49);
+}
+
QTEST_MAIN(tst_QSemaphore)
#include "tst_qsemaphore.moc"
diff --git a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp
index fdc4ecb5c8..1dcd642023 100644
--- a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp
+++ b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp
@@ -961,21 +961,6 @@ void tst_QThreadPool::cancel()
QSemaphore sem(0);
QSemaphore startedThreads(0);
- class SemaphoreReleaser
- {
- QSemaphore &sem;
- int n;
- Q_DISABLE_COPY(SemaphoreReleaser)
- public:
- explicit SemaphoreReleaser(QSemaphore &sem, int n)
- : sem(sem), n(n) {}
-
- ~SemaphoreReleaser()
- {
- sem.release(n);
- }
- };
-
class BlockingRunnable : public QRunnable
{
public:
@@ -1014,7 +999,7 @@ void tst_QThreadPool::cancel()
// ensure that the QThreadPool doesn't deadlock if any of the checks fail
// and cause an early return:
- const SemaphoreReleaser semReleaser(sem, runs);
+ const QSemaphoreReleaser semReleaser(sem, runs);
count.store(0);
QAtomicInt dtorCounter = 0;
@@ -1048,21 +1033,6 @@ void tst_QThreadPool::tryTake()
QSemaphore sem(0);
QSemaphore startedThreads(0);
- class SemaphoreReleaser
- {
- QSemaphore &sem;
- int n;
- Q_DISABLE_COPY(SemaphoreReleaser)
- public:
- explicit SemaphoreReleaser(QSemaphore &sem, int n)
- : sem(sem), n(n) {}
-
- ~SemaphoreReleaser()
- {
- sem.release(n);
- }
- };
-
class BlockingRunnable : public QRunnable
{
public:
@@ -1101,7 +1071,7 @@ void tst_QThreadPool::tryTake()
// ensure that the QThreadPool doesn't deadlock if any of the checks fail
// and cause an early return:
- const SemaphoreReleaser semReleaser(sem, Runs);
+ const QSemaphoreReleaser semReleaser(sem, Runs);
count.store(0);
QAtomicInt dtorCounter = 0;