QmlDesigner: Parameterize project storage watcher updater test

Using parameters allows for generating more test combinations. This
reduces the amount of test code needed while increasing coverage.
However, it can also make the test logic more complex.

Fixes: QDS-15280
Change-Id: Iccc018903be4baf0e8e40581c8ae166a529be730
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
Marco Bubke
2025-05-02 18:28:21 +02:00
parent f7ccb2988c
commit 56164d1422
5 changed files with 1275 additions and 1595 deletions

View File

@@ -413,6 +413,7 @@ std::string_view directoryName(std::string_view directoryPath)
void ProjectStorageUpdater::updateDirectoryChanged(Utils::SmallStringView directoryPath, void ProjectStorageUpdater::updateDirectoryChanged(Utils::SmallStringView directoryPath,
Utils::SmallStringView annotationDirectoryPath, Utils::SmallStringView annotationDirectoryPath,
FileState directoryState,
FileState qmldirState, FileState qmldirState,
FileState annotationDirectoryState, FileState annotationDirectoryState,
SourcePath qmldirSourcePath, SourcePath qmldirSourcePath,
@@ -466,6 +467,7 @@ void ProjectStorageUpdater::updateDirectoryChanged(Utils::SmallStringView direct
toImportNames(imports), toImportNames(imports),
directoryId, directoryId,
directoryPathAsQString, directoryPathAsQString,
directoryState,
cppModuleId, cppModuleId,
package, package,
notUpdatedSourceIds, notUpdatedSourceIds,
@@ -481,10 +483,12 @@ void ProjectStorageUpdater::updateDirectoryChanged(Utils::SmallStringView direct
package, package,
notUpdatedSourceIds, notUpdatedSourceIds,
WatchedSourceIds, WatchedSourceIds,
directoryState,
qmldirState, qmldirState,
qmldirSourceId, qmldirSourceId,
isInsideProject); isInsideProject);
tracer.tick("append updated directory source id", keyValue("module id", moduleId)); tracer.tick("append updated directory source id", keyValue("module id", moduleId));
if (isChanged(directoryState))
package.updatedDirectoryInfoDirectoryIds.push_back(directoryId); package.updatedDirectoryInfoDirectoryIds.push_back(directoryId);
if (isInsideProject == IsInsideProject::Yes) { if (isInsideProject == IsInsideProject::Yes) {
@@ -689,6 +693,7 @@ void ProjectStorageUpdater::updateDirectory(const Utils::PathString &directoryPa
tracer.tick("update directory changed"); tracer.tick("update directory changed");
updateDirectoryChanged(directoryPath, updateDirectoryChanged(directoryPath,
annotationDirectoryPath, annotationDirectoryPath,
directoryState,
qmldirState, qmldirState,
annotationDirectoryState, annotationDirectoryState,
qmldirPath, qmldirPath,
@@ -1027,6 +1032,7 @@ void ProjectStorageUpdater::pathsWithIdsChanged(const std::vector<IdPaths> &chan
category(), category(),
keyValue("id paths", changedIdPaths)}; keyValue("id paths", changedIdPaths)};
try {
m_changedIdPaths.insert(m_changedIdPaths.end(), changedIdPaths.begin(), changedIdPaths.end()); m_changedIdPaths.insert(m_changedIdPaths.end(), changedIdPaths.begin(), changedIdPaths.end());
Storage::Synchronization::SynchronizationPackage package; Storage::Synchronization::SynchronizationPackage package;
@@ -1048,7 +1054,8 @@ void ProjectStorageUpdater::pathsWithIdsChanged(const std::vector<IdPaths> &chan
} }
auto updateDirectory = [&](const SourceIds &directorySourceIds, auto updateDirectory = [&](const SourceIds &directorySourceIds,
WatchedSourceIds &watchedSourceIds) { WatchedSourceIds &watchedSourceIds,
IsInsideProject isInsideProject) {
auto directoryIds = filterUniqueDirectoryPathIds(directorySourceIds); auto directoryIds = filterUniqueDirectoryPathIds(directorySourceIds);
for (auto directoryId : directoryIds) { for (auto directoryId : directoryIds) {
Utils::PathString directory = m_pathCache.directoryPath(directoryId); Utils::PathString directory = m_pathCache.directoryPath(directoryId);
@@ -1057,14 +1064,16 @@ void ProjectStorageUpdater::pathsWithIdsChanged(const std::vector<IdPaths> &chan
package, package,
notUpdatedSourceIds, notUpdatedSourceIds,
watchedSourceIds, watchedSourceIds,
IsInsideProject::No); isInsideProject);
} }
return directoryIds; return directoryIds;
}; };
auto qtDirectoryIds = updateDirectory(qt.directory, watchedQtSourceIds); auto qtDirectoryIds = updateDirectory(qt.directory, watchedQtSourceIds, IsInsideProject::No);
auto projectDirectoryIds = updateDirectory(project.directory, watchedProjectSourceIds); auto projectDirectoryIds = updateDirectory(project.directory,
watchedProjectSourceIds,
IsInsideProject::Yes);
auto parseQmlComponent = [&](SourceIds qmlDocumentSourceIds, auto parseQmlComponent = [&](SourceIds qmlDocumentSourceIds,
const DirectoryPathIds &directoryIds, const DirectoryPathIds &directoryIds,
@@ -1095,12 +1104,8 @@ void ProjectStorageUpdater::pathsWithIdsChanged(const std::vector<IdPaths> &chan
} }
}; };
try {
parseTypeInfo(std::move(qt.qmltypes), qtDirectoryIds, IsInsideProject::No); parseTypeInfo(std::move(qt.qmltypes), qtDirectoryIds, IsInsideProject::No);
parseTypeInfo(std::move(project.qmltypes), projectDirectoryIds, IsInsideProject::Yes); parseTypeInfo(std::move(project.qmltypes), projectDirectoryIds, IsInsideProject::Yes);
} catch (const QmlDesigner::CannotParseQmlTypesFile &) {
return;
}
package.updatedSourceIds = filterNotUpdatedSourceIds(std::move(package.updatedSourceIds), package.updatedSourceIds = filterNotUpdatedSourceIds(std::move(package.updatedSourceIds),
std::move(notUpdatedSourceIds.sourceIds)); std::move(notUpdatedSourceIds.sourceIds));
@@ -1108,11 +1113,7 @@ void ProjectStorageUpdater::pathsWithIdsChanged(const std::vector<IdPaths> &chan
std::move(package.updatedFileStatusSourceIds), std::move(package.updatedFileStatusSourceIds),
std::move(notUpdatedSourceIds.fileStatusSourceIds)); std::move(notUpdatedSourceIds.fileStatusSourceIds));
try {
m_projectStorage.synchronize(std::move(package)); m_projectStorage.synchronize(std::move(package));
} catch (const ProjectStorageError &) {
return;
}
auto directoryIdsSize = projectDirectoryIds.size() + qtDirectoryIds.size(); auto directoryIdsSize = projectDirectoryIds.size() + qtDirectoryIds.size();
if (directoryIdsSize > 0) { if (directoryIdsSize > 0) {
@@ -1128,6 +1129,9 @@ void ProjectStorageUpdater::pathsWithIdsChanged(const std::vector<IdPaths> &chan
} }
m_changedIdPaths.clear(); m_changedIdPaths.clear();
} catch (...) {
}
} }
void ProjectStorageUpdater::pathsChanged(const SourceIds &) {} void ProjectStorageUpdater::pathsChanged(const SourceIds &) {}
@@ -1137,6 +1141,7 @@ void ProjectStorageUpdater::parseTypeInfos(const QStringList &typeInfos,
const std::vector<Utils::PathString> &qmldirImports, const std::vector<Utils::PathString> &qmldirImports,
DirectoryPathId directoryId, DirectoryPathId directoryId,
const QString &directoryPath, const QString &directoryPath,
FileState directoryState,
ModuleId moduleId, ModuleId moduleId,
Storage::Synchronization::SynchronizationPackage &package, Storage::Synchronization::SynchronizationPackage &package,
NotUpdatedSourceIds &notUpdatedSourceIds, NotUpdatedSourceIds &notUpdatedSourceIds,
@@ -1179,7 +1184,7 @@ void ProjectStorageUpdater::parseTypeInfos(const QStringList &typeInfos,
notUpdatedSourceIds, notUpdatedSourceIds,
isInsideProject); isInsideProject);
if (isExisting(state)) { if (isExisting(state) && isChanged(directoryState)) {
package.directoryInfos.push_back(directoryInfo); package.directoryInfos.push_back(directoryInfo);
tracer.tick("append directory info", keyValue("source id", directoryInfo.sourceId)); tracer.tick("append directory info", keyValue("source id", directoryInfo.sourceId));
} }
@@ -1262,6 +1267,7 @@ void ProjectStorageUpdater::parseQmlComponent(Utils::SmallStringView relativeFil
Storage::Synchronization::SynchronizationPackage &package, Storage::Synchronization::SynchronizationPackage &package,
NotUpdatedSourceIds &notUpdatedSourceIds, NotUpdatedSourceIds &notUpdatedSourceIds,
WatchedSourceIds &watchedSourceIds, WatchedSourceIds &watchedSourceIds,
FileState directoryState,
FileState qmldirState, FileState qmldirState,
SourceId qmldirSourceId, SourceId qmldirSourceId,
IsInsideProject isInsideProject) IsInsideProject isInsideProject)
@@ -1319,9 +1325,11 @@ void ProjectStorageUpdater::parseQmlComponent(Utils::SmallStringView relativeFil
break; break;
} }
if (isChanged(directoryState)) {
const auto &directoryInfo = package.directoryInfos.emplace_back( const auto &directoryInfo = package.directoryInfos.emplace_back(
directoryId, sourceId, ModuleId{}, Storage::Synchronization::FileType::QmlDocument); directoryId, sourceId, ModuleId{}, Storage::Synchronization::FileType::QmlDocument);
tracer.tick("append directory info", keyValue("project data", directoryInfo)); tracer.tick("append directory info", keyValue("project data", directoryInfo));
}
tracer.tick("append updated source id", keyValue("source id", sourceId)); tracer.tick("append updated source id", keyValue("source id", sourceId));
package.updatedSourceIds.push_back(sourceId); package.updatedSourceIds.push_back(sourceId);
@@ -1430,6 +1438,7 @@ void ProjectStorageUpdater::parseQmlComponents(Components components,
Storage::Synchronization::SynchronizationPackage &package, Storage::Synchronization::SynchronizationPackage &package,
NotUpdatedSourceIds &notUpdatedSourceIds, NotUpdatedSourceIds &notUpdatedSourceIds,
WatchedSourceIds &WatchedSourceIds, WatchedSourceIds &WatchedSourceIds,
FileState directoryState,
FileState qmldirState, FileState qmldirState,
SourceId qmldirSourceId, SourceId qmldirSourceId,
IsInsideProject isInsideProject) IsInsideProject isInsideProject)
@@ -1454,6 +1463,7 @@ void ProjectStorageUpdater::parseQmlComponents(Components components,
package, package,
notUpdatedSourceIds, notUpdatedSourceIds,
WatchedSourceIds, WatchedSourceIds,
directoryState,
qmldirState, qmldirState,
qmldirSourceId, qmldirSourceId,
isInsideProject); isInsideProject);

