forked from qt-creator/qt-creator
CppEditor: Avoid a use of FileReader
Change-Id: Icb97756dfbedddd474a711ba654b1f40688167fc Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -139,16 +139,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Saves the contents also internally so it can be restored on destruction
|
/// Saves the contents also internally so it can be restored on destruction
|
||||||
bool readContents(QByteArray *contents)
|
Result<QByteArray> readContents()
|
||||||
{
|
{
|
||||||
Utils::FileReader fileReader;
|
const Result<QByteArray> result = m_filePath.fileContents();
|
||||||
const bool isFetchOk = fileReader.fetch(m_filePath);
|
if (result)
|
||||||
if (isFetchOk) {
|
m_originalFileContents = *result;
|
||||||
m_originalFileContents = fileReader.data();
|
return result;
|
||||||
if (contents)
|
|
||||||
*contents = m_originalFileContents;
|
|
||||||
}
|
|
||||||
return isFetchOk;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool writeContents(const QByteArray &contents) const
|
bool writeContents(const QByteArray &contents) const
|
||||||
@@ -493,9 +489,10 @@ void ModelManagerTest::testRefreshTimeStampModifiedIfSourcefilesChange()
|
|||||||
// Modify the file
|
// Modify the file
|
||||||
QTest::qSleep(1000); // Make sure the timestamp is different
|
QTest::qSleep(1000); // Make sure the timestamp is different
|
||||||
FileChangerAndRestorer fileChangerAndRestorer(filePath);
|
FileChangerAndRestorer fileChangerAndRestorer(filePath);
|
||||||
QByteArray originalContents;
|
const Result<QByteArray> originalContents = fileChangerAndRestorer.readContents();
|
||||||
QVERIFY(fileChangerAndRestorer.readContents(&originalContents));
|
QVERIFY(originalContents);
|
||||||
const QByteArray newFileContentes = originalContents + "\nint addedOtherGlobal;";
|
const QByteArray newFileContentes = originalContents.value_or(QByteArray())
|
||||||
|
+ "\nint addedOtherGlobal;";
|
||||||
QVERIFY(fileChangerAndRestorer.writeContents(newFileContentes));
|
QVERIFY(fileChangerAndRestorer.writeContents(newFileContentes));
|
||||||
|
|
||||||
// Add or remove source file. The configuration stays the same.
|
// Add or remove source file. The configuration stays the same.
|
||||||
|
Reference in New Issue
Block a user