0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the test suite of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
|
|
43 |
#include <qcoreapplication.h>
|
|
44 |
#include <qprocess.h>
|
|
45 |
#include <qtemporaryfile.h>
|
|
46 |
#include <qdebug.h>
|
|
47 |
|
|
48 |
#include <QtTest/QtTest>
|
|
49 |
|
|
50 |
#ifdef QT_NO_PROCESS
|
|
51 |
QTEST_NOOP_MAIN
|
|
52 |
#else
|
|
53 |
|
|
54 |
#include <stdlib.h>
|
|
55 |
|
|
56 |
QT_USE_NAMESPACE
|
|
57 |
|
|
58 |
class tst_CompilerWarnings: public QObject
|
|
59 |
{
|
|
60 |
Q_OBJECT
|
|
61 |
|
|
62 |
private slots:
|
|
63 |
void warnings_data();
|
|
64 |
void warnings();
|
|
65 |
};
|
|
66 |
|
|
67 |
#if 0
|
|
68 |
/*
|
|
69 |
Return list of all documented qfeatures (QT_NO_*)
|
|
70 |
*/
|
|
71 |
static QStringList getFeatures()
|
|
72 |
{
|
|
73 |
QStringList srcDirs;
|
|
74 |
srcDirs << QString::fromLocal8Bit(qgetenv("QTDIR"))
|
|
75 |
<< QString::fromLocal8Bit(qgetenv("QTSRCDIR"));
|
|
76 |
|
|
77 |
QString featurefile;
|
|
78 |
foreach (QString dir, srcDirs) {
|
|
79 |
QString str = dir + "/src/corelib/global/qfeatures.txt";
|
|
80 |
if (QFile::exists(str)) {
|
|
81 |
featurefile = str;
|
|
82 |
break;
|
|
83 |
}
|
|
84 |
}
|
|
85 |
|
|
86 |
if (featurefile.isEmpty()) {
|
|
87 |
qWarning("Unable to find qfeatures.txt");
|
|
88 |
return QStringList();
|
|
89 |
}
|
|
90 |
|
|
91 |
QFile file(featurefile);
|
|
92 |
if (!file.open(QIODevice::ReadOnly)) {
|
|
93 |
qWarning("Unable to open feature file '%s'", qPrintable(featurefile));
|
|
94 |
return QStringList();
|
|
95 |
}
|
|
96 |
|
|
97 |
QStringList features;
|
|
98 |
QTextStream s(&file);
|
|
99 |
QRegExp regexp("Feature:\\s+(\\w+)\\s*");
|
|
100 |
for (QString line = s.readLine(); !s.atEnd(); line = s.readLine()) {
|
|
101 |
if (regexp.exactMatch(line))
|
|
102 |
features << regexp.cap(1);
|
|
103 |
}
|
|
104 |
|
|
105 |
return features;
|
|
106 |
}
|
|
107 |
#endif
|
|
108 |
|
|
109 |
void tst_CompilerWarnings::warnings_data()
|
|
110 |
{
|
|
111 |
QTest::addColumn<QStringList>("cflags");
|
|
112 |
|
|
113 |
QTest::newRow("standard") << QStringList();
|
|
114 |
|
|
115 |
#if 0
|
|
116 |
#ifdef Q_WS_QWS
|
|
117 |
QStringList features = getFeatures();
|
|
118 |
foreach (QString feature, features) {
|
|
119 |
QStringList args;
|
|
120 |
QString macro = QString("QT_NO_%1").arg(feature);
|
|
121 |
args << (QString("-D%1").arg(macro));
|
|
122 |
QTest::newRow(qPrintable(macro)) << args;
|
|
123 |
}
|
|
124 |
#endif
|
|
125 |
#endif
|
|
126 |
}
|
|
127 |
|
|
128 |
void tst_CompilerWarnings::warnings()
|
|
129 |
{
|
|
130 |
QFETCH(QStringList, cflags);
|
|
131 |
|
|
132 |
#if !defined(Q_CC_INTEL) && defined(Q_CC_GNU) && __GNUC__ == 3
|
|
133 |
QSKIP("gcc 3.x outputs too many bogus warnings", SkipAll);
|
|
134 |
#endif
|
|
135 |
|
|
136 |
static QString tmpFile;
|
|
137 |
if (tmpFile.isEmpty()) {
|
|
138 |
QTemporaryFile tmpQFile;
|
|
139 |
tmpQFile.open();
|
|
140 |
tmpFile = tmpQFile.fileName();
|
|
141 |
tmpQFile.close();
|
|
142 |
}
|
|
143 |
static QString tmpSourceFile;
|
|
144 |
bool openResult = true;
|
|
145 |
const QString tmpBaseName("XXXXXX-test.cpp");
|
|
146 |
QString templatePath = QDir::temp().absoluteFilePath(tmpBaseName);
|
|
147 |
QFile tmpQSourceFile(templatePath);
|
|
148 |
if (tmpSourceFile.isEmpty()) {
|
|
149 |
tmpQSourceFile.open(QIODevice::ReadWrite | QIODevice::Truncate);
|
|
150 |
tmpSourceFile = tmpQSourceFile.fileName();
|
|
151 |
QFile cppSource(":/test.cpp");
|
|
152 |
bool openResult = cppSource.open(QIODevice::ReadOnly);
|
|
153 |
if (openResult)
|
|
154 |
{
|
|
155 |
QTextStream in(&cppSource);
|
|
156 |
QTextStream out(&tmpQSourceFile);
|
|
157 |
out << in.readAll();
|
|
158 |
}
|
|
159 |
}
|
|
160 |
tmpQSourceFile.close();
|
|
161 |
QVERIFY2(openResult, "Need resource temporary \"test.cpp\"");
|
|
162 |
|
|
163 |
QStringList args;
|
|
164 |
QString compilerName;
|
|
165 |
|
|
166 |
static QString qtDir = QString::fromLocal8Bit(qgetenv("QTDIR"));
|
|
167 |
QVERIFY2(!qtDir.isEmpty(), "This test needs $QTDIR");
|
|
168 |
|
|
169 |
args << cflags;
|
|
170 |
#if !defined(Q_CC_INTEL) && defined(Q_CC_GNU)
|
|
171 |
compilerName = "g++";
|
|
172 |
args << "-I" + qtDir + "/include";
|
|
173 |
args << "-I/usr/X11R6/include/";
|
|
174 |
#ifdef Q_OS_HPUX
|
|
175 |
args << "-I/usr/local/mesa/aCC-64/include";
|
|
176 |
#endif
|
|
177 |
args << "-c";
|
|
178 |
args << "-Wall" << "-Wold-style-cast" << "-Woverloaded-virtual" << "-pedantic" << "-ansi"
|
|
179 |
<< "-Wno-long-long" << "-Wshadow" << "-Wpacked" << "-Wunreachable-code"
|
|
180 |
<< "-Wundef" << "-Wchar-subscripts" << "-Wformat-nonliteral" << "-Wformat-security"
|
|
181 |
<< "-Wcast-align"
|
|
182 |
<< "-o" << tmpFile
|
|
183 |
<< tmpSourceFile;
|
|
184 |
#elif defined(Q_CC_XLC)
|
|
185 |
compilerName = "xlC_r";
|
|
186 |
args << "-I" + qtDir + "/include"
|
|
187 |
# if QT_POINTER_SIZE == 8
|
|
188 |
<< "-q64"
|
|
189 |
# endif
|
|
190 |
<< "-c" << "-o" << tmpFile
|
|
191 |
<< "-info=all"
|
|
192 |
<< tmpSourceFile;
|
|
193 |
#elif defined(Q_CC_MSVC)
|
|
194 |
compilerName = "cl";
|
|
195 |
args << "-I" + qtDir + "/include"
|
|
196 |
<< "-nologo" << "-W3"
|
|
197 |
<< tmpSourceFile;
|
|
198 |
#elif defined (Q_CC_SUN)
|
|
199 |
compilerName = "CC";
|
|
200 |
// +w or +w2 outputs too much bogus
|
|
201 |
args << "-I" + qtDir + "/include"
|
|
202 |
# if QT_POINTER_SIZE == 8
|
|
203 |
<< "-xarch=v9"
|
|
204 |
# endif
|
|
205 |
<< "-o" << tmpFile
|
|
206 |
<< tmpSourceFile;
|
|
207 |
#elif defined (Q_CC_HPACC)
|
|
208 |
compilerName = "aCC";
|
|
209 |
args << "-I" + qtDir + "/include"
|
|
210 |
<< "-I/usr/local/mesa/aCC-64/include"
|
|
211 |
<< "-I/opt/graphics/OpenGL/include"
|
|
212 |
# if QT_POINTER_SIZE == 8 && !defined __ia64
|
|
213 |
<< "+DA2.0W"
|
|
214 |
# endif
|
|
215 |
// aCC generates too much bogus.
|
|
216 |
<< "-DQT_NO_STL" << "-c" << "-w"
|
|
217 |
<< "-o" << tmpFile
|
|
218 |
<< tmpSourceFile;
|
|
219 |
#elif defined(Q_CC_MIPS)
|
|
220 |
compilerName = "CC";
|
|
221 |
args << "-I" + qtDir + "/include"
|
|
222 |
<< "-c"
|
|
223 |
<< "-woff" << "3303" // const qualifier on return
|
|
224 |
<< "-o" << tmpFile
|
|
225 |
<< tmpSourceFile;
|
|
226 |
#else
|
|
227 |
QSKIP("Test not implemented for this compiler", SkipAll);
|
|
228 |
#endif
|
|
229 |
|
|
230 |
QProcess proc;
|
|
231 |
proc.start(compilerName, args, QIODevice::ReadOnly);
|
|
232 |
QVERIFY2(proc.waitForFinished(6000000), proc.errorString().toLocal8Bit());
|
|
233 |
|
|
234 |
#ifdef Q_CC_MSVC
|
|
235 |
QString errs = QString::fromLocal8Bit(proc.readAllStandardOutput().constData());
|
|
236 |
if (errs.startsWith(tmpBaseName))
|
|
237 |
errs = errs.mid(tmpBaseName.size()).simplified();;
|
|
238 |
#else
|
|
239 |
QString errs = QString::fromLocal8Bit(proc.readAllStandardError().constData());
|
|
240 |
#endif
|
|
241 |
QStringList errList;
|
|
242 |
if (!errs.isEmpty()) {
|
|
243 |
errList = errs.split("\n");
|
|
244 |
qDebug() << "Arguments:" << args;
|
|
245 |
foreach (QString err, errList) {
|
|
246 |
qDebug() << err;
|
|
247 |
}
|
|
248 |
}
|
|
249 |
QCOMPARE(errList.count(), 0); // verbose info how many lines of errors in output
|
|
250 |
QVERIFY(errs.isEmpty());
|
|
251 |
|
|
252 |
tmpQSourceFile.remove();
|
|
253 |
}
|
|
254 |
|
|
255 |
QTEST_APPLESS_MAIN(tst_CompilerWarnings)
|
|
256 |
|
|
257 |
#include "tst_compilerwarnings.moc"
|
|
258 |
#endif // QT_NO_PROCESS
|