From 274d866c19bac4d53d0e963917a5470e5f1ea9da Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Sun, 17 Sep 2023 11:09:02 +0200 Subject: [PATCH] fix failing automated test that erases invalid iterator Signed-off-by: Matthieu Gallien --- test/syncenginetestutils.cpp | 9 +++++++-- test/testsyncengine.cpp | 3 +-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/test/syncenginetestutils.cpp b/test/syncenginetestutils.cpp index 98519731c7..80e662f462 100644 --- a/test/syncenginetestutils.cpp +++ b/test/syncenginetestutils.cpp @@ -159,8 +159,13 @@ void FileInfo::remove(const QString &relativePath) const PathComponents pathComponents { relativePath }; FileInfo *parent = findInvalidatingEtags(pathComponents.parentDirComponents()); Q_ASSERT(parent); - parent->children.erase(std::find_if(parent->children.begin(), parent->children.end(), - [&pathComponents](const FileInfo &fi) { return fi.name == pathComponents.fileName(); })); + auto childrenIt = std::find_if(parent->children.begin(), parent->children.end(), + [&pathComponents](const FileInfo &fi) { + return fi.name == pathComponents.fileName(); + }); + if (childrenIt != parent->children.end()) { + parent->children.erase(childrenIt); + } } void FileInfo::insert(const QString &relativePath, qint64 size, char contentChar) diff --git a/test/testsyncengine.cpp b/test/testsyncengine.cpp index 746f4c133e..f0d55d86d6 100644 --- a/test/testsyncengine.cpp +++ b/test/testsyncengine.cpp @@ -1700,8 +1700,7 @@ private slots: conflicts = findCaseClashConflicts(fakeFolder.currentLocalState()); QCOMPARE(conflicts.size(), 0); - // remove both files from the server(lower and UPPER case) - fakeFolder.remoteModifier().remove(testLowerCaseFile); + // remove the other file fakeFolder.remoteModifier().remove(testUpperCaseFile); QVERIFY(fakeFolder.syncOnce()); }