summaryrefslogtreecommitdiffstats
path: root/tests/auto/tools/moc/tst_moc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/tools/moc/tst_moc.cpp')
-rw-r--r--tests/auto/tools/moc/tst_moc.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp
index 89f563f11d..9fc00288fe 100644
--- a/tests/auto/tools/moc/tst_moc.cpp
+++ b/tests/auto/tools/moc/tst_moc.cpp
@@ -33,6 +33,7 @@
#include <stdio.h>
#include <qobject.h>
#include <qmetaobject.h>
+#include <qjsondocument.h>
#include "using-namespaces.h"
#include "assign-namespace.h"
@@ -717,6 +718,7 @@ private slots:
void testQNamespace();
void cxx17Namespaces();
void cxxAttributes();
+ void mocJsonOutput();
signals:
void sigWithUnsignedArg(unsigned foo);
@@ -3971,6 +3973,57 @@ void tst_Moc::cxxAttributes()
QCOMPARE(meta.keyCount(), 7);
}
+void tst_Moc::mocJsonOutput()
+{
+ const auto readFile = [](const QString &fileName) {
+ QFile f(fileName);
+ f.open(QIODevice::ReadOnly);
+ return QJsonDocument::fromJson(f.readAll());
+ };
+
+ const QString actualFile = QStringLiteral(":/allmocs.json");
+ const QString expectedFile = QStringLiteral(":/allmocs_baseline.json");
+
+ QVERIFY2(QFile::exists(actualFile), qPrintable(actualFile));
+ QVERIFY2(QFile::exists(expectedFile), qPrintable(expectedFile));
+
+ QJsonDocument actualOutput = readFile(QLatin1String(":/allmocs.json"));
+ QJsonDocument expectedOutput = readFile(QLatin1String(":/allmocs_baseline.json"));
+
+ const auto showPotentialDiff = [](const QJsonDocument &actual, const QJsonDocument &expected) -> QByteArray {
+#if defined(Q_OS_UNIX)
+ QByteArray actualStr = actual.toJson();
+ QByteArray expectedStr = expected.toJson();
+
+ QTemporaryFile actualFile;
+ if (!actualFile.open())
+ return "Error opening actual temp file";
+ actualFile.write(actualStr);
+ actualFile.flush();
+
+ QTemporaryFile expectedFile;
+ if (!expectedFile.open())
+ return "Error opening expected temp file";
+ expectedFile.write(expectedStr);
+ expectedFile.flush();
+
+ QProcess diffProc;
+ diffProc.setProgram("diff");
+ diffProc.setArguments(QStringList() << "-ub" << expectedFile.fileName() << actualFile.fileName());
+ diffProc.start();
+ if (!diffProc.waitForStarted())
+ return "Error waiting for diff process to start.";
+ if (!diffProc.waitForFinished())
+ return "Error waiting for diff process to finish.";
+ return diffProc.readAllStandardOutput();
+#else
+ return "Cannot launch diff. Please check allmocs.json and allmocs_baseline.json on disk.";
+#endif
+ };
+
+ QVERIFY2(actualOutput == expectedOutput, showPotentialDiff(actualOutput, expectedOutput).constData());
+}
+
QTEST_MAIN(tst_Moc)
// the generated code must compile with QT_NO_KEYWORDS