From c72322804d47a38ea254bc6c81b5a7b810f5a10d Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 6 Jan 2020 09:48:37 +0100 Subject: uic: Extend the baseline test for Python Previously, there was only a Python compile test which triggers only when PySide2 is found. Rename it to pythonCompile(). Extend the TestEntry structure by adding the base line file and flags, which represent all special cases found in the code. Check for the presence of a Python base line file in addition to the C++ one. Prototypically add one form. Further forms can be added on the go. Task-number: PYSIDE-797 Change-Id: Ic2983fa3cab2399a6809e244f93c663e0212f675 Reviewed-by: Cristian Maureira-Fredes --- tests/auto/tools/uic/tst_uic.cpp | 73 ++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 21 deletions(-) (limited to 'tests/auto/tools/uic/tst_uic.cpp') diff --git a/tests/auto/tools/uic/tst_uic.cpp b/tests/auto/tools/uic/tst_uic.cpp index 5b2f1f008b..4c0a4bbe26 100644 --- a/tests/auto/tools/uic/tst_uic.cpp +++ b/tests/auto/tools/uic/tst_uic.cpp @@ -45,11 +45,23 @@ static const char diffToStderrEnvVar[] = "UIC_STDERR_DIFF"; struct TestEntry { + enum Flag + { + IdBasedTranslation = 0x1, + Python = 0x2, // Python baseline is present + DontTestPythonCompile = 0x4 // Do not test Python compilation + }; + Q_DECLARE_FLAGS(Flags, Flag) + QByteArray name; - QString baselineBaseName; + QString uiFileName; + QString baseLineFileName; QString generatedFileName; + Flags flags; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(TestEntry::Flags) + class tst_uic : public QObject { Q_OBJECT @@ -73,8 +85,8 @@ private Q_SLOTS: void compare(); void compare_data() const; - void python(); - void python_data() const; + void pythonCompile(); + void pythonCompile_data() const; void runCompare(); @@ -89,9 +101,12 @@ private: QString m_python; }; +static const char versionRegexp[] = + R"([*#][*#] Created by: Qt User Interface Compiler version \d{1,2}\.\d{1,2}\.\d{1,2})"; + tst_uic::tst_uic() : m_command(QLibraryInfo::location(QLibraryInfo::BinariesPath) + QLatin1String("/uic")) - , m_versionRegexp(QLatin1String(R"(\*\* Created by: Qt User Interface Compiler version \d{1,2}\.\d{1,2}\.\d{1,2})")) + , m_versionRegexp(QLatin1String(versionRegexp)) { } @@ -165,10 +180,27 @@ void tst_uic::populateTestEntries() 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}); + TestEntry entry; + // qprintsettingsoutput: variable named 'from' clashes with Python + if (baseName == QLatin1String("qprintsettingsoutput")) + entry.flags.setFlag(TestEntry::DontTestPythonCompile); + else if (baseName == QLatin1String("qttrid")) + entry.flags.setFlag(TestEntry::IdBasedTranslation); + entry.name = baseName.toLocal8Bit(); + entry.uiFileName = baselineFile.absoluteFilePath(); + entry.baseLineFileName = entry.uiFileName + QLatin1String(".h"); + const QString generatedFilePrefix = generatedPrefix + baselineFile.fileName(); + entry.generatedFileName = generatedFilePrefix + QLatin1String(".h"); + m_testEntries.append(entry); + // Check for a Python baseline + entry.baseLineFileName = entry.uiFileName + QLatin1String(".py"); + if (QFileInfo::exists(entry.baseLineFileName)) { + entry.name.append(QByteArrayLiteral("-python")); + entry.flags.setFlag(TestEntry::DontTestPythonCompile); + entry.flags.setFlag(TestEntry::Python); + entry.generatedFileName = generatedFilePrefix + QLatin1String(".py"); + m_testEntries.append(entry); + } } } @@ -237,9 +269,11 @@ void tst_uic::run_data() const for (const TestEntry &te : m_testEntries) { QStringList options; - if (te.name == QByteArrayLiteral("qttrid")) - options << QStringList(QLatin1String("-idbased")); - QTest::newRow(te.name.constData()) << (te.baselineBaseName + QLatin1String(".ui")) + if (te.flags.testFlag(TestEntry::IdBasedTranslation)) + options.append(QLatin1String("-idbased")); + if (te.flags.testFlag(TestEntry::Python)) + options << QLatin1String("-g") << QLatin1String("python"); + QTest::newRow(te.name.constData()) << te.uiFileName << te.generatedFileName << options; } } @@ -319,7 +353,7 @@ void tst_uic::compare_data() const QTest::addColumn("generatedFile"); for (const TestEntry &te : m_testEntries) { - QTest::newRow(te.name.constData()) << (te.baselineBaseName + QLatin1String(".ui.h")) + QTest::newRow(te.name.constData()) << te.baseLineFileName << te.generatedFileName; } } @@ -396,7 +430,8 @@ static inline QByteArray msgCompilePythonFailed(const QByteArray &error) return lines.join('\n'); } -void tst_uic::python_data() const +// Test Python code generation by compiling the file +void tst_uic::pythonCompile_data() const { QTest::addColumn("originalFile"); QTest::addColumn("generatedFile"); @@ -405,19 +440,15 @@ void tst_uic::python_data() const ? 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")); + if (!te.flags.testFlag(TestEntry::DontTestPythonCompile)) { QTest::newRow(te.name.constData()) - << (te.baselineBaseName + QLatin1String(".ui")) - << generatedFile; + << te.uiFileName + << te.generatedFileName; } } } -void tst_uic::python() +void tst_uic::pythonCompile() { QFETCH(QString, originalFile); QFETCH(QString, generatedFile); -- cgit v1.2.3