summaryrefslogtreecommitdiffstats
path: root/tests/auto/compilerwarnings
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2009-03-23 09:34:13 (GMT)
committerSimon Hausmann <simon.hausmann@nokia.com>2009-03-23 09:34:13 (GMT)
commit67ad0519fd165acee4a4d2a94fa502e9e4847bd0 (patch)
tree1dbf50b3dff8d5ca7e9344733968c72704eb15ff /tests/auto/compilerwarnings
downloadQt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.zip
Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.tar.gz
Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.tar.bz2
Long live Qt!
Diffstat (limited to 'tests/auto/compilerwarnings')
-rw-r--r--tests/auto/compilerwarnings/.gitignore1
-rw-r--r--tests/auto/compilerwarnings/compilerwarnings.pro5
-rw-r--r--tests/auto/compilerwarnings/compilerwarnings.qrc5
-rw-r--r--tests/auto/compilerwarnings/test.cpp67
-rw-r--r--tests/auto/compilerwarnings/tst_compilerwarnings.cpp253
5 files changed, 331 insertions, 0 deletions
diff --git a/tests/auto/compilerwarnings/.gitignore b/tests/auto/compilerwarnings/.gitignore
new file mode 100644
index 0000000..3d70caf
--- /dev/null
+++ b/tests/auto/compilerwarnings/.gitignore
@@ -0,0 +1 @@
+tst_compilerwarnings
diff --git a/tests/auto/compilerwarnings/compilerwarnings.pro b/tests/auto/compilerwarnings/compilerwarnings.pro
new file mode 100644
index 0000000..9e16c5e
--- /dev/null
+++ b/tests/auto/compilerwarnings/compilerwarnings.pro
@@ -0,0 +1,5 @@
+load(qttest_p4)
+SOURCES += tst_compilerwarnings.cpp
+QT = core
+
+RESOURCES = compilerwarnings.qrc
diff --git a/tests/auto/compilerwarnings/compilerwarnings.qrc b/tests/auto/compilerwarnings/compilerwarnings.qrc
new file mode 100644
index 0000000..40fa8f1
--- /dev/null
+++ b/tests/auto/compilerwarnings/compilerwarnings.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+ <qresource>
+ <file>test.cpp</file>
+ </qresource>
+ </RCC>
diff --git a/tests/auto/compilerwarnings/test.cpp b/tests/auto/compilerwarnings/test.cpp
new file mode 100644
index 0000000..d5dd2ee
--- /dev/null
+++ b/tests/auto/compilerwarnings/test.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtCore/QtCore>
+#include <QtNetwork/QtNetwork>
+#include <QtXml/QtXml>
+#include <QtSql/QtSql>
+#include <QtGui/QtGui>
+
+#ifndef QT_NO_OPENGL
+#include <QtOpenGL/QtOpenGL>
+#endif
+
+#include <QtDesigner/QtDesigner>
+
+#include <QtTest/QtTest>
+
+#if !defined(QT_NO_DBUS) && defined(Q_OS_UNIX)
+#include <QtDBus/QtDBus>
+#endif
+
+#ifndef Q_OS_MAC
+int main(int, char **)
+{
+ return 0;
+}
+#endif
+
diff --git a/tests/auto/compilerwarnings/tst_compilerwarnings.cpp b/tests/auto/compilerwarnings/tst_compilerwarnings.cpp
new file mode 100644
index 0000000..232af55
--- /dev/null
+++ b/tests/auto/compilerwarnings/tst_compilerwarnings.cpp
@@ -0,0 +1,253 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <qcoreapplication.h>
+#include <qprocess.h>
+#include <qtemporaryfile.h>
+#include <qdebug.h>
+
+#include <QtTest/QtTest>
+
+#include <stdlib.h>
+
+QT_USE_NAMESPACE
+
+class tst_CompilerWarnings: public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void warnings_data();
+ void warnings();
+};
+
+#if 0
+/*
+ Return list of all documented qfeatures (QT_NO_*)
+ */
+static QStringList getFeatures()
+{
+ QStringList srcDirs;
+ srcDirs << QString::fromLocal8Bit(getenv("QTDIR"))
+ << QString::fromLocal8Bit(getenv("QTSRCDIR"));
+
+ QString featurefile;
+ foreach (QString dir, srcDirs) {
+ QString str = dir + "/src/corelib/global/qfeatures.txt";
+ if (QFile::exists(str)) {
+ featurefile = str;
+ break;
+ }
+ }
+
+ if (featurefile.isEmpty()) {
+ qWarning("Unable to find qfeatures.txt");
+ return QStringList();
+ }
+
+ QFile file(featurefile);
+ if (!file.open(QIODevice::ReadOnly)) {
+ qWarning("Unable to open feature file '%s'", qPrintable(featurefile));
+ return QStringList();
+ }
+
+ QStringList features;
+ QTextStream s(&file);
+ QRegExp regexp("Feature:\\s+(\\w+)\\s*");
+ for (QString line = s.readLine(); !s.atEnd(); line = s.readLine()) {
+ if (regexp.exactMatch(line))
+ features << regexp.cap(1);
+ }
+
+ return features;
+}
+#endif
+
+void tst_CompilerWarnings::warnings_data()
+{
+ QTest::addColumn<QStringList>("cflags");
+
+ QTest::newRow("standard") << QStringList();
+
+#if 0
+#ifdef Q_WS_QWS
+ QStringList features = getFeatures();
+ foreach (QString feature, features) {
+ QStringList args;
+ QString macro = QString("QT_NO_%1").arg(feature);
+ args << (QString("-D%1").arg(macro));
+ QTest::newRow(qPrintable(macro)) << args;
+ }
+#endif
+#endif
+}
+
+void tst_CompilerWarnings::warnings()
+{
+ QFETCH(QStringList, cflags);
+
+#if !defined(Q_CC_INTEL) && defined(Q_CC_GNU) && __GNUC__ == 3
+ QSKIP("gcc 3.x outputs too many bogus warnings", SkipAll);
+#endif
+
+ static QString tmpFile;
+ if (tmpFile.isEmpty()) {
+ QTemporaryFile tmpQFile;
+ tmpQFile.open();
+ tmpFile = tmpQFile.fileName();
+ tmpQFile.close();
+ }
+ static QString tmpSourceFile;
+ bool openResult = true;
+ QString templatePath = QDir::temp().absoluteFilePath("XXXXXX-test.cpp");
+ QTemporaryFile tmpQSourceFile(templatePath);
+ if (tmpSourceFile.isEmpty()) {
+ tmpQSourceFile.open();
+ tmpSourceFile = tmpQSourceFile.fileName();
+ QFile cppSource(":/test.cpp");
+ bool openResult = cppSource.open(QIODevice::ReadOnly);
+ if (openResult)
+ {
+ QTextStream in(&cppSource);
+ QTextStream out(&tmpQSourceFile);
+ out << in.readAll();
+ }
+ }
+ QVERIFY2(openResult, "Need resource temporary \"test.cpp\"");
+
+ QStringList args;
+ QString compilerName;
+
+ static QString qtDir = QString::fromLocal8Bit(getenv("QTDIR"));
+ QVERIFY2(!qtDir.isEmpty(), "This test needs $QTDIR");
+
+ args << cflags;
+#if !defined(Q_CC_INTEL) && defined(Q_CC_GNU)
+ compilerName = "g++";
+ args << "-I" + qtDir + "/include";
+ args << "-I/usr/X11R6/include/";
+#ifdef Q_OS_HPUX
+ args << "-I/usr/local/mesa/aCC-64/include";
+#endif
+ args << "-c";
+ args << "-Wall" << "-Wold-style-cast" << "-Woverloaded-virtual" << "-pedantic" << "-ansi"
+ << "-Wno-long-long" << "-Wshadow" << "-Wpacked" << "-Wunreachable-code"
+ << "-Wundef" << "-Wchar-subscripts" << "-Wformat-nonliteral" << "-Wformat-security"
+ << "-Wcast-align"
+#if QT_VERSION >= 0x040100
+ << "-Wfloat-equal"
+#endif
+ << "-o" << tmpFile
+ << tmpSourceFile;
+#elif defined(Q_CC_XLC)
+ compilerName = "xlC_r";
+ args << "-I" + qtDir + "/include"
+# if QT_POINTER_SIZE == 8
+ << "-q64"
+# endif
+ << "-c" << "-o" << tmpFile
+ << "-info=all"
+ << tmpSourceFile;
+#elif defined(Q_CC_MSVC)
+ compilerName = "cl";
+ args << "-I" + qtDir + "/include"
+ << "-nologo" << "-W3"
+ << tmpSourceFile;
+#elif defined (Q_CC_SUN)
+ compilerName = "CC";
+ // +w or +w2 outputs too much bogus
+ args << "-I" + qtDir + "/include"
+# if QT_POINTER_SIZE == 8
+ << "-xarch=v9"
+# endif
+ << "-o" << tmpFile
+ << tmpSourceFile;
+#elif defined (Q_CC_HPACC)
+ compilerName = "aCC";
+ args << "-I" + qtDir + "/include"
+ << "-I/usr/local/mesa/aCC-64/include"
+ << "-I/opt/graphics/OpenGL/include"
+# if QT_POINTER_SIZE == 8 && !defined __ia64
+ << "+DA2.0W"
+# endif
+ // aCC generates too much bogus.
+ << "-DQT_NO_STL" << "-c" << "-w"
+ << "-o" << tmpFile
+ << tmpSourceFile;
+#elif defined(Q_CC_MIPS)
+ compilerName = "CC";
+ args << "-I" + qtDir + "/include"
+ << "-c"
+ << "-woff" << "3303" // const qualifier on return
+ << "-o" << tmpFile
+ << tmpSourceFile;
+#else
+ QSKIP("Test not implemented for this compiler", SkipAll);
+#endif
+
+ QProcess proc;
+ proc.start(compilerName, args, QIODevice::ReadOnly);
+ QVERIFY2(proc.waitForFinished(6000000), proc.errorString().toLocal8Bit());
+
+#ifdef Q_CC_MSVC
+ QString errs = QString::fromLocal8Bit(proc.readAllStandardOutput().constData());
+ if (errs.startsWith(tmpSourceFile))
+ errs = errs.mid(10);
+#else
+ QString errs = QString::fromLocal8Bit(proc.readAllStandardError().constData());
+#endif
+ QStringList errList;
+ if (!errs.isEmpty()) {
+ errList = errs.split("\n");
+ qDebug() << "Arguments:" << args;
+ foreach (QString err, errList) {
+ qDebug() << err;
+ }
+ }
+ QCOMPARE(errList.count(), 0); // verbose info how many lines of errors in output
+ QVERIFY(errs.isEmpty());
+}
+
+QTEST_APPLESS_MAIN(tst_CompilerWarnings)
+
+#include "tst_compilerwarnings.moc"
+