From 5e012dbd73cee3da9fc36f6248c5dd2faddd607f Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 15 Apr 2025 12:45:41 +0200 Subject: [PATCH] CppEditor: Avoid a use of FileReader Change-Id: Icb97756dfbedddd474a711ba654b1f40688167fc Reviewed-by: Christian Kandeler --- .../cppeditor/cppmodelmanager_test.cpp | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/plugins/cppeditor/cppmodelmanager_test.cpp b/src/plugins/cppeditor/cppmodelmanager_test.cpp index 5a1eeff22df..a1389f5f3cc 100644 --- a/src/plugins/cppeditor/cppmodelmanager_test.cpp +++ b/src/plugins/cppeditor/cppmodelmanager_test.cpp @@ -139,16 +139,12 @@ public: } /// Saves the contents also internally so it can be restored on destruction - bool readContents(QByteArray *contents) + Result readContents() { - Utils::FileReader fileReader; - const bool isFetchOk = fileReader.fetch(m_filePath); - if (isFetchOk) { - m_originalFileContents = fileReader.data(); - if (contents) - *contents = m_originalFileContents; - } - return isFetchOk; + const Result result = m_filePath.fileContents(); + if (result) + m_originalFileContents = *result; + return result; } bool writeContents(const QByteArray &contents) const @@ -493,9 +489,10 @@ void ModelManagerTest::testRefreshTimeStampModifiedIfSourcefilesChange() // Modify the file QTest::qSleep(1000); // Make sure the timestamp is different FileChangerAndRestorer fileChangerAndRestorer(filePath); - QByteArray originalContents; - QVERIFY(fileChangerAndRestorer.readContents(&originalContents)); - const QByteArray newFileContentes = originalContents + "\nint addedOtherGlobal;"; + const Result originalContents = fileChangerAndRestorer.readContents(); + QVERIFY(originalContents); + const QByteArray newFileContentes = originalContents.value_or(QByteArray()) + + "\nint addedOtherGlobal;"; QVERIFY(fileChangerAndRestorer.writeContents(newFileContentes)); // Add or remove source file. The configuration stays the same.