aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2024-04-11 18:13:10 +0200
committerMarco Bubke <marco.bubke@qt.io>2024-04-15 09:25:46 +0000
commitdb84bc43a9086e1ebc2662f7f04a03ab1aed82ca (patch)
tree33a1d86ceb792a13fedeec0304eb0bfd79c8719f /tests
parentc9f9804edf9d15a251b90724eff4b0587ebbe018 (diff)
QmlDesigner: Improve node creation with project storage
The file url was missing, so no valid source id could be created. That lead to invalid imports. The qualified path for the node instances is now created in the node instance view. Change-Id: I2685ab2fdbdb0fa8a5f89793be52c8fae2b8db8c Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/tests/mocks/projectstoragemock.cpp13
-rw-r--r--tests/unit/tests/mocks/projectstoragemock.h8
-rw-r--r--tests/unit/tests/unittests/model/modelutils-test.cpp2
3 files changed, 22 insertions, 1 deletions
diff --git a/tests/unit/tests/mocks/projectstoragemock.cpp b/tests/unit/tests/mocks/projectstoragemock.cpp
index 27e5c152d2..48357ff3e6 100644
--- a/tests/unit/tests/mocks/projectstoragemock.cpp
+++ b/tests/unit/tests/mocks/projectstoragemock.cpp
@@ -51,6 +51,7 @@ ModuleId ProjectStorageMock::createModule(Utils::SmallStringView moduleName)
incrementBasicId(moduleId);
ON_CALL(*this, moduleId(Eq(moduleName))).WillByDefault(Return(moduleId));
+ ON_CALL(*this, moduleName(Eq(moduleId))).WillByDefault(Return(moduleName));
ON_CALL(*this, fetchModuleIdUnguarded(Eq(moduleName))).WillByDefault(Return(moduleId));
return moduleId;
@@ -122,6 +123,14 @@ void ProjectStorageMock::addExportedTypeName(QmlDesigner::TypeId typeId,
exportedTypeName[typeId].emplace_back(moduleId, typeName);
}
+void ProjectStorageMock::addExportedTypeNameBySourceId(QmlDesigner::TypeId typeId,
+ QmlDesigner::ModuleId moduleId,
+ Utils::SmallStringView typeName,
+ QmlDesigner::SourceId sourceId)
+{
+ exportedTypeNameBySourceId[{typeId, sourceId}].emplace_back(moduleId, typeName);
+}
+
void ProjectStorageMock::removeExportedTypeName(QmlDesigner::TypeId typeId,
QmlDesigner::ModuleId moduleId,
Utils::SmallStringView typeName)
@@ -364,6 +373,10 @@ ProjectStorageMock::ProjectStorageMock()
ON_CALL(*this, exportedTypeNames(_)).WillByDefault([&](TypeId id) {
return exportedTypeName[id];
});
+
+ ON_CALL(*this, exportedTypeNames(_, _)).WillByDefault([&](TypeId typeId, SourceId sourceId) {
+ return exportedTypeNameBySourceId[{typeId, sourceId}];
+ });
}
void ProjectStorageMock::setupQtQuick()
diff --git a/tests/unit/tests/mocks/projectstoragemock.h b/tests/unit/tests/mocks/projectstoragemock.h
index ed370bde96..a68e37c2a1 100644
--- a/tests/unit/tests/mocks/projectstoragemock.h
+++ b/tests/unit/tests/mocks/projectstoragemock.h
@@ -46,6 +46,11 @@ public:
QmlDesigner::ModuleId moduleId,
Utils::SmallStringView typeName);
+ void addExportedTypeNameBySourceId(QmlDesigner::TypeId typeId,
+ QmlDesigner::ModuleId moduleId,
+ Utils::SmallStringView typeName,
+ QmlDesigner::SourceId sourceId);
+
void removeExportedTypeName(QmlDesigner::TypeId typeId,
QmlDesigner::ModuleId moduleId,
Utils::SmallStringView typeName);
@@ -122,6 +127,7 @@ public:
MOCK_METHOD(void, removeObserver, (QmlDesigner::ProjectStorageObserver *), (override));
MOCK_METHOD(QmlDesigner::ModuleId, moduleId, (::Utils::SmallStringView), (const, override));
+ MOCK_METHOD(Utils::SmallString, moduleName, (QmlDesigner::ModuleId), (const, override));
MOCK_METHOD(std::optional<QmlDesigner::Storage::Info::PropertyDeclaration>,
propertyDeclaration,
@@ -331,6 +337,8 @@ public:
QmlDesigner::Storage::Info::CommonTypeCache<QmlDesigner::ProjectStorageInterface> typeCache{*this};
std::map<QmlDesigner::TypeId, QmlDesigner::Storage::Info::ExportedTypeNames> exportedTypeName;
+ std::map<std::pair<QmlDesigner::TypeId, QmlDesigner::SourceId>, QmlDesigner::Storage::Info::ExportedTypeNames>
+ exportedTypeNameBySourceId;
};
class ProjectStorageMockWithQtQtuick : public ProjectStorageMock
diff --git a/tests/unit/tests/unittests/model/modelutils-test.cpp b/tests/unit/tests/unittests/model/modelutils-test.cpp
index c7a70cfbdb..5a9e63b60d 100644
--- a/tests/unit/tests/unittests/model/modelutils-test.cpp
+++ b/tests/unit/tests/unittests/model/modelutils-test.cpp
@@ -141,7 +141,7 @@ TEST_F(ModelUtils, find_lowest_common_ancestor_when_one_of_the_nodes_is_parent)
ASSERT_THAT(commonAncestor, parentNode);
}
-TEST_F(ModelUtils, lowest_common_ancestor_for_uncle_and_nephew_should_return_the_grandFather)
+TEST_F(ModelUtils, lowest_common_ancestor_for_uncle_and_nephew_should_return_the_grandfather)
{
auto grandFatherNode = model.createModelNode("Item");
auto fatherNode = model.createModelNode("Item");