| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
#include <QtTest/QtTest> |
| 4 |
|
| 5 |
#include <QtCore/QProcess> |
| 6 |
#include <QtCore/QLibraryInfo> |
| 7 |
#include <QtCore/QFileInfo> |
| 8 |
#include <QtCore/QDir> |
| 9 |
|
| 10 |
class tst_QtDiag : public QObject |
| 11 |
{ |
| 12 |
Q_OBJECT |
| 13 |
|
| 14 |
private slots: |
| 15 |
void initTestCase(); |
| 16 |
void run(); |
| 17 |
|
| 18 |
private: |
| 19 |
QString m_binary; |
| 20 |
}; |
| 21 |
|
| 22 |
void tst_QtDiag::initTestCase() |
| 23 |
{ |
| 24 |
QString binary = QLibraryInfo::path(QLibraryInfo::BinariesPath) + QStringLiteral("/qtdiag"); |
| 25 |
# ifdef Q_OS_WIN |
| 26 |
binary += QStringLiteral(".exe"); |
| 27 |
# endif |
| 28 |
const QFileInfo fi(binary); |
| 29 |
if (fi.isFile()) { |
| 30 |
m_binary = fi.absoluteFilePath(); |
| 31 |
} else { |
| 32 |
const QByteArray message = QByteArrayLiteral("The binary '") |
| 33 |
+ QDir::toNativeSeparators(binary).toLocal8Bit() |
| 34 |
+ QByteArrayLiteral("' does not exist."); |
| 35 |
QSKIP(message.constData()); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
void tst_QtDiag::run() |
| 40 |
{ |
| 41 |
if (m_binary.isEmpty()) |
| 42 |
QSKIP("Binary could not be found"); |
| 43 |
QProcess process; |
| 44 |
qDebug() << "Launching " << QDir::toNativeSeparators(m_binary); |
| 45 |
process.start(m_binary, QStringList{}); |
| 46 |
QVERIFY2(process.waitForStarted(), qPrintable(process.errorString())); |
| 47 |
QVERIFY(process.waitForFinished()); |
| 48 |
QCOMPARE(process.exitStatus(), QProcess::NormalExit); |
| 49 |
QCOMPARE(process.exitCode(), 0); |
| 50 |
QByteArray output = process.readAll(); |
| 51 |
QVERIFY(!output.isEmpty()); |
| 52 |
output.replace('\r', ""); |
| 53 |
qDebug("\n%s", output.constData()); |
| 54 |
} |
| 55 |
|
| 56 |
QTEST_MAIN(tst_QtDiag) |
| 57 |
#include "tst_qtdiag.moc" |