View File

@@ -157,6 +157,7 @@ private:
IsInsideProject isInsideProject); IsInsideProject isInsideProject);
void updateDirectoryChanged(Utils::SmallStringView directoryPath, void updateDirectoryChanged(Utils::SmallStringView directoryPath,
Utils::SmallStringView annotationDirectoryPath, Utils::SmallStringView annotationDirectoryPath,
FileState directoryState,
FileState qmldirState, FileState qmldirState,
FileState annotationDirectoryState, FileState annotationDirectoryState,
SourcePath qmldirSourcePath, SourcePath qmldirSourcePath,
@@ -213,6 +214,7 @@ private:
const std::vector<Utils::PathString> &qmldirImports, const std::vector<Utils::PathString> &qmldirImports,
DirectoryPathId directoryId, DirectoryPathId directoryId,
const QString &directoryPath, const QString &directoryPath,
FileState directoryState,
ModuleId moduleId, ModuleId moduleId,
Storage::Synchronization::SynchronizationPackage &package, Storage::Synchronization::SynchronizationPackage &package,
NotUpdatedSourceIds &notUpdatedSourceIds, NotUpdatedSourceIds &notUpdatedSourceIds,
@@ -233,6 +235,7 @@ private:
Storage::Synchronization::SynchronizationPackage &package, Storage::Synchronization::SynchronizationPackage &package,
NotUpdatedSourceIds &notUpdatedSourceIds, NotUpdatedSourceIds &notUpdatedSourceIds,
WatchedSourceIds &WatchedSourceIds, WatchedSourceIds &WatchedSourceIds,
FileState directoryState,
FileState qmldirState, FileState qmldirState,
SourceId qmldirSourceId, SourceId qmldirSourceId,
IsInsideProject isInsideProject); IsInsideProject isInsideProject);
@@ -243,6 +246,7 @@ private:
Storage::Synchronization::SynchronizationPackage &package, Storage::Synchronization::SynchronizationPackage &package,
NotUpdatedSourceIds &notUpdatedSourceIds, NotUpdatedSourceIds &notUpdatedSourceIds,
WatchedSourceIds &WatchedSourceIds, WatchedSourceIds &WatchedSourceIds,
FileState directoryState,
FileState qmldirState, FileState qmldirState,
SourceId qmldirSourceId, SourceId qmldirSourceId,
IsInsideProject isInsideProject); IsInsideProject isInsideProject);

View File

@@ -878,7 +878,7 @@ std::ostream &operator<<(std::ostream &out, const SynchronizationPackage &packag
<< package.updatedPropertyEditorQmlPathDirectoryIds << package.updatedPropertyEditorQmlPathDirectoryIds
<< ",\n\t\ttypeAnnotations: " << package.typeAnnotations << ",\n\t\ttypeAnnotations: " << package.typeAnnotations
<< ",\n\t\tupdatedTypeAnnotationSourceIds: " << package.updatedTypeAnnotationSourceIds << ",\n\t\tupdatedTypeAnnotationSourceIds: " << package.updatedTypeAnnotationSourceIds
<< ",\n\t\ttmoduleDependencies: " << package.moduleDependencies << ",\n\t\tmoduleDependencies: " << package.moduleDependencies
<< ",\n\t\tupdatedTypeAnnotationSourceIds: " << package.updatedModuleDependencySourceIds << ",\n\t\tupdatedTypeAnnotationSourceIds: " << package.updatedModuleDependencySourceIds
<< ",\n\t\tmoduleExportedImports: " << package.moduleExportedImports << ",\n\t\tmoduleExportedImports: " << package.moduleExportedImports
<< ",\n\t\tupdatedModuleIds: " << package.updatedModuleIds << "\n)"; << ",\n\t\tupdatedModuleIds: " << package.updatedModuleIds << "\n)";

View File

@@ -18,6 +18,7 @@ using testing::AtMost;
using testing::Between; using testing::Between;
using testing::ByMove; using testing::ByMove;
using testing::ByRef; using testing::ByRef;
using testing::Combine;
using testing::Conditional; using testing::Conditional;
using testing::ContainerEq; using testing::ContainerEq;
using testing::Contains; using testing::Contains;
@@ -62,5 +63,6 @@ using testing::Throw;
using testing::TypedEq; using testing::TypedEq;
using testing::UnorderedElementsAre; using testing::UnorderedElementsAre;
using testing::UnorderedElementsAreArray; using testing::UnorderedElementsAreArray;
using testing::Values;
using testing::VariantWith; using testing::VariantWith;
using testing::WithArg; using testing::WithArg;