Remove Q_ASSERT calls that wrap side-effecting code.
authorJason McDonald <jason.mcdonald@nokia.com>
Fri, 15 Apr 2011 04:15:49 +0000 (14:15 +1000)
committerRohan McGovern <rohan.mcgovern@nokia.com>
Wed, 18 May 2011 00:59:10 +0000 (10:59 +1000)
In release mode builds, code inside Q_ASSERT macros is not executed, so
putting code with side-effects inside Q_ASSERT is not a good idea.

Task-number: QTBUG-17582
Change-Id: I1a5d8ccce666ee7b7f120bf9cbb49e30dac9add4
Reviewed-by: Rohan McGovern
(cherry picked from commit 1750a4351a8125756bf38a53d6d8312993c7d85e)

tests/auto/declarative/qmlvisual/tst_qmlvisual.cpp

index 2dbed3b..50c634f 100644 (file)
@@ -185,16 +185,22 @@ QString tst_qmlvisual::toTestScript(const QString &file, Mode mode)
     if (platformsuffix && (mode == UpdatePlatformVisuals || QFile::exists(testdata+QLatin1String(platformsuffix)+QDir::separator()+testname+".qml"))) {
         QString platformdir = testdata + QLatin1String(platformsuffix);
         if (mode == UpdatePlatformVisuals) {
-            Q_ASSERT(QDir().mkpath(platformdir));
+            if (!QDir().mkpath(platformdir)) {
+                qFatal("Cannot make path %s", qPrintable(platformdir));
+            }
             // Copy from base
             QDir dir(testdata,testname+".*");
             dir.setFilter(QDir::Files);
             QFileInfoList list = dir.entryInfoList();
             for (int i = 0; i < list.size(); ++i) {
                 QFile in(list.at(i).filePath());
-                Q_ASSERT(in.open(QIODevice::ReadOnly));
+                if (!in.open(QIODevice::ReadOnly)) {
+                    qFatal("Cannot open file %s: %s", qPrintable(in.fileName()), qPrintable(in.errorString()));
+                }
                 QFile out(platformdir + QDir::separator() + list.at(i).fileName());
-                Q_ASSERT(out.open(QIODevice::WriteOnly));
+                if (!out.open(QIODevice::WriteOnly)) {
+                    qFatal("Cannot open file %s: %s", qPrintable(out.fileName()), qPrintable(out.errorString()));
+                }
                 out.write(in.readAll());
             }
         }