Tests: make some QFile::open calls fail
In some cases calls to QFile::open are made outside of a testfunction (so we can't use QVERIFY), or even in standalone executables that are executed by tests. Make them fail "visibly". Change-Id: Iec4d56f6d874be16aa2e9ad6974eeec2a98caa3f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
223b92490e
commit
c68f8db62b
@ -16,13 +16,16 @@ int main(int argc, char *argv[])
|
||||
QFile file;
|
||||
|
||||
if (strcmp(argv[1], "all") == 0) {
|
||||
file.open(stdin, QFile::ReadWrite);
|
||||
if (!file.open(stdin, QFile::ReadWrite))
|
||||
return 1;
|
||||
printf("%s", file.readAll().constData());
|
||||
} else if (strcmp(argv[1], "line") == 0) {
|
||||
if (strcmp(argv[2], "0") == 0) {
|
||||
file.open(stdin, QFile::ReadWrite);
|
||||
if (!file.open(stdin, QFile::ReadWrite))
|
||||
return 1;
|
||||
} else {
|
||||
file.open(0, QFile::ReadWrite);
|
||||
if (!file.open(0, QFile::ReadWrite))
|
||||
return 1;
|
||||
}
|
||||
|
||||
char line[1024];
|
||||
|
@ -9,7 +9,8 @@ int main(int argc, char **argv)
|
||||
{
|
||||
QCoreApplication ca(argc, argv);
|
||||
QFile f;
|
||||
f.open(stdin, QIODevice::ReadOnly);
|
||||
if (!f.open(stdin, QIODevice::ReadOnly))
|
||||
return 1;
|
||||
QByteArray input;
|
||||
char buf[1024];
|
||||
qint64 len;
|
||||
|
@ -95,8 +95,8 @@ static QByteArray makeCanonical(const QString &filename,
|
||||
bool testIncremental = false)
|
||||
{
|
||||
QFile file(filename);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
qFatal("Could not open file %s", qPrintable(filename));
|
||||
QXmlStreamReader reader;
|
||||
|
||||
QByteArray buffer;
|
||||
@ -747,7 +747,8 @@ void tst_QXmlStream::reportSuccess_data() const
|
||||
QByteArray tst_QXmlStream::readFile(const QString &filename)
|
||||
{
|
||||
QFile file(filename);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
qFatal("Could not open file %s", qPrintable(filename));
|
||||
|
||||
QXmlStreamReader reader;
|
||||
|
||||
|
@ -79,7 +79,8 @@ void tst_qfileopenevent::constructor()
|
||||
QByteArray tst_qfileopenevent::readFileContent(QFileOpenEvent& event)
|
||||
{
|
||||
QFile file(event.file());
|
||||
file.open(QFile::ReadOnly);
|
||||
if (!file.open(QFile::ReadOnly))
|
||||
qFatal("Cannot open file %s", qPrintable(event.file()));
|
||||
file.seek(0);
|
||||
QByteArray data = file.readAll();
|
||||
return data;
|
||||
|
@ -328,7 +328,8 @@ void Http2Server::incomingConnection(qintptr socketDescriptor)
|
||||
connect(sslSocket, SIGNAL(sslErrors(QList<QSslError>)),
|
||||
this, SLOT(ignoreErrorSlot()));
|
||||
QFile file(QT_TESTCASE_SOURCEDIR "/certs/fluke.key");
|
||||
file.open(QIODevice::ReadOnly);
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
qFatal("Cannot open certificate file %s", qPrintable(file.fileName()));
|
||||
QSslKey key(file.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
|
||||
sslSocket->setPrivateKey(key);
|
||||
auto localCert = QSslCertificate::fromPath(QT_TESTCASE_SOURCEDIR "/certs/fluke.cert");
|
||||
|
@ -12,11 +12,13 @@ int main(int argc, char **)
|
||||
}
|
||||
|
||||
QFile file;
|
||||
file.open(stdin, QFile::ReadWrite);
|
||||
if (!file.open(stdin, QFile::ReadWrite))
|
||||
return 1;
|
||||
QByteArray data = file.readAll();
|
||||
file.close();
|
||||
|
||||
file.open(stdout, QFile::WriteOnly);
|
||||
if (!file.open(stdout, QFile::WriteOnly))
|
||||
return 1;
|
||||
file.write(data);
|
||||
file.close();
|
||||
return 0;
|
||||
|
@ -5088,6 +5088,10 @@ void tst_QNetworkReply::ioPutToFileFromProcess()
|
||||
QByteArray contents = file.readAll();
|
||||
QCOMPARE(contents, data);
|
||||
|
||||
if (process.state() == QProcess::Running)
|
||||
QVERIFY(process.waitForFinished());
|
||||
QCOMPARE(process.exitCode(), 0);
|
||||
|
||||
#endif // QT_CONFIG(process)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user