2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
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
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 12:36:27 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
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>
|
2017-02-03 07:43:03 +00:00
|
|
|
#include <QtCore/QRegularExpression>
|
2015-04-20 14:03:34 +00:00
|
|
|
#include <QtCore/QStandardPaths>
|
2018-12-03 15:20:29 +00:00
|
|
|
#include <QtCore/QVector>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2018-10-23 11:27:31 +00:00
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
static const char keepEnvVar[] = "UIC_KEEP_GENERATED_FILES";
|
|
|
|
static const char diffToStderrEnvVar[] = "UIC_STDERR_DIFF";
|
|
|
|
|
2018-12-03 15:20:29 +00:00
|
|
|
struct TestEntry
|
|
|
|
{
|
|
|
|
QByteArray name;
|
|
|
|
QString baselineBaseName;
|
|
|
|
QString generatedFileName;
|
|
|
|
};
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
class tst_uic : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-12-03 15:20:29 +00:00
|
|
|
using TestEntries = QVector<TestEntry>;
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
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;
|
|
|
|
|
2013-11-11 13:52:11 +00:00
|
|
|
void runTranslation();
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void compare();
|
|
|
|
void compare_data() const;
|
|
|
|
|
2018-12-03 15:57:04 +00:00
|
|
|
void python();
|
|
|
|
void python_data() const;
|
|
|
|
|
2013-11-11 13:52:11 +00:00
|
|
|
void runCompare();
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
private:
|
2018-12-03 15:20:29 +00:00
|
|
|
void populateTestEntries();
|
|
|
|
|
2012-08-02 09:02:24 +00:00
|
|
|
const QString m_command;
|
|
|
|
QString m_baseline;
|
|
|
|
QTemporaryDir m_generated;
|
2018-12-03 15:20:29 +00:00
|
|
|
TestEntries m_testEntries;
|
2017-02-03 07:43:03 +00:00
|
|
|
QRegularExpression m_versionRegexp;
|
2018-12-03 15:57:04 +00:00
|
|
|
QString m_python;
|
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"))
|
2018-10-23 11:27:31 +00:00
|
|
|
, m_versionRegexp(QLatin1String(R"(\*\* Created by: Qt User Interface Compiler version \d{1,2}\.\d{1,2}\.\d{1,2})"))
|
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();
|
|
|
|
}
|
|
|
|
|
2018-12-03 15:57:04 +00:00
|
|
|
// Locate Python and check whether PySide2 is installed
|
|
|
|
static QString locatePython(QTemporaryDir &generatedDir)
|
|
|
|
{
|
|
|
|
QString python = QStandardPaths::findExecutable(QLatin1String("python"));
|
|
|
|
if (python.isEmpty()) {
|
|
|
|
qWarning("Cannot locate python, skipping tests");
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
QFile importTestFile(generatedDir.filePath(QLatin1String("import_test.py")));
|
|
|
|
if (!importTestFile.open(QIODevice::WriteOnly| QIODevice::Text))
|
|
|
|
return QString();
|
|
|
|
importTestFile.write("import PySide2.QtCore\n");
|
|
|
|
importTestFile.close();
|
|
|
|
QProcess process;
|
|
|
|
process.start(python, {importTestFile.fileName()});
|
|
|
|
if (!process.waitForStarted() || !process.waitForFinished())
|
|
|
|
return QString();
|
|
|
|
if (process.exitStatus() != QProcess::NormalExit || process.exitCode() != 0) {
|
|
|
|
const QString stdErr = QString::fromLocal8Bit(process.readAllStandardError()).simplified();
|
|
|
|
qWarning("PySide2 is not installed (%s)", qPrintable(stdErr));
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
importTestFile.remove();
|
|
|
|
return python;
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_uic::initTestCase()
|
|
|
|
{
|
2015-09-24 13:56:57 +00:00
|
|
|
QVERIFY2(m_generated.isValid(), qPrintable(m_generated.errorString()));
|
2015-04-20 14:03:34 +00:00
|
|
|
QVERIFY(m_versionRegexp.isValid());
|
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
|
2015-02-02 21:30:17 +00:00
|
|
|
QString msg = QString::fromLatin1("uic test running in '%1' using: ").
|
|
|
|
arg(QDir::currentPath());
|
2011-04-27 10:05:43 +00:00
|
|
|
if (!outLines.empty())
|
|
|
|
msg += outLines.front();
|
2018-12-03 15:20:29 +00:00
|
|
|
populateTestEntries();
|
|
|
|
QVERIFY(!m_testEntries.isEmpty());
|
2012-08-02 09:02:24 +00:00
|
|
|
qDebug("%s", qPrintable(msg));
|
2018-12-03 15:57:04 +00:00
|
|
|
|
|
|
|
m_python = locatePython(m_generated);
|
2012-08-02 09:02:24 +00:00
|
|
|
}
|
|
|
|
|
2018-12-03 15:20:29 +00:00
|
|
|
void tst_uic::populateTestEntries()
|
|
|
|
{
|
|
|
|
const QString generatedPrefix = m_generated.path() + QLatin1Char('/');
|
|
|
|
QDir baseline(m_baseline);
|
|
|
|
const QString baseLinePrefix = baseline.path() + QLatin1Char('/');
|
|
|
|
const QFileInfoList baselineFiles =
|
|
|
|
baseline.entryInfoList(QStringList(QString::fromLatin1("*.ui")), QDir::Files);
|
|
|
|
m_testEntries.reserve(baselineFiles.size());
|
|
|
|
for (const QFileInfo &baselineFile : baselineFiles) {
|
|
|
|
const QString baseName = baselineFile.baseName();
|
|
|
|
const QString baselineBaseName = baseLinePrefix + baseName;
|
|
|
|
const QString generatedFile = generatedPrefix + baselineFile.fileName()
|
|
|
|
+ QLatin1String(".h");
|
|
|
|
m_testEntries.append(TestEntry{baseName.toLocal8Bit(), baselineBaseName, generatedFile});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-23 11:27:31 +00:00
|
|
|
static const char helpFormat[] = R"(
|
|
|
|
Note: The environment variable '%s' can be set to keep the temporary files
|
|
|
|
for error analysis.
|
|
|
|
The environment variable '%s' can be set to redirect the diff output to
|
|
|
|
stderr.)";
|
|
|
|
|
2012-08-02 09:02:24 +00:00
|
|
|
void tst_uic::cleanupTestCase()
|
|
|
|
{
|
2018-10-23 11:27:31 +00:00
|
|
|
if (qEnvironmentVariableIsSet(keepEnvVar)) {
|
2012-08-02 09:02:24 +00:00
|
|
|
m_generated.setAutoRemove(false);
|
|
|
|
qDebug("Keeping generated files in '%s'", qPrintable(QDir::toNativeSeparators(m_generated.path())));
|
2018-10-23 11:27:31 +00:00
|
|
|
} else {
|
|
|
|
qDebug(helpFormat, keepEnvVar, diffToStderrEnvVar);
|
2012-08-02 09:02:24 +00:00
|
|
|
}
|
|
|
|
}
|
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);
|
2016-01-05 12:05:47 +00:00
|
|
|
QFETCH(QStringList, options);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QProcess process;
|
2012-08-02 09:02:24 +00:00
|
|
|
process.start(m_command, QStringList(originalFile)
|
2016-01-05 12:05:47 +00:00
|
|
|
<< QString(QLatin1String("-o")) << generatedFile << options);
|
2012-08-02 09:02:24 +00:00
|
|
|
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);
|
2018-10-23 11:27:31 +00:00
|
|
|
QVERIFY(QFileInfo::exists(generatedFile));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_uic::run_data() const
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("originalFile");
|
|
|
|
QTest::addColumn<QString>("generatedFile");
|
2016-01-05 12:05:47 +00:00
|
|
|
QTest::addColumn<QStringList>("options");
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2018-12-03 15:20:29 +00:00
|
|
|
for (const TestEntry &te : m_testEntries) {
|
2016-01-05 12:05:47 +00:00
|
|
|
QStringList options;
|
2018-12-03 15:20:29 +00:00
|
|
|
if (te.name == QByteArrayLiteral("qttrid"))
|
2016-01-05 12:05:47 +00:00
|
|
|
options << QStringList(QLatin1String("-idbased"));
|
2018-12-03 15:20:29 +00:00
|
|
|
QTest::newRow(te.name.constData()) << (te.baselineBaseName + QLatin1String(".ui"))
|
|
|
|
<< te.generatedFileName << options;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-20 14:03:34 +00:00
|
|
|
// Helpers to generate a diff using the standard diff tool if present for failures.
|
|
|
|
static inline QString diffBinary()
|
|
|
|
{
|
|
|
|
QString binary = QLatin1String("diff");
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
binary += QLatin1String(".exe");
|
|
|
|
#endif
|
|
|
|
return QStandardPaths::findExecutable(binary);
|
|
|
|
}
|
|
|
|
|
|
|
|
static QString generateDiff(const QString &originalFile, const QString &generatedFile)
|
|
|
|
{
|
|
|
|
static const QString diff = diffBinary();
|
|
|
|
if (diff.isEmpty())
|
|
|
|
return QString();
|
|
|
|
const QStringList args = QStringList() << QLatin1String("-u")
|
|
|
|
<< QDir::toNativeSeparators(originalFile)
|
|
|
|
<< QDir::toNativeSeparators(generatedFile);
|
|
|
|
QProcess diffProcess;
|
|
|
|
diffProcess.start(diff, args);
|
|
|
|
return diffProcess.waitForStarted() && diffProcess.waitForFinished()
|
|
|
|
? QString::fromLocal8Bit(diffProcess.readAllStandardOutput()) : QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
static QByteArray msgCannotReadFile(const QFile &file)
|
|
|
|
{
|
|
|
|
const QString result = QLatin1String("Could not read file: ")
|
|
|
|
+ QDir::toNativeSeparators(file.fileName())
|
|
|
|
+ QLatin1String(": ") + file.errorString();
|
|
|
|
return result.toLocal8Bit();
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2018-10-23 11:27:31 +00:00
|
|
|
static void outputDiff(const QString &diff)
|
|
|
|
{
|
|
|
|
// Use patch -p3 < diff to apply the obtained diff output in the baseline directory.
|
|
|
|
static const bool diffToStderr = qEnvironmentVariableIsSet(diffToStderrEnvVar);
|
|
|
|
if (diffToStderr)
|
|
|
|
std::fputs(qPrintable(diff), stderr);
|
|
|
|
else
|
|
|
|
qWarning("Difference:\n%s", qPrintable(diff));
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_uic::compare()
|
|
|
|
{
|
|
|
|
QFETCH(QString, originalFile);
|
|
|
|
QFETCH(QString, generatedFile);
|
|
|
|
|
|
|
|
QFile orgFile(originalFile);
|
|
|
|
QFile genFile(generatedFile);
|
|
|
|
|
2015-04-20 14:03:34 +00:00
|
|
|
QVERIFY2(orgFile.open(QIODevice::ReadOnly | QIODevice::Text), msgCannotReadFile(orgFile));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-04-20 14:03:34 +00:00
|
|
|
QVERIFY2(genFile.open(QIODevice::ReadOnly | QIODevice::Text), msgCannotReadFile(genFile));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-04-20 14:03:34 +00:00
|
|
|
QString originalFileContents = orgFile.readAll();
|
|
|
|
originalFileContents.replace(m_versionRegexp, QString());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-04-20 14:03:34 +00:00
|
|
|
QString generatedFileContents = genFile.readAll();
|
|
|
|
generatedFileContents.replace(m_versionRegexp, QString());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-04-20 14:03:34 +00:00
|
|
|
if (generatedFileContents != originalFileContents) {
|
|
|
|
const QString diff = generateDiff(originalFile, generatedFile);
|
|
|
|
if (!diff.isEmpty())
|
2018-10-23 11:27:31 +00:00
|
|
|
outputDiff(diff);
|
2015-04-20 14:03:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QCOMPARE(generatedFileContents, originalFileContents);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_uic::compare_data() const
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("originalFile");
|
|
|
|
QTest::addColumn<QString>("generatedFile");
|
|
|
|
|
2018-12-03 15:20:29 +00:00
|
|
|
for (const TestEntry &te : m_testEntries) {
|
|
|
|
QTest::newRow(te.name.constData()) << (te.baselineBaseName + QLatin1String(".ui.h"))
|
|
|
|
<< te.generatedFileName;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-11 13:52:11 +00:00
|
|
|
void tst_uic::runTranslation()
|
|
|
|
{
|
|
|
|
QProcess process;
|
|
|
|
|
2018-12-03 15:20:29 +00:00
|
|
|
const QDir baseline(m_baseline);
|
2013-11-11 13:52:11 +00:00
|
|
|
|
|
|
|
QDir generated(m_generated.path());
|
|
|
|
generated.mkdir(QLatin1String("translation"));
|
|
|
|
QString generatedFile = generated.absolutePath() + QLatin1String("/translation/Dialog_without_Buttons_tr.h");
|
|
|
|
|
|
|
|
process.start(m_command, QStringList(baseline.filePath("Dialog_without_Buttons.ui"))
|
|
|
|
<< QString(QLatin1String("-tr")) << "i18n"
|
|
|
|
<< QString(QLatin1String("-include")) << "ki18n.h"
|
|
|
|
<< QString(QLatin1String("-o")) << generatedFile);
|
|
|
|
QVERIFY2(process.waitForStarted(), msgProcessStartFailed(m_command, process.errorString()));
|
|
|
|
QVERIFY(process.waitForFinished());
|
|
|
|
QCOMPARE(process.exitStatus(), QProcess::NormalExit);
|
|
|
|
QCOMPARE(process.exitCode(), 0);
|
2018-10-23 11:27:31 +00:00
|
|
|
QVERIFY(QFileInfo::exists(generatedFile));
|
2013-11-11 13:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_uic::runCompare()
|
|
|
|
{
|
2015-04-20 14:03:34 +00:00
|
|
|
const QString dialogFile = QLatin1String("/translation/Dialog_without_Buttons_tr.h");
|
|
|
|
const QString originalFile = m_baseline + dialogFile;
|
|
|
|
QFile orgFile(originalFile);
|
2013-11-11 13:52:11 +00:00
|
|
|
|
|
|
|
QDir generated(m_generated.path());
|
2015-04-20 14:03:34 +00:00
|
|
|
const QString generatedFile = generated.absolutePath() + dialogFile;
|
|
|
|
QFile genFile(generatedFile);
|
2013-11-11 13:52:11 +00:00
|
|
|
|
2015-04-20 14:03:34 +00:00
|
|
|
QVERIFY2(orgFile.open(QIODevice::ReadOnly | QIODevice::Text), msgCannotReadFile(orgFile));
|
2013-11-11 13:52:11 +00:00
|
|
|
|
2015-04-20 14:03:34 +00:00
|
|
|
QVERIFY2(genFile.open(QIODevice::ReadOnly | QIODevice::Text), msgCannotReadFile(genFile));
|
2013-11-11 13:52:11 +00:00
|
|
|
|
2015-04-20 14:03:34 +00:00
|
|
|
QString originalFileContents = orgFile.readAll();
|
|
|
|
originalFileContents.replace(m_versionRegexp, QString());
|
2013-11-11 13:52:11 +00:00
|
|
|
|
2015-04-20 14:03:34 +00:00
|
|
|
QString generatedFileContents = genFile.readAll();
|
|
|
|
generatedFileContents.replace(m_versionRegexp, QString());
|
|
|
|
|
|
|
|
if (generatedFileContents != originalFileContents) {
|
|
|
|
const QString diff = generateDiff(originalFile, generatedFile);
|
|
|
|
if (!diff.isEmpty())
|
2018-10-23 11:27:31 +00:00
|
|
|
outputDiff(diff);
|
2015-04-20 14:03:34 +00:00
|
|
|
}
|
2013-11-11 13:52:11 +00:00
|
|
|
|
2015-04-20 14:03:34 +00:00
|
|
|
QCOMPARE(generatedFileContents, originalFileContents);
|
2013-11-11 13:52:11 +00:00
|
|
|
}
|
|
|
|
|
2018-12-03 15:57:04 +00:00
|
|
|
// Let uic generate Python code and verify that it is syntactically
|
|
|
|
// correct by compiling it into .pyc. This test is executed only
|
|
|
|
// when python with an installed Qt for Python is detected (see locatePython()).
|
|
|
|
|
|
|
|
static inline QByteArray msgCompilePythonFailed(const QByteArray &error)
|
|
|
|
{
|
|
|
|
// If there is a line with blanks and caret indicating an error in the line
|
|
|
|
// above, insert the cursor into the offending line and remove the caret.
|
|
|
|
QByteArrayList lines = error.trimmed().split('\n');
|
|
|
|
for (int i = lines.size() - 1; i > 0; --i) {
|
|
|
|
const auto &line = lines.at(i);
|
|
|
|
const int caret = line.indexOf('^');
|
|
|
|
if (caret == 0 || (caret > 0 && line.at(caret - 1) == ' ')) {
|
|
|
|
lines.removeAt(i);
|
|
|
|
lines[i - 1].insert(caret, '|');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lines.join('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_uic::python_data() const
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("originalFile");
|
|
|
|
QTest::addColumn<QString>("generatedFile");
|
|
|
|
|
|
|
|
const int size = m_python.isEmpty()
|
|
|
|
? qMin(1, m_testEntries.size()) : m_testEntries.size();
|
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
const TestEntry &te = m_testEntries.at(i);
|
|
|
|
// qprintsettingsoutput: variable named 'from' clashes with Python
|
|
|
|
if (!te.baselineBaseName.endsWith(QLatin1String("/qprintsettingsoutput"))) {
|
|
|
|
QString generatedFile = te.generatedFileName;
|
|
|
|
generatedFile.chop(1); // foo.h -> foo.py
|
|
|
|
generatedFile.append(QLatin1String("py"));
|
|
|
|
QTest::newRow(te.name.constData())
|
|
|
|
<< (te.baselineBaseName + QLatin1String(".ui"))
|
|
|
|
<< generatedFile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_uic::python()
|
|
|
|
{
|
|
|
|
QFETCH(QString, originalFile);
|
|
|
|
QFETCH(QString, generatedFile);
|
|
|
|
if (m_python.isEmpty())
|
|
|
|
QSKIP("Python was not found");
|
|
|
|
|
|
|
|
QStringList uicArguments{QLatin1String("-g"), QLatin1String("python"),
|
|
|
|
originalFile, QLatin1String("-o"), generatedFile};
|
|
|
|
QProcess process;
|
|
|
|
process.setWorkingDirectory(m_generated.path());
|
|
|
|
process.start(m_command, uicArguments);
|
|
|
|
QVERIFY2(process.waitForStarted(), msgProcessStartFailed(m_command, process.errorString()));
|
|
|
|
QVERIFY(process.waitForFinished());
|
|
|
|
QCOMPARE(process.exitStatus(), QProcess::NormalExit);
|
|
|
|
QCOMPARE(process.exitCode(), 0);
|
|
|
|
QVERIFY(QFileInfo::exists(generatedFile));
|
|
|
|
|
|
|
|
// Test Python code generation by compiling the file
|
|
|
|
QStringList compileArguments{QLatin1String("-m"), QLatin1String("py_compile"), generatedFile};
|
|
|
|
process.start(m_python, compileArguments);
|
|
|
|
QVERIFY2(process.waitForStarted(), msgProcessStartFailed(m_command, process.errorString()));
|
|
|
|
QVERIFY(process.waitForFinished());
|
|
|
|
const bool compiled = process.exitStatus() == QProcess::NormalExit
|
|
|
|
&& process.exitCode() == 0;
|
|
|
|
QVERIFY2(compiled, msgCompilePythonFailed(process.readAllStandardError()).constData());
|
|
|
|
}
|
|
|
|
|
2012-06-05 04:03:35 +00:00
|
|
|
QTEST_MAIN(tst_uic)
|
2011-04-27 10:05:43 +00:00
|
|
|
#include "tst_uic.moc"
|