Remove Q_ASSERT's from QMutex autotest
authorJason McDonald <jason.mcdonald@nokia.com>
Fri, 6 May 2011 06:55:31 +0000 (16:55 +1000)
committerRohan McGovern <rohan.mcgovern@nokia.com>
Wed, 18 May 2011 00:46:46 +0000 (10:46 +1000)
Don't perform actions needed for the test inside Q_ASSERT, because these
actions won't happen in a non-debug build. Instead count the number of
failures and verify that the count is zero at the end of the test.

Change-Id: Ibe0d194111e5247118d59a7760f0946d2c44faf9
Task-number: QTBUG-17582
Reviewed-by: Rohan McGovern
(cherry picked from commit 8d2127d44e6c8af6b041688376de0e5747a1810a)

tests/auto/qmutex/tst_qmutex.cpp

index 99fa985..c3b3575 100644 (file)
@@ -462,6 +462,7 @@ public:
     static QBasicAtomicInt lockCount;
     static QBasicAtomicInt sentinel;
     static QMutex mutex;
+    static int errorCount;
     void start()
     {
         t.start();
@@ -471,13 +472,13 @@ public:
     {
         while (t.elapsed() < one_minute) {
             mutex.lock();
-            Q_ASSERT(!sentinel.ref());
-            Q_ASSERT(sentinel.deref());
+            if (sentinel.ref()) ++errorCount;
+            if (!sentinel.deref()) ++errorCount;
             lockCount.ref();
             mutex.unlock();
             if (mutex.tryLock()) {
-                Q_ASSERT(!sentinel.ref());
-                Q_ASSERT(sentinel.deref());
+                if (sentinel.ref()) ++errorCount;
+                if (!sentinel.deref()) ++errorCount;
                 lockCount.ref();
                 mutex.unlock();
             }
@@ -487,6 +488,7 @@ public:
 QMutex StressTestThread::mutex;
 QBasicAtomicInt StressTestThread::lockCount = Q_BASIC_ATOMIC_INITIALIZER(0);
 QBasicAtomicInt StressTestThread::sentinel = Q_BASIC_ATOMIC_INITIALIZER(-1);
+int StressTestThread::errorCount = 0;
 
 void tst_QMutex::stressTest()
 {
@@ -496,6 +498,7 @@ void tst_QMutex::stressTest()
     QVERIFY(threads[0].wait(one_minute + 10000));
     for (int i = 1; i < threadCount; ++i)
         QVERIFY(threads[i].wait(10000));
+    QCOMPARE(StressTestThread::errorCount, 0);
     qDebug("locked %d times", int(StressTestThread::lockCount));
 }