author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
child 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
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 <QtCore/QtCore> |
|
44 |
#include <QtTest/QtTest> |
|
45 |
||
46 |
#ifdef QT_NO_PROCESS |
|
47 |
QTEST_NOOP_MAIN |
|
48 |
#else |
|
49 |
||
50 |
#include "qbic.h" |
|
51 |
||
52 |
#include <stdlib.h> |
|
53 |
||
54 |
class tst_Bic: public QObject |
|
55 |
{ |
|
56 |
Q_OBJECT |
|
57 |
||
58 |
public: |
|
59 |
tst_Bic(); |
|
60 |
QBic::Info getCurrentInfo(const QString &libName); |
|
61 |
||
62 |
private slots: |
|
63 |
void initTestCase_data(); |
|
64 |
void initTestCase(); |
|
65 |
||
66 |
void sizesAndVTables_data(); |
|
67 |
void sizesAndVTables(); |
|
68 |
||
69 |
private: |
|
70 |
QBic bic; |
|
71 |
}; |
|
72 |
||
73 |
typedef QPair<QString, QString> QStringPair; |
|
74 |
||
75 |
tst_Bic::tst_Bic() |
|
76 |
{ |
|
77 |
bic.addBlacklistedClass(QLatin1String("std::*")); |
|
78 |
bic.addBlacklistedClass(QLatin1String("qIsNull*")); |
|
79 |
bic.addBlacklistedClass(QLatin1String("_*")); |
|
80 |
bic.addBlacklistedClass(QLatin1String("<anonymous*")); |
|
81 |
||
82 |
/* some system stuff we don't care for */ |
|
83 |
bic.addBlacklistedClass(QLatin1String("timespec")); |
|
84 |
bic.addBlacklistedClass(QLatin1String("itimerspec")); |
|
85 |
bic.addBlacklistedClass(QLatin1String("sched_param")); |
|
86 |
bic.addBlacklistedClass(QLatin1String("timeval")); |
|
87 |
bic.addBlacklistedClass(QLatin1String("drand")); |
|
88 |
bic.addBlacklistedClass(QLatin1String("lconv")); |
|
89 |
bic.addBlacklistedClass(QLatin1String("random")); |
|
90 |
bic.addBlacklistedClass(QLatin1String("wait")); |
|
91 |
bic.addBlacklistedClass(QLatin1String("tm")); |
|
92 |
bic.addBlacklistedClass(QLatin1String("sigcontext")); |
|
93 |
bic.addBlacklistedClass(QLatin1String("ucontext")); |
|
94 |
bic.addBlacklistedClass(QLatin1String("ucontext64")); |
|
95 |
bic.addBlacklistedClass(QLatin1String("sigaltstack")); |
|
96 |
||
97 |
/* QtOpenGL includes qt_windows.h, and some SDKs dont have these structs present */ |
|
98 |
bic.addBlacklistedClass(QLatin1String("tagTITLEBARINFO")); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
99 |
bic.addBlacklistedClass(QLatin1String("tagMENUITEMINFOA")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
100 |
bic.addBlacklistedClass(QLatin1String("tagMENUITEMINFOW")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
101 |
bic.addBlacklistedClass(QLatin1String("tagENHMETAHEADER")); |
0 | 102 |
|
103 |
/* some bug in gcc also reported template instanciations */ |
|
104 |
bic.addBlacklistedClass(QLatin1String("QTypeInfo<*>")); |
|
105 |
bic.addBlacklistedClass(QLatin1String("QMetaTypeId<*>")); |
|
106 |
bic.addBlacklistedClass(QLatin1String("QVector<QGradientStop>*")); |
|
107 |
||
108 |
/* this guy is never instantiated, just for compile-time checking */ |
|
109 |
bic.addBlacklistedClass(QLatin1String("QMap<*>::PayloadNode")); |
|
110 |
||
111 |
/* QFileEngine was removed in 4.1 */ |
|
112 |
bic.addBlacklistedClass(QLatin1String("QFileEngine")); |
|
113 |
bic.addBlacklistedClass(QLatin1String("QFileEngineHandler")); |
|
114 |
bic.addBlacklistedClass(QLatin1String("QFlags<QFileEngine::FileFlag>")); |
|
115 |
||
116 |
/* Private classes */ |
|
117 |
bic.addBlacklistedClass(QLatin1String("QBrushData")); |
|
118 |
bic.addBlacklistedClass(QLatin1String("QObjectData")); |
|
119 |
bic.addBlacklistedClass(QLatin1String("QAtomic")); |
|
120 |
bic.addBlacklistedClass(QLatin1String("QBasicAtomic")); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
121 |
bic.addBlacklistedClass(QLatin1String("QRegion::QRegionData")); |
0 | 122 |
|
123 |
/* Jambi-related classes in Designer */ |
|
124 |
bic.addBlacklistedClass(QLatin1String("QDesignerLanguageExtension")); |
|
125 |
||
126 |
/* Harald says it's undocumented and private :) */ |
|
127 |
bic.addBlacklistedClass(QLatin1String("QAccessibleInterfaceEx")); |
|
128 |
bic.addBlacklistedClass(QLatin1String("QAccessibleObjectEx")); |
|
129 |
bic.addBlacklistedClass(QLatin1String("QAccessibleWidgetEx")); |
|
130 |
||
131 |
/* This structure is semi-private and should never shrink */ |
|
132 |
bic.addBlacklistedClass(QLatin1String("QVFbHeader")); |
|
133 |
} |
|
134 |
||
135 |
void tst_Bic::initTestCase_data() |
|
136 |
{ |
|
137 |
QTest::addColumn<QString>("libName"); |
|
138 |
||
139 |
QTest::newRow("QtCore") << "QtCore"; |
|
140 |
QTest::newRow("QtGui") << "QtGui"; |
|
141 |
QTest::newRow("QtScript") << "QtScript"; |
|
142 |
QTest::newRow("QtSql") << "QtSql"; |
|
143 |
QTest::newRow("QtSvg") << "QtSvg"; |
|
144 |
QTest::newRow("QtNetwork") << "QtNetwork"; |
|
145 |
QTest::newRow("QtOpenGL") << "QtOpenGL"; |
|
146 |
QTest::newRow("QtXml") << "QtXml"; |
|
147 |
QTest::newRow("QtXmlPatterns") << "QtXmlPatterns"; |
|
148 |
QTest::newRow("Qt3Support") << "Qt3Support"; |
|
149 |
QTest::newRow("QtTest") << "QtTest"; |
|
150 |
QTest::newRow("QtDBus") << "QtDBus"; |
|
151 |
QTest::newRow("QtDesigner") << "QtDesigner"; |
|
152 |
} |
|
153 |
||
154 |
void tst_Bic::initTestCase() |
|
155 |
{ |
|
156 |
QString qtDir = QString::fromLocal8Bit(qgetenv("QTDIR")); |
|
157 |
QVERIFY2(!qtDir.isEmpty(), "This test needs $QTDIR"); |
|
158 |
||
159 |
if (qgetenv("PATH").contains("teambuilder")) |
|
160 |
QTest::qWarn("This test might not work with teambuilder, consider switching it off."); |
|
161 |
} |
|
162 |
||
163 |
void tst_Bic::sizesAndVTables_data() |
|
164 |
{ |
|
165 |
#if !defined(Q_CC_GNU) || defined(Q_CC_INTEL) |
|
166 |
QSKIP("Test not implemented for this compiler/platform", SkipAll); |
|
167 |
#else |
|
168 |
||
169 |
QString archFileName400; |
|
170 |
QString archFileName410; |
|
171 |
QString archFileName420; |
|
172 |
QString archFileName430; |
|
173 |
||
174 |
#if defined Q_OS_LINUX && defined Q_WS_X11 |
|
175 |
# if defined(__powerpc__) && !defined(__powerpc64__) |
|
176 |
archFileName400 = SRCDIR "data/%1.4.0.0.linux-gcc-ppc32.txt"; |
|
177 |
archFileName410 = SRCDIR "data/%1.4.1.0.linux-gcc-ppc32.txt"; |
|
178 |
archFileName420 = SRCDIR "data/%1.4.2.0.linux-gcc-ppc32.txt"; |
|
179 |
# elif defined(__amd64__) |
|
180 |
archFileName400 = SRCDIR "data/%1.4.0.0.linux-gcc-amd64.txt"; |
|
181 |
# elif defined(__i386__) |
|
182 |
archFileName400 = SRCDIR "data/%1.4.0.0.linux-gcc-ia32.txt"; |
|
183 |
archFileName410 = SRCDIR "data/%1.4.1.0.linux-gcc-ia32.txt"; |
|
184 |
archFileName420 = SRCDIR "data/%1.4.2.0.linux-gcc-ia32.txt"; |
|
185 |
archFileName430 = SRCDIR "data/%1.4.3.0.linux-gcc-ia32.txt"; |
|
186 |
# endif |
|
187 |
#elif defined Q_OS_AIX |
|
188 |
if (sizeof(void*) == 4) |
|
189 |
archFileName400 = SRCDIR "data/%1.4.0.0.aix-gcc-power32.txt"; |
|
190 |
#elif defined Q_OS_MAC && defined(__powerpc__) |
|
191 |
archFileName400 = SRCDIR "data/%1.4.0.0.macx-gcc-ppc32.txt"; |
|
192 |
archFileName410 = SRCDIR "data/%1.4.1.0.macx-gcc-ppc32.txt"; |
|
193 |
archFileName420 = SRCDIR "data/%1.4.2.0.macx-gcc-ppc32.txt"; |
|
194 |
#elif defined Q_OS_MAC && defined(__i386__) |
|
195 |
archFileName410 = SRCDIR "data/%1.4.1.0.macx-gcc-ia32.txt"; |
|
196 |
archFileName420 = SRCDIR "data/%1.4.2.0.macx-gcc-ia32.txt"; |
|
197 |
#elif defined Q_OS_WIN && defined Q_CC_GNU |
|
198 |
archFileName410 = SRCDIR "data/%1.4.1.0.win32-gcc-ia32.txt"; |
|
199 |
archFileName420 = SRCDIR "data/%1.4.2.0.win32-gcc-ia32.txt"; |
|
200 |
#endif |
|
201 |
||
202 |
if (archFileName400.isEmpty() && archFileName410.isEmpty() |
|
203 |
&& archFileName420.isEmpty()) |
|
204 |
QSKIP("No reference files found for this platform", SkipAll); |
|
205 |
||
206 |
bool isPatchRelease400 = false; |
|
207 |
bool isPatchRelease410 = false; |
|
208 |
bool isPatchRelease420 = false; |
|
209 |
bool isPatchRelease430 = false; |
|
210 |
||
211 |
QTest::addColumn<QString>("oldLib"); |
|
212 |
QTest::addColumn<bool>("isPatchRelease"); |
|
213 |
||
214 |
QTest::newRow("4.0") << archFileName400 << isPatchRelease400; |
|
215 |
QTest::newRow("4.1") << archFileName410 << isPatchRelease410; |
|
216 |
QTest::newRow("4.2") << archFileName420 << isPatchRelease420; |
|
217 |
QTest::newRow("4.3") << archFileName430 << isPatchRelease430; |
|
218 |
#endif |
|
219 |
} |
|
220 |
||
221 |
QBic::Info tst_Bic::getCurrentInfo(const QString &libName) |
|
222 |
{ |
|
223 |
QTemporaryFile tmpQFile; |
|
224 |
tmpQFile.open(); |
|
225 |
QString tmpFileName = tmpQFile.fileName(); |
|
226 |
||
227 |
QByteArray tmpFileContents = "#include<" + libName.toLatin1() + "/" + libName.toLatin1() + ">\n"; |
|
228 |
tmpQFile.write(tmpFileContents); |
|
229 |
tmpQFile.flush(); |
|
230 |
||
231 |
QString qtDir = QString::fromLocal8Bit(qgetenv("QTDIR")); |
|
232 |
#ifdef Q_OS_WIN |
|
233 |
qtDir.replace('\\', '/'); |
|
234 |
#endif |
|
235 |
QString compilerName = "g++"; |
|
236 |
||
237 |
QStringList args; |
|
238 |
args << "-c" |
|
239 |
<< "-I" + qtDir + "/include" |
|
240 |
#ifndef Q_OS_WIN |
|
241 |
<< "-I/usr/X11R6/include/" |
|
242 |
#endif |
|
243 |
<< "-DQT_NO_STL" << "-DQT3_SUPPORT" |
|
244 |
<< "-xc++" |
|
245 |
#if !defined(Q_OS_AIX) && !defined(Q_OS_WIN) |
|
246 |
<< "-o" << "/dev/null" |
|
247 |
#endif |
|
248 |
<< "-fdump-class-hierarchy" |
|
249 |
<< tmpFileName; |
|
250 |
||
251 |
QProcess proc; |
|
252 |
proc.start(compilerName, args, QIODevice::ReadOnly); |
|
253 |
if (!proc.waitForFinished(6000000)) { |
|
254 |
qWarning() << "gcc didn't finish" << proc.errorString(); |
|
255 |
return QBic::Info(); |
|
256 |
} |
|
257 |
if (proc.exitCode() != 0) { |
|
258 |
qWarning() << "gcc returned with" << proc.exitCode(); |
|
259 |
qDebug() << proc.readAllStandardError(); |
|
260 |
return QBic::Info(); |
|
261 |
} |
|
262 |
||
263 |
QString errs = QString::fromLocal8Bit(proc.readAllStandardError().constData()); |
|
264 |
if (!errs.isEmpty()) { |
|
265 |
qDebug() << "Arguments:" << args << "Warnings:" << errs; |
|
266 |
return QBic::Info(); |
|
267 |
} |
|
268 |
||
269 |
// See if we find the gcc output file, which seems to change |
|
270 |
// from release to release |
|
271 |
QStringList files = QDir().entryList(QStringList() << "*.class"); |
|
272 |
if (files.isEmpty()) { |
|
273 |
qFatal("Could not locate the GCC output file, update this test"); |
|
274 |
return QBic::Info(); |
|
275 |
} else if (files.size() > 1) { |
|
276 |
qDebug() << files; |
|
277 |
qFatal("Located more than one output file, please clean up before running this test"); |
|
278 |
return QBic::Info(); |
|
279 |
} |
|
280 |
||
281 |
QString resultFileName = files.first(); |
|
282 |
QBic::Info inf = bic.parseFile(resultFileName); |
|
283 |
||
284 |
QFile::remove(resultFileName); |
|
285 |
tmpQFile.close(); |
|
286 |
||
287 |
return inf; |
|
288 |
} |
|
289 |
||
290 |
void tst_Bic::sizesAndVTables() |
|
291 |
{ |
|
292 |
#if !defined(Q_CC_GNU) || defined(Q_CC_INTEL) |
|
293 |
QSKIP("Test not implemented for this compiler/platform", SkipAll); |
|
294 |
#else |
|
295 |
||
296 |
QFETCH_GLOBAL(QString, libName); |
|
297 |
QFETCH(QString, oldLib); |
|
298 |
QFETCH(bool, isPatchRelease); |
|
299 |
||
300 |
bool isFailed = false; |
|
301 |
||
302 |
//qDebug() << oldLib.arg(libName); |
|
303 |
if (oldLib.isEmpty() || !QFile::exists(oldLib.arg(libName))) |
|
304 |
QSKIP("No platform spec found for this platform/version.", SkipSingle); |
|
305 |
||
306 |
const QBic::Info oldLibInfo = bic.parseFile(oldLib.arg(libName)); |
|
307 |
QVERIFY(!oldLibInfo.classVTables.isEmpty()); |
|
308 |
||
309 |
const QBic::Info currentLibInfo = getCurrentInfo(libName); |
|
310 |
QVERIFY(!currentLibInfo.classVTables.isEmpty()); |
|
311 |
||
312 |
QBic::VTableDiff diff = bic.diffVTables(oldLibInfo, currentLibInfo); |
|
313 |
||
314 |
if (!diff.removedVTables.isEmpty()) { |
|
315 |
qWarning() << "VTables for the following classes were removed" << diff.removedVTables; |
|
316 |
isFailed = true; |
|
317 |
} |
|
318 |
||
319 |
if (!diff.modifiedVTables.isEmpty()) { |
|
320 |
foreach(QStringPair entry, diff.modifiedVTables) |
|
321 |
qWarning() << "modified VTable:\n Old: " << entry.first |
|
322 |
<< "\n New: " << entry.second; |
|
323 |
isFailed = true; |
|
324 |
} |
|
325 |
||
326 |
if (isPatchRelease && !diff.addedVTables.isEmpty()) { |
|
327 |
qWarning() << "VTables for the following classes were added in a patch release:" |
|
328 |
<< diff.addedVTables; |
|
329 |
isFailed = true; |
|
330 |
} |
|
331 |
||
332 |
if (isPatchRelease && !diff.reimpMethods.isEmpty()) { |
|
333 |
foreach(QStringPair entry, diff.reimpMethods) |
|
334 |
qWarning() << "reimplemented virtual in patch release:\n Old: " << entry.first |
|
335 |
<< "\n New: " << entry.second; |
|
336 |
isFailed = true; |
|
337 |
} |
|
338 |
||
339 |
QBic::SizeDiff sizeDiff = bic.diffSizes(oldLibInfo, currentLibInfo); |
|
340 |
if (!sizeDiff.mismatch.isEmpty()) { |
|
341 |
foreach (QString className, sizeDiff.mismatch) |
|
342 |
qWarning() << "size mismatch for" << className |
|
343 |
<< "old" << oldLibInfo.classSizes.value(className) |
|
344 |
<< "new" << currentLibInfo.classSizes.value(className); |
|
345 |
isFailed = true; |
|
346 |
} |
|
347 |
||
348 |
#ifdef Q_CC_MINGW |
|
349 |
/** |
|
350 |
* These symbols are from Windows' imm.h header, and is available |
|
351 |
* conditionally depending on the value of the WINVER define. We pull |
|
352 |
* them out since they're not relevant to the testing done. |
|
353 |
*/ |
|
354 |
sizeDiff.removed.removeAll(QLatin1String("tagIMECHARPOSITION")); |
|
355 |
sizeDiff.removed.removeAll(QLatin1String("tagRECONVERTSTRING")); |
|
356 |
#endif |
|
357 |
||
358 |
if (!sizeDiff.removed.isEmpty()) { |
|
359 |
qWarning() << "the following classes were removed:" << sizeDiff.removed; |
|
360 |
isFailed = true; |
|
361 |
} |
|
362 |
||
363 |
if (isPatchRelease && !sizeDiff.added.isEmpty()) { |
|
364 |
qWarning() << "the following classes were added in a patch release:" << sizeDiff.added; |
|
365 |
isFailed = true; |
|
366 |
} |
|
367 |
||
368 |
if (isFailed) |
|
369 |
QFAIL("Test failed, read warnings above."); |
|
370 |
#endif |
|
371 |
} |
|
372 |
||
373 |
QTEST_APPLESS_MAIN(tst_Bic) |
|
374 |
||
375 |
#include "tst_bic.moc" |
|
376 |
#endif |