aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2024-03-23 20:41:57 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2024-04-04 09:43:49 +0100
commit082634268a4bd23ff08b9a58d4537eaf800b7b84 (patch)
treea135b81a516b0b5f71f1fa87a45548cc1e196cca /tests/auto/qml
parentcd5d2ec701be8de32e83ee778d161de17f1400b4 (diff)
Tests: check that QFile::open succeeds
Wrap it in QVERIFY if possible. If not possible (e.g. a function that returns non-void, or not an autotest function) use qFatal to abort the test. Change-Id: Ie255024d29507e928a94e67d9af1cd436df4f1df Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml')
-rw-r--r--tests/auto/qml/ecmascripttests/test262runner.cpp15
-rw-r--r--tests/auto/qml/qjsonbinding/tst_qjsonbinding.cpp3
-rw-r--r--tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp2
-rw-r--r--tests/auto/qml/qmlformat/tst_qmlformat.cpp3
-rw-r--r--tests/auto/qml/qmlimportscanner/tst_qmlimportscanner.cpp2
-rw-r--r--tests/auto/qml/qmllint/tst_qmllint.cpp2
-rw-r--r--tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp2
-rw-r--r--tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp2
-rw-r--r--tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp6
-rw-r--r--tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp2
10 files changed, 25 insertions, 14 deletions
diff --git a/tests/auto/qml/ecmascripttests/test262runner.cpp b/tests/auto/qml/ecmascripttests/test262runner.cpp
index ab2dc20e51..90ac10a38b 100644
--- a/tests/auto/qml/ecmascripttests/test262runner.cpp
+++ b/tests/auto/qml/ecmascripttests/test262runner.cpp
@@ -688,7 +688,10 @@ void Test262Runner::updateTestExpectations()
}
QTemporaryFile updatedExpectations;
- updatedExpectations.open();
+ if (!updatedExpectations.open()) {
+ qFatal("Could not open temporary TestExpectations file: %s",
+ qPrintable(updatedExpectations.errorString()));
+ }
while (!file.atEnd()) {
QByteArray originalLine = file.readLine();
@@ -726,7 +729,10 @@ void Test262Runner::writeTestExpectations()
QFile file(expectationsFile);
QTemporaryFile expectations;
- expectations.open();
+ if (!expectations.open()) {
+ qFatal("Could not open temporary TestExpectations file: %s",
+ qPrintable(expectations.errorString()));
+ }
for (const auto &c : std::as_const(testCases)) {
TestExpectationLine line = TestExpectationLine::fromTestCase(c);
@@ -747,7 +753,10 @@ void Test262Runner::runAsExternalTests()
for (TestData &testData : tasks) {
auto runTest = [&] (const char *header, TestCase::Result *result) {
QTemporaryFile tempFile;
- tempFile.open();
+ if (!tempFile.open()) {
+ qFatal("Could not open temporary test data file: %s",
+ qPrintable(tempFile.errorString()));
+ }
tempFile.write(header);
tempFile.write(testData.content);
tempFile.close();
diff --git a/tests/auto/qml/qjsonbinding/tst_qjsonbinding.cpp b/tests/auto/qml/qjsonbinding/tst_qjsonbinding.cpp
index 00372612f1..76fa1328e7 100644
--- a/tests/auto/qml/qjsonbinding/tst_qjsonbinding.cpp
+++ b/tests/auto/qml/qjsonbinding/tst_qjsonbinding.cpp
@@ -67,7 +67,8 @@ private:
QByteArray tst_qjsonbinding::readAsUtf8(const QString &fileName)
{
QFile file(testFile(fileName));
- file.open(QIODevice::ReadOnly);
+ if (!file.open(QIODevice::ReadOnly))
+ qFatal("Cannot open file %s", qPrintable(fileName));
QTextStream stream(&file);
return stream.readAll().trimmed().toUtf8();
}
diff --git a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp
index 721c9e3af2..c1df8ec467 100644
--- a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp
+++ b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp
@@ -1162,7 +1162,7 @@ void tst_qmldiskcache::invalidateSaveLoadCache()
e->clearComponentCache();
{
QFile file(fileName);
- file.open(QIODevice::WriteOnly | QIODevice::Append);
+ QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Append));
file.write(" ");
}
waitForFileSystem();
diff --git a/tests/auto/qml/qmlformat/tst_qmlformat.cpp b/tests/auto/qml/qmlformat/tst_qmlformat.cpp
index 9dd0a6329e..f1a7ffbc4a 100644
--- a/tests/auto/qml/qmlformat/tst_qmlformat.cpp
+++ b/tests/auto/qml/qmlformat/tst_qmlformat.cpp
@@ -695,7 +695,8 @@ QString TestQmlformat::runQmlformat(const QString &fileToFormat, QStringList arg
QFile temp(tempFile);
- temp.open(QIODevice::ReadOnly);
+ if (!temp.open(QIODevice::ReadOnly))
+ qFatal("Could not open %s", qPrintable(tempFile));
QString formatted = QString::fromUtf8(temp.readAll());
return formatted;
diff --git a/tests/auto/qml/qmlimportscanner/tst_qmlimportscanner.cpp b/tests/auto/qml/qmlimportscanner/tst_qmlimportscanner.cpp
index 4ae4d1b0d7..49b3418401 100644
--- a/tests/auto/qml/qmlimportscanner/tst_qmlimportscanner.cpp
+++ b/tests/auto/qml/qmlimportscanner/tst_qmlimportscanner.cpp
@@ -149,7 +149,7 @@ void TestQmlimportscanner::runQmlimportscanner(const QString &mode, const QStrin
QVERIFY(generated.isArray());
QFile imports(resultFile);
- imports.open(QIODevice::ReadOnly);
+ QVERIFY(imports.open(QIODevice::ReadOnly));
QJsonDocument expected = QJsonDocument::fromJson(imports.readAll(), &error);
QCOMPARE(error.error, QJsonParseError::NoError);
QVERIFY(expected.isArray());
diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp
index ea4a0c8492..6a646c96f0 100644
--- a/tests/auto/qml/qmllint/tst_qmllint.cpp
+++ b/tests/auto/qml/qmllint/tst_qmllint.cpp
@@ -1560,7 +1560,7 @@ void TestQmllint::callQmllint(const QString &fileToLint, bool shouldSucceed, QJs
if (QFileInfo(fixedPath).exists()) {
QFile fixedFile(fixedPath);
- fixedFile.open(QFile::ReadOnly);
+ QVERIFY(fixedFile.open(QFile::ReadOnly));
QString fixedFileContents = QString::fromUtf8(fixedFile.readAll());
#ifdef Q_OS_WIN
fixedCode = fixedCode.replace(u"\r\n"_s, u"\n"_s);
diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp
index efbf4ee0eb..47b58889ac 100644
--- a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp
+++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp
@@ -464,7 +464,7 @@ void tst_qmltyperegistrar::consistencyWarnings()
r.write(output, "tst_qmltyperegistrar_qmltyperegistrations.cpp");
QTemporaryFile pluginTypes;
- pluginTypes.open();
+ QVERIFY(pluginTypes.open());
expectWarning("Warning: tst_qmltyperegistrar.h:: Refusing to generate non-lowercase name "
"Invisible for unknown foreign type");
diff --git a/tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp b/tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp
index dffb883d66..4cbb7aaf47 100644
--- a/tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp
+++ b/tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp
@@ -447,7 +447,7 @@ void tst_qqmldirparser::parse()
QFETCH(bool, designerSupported);
QFile f(testFile(file));
- f.open(QIODevice::ReadOnly);
+ QVERIFY(f.open(QIODevice::ReadOnly));
QQmlDirParser p;
p.parse(f.readAll());
diff --git a/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp b/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp
index 4acf27b173..60c0da78de 100644
--- a/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp
+++ b/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp
@@ -35,9 +35,9 @@ class tst_qqmljsscope : public QQmlDataTest
{
const QFileInfo fi(url);
QFile f(fi.absoluteFilePath());
- f.open(QIODevice::ReadOnly);
- QByteArray data(fi.size(), Qt::Uninitialized);
- f.read(data.data(), data.size());
+ if (!f.open(QIODevice::ReadOnly))
+ qFatal("Could not open file %s", qPrintable(url));
+ QByteArray data = f.readAll();
return QString::fromUtf8(data);
}
diff --git a/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp b/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp
index defaec318e..f908633193 100644
--- a/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp
+++ b/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp
@@ -1131,7 +1131,7 @@ void tst_qqmlxmlhttprequest::doFileRequest(std::function<void(QObject *component
QTemporaryFile writeFile;
QTemporaryFile readFile;
- writeFile.open();
+ QVERIFY(writeFile.open());
writeFile.close();
QVERIFY(readFile.open());