| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2011 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 |
** GNU Lesser General Public License Usage |
| 11 |
** This file may be used under the terms of the GNU Lesser General Public |
| 12 |
** License version 2.1 as published by the Free Software Foundation and |
| 13 |
** appearing in the file LICENSE.LGPL included in the packaging of this |
| 14 |
** file. Please review the following information to ensure the GNU Lesser |
| 15 |
** General Public License version 2.1 requirements will be met: |
| 16 |
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 17 |
** |
| 18 |
** In addition, as a special exception, Nokia gives you certain additional |
| 19 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
| 20 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 21 |
** |
| 22 |
** GNU General Public License Usage |
| 23 |
** Alternatively, this file may be used under the terms of the GNU General |
| 24 |
** Public License version 3.0 as published by the Free Software Foundation |
| 25 |
** and appearing in the file LICENSE.GPL included in the packaging of this |
| 26 |
** file. Please review the following information to ensure the GNU General |
| 27 |
** Public License version 3.0 requirements will be met: |
| 28 |
** http://www.gnu.org/copyleft/gpl.html. |
| 29 |
** |
| 30 |
** Other Usage |
| 31 |
** Alternatively, this file may be used in accordance with the terms and |
| 32 |
** conditions contained in a signed written agreement between you and Nokia. |
| 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 |
QHash<QString, QBic::Info> cachedCurrentInfo; |
| 63 |
|
| 64 |
private slots: |
| 65 |
void initTestCase_data(); |
| 66 |
void initTestCase(); |
| 67 |
|
| 68 |
void sizesAndVTables_data(); |
| 69 |
void sizesAndVTables(); |
| 70 |
|
| 71 |
private: |
| 72 |
QBic bic; |
| 73 |
}; |
| 74 |
|
| 75 |
typedef QPair<QString, QString> QStringPair; |
| 76 |
|
| 77 |
tst_Bic::tst_Bic() |
| 78 |
{ |
| 79 |
bic.addBlacklistedClass(QLatin1String("std::*")); |
| 80 |
bic.addBlacklistedClass(QLatin1String("qIsNull*")); |
| 81 |
bic.addBlacklistedClass(QLatin1String("_*")); |
| 82 |
bic.addBlacklistedClass(QLatin1String("<anonymous*")); |
| 83 |
|
| 84 |
/* some system stuff we don't care for */ |
| 85 |
bic.addBlacklistedClass(QLatin1String("timespec")); |
| 86 |
bic.addBlacklistedClass(QLatin1String("itimerspec")); |
| 87 |
bic.addBlacklistedClass(QLatin1String("sched_param")); |
| 88 |
bic.addBlacklistedClass(QLatin1String("timeval")); |
| 89 |
bic.addBlacklistedClass(QLatin1String("drand")); |
| 90 |
bic.addBlacklistedClass(QLatin1String("lconv")); |
| 91 |
bic.addBlacklistedClass(QLatin1String("random")); |
| 92 |
bic.addBlacklistedClass(QLatin1String("wait")); |
| 93 |
bic.addBlacklistedClass(QLatin1String("tm")); |
| 94 |
bic.addBlacklistedClass(QLatin1String("sigcontext")); |
| 95 |
bic.addBlacklistedClass(QLatin1String("ucontext")); |
| 96 |
bic.addBlacklistedClass(QLatin1String("ucontext64")); |
| 97 |
bic.addBlacklistedClass(QLatin1String("sigaltstack")); |
| 98 |
|
| 99 |
/* QtOpenGL includes qt_windows.h, and some SDKs dont have these structs present */ |
| 100 |
bic.addBlacklistedClass(QLatin1String("tagTITLEBARINFO")); |
| 101 |
bic.addBlacklistedClass(QLatin1String("tagMENUITEMINFOA")); |
| 102 |
bic.addBlacklistedClass(QLatin1String("tagMENUITEMINFOW")); |
| 103 |
bic.addBlacklistedClass(QLatin1String("tagENHMETAHEADER")); |
| 104 |
|
| 105 |
/* some bug in gcc also reported template instanciations */ |
| 106 |
bic.addBlacklistedClass(QLatin1String("QTypeInfo<*>")); |
| 107 |
bic.addBlacklistedClass(QLatin1String("QMetaTypeId<*>")); |
| 108 |
bic.addBlacklistedClass(QLatin1String("QVector<QGradientStop>*")); |
| 109 |
|
| 110 |
/* this guy is never instantiated, just for compile-time checking */ |
| 111 |
bic.addBlacklistedClass(QLatin1String("QMap<*>::PayloadNode")); |
| 112 |
|
| 113 |
/* QFileEngine was removed in 4.1 */ |
| 114 |
bic.addBlacklistedClass(QLatin1String("QFileEngine")); |
| 115 |
bic.addBlacklistedClass(QLatin1String("QFileEngineHandler")); |
| 116 |
bic.addBlacklistedClass(QLatin1String("QFlags<QFileEngine::FileFlag>")); |
| 117 |
|
| 118 |
/* Private classes */ |
| 119 |
bic.addBlacklistedClass(QLatin1String("QBrushData")); |
| 120 |
bic.addBlacklistedClass(QLatin1String("QObjectData")); |
| 121 |
bic.addBlacklistedClass(QLatin1String("QAtomic")); |
| 122 |
bic.addBlacklistedClass(QLatin1String("QBasicAtomic")); |
| 123 |
bic.addBlacklistedClass(QLatin1String("QRegion::QRegionData")); |
| 124 |
bic.addBlacklistedClass(QLatin1String("QtConcurrent::ThreadEngineSemaphore")); |
| 125 |
bic.addBlacklistedClass(QLatin1String("QDrawPixmaps::Data")); |
| 126 |
bic.addBlacklistedClass(QLatin1String("QS60Style")); |
| 127 |
|
| 128 |
/* Jambi-related classes in Designer */ |
| 129 |
bic.addBlacklistedClass(QLatin1String("QDesignerLanguageExtension")); |
| 130 |
|
| 131 |
/* Harald says it's undocumented and private :) */ |
| 132 |
bic.addBlacklistedClass(QLatin1String("QAccessibleInterfaceEx")); |
| 133 |
bic.addBlacklistedClass(QLatin1String("QAccessibleObjectEx")); |
| 134 |
bic.addBlacklistedClass(QLatin1String("QAccessibleWidgetEx")); |
| 135 |
|
| 136 |
/* This structure is semi-private and should never shrink */ |
| 137 |
bic.addBlacklistedClass(QLatin1String("QVFbHeader")); |
| 138 |
|
| 139 |
/* This structure has a version field that allows extension */ |
| 140 |
bic.addBlacklistedClass(QLatin1String("QDeclarativePrivate::RegisterType")); |
| 141 |
} |
| 142 |
|
| 143 |
void tst_Bic::initTestCase_data() |
| 144 |
{ |
| 145 |
QTest::addColumn<QString>("libName"); |
| 146 |
|
| 147 |
QTest::newRow("QtCore") << "QtCore"; |
| 148 |
QTest::newRow("QtGui") << "QtGui"; |
| 149 |
|
| 150 |
QTest::newRow("Qt3Support") << "Qt3Support"; |
| 151 |
#ifndef QT_NO_DBUS |
| 152 |
QTest::newRow("QtDBus") << "QtDBus"; |
| 153 |
#endif |
| 154 |
QTest::newRow("QtDesigner") << "QtDesigner"; |
| 155 |
QTest::newRow("QtDeclarative") << "QtDeclarative"; |
| 156 |
QTest::newRow("QtMultimedia") << "QtMultimedia"; |
| 157 |
QTest::newRow("QtNetwork") << "QtNetwork"; |
| 158 |
QTest::newRow("QtOpenGL") << "QtOpenGL"; |
| 159 |
QTest::newRow("QtScript") << "QtScript"; |
| 160 |
QTest::newRow("QtScriptTools") << "QtScriptTools"; |
| 161 |
QTest::newRow("QtSql") << "QtSql"; |
| 162 |
QTest::newRow("QtSvg") << "QtSvg"; |
| 163 |
QTest::newRow("QtTest") << "QtTest"; |
| 164 |
QTest::newRow("QtWebKit") << "QtWebKit"; |
| 165 |
QTest::newRow("QtXml") << "QtXml"; |
| 166 |
QTest::newRow("QtXmlPatterns") << "QtXmlPatterns"; |
| 167 |
QTest::newRow("phonon") << "phonon"; |
| 168 |
} |
| 169 |
|
| 170 |
void tst_Bic::initTestCase() |
| 171 |
{ |
| 172 |
QString qtDir = QString::fromLocal8Bit(qgetenv("QTDIR")); |
| 173 |
QVERIFY2(!qtDir.isEmpty(), "This test needs $QTDIR"); |
| 174 |
|
| 175 |
if (qgetenv("PATH").contains("teambuilder")) |
| 176 |
QTest::qWarn("This test might not work with teambuilder, consider switching it off."); |
| 177 |
} |
| 178 |
|
| 179 |
void tst_Bic::sizesAndVTables_data() |
| 180 |
{ |
| 181 |
#if !defined(Q_CC_GNU) || defined(Q_CC_INTEL) |
| 182 |
QSKIP("Test not implemented for this compiler/platform", SkipAll); |
| 183 |
#else |
| 184 |
|
| 185 |
#if defined Q_OS_LINUX && defined Q_WS_X11 |
| 186 |
# if defined(__powerpc__) && !defined(__powerpc64__) |
| 187 |
# define FILESUFFIX "linux-gcc-ppc32" |
| 188 |
# elif defined(__amd64__) |
| 189 |
# define FILESUFFIX "linux-gcc-amd64" |
| 190 |
# elif defined(__i386__) |
| 191 |
# define FILESUFFIX "linux-gcc-ia32" |
| 192 |
# endif |
| 193 |
#elif defined Q_OS_MAC && defined(__powerpc__) |
| 194 |
# define FILESUFFIX "macx-gcc-ppc32" |
| 195 |
#elif defined Q_OS_MAC && defined(__i386__) |
| 196 |
# define FILESUFFIX "macx-gcc-ia32" |
| 197 |
#elif defined Q_OS_MAC && defined(__amd64__) |
| 198 |
# define FILESUFFIX "macx-gcc-amd64" |
| 199 |
#elif defined Q_OS_WIN && defined Q_CC_GNU |
| 200 |
# define FILESUFFIX "win32-gcc-ia32" |
| 201 |
#else |
| 202 |
# define FILESUFFIX "nonsuch" |
| 203 |
QSKIP("No reference files found for this platform", SkipAll); |
| 204 |
#endif |
| 205 |
|
| 206 |
QTest::addColumn<QString>("oldLib"); |
| 207 |
QTest::addColumn<bool>("isPatchRelease"); |
| 208 |
|
| 209 |
int minor = (QT_VERSION >> 8) & 0xFF; |
| 210 |
int patch = QT_VERSION & 0xFF; |
| 211 |
for (int i = 0; i <= minor; ++i) { |
| 212 |
if (i != minor || patch) |
| 213 |
QTest::newRow("4." + QByteArray::number(i)) |
| 214 |
<< (QString(SRCDIR "data/%1.4.") |
| 215 |
+ QString::number(i) |
| 216 |
+ QString(".0." FILESUFFIX ".txt")) |
| 217 |
<< (i == minor && patch); |
| 218 |
} |
| 219 |
#endif |
| 220 |
} |
| 221 |
|
| 222 |
QBic::Info tst_Bic::getCurrentInfo(const QString &libName) |
| 223 |
{ |
| 224 |
QBic::Info &inf = cachedCurrentInfo[libName]; |
| 225 |
if (!inf.classSizes.isEmpty()) |
| 226 |
return inf; |
| 227 |
|
| 228 |
QTemporaryFile tmpQFile; |
| 229 |
tmpQFile.open(); |
| 230 |
QString tmpFileName = tmpQFile.fileName(); |
| 231 |
|
| 232 |
QByteArray tmpFileContents = "#include<" + libName.toLatin1() + "/" + libName.toLatin1() + ">\n"; |
| 233 |
tmpQFile.write(tmpFileContents); |
| 234 |
tmpQFile.flush(); |
| 235 |
|
| 236 |
QString qtDir = QString::fromLocal8Bit(qgetenv("QTDIR")); |
| 237 |
#ifdef Q_OS_WIN |
| 238 |
qtDir.replace('\\', '/'); |
| 239 |
#endif |
| 240 |
QString compilerName = "g++"; |
| 241 |
|
| 242 |
QStringList args; |
| 243 |
args << "-c" |
| 244 |
<< "-I" + qtDir + "/include" |
| 245 |
#ifdef Q_OS_MAC |
| 246 |
<< "-arch" << "i386" // Always use 32-bit data on Mac. |
| 247 |
#endif |
| 248 |
#ifndef Q_OS_WIN |
| 249 |
<< "-I/usr/X11R6/include/" |
| 250 |
#endif |
| 251 |
<< "-DQT_NO_STL" << "-DQT3_SUPPORT" |
| 252 |
<< "-xc++" |
| 253 |
#if !defined(Q_OS_AIX) && !defined(Q_OS_WIN) |
| 254 |
<< "-o" << "/dev/null" |
| 255 |
#endif |
| 256 |
<< "-fdump-class-hierarchy" |
| 257 |
<< tmpFileName; |
| 258 |
|
| 259 |
QProcess proc; |
| 260 |
proc.start(compilerName, args, QIODevice::ReadOnly); |
| 261 |
if (!proc.waitForFinished(6000000)) { |
| 262 |
qWarning() << "gcc didn't finish" << proc.errorString(); |
| 263 |
return QBic::Info(); |
| 264 |
} |
| 265 |
if (proc.exitCode() != 0) { |
| 266 |
qWarning() << "gcc returned with" << proc.exitCode(); |
| 267 |
qDebug() << proc.readAllStandardError(); |
| 268 |
return QBic::Info(); |
| 269 |
} |
| 270 |
|
| 271 |
QString errs = QString::fromLocal8Bit(proc.readAllStandardError().constData()); |
| 272 |
if (!errs.isEmpty()) { |
| 273 |
qDebug() << "Arguments:" << args << "Warnings:" << errs; |
| 274 |
return QBic::Info(); |
| 275 |
} |
| 276 |
|
| 277 |
// See if we find the gcc output file, which seems to change |
| 278 |
// from release to release |
| 279 |
QStringList files = QDir().entryList(QStringList() << "*.class"); |
| 280 |
if (files.isEmpty()) { |
| 281 |
qFatal("Could not locate the GCC output file, update this test"); |
| 282 |
return QBic::Info(); |
| 283 |
} else if (files.size() > 1) { |
| 284 |
qDebug() << files; |
| 285 |
qFatal("Located more than one output file, please clean up before running this test"); |
| 286 |
return QBic::Info(); |
| 287 |
} |
| 288 |
|
| 289 |
QString resultFileName = files.first(); |
| 290 |
inf = bic.parseFile(resultFileName); |
| 291 |
|
| 292 |
QFile::remove(resultFileName); |
| 293 |
tmpQFile.close(); |
| 294 |
|
| 295 |
return inf; |
| 296 |
} |
| 297 |
|
| 298 |
void tst_Bic::sizesAndVTables() |
| 299 |
{ |
| 300 |
#if !defined(Q_CC_GNU) || defined(Q_CC_INTEL) |
| 301 |
QSKIP("Test not implemented for this compiler/platform", SkipAll); |
| 302 |
#else |
| 303 |
|
| 304 |
QFETCH_GLOBAL(QString, libName); |
| 305 |
QFETCH(QString, oldLib); |
| 306 |
QFETCH(bool, isPatchRelease); |
| 307 |
|
| 308 |
bool isFailed = false; |
| 309 |
|
| 310 |
//qDebug() << oldLib.arg(libName); |
| 311 |
if (oldLib.isEmpty() || !QFile::exists(oldLib.arg(libName))) |
| 312 |
QSKIP("No platform spec found for this platform/version.", SkipSingle); |
| 313 |
|
| 314 |
const QBic::Info oldLibInfo = bic.parseFile(oldLib.arg(libName)); |
| 315 |
QVERIFY(!oldLibInfo.classVTables.isEmpty()); |
| 316 |
|
| 317 |
const QBic::Info currentLibInfo = getCurrentInfo(libName); |
| 318 |
QVERIFY(!currentLibInfo.classVTables.isEmpty()); |
| 319 |
|
| 320 |
QBic::VTableDiff diff = bic.diffVTables(oldLibInfo, currentLibInfo); |
| 321 |
|
| 322 |
if (!diff.removedVTables.isEmpty()) { |
| 323 |
qWarning() << "VTables for the following classes were removed" << diff.removedVTables; |
| 324 |
isFailed = true; |
| 325 |
} |
| 326 |
|
| 327 |
if (!diff.modifiedVTables.isEmpty()) { |
| 328 |
if (diff.modifiedVTables.size() != 1 || |
| 329 |
strcmp(QTest::currentDataTag(), "4.4") != 0 || |
| 330 |
diff.modifiedVTables.at(0).first != "QGraphicsProxyWidget") { |
| 331 |
foreach(QStringPair entry, diff.modifiedVTables) |
| 332 |
qWarning() << "modified VTable:\n Old: " << entry.first |
| 333 |
<< "\n New: " << entry.second; |
| 334 |
isFailed = true; |
| 335 |
} |
| 336 |
} |
| 337 |
|
| 338 |
if (isPatchRelease && !diff.addedVTables.isEmpty()) { |
| 339 |
qWarning() << "VTables for the following classes were added in a patch release:" |
| 340 |
<< diff.addedVTables; |
| 341 |
isFailed = true; |
| 342 |
} |
| 343 |
|
| 344 |
if (isPatchRelease && !diff.reimpMethods.isEmpty()) { |
| 345 |
foreach(QStringPair entry, diff.reimpMethods) |
| 346 |
qWarning() << "reimplemented virtual in patch release:\n Old: " << entry.first |
| 347 |
<< "\n New: " << entry.second; |
| 348 |
isFailed = true; |
| 349 |
} |
| 350 |
|
| 351 |
QBic::SizeDiff sizeDiff = bic.diffSizes(oldLibInfo, currentLibInfo); |
| 352 |
if (!sizeDiff.mismatch.isEmpty()) { |
| 353 |
foreach (QString className, sizeDiff.mismatch) |
| 354 |
qWarning() << "size mismatch for" << className |
| 355 |
<< "old" << oldLibInfo.classSizes.value(className) |
| 356 |
<< "new" << currentLibInfo.classSizes.value(className); |
| 357 |
isFailed = true; |
| 358 |
} |
| 359 |
|
| 360 |
#ifdef Q_CC_MINGW |
| 361 |
/** |
| 362 |
* These symbols are from Windows' imm.h header, and is available |
| 363 |
* conditionally depending on the value of the WINVER define. We pull |
| 364 |
* them out since they're not relevant to the testing done. |
| 365 |
*/ |
| 366 |
sizeDiff.removed.removeAll(QLatin1String("tagIMECHARPOSITION")); |
| 367 |
sizeDiff.removed.removeAll(QLatin1String("tagRECONVERTSTRING")); |
| 368 |
#endif |
| 369 |
|
| 370 |
if (!sizeDiff.removed.isEmpty()) { |
| 371 |
qWarning() << "the following classes were removed:" << sizeDiff.removed; |
| 372 |
isFailed = true; |
| 373 |
} |
| 374 |
|
| 375 |
if (isPatchRelease && !sizeDiff.added.isEmpty()) { |
| 376 |
qWarning() << "the following classes were added in a patch release:" << sizeDiff.added; |
| 377 |
isFailed = true; |
| 378 |
} |
| 379 |
|
| 380 |
if (isFailed) |
| 381 |
QFAIL("Test failed, read warnings above."); |
| 382 |
#endif |
| 383 |
} |
| 384 |
|
| 385 |
QTEST_APPLESS_MAIN(tst_Bic) |
| 386 |
|
| 387 |
#include "tst_bic.moc" |
| 388 |
#endif |