2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2013-01-02 11:13:29 +00:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-09-19 12:28:29 +00:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** 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, Digia gives you certain additional
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-04-27 10:05:43 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-05-24 09:34:08 +00:00
|
|
|
** GNU General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** 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.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
2012-01-24 06:17:24 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QDir>
|
|
|
|
#include <QtCore/QString>
|
|
|
|
#include <QtTest/QtTest>
|
|
|
|
#include <QtCore/QProcess>
|
|
|
|
#include <QtCore/QByteArray>
|
|
|
|
#include <QtCore/QLibraryInfo>
|
2012-08-02 09:02:24 +00:00
|
|
|
#include <QtCore/QTemporaryDir>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
class tst_uic : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
tst_uic();
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
2012-08-02 09:02:24 +00:00
|
|
|
void cleanupTestCase();
|
|
|
|
|
|
|
|
void stdOut();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void run();
|
|
|
|
void run_data() const;
|
|
|
|
|
|
|
|
void compare();
|
|
|
|
void compare_data() const;
|
|
|
|
|
|
|
|
private:
|
2012-08-02 09:02:24 +00:00
|
|
|
const QString m_command;
|
|
|
|
QString m_baseline;
|
|
|
|
QTemporaryDir m_generated;
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
tst_uic::tst_uic()
|
2012-08-02 09:02:24 +00:00
|
|
|
: m_command(QLibraryInfo::location(QLibraryInfo::BinariesPath) + QLatin1String("/uic"))
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-08-02 09:02:24 +00:00
|
|
|
static QByteArray msgProcessStartFailed(const QString &command, const QString &why)
|
|
|
|
{
|
|
|
|
const QString result = QString::fromLatin1("Could not start %1: %2")
|
|
|
|
.arg(command, why);
|
|
|
|
return result.toLocal8Bit();
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_uic::initTestCase()
|
|
|
|
{
|
2012-08-02 09:02:24 +00:00
|
|
|
m_baseline = QFINDTESTDATA("baseline");
|
|
|
|
QVERIFY2(!m_baseline.isEmpty(), "Could not find 'baseline'.");
|
2011-04-27 10:05:43 +00:00
|
|
|
QProcess process;
|
2012-08-02 09:02:24 +00:00
|
|
|
process.start(m_command, QStringList(QLatin1String("-help")));
|
|
|
|
QVERIFY2(process.waitForStarted(), msgProcessStartFailed(m_command, process.errorString()));
|
|
|
|
QVERIFY(process.waitForFinished());
|
|
|
|
QCOMPARE(process.exitStatus(), QProcess::NormalExit);
|
|
|
|
QCOMPARE(process.exitCode(), 0);
|
2011-04-27 10:05:43 +00:00
|
|
|
// Print version
|
|
|
|
const QString out = QString::fromLocal8Bit(process.readAllStandardError()).remove(QLatin1Char('\r'));
|
|
|
|
const QStringList outLines = out.split(QLatin1Char('\n'));
|
|
|
|
// Print version
|
|
|
|
QString msg = QString::fromLatin1("uic test built %1 running in '%2' using: ").
|
2012-05-02 14:32:26 +00:00
|
|
|
arg(QString::fromLatin1(__DATE__), QDir::currentPath());
|
2011-04-27 10:05:43 +00:00
|
|
|
if (!outLines.empty())
|
|
|
|
msg += outLines.front();
|
2012-08-02 09:02:24 +00:00
|
|
|
qDebug("%s", qPrintable(msg));
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_uic::cleanupTestCase()
|
|
|
|
{
|
|
|
|
static const char envVar[] = "UIC_KEEP_GENERATED_FILES";
|
|
|
|
if (qgetenv(envVar).isEmpty()) {
|
|
|
|
qDebug("Note: The environment variable '%s' can be set to keep the temporary files for error analysis.", envVar);
|
|
|
|
} else {
|
|
|
|
m_generated.setAutoRemove(false);
|
|
|
|
qDebug("Keeping generated files in '%s'", qPrintable(QDir::toNativeSeparators(m_generated.path())));
|
|
|
|
}
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-08-02 09:02:24 +00:00
|
|
|
void tst_uic::stdOut()
|
|
|
|
{
|
|
|
|
// Checks of everything works when using stdout and whether
|
|
|
|
// the OS file format conventions regarding newlines are met.
|
|
|
|
QDir baseline(m_baseline);
|
|
|
|
const QFileInfoList baselineFiles = baseline.entryInfoList(QStringList(QLatin1String("*.ui")), QDir::Files);
|
|
|
|
QVERIFY(!baselineFiles.isEmpty());
|
|
|
|
QProcess process;
|
|
|
|
process.start(m_command, QStringList(baselineFiles.front().absoluteFilePath()));
|
|
|
|
process.closeWriteChannel();
|
|
|
|
QVERIFY2(process.waitForStarted(), msgProcessStartFailed(m_command, process.errorString()));
|
|
|
|
QVERIFY(process.waitForFinished());
|
|
|
|
QCOMPARE(process.exitStatus(), QProcess::NormalExit);
|
|
|
|
QCOMPARE(process.exitCode(), 0);
|
|
|
|
const QByteArray output = process.readAllStandardOutput();
|
|
|
|
QByteArray expected = "/********************************************************************************";
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
expected += "\r\n";
|
|
|
|
#else
|
|
|
|
expected += '\n';
|
|
|
|
#endif
|
|
|
|
expected += "** ";
|
|
|
|
QVERIFY2(output.startsWith(expected), (QByteArray("Got: ") + output.toHex()).constData());
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_uic::run()
|
|
|
|
{
|
|
|
|
QFETCH(QString, originalFile);
|
|
|
|
QFETCH(QString, generatedFile);
|
|
|
|
|
|
|
|
QProcess process;
|
2012-08-02 09:02:24 +00:00
|
|
|
process.start(m_command, QStringList(originalFile)
|
|
|
|
<< QString(QLatin1String("-o")) << generatedFile);
|
|
|
|
QVERIFY2(process.waitForStarted(), msgProcessStartFailed(m_command, process.errorString()));
|
|
|
|
QVERIFY(process.waitForFinished());
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(process.exitStatus(), QProcess::NormalExit);
|
2012-08-02 09:02:24 +00:00
|
|
|
QCOMPARE(process.exitCode(), 0);
|
|
|
|
QCOMPARE(QFileInfo(generatedFile).exists(), true);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_uic::run_data() const
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("originalFile");
|
|
|
|
QTest::addColumn<QString>("generatedFile");
|
|
|
|
|
2012-08-02 09:02:24 +00:00
|
|
|
QDir generated(m_generated.path());
|
|
|
|
QDir baseline(m_baseline);
|
|
|
|
const QFileInfoList baselineFiles = baseline.entryInfoList(QStringList("*.ui"), QDir::Files);
|
|
|
|
foreach (const QFileInfo &baselineFile, baselineFiles) {
|
|
|
|
const QString generatedFile = generated.absolutePath()
|
|
|
|
+ QLatin1Char('/') + baselineFile.fileName()
|
|
|
|
+ QLatin1String(".h");
|
|
|
|
QTest::newRow(qPrintable(baselineFile.baseName()))
|
|
|
|
<< baselineFile.absoluteFilePath()
|
|
|
|
<< generatedFile;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_uic::compare()
|
|
|
|
{
|
|
|
|
QFETCH(QString, originalFile);
|
|
|
|
QFETCH(QString, generatedFile);
|
|
|
|
|
|
|
|
QFile orgFile(originalFile);
|
|
|
|
QFile genFile(generatedFile);
|
|
|
|
|
|
|
|
if (!orgFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
|
|
QString err(QLatin1String("Could not read file: %1..."));
|
|
|
|
QFAIL(err.arg(orgFile.fileName()).toUtf8());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!genFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
|
|
QString err(QLatin1String("Could not read file: %1..."));
|
|
|
|
QFAIL(err.arg(genFile.fileName()).toUtf8());
|
|
|
|
}
|
|
|
|
|
|
|
|
originalFile = orgFile.readAll();
|
2012-12-13 12:48:18 +00:00
|
|
|
originalFile.replace(QRegExp(QLatin1String("Created by: Qt User Interface Compiler version [.\\d]{5,5}")), "");
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
generatedFile = genFile.readAll();
|
2012-12-13 12:48:18 +00:00
|
|
|
generatedFile.replace(QRegExp(QLatin1String("Created by: Qt User Interface Compiler version [.\\d]{5,5}")), "");
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QCOMPARE(generatedFile, originalFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_uic::compare_data() const
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("originalFile");
|
|
|
|
QTest::addColumn<QString>("generatedFile");
|
|
|
|
|
2012-08-02 09:02:24 +00:00
|
|
|
QDir generated(m_generated.path());
|
|
|
|
QDir baseline(m_baseline);
|
|
|
|
const QFileInfoList baselineFiles = baseline.entryInfoList(QStringList("*.h"), QDir::Files);
|
|
|
|
foreach (const QFileInfo &baselineFile, baselineFiles) {
|
|
|
|
const QString generatedFile = generated.absolutePath()
|
|
|
|
+ QLatin1Char('/') + baselineFile.fileName();
|
|
|
|
QTest::newRow(qPrintable(baselineFile.baseName()))
|
|
|
|
<< baselineFile.absoluteFilePath()
|
|
|
|
<< generatedFile;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-05 04:03:35 +00:00
|
|
|
QTEST_MAIN(tst_uic)
|
2011-04-27 10:05:43 +00:00
|
|
|
#include "tst_uic.moc"
|