diff options
author | Tim Jenssen <tim.jenssen@qt.io> | 2022-11-16 19:12:59 +0100 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@qt.io> | 2022-11-16 18:22:59 +0000 |
commit | 213d60ad6427229080d4611a11ed42c94fc8063d (patch) | |
tree | b72578f133f777b2c90a95224bdd7ca369cf169a /tests | |
parent | 9381429e4fce3fc9a294fee2582266439a3ba6e6 (diff) | |
parent | 2a44f8caafbe8d7ed85c136616f9e82ce0973893 (diff) |
Merge remote-tracking branch 'origin/qds/dev'
Change-Id: I74bf2bfb1eacb60675640c47eb41ce51dd6eb99f
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp | 16 | ||||
-rw-r--r-- | tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp | 35 | ||||
-rw-r--r-- | tests/unit/unittest/CMakeLists.txt | 6 | ||||
-rw-r--r-- | tests/unit/unittest/filesystemmock.h | 1 | ||||
-rw-r--r-- | tests/unit/unittest/gtest-creator-printing.cpp | 9 | ||||
-rw-r--r-- | tests/unit/unittest/listmodeleditor-test.cpp | 4 | ||||
-rw-r--r-- | tests/unit/unittest/projectstorageupdater-test.cpp | 694 |
7 files changed, 470 insertions, 295 deletions
diff --git a/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp b/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp index cc29b586524..365748c1fb2 100644 --- a/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp +++ b/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp @@ -166,10 +166,10 @@ public: Model &model; }; -std::unique_ptr<QmlDesigner::Model> createModel(const QString &typeName, - int major = 2, - int minor = 1, - Model *metaInfoPropxyModel = 0) +ModelPointer createModel(const QString &typeName, + int major = 2, + int minor = 1, + Model *metaInfoPropxyModel = 0) { QApplication::processEvents(); @@ -4821,7 +4821,7 @@ void tst_TestCore::testMetaInfoSimpleType() QCOMPARE(itemMetaInfo.minorVersion(), 1); // super classes - NodeMetaInfo qobject = itemMetaInfo.superClasses().front(); + NodeMetaInfo qobject = itemMetaInfo.superClasses()[1]; QVERIFY(qobject.isValid()); QVERIFY(qobject.isQtObject()); @@ -4849,7 +4849,7 @@ void tst_TestCore::testMetaInfoUncreatableType() QCOMPARE(animationTypeInfo.majorVersion(), 2); QCOMPARE(animationTypeInfo.minorVersion(), 1); - NodeMetaInfo qObjectTypeInfo = animationTypeInfo.superClasses().front(); + NodeMetaInfo qObjectTypeInfo = animationTypeInfo.superClasses()[1]; QVERIFY(qObjectTypeInfo.isValid()); QCOMPARE(qObjectTypeInfo.simplifiedTypeName(), QmlDesigner::TypeName("QtObject")); @@ -4867,7 +4867,7 @@ void tst_TestCore::testMetaInfoExtendedType() QVERIFY(typeInfo.hasProperty("font")); // from QGraphicsWidget QVERIFY(typeInfo.hasProperty("enabled")); // from QGraphicsItem - NodeMetaInfo graphicsObjectTypeInfo = typeInfo.superClasses().front(); + NodeMetaInfo graphicsObjectTypeInfo = typeInfo.superClasses()[1]; QVERIFY(graphicsObjectTypeInfo.isValid()); } @@ -4889,7 +4889,7 @@ void tst_TestCore::testMetaInfoCustomType() QVERIFY(propertyChangesInfo.hasProperty("restoreEntryValues")); QVERIFY(propertyChangesInfo.hasProperty("explicit")); - NodeMetaInfo stateOperationInfo = propertyChangesInfo.superClasses().front(); + NodeMetaInfo stateOperationInfo = propertyChangesInfo.superClasses()[1]; QVERIFY(stateOperationInfo.isValid()); QCOMPARE(stateOperationInfo.typeName(), QmlDesigner::TypeName("QtQuick.QQuickStateOperation")); QCOMPARE(stateOperationInfo.majorVersion(), -1); diff --git a/tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp b/tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp index f3329d97c8e..028a29b01a7 100644 --- a/tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp +++ b/tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp @@ -41,7 +41,7 @@ tst_FileFormat::tst_FileFormat() static QString testDataDir = QLatin1String(SRCDIR "/data"); -static QmlProjectItem *loadQmlProject(QString name, QString *error) +static std::unique_ptr<QmlProjectItem> loadQmlProject(QString name, QString *error) { return QmlProjectFileFormat::parseProjectFile( Utils::FilePath::fromString(testDataDir).pathAppended(name + ".qmlproject"), error); @@ -54,7 +54,7 @@ void tst_FileFormat::testFileFilter() // Search for qml files in directory + subdirectories // { - QmlProjectItem *project = loadQmlProject(QLatin1String("testFileFilter1"), &error); + auto project = loadQmlProject(QLatin1String("testFileFilter1"), &error); QVERIFY(project); QVERIFY(error.isEmpty()); @@ -64,14 +64,13 @@ void tst_FileFormat::testFileFilter() << testDataDir + "/file2.qml" << testDataDir + "/subdir/file3.qml"); COMPARE_AS_SETS(project->files(), expectedFiles); - delete project; } // // search for all qml files in directory // { - QmlProjectItem *project = loadQmlProject(QLatin1String("testFileFilter2"), &error); + auto project = loadQmlProject(QLatin1String("testFileFilter2"), &error); QVERIFY(project); QVERIFY(error.isEmpty()); @@ -80,14 +79,13 @@ void tst_FileFormat::testFileFilter() QStringList expectedFiles(QStringList() << testDataDir + "/file1.qml" << testDataDir + "/file2.qml"); COMPARE_AS_SETS(project->files(), expectedFiles); - delete project; } // // search for all qml files in subdirectory // { - QmlProjectItem *project = loadQmlProject(QLatin1String("testFileFilter3"), &error); + auto project = loadQmlProject(QLatin1String("testFileFilter3"), &error); QVERIFY(project); QVERIFY(error.isEmpty()); @@ -95,14 +93,13 @@ void tst_FileFormat::testFileFilter() QStringList expectedFiles(QStringList() << testDataDir + "/subdir/file3.qml"); COMPARE_AS_SETS(project->files(), expectedFiles); - delete project; } // // multiple entries // { - QmlProjectItem *project = loadQmlProject(QLatin1String("testFileFilter4"), &error); + auto project = loadQmlProject(QLatin1String("testFileFilter4"), &error); QVERIFY(project); QVERIFY(error.isEmpty()); @@ -113,14 +110,13 @@ void tst_FileFormat::testFileFilter() << testDataDir + "/subdir/file3.qml"); QCOMPARE(project->files().size(), 3); COMPARE_AS_SETS(project->files(), expectedFiles); - delete project; } // // include specific list // { - QmlProjectItem *project = loadQmlProject(QLatin1String("testFileFilter5"), &error); + auto project = loadQmlProject(QLatin1String("testFileFilter5"), &error); QVERIFY(project); QVERIFY(error.isEmpty()); @@ -129,14 +125,13 @@ void tst_FileFormat::testFileFilter() QStringList expectedFiles(QStringList() << testDataDir + "/file1.qml" << testDataDir + "/file2.qml"); COMPARE_AS_SETS(project->files(), expectedFiles); - delete project; } // // include specific list // { - QmlProjectItem *project = loadQmlProject(QLatin1String("testFileFilter6"), &error); + auto project = loadQmlProject(QLatin1String("testFileFilter6"), &error); QVERIFY(project); QVERIFY(error.isEmpty()); @@ -144,14 +139,13 @@ void tst_FileFormat::testFileFilter() QStringList expectedFiles(QStringList() << testDataDir + "/image.gif"); COMPARE_AS_SETS(project->files(), expectedFiles); - delete project; } // // use wildcards // { - QmlProjectItem *project = loadQmlProject(QLatin1String("testFileFilter7"), &error); + auto project = loadQmlProject(QLatin1String("testFileFilter7"), &error); QVERIFY(project); QVERIFY(error.isEmpty()); @@ -159,14 +153,13 @@ void tst_FileFormat::testFileFilter() QStringList expectedFiles(QStringList() << testDataDir + "/image.gif"); COMPARE_AS_SETS(project->files(), expectedFiles); - delete project; } // // use Files element (1.1) // { - QmlProjectItem *project = loadQmlProject(QLatin1String("testFileFilter8"), &error); + auto project = loadQmlProject(QLatin1String("testFileFilter8"), &error); QVERIFY(project); QVERIFY(error.isEmpty()); @@ -174,7 +167,6 @@ void tst_FileFormat::testFileFilter() QStringList expectedFiles(QStringList() << testDataDir + "/image.gif"); COMPARE_AS_SETS(project->files(), expectedFiles); - delete project; } } @@ -184,7 +176,7 @@ void tst_FileFormat::testMatchesFile() // // search for qml files in local directory // - QmlProjectItem *project = loadQmlProject(QLatin1String("testMatchesFile"), &error); + auto project = loadQmlProject(QLatin1String("testMatchesFile"), &error); QVERIFY(project); QVERIFY(error.isEmpty()); @@ -195,7 +187,6 @@ void tst_FileFormat::testMatchesFile() QVERIFY(project->matchesFile(testDataDir + "/subdir/notyetexistingfile.qml")); QVERIFY(project->matchesFile(testDataDir + "/script.js")); QVERIFY(!project->matchesFile(testDataDir + "/script.css")); - delete project; } void tst_FileFormat::testLibraryPaths() @@ -204,7 +195,7 @@ void tst_FileFormat::testLibraryPaths() // // search for qml files in local directory // - QmlProjectItem *project = loadQmlProject(QLatin1String("testLibraryPaths"), &error); + auto project = loadQmlProject(QLatin1String("testLibraryPaths"), &error); QVERIFY(project); QVERIFY(error.isEmpty()); @@ -214,7 +205,6 @@ void tst_FileFormat::testLibraryPaths() const QStringList expectedPaths({base.relativeFilePath(SRCDIR "/otherLibrary"), base.relativeFilePath(SRCDIR "/data/library")}); COMPARE_AS_SETS(project->importPaths(), expectedPaths); - delete project; } void tst_FileFormat::testMainFile() @@ -223,12 +213,11 @@ void tst_FileFormat::testMainFile() // // search for qml files in local directory // - QmlProjectItem *project = loadQmlProject(QLatin1String("testMainFile"), &error); + auto project = loadQmlProject(QLatin1String("testMainFile"), &error); QVERIFY(project); QVERIFY(error.isEmpty()); QCOMPARE(project->mainFile(), QString("file1.qml")); - delete project; } QTEST_GUILESS_MAIN(tst_FileFormat); diff --git a/tests/unit/unittest/CMakeLists.txt b/tests/unit/unittest/CMakeLists.txt index dc390d92633..4e2deb605d0 100644 --- a/tests/unit/unittest/CMakeLists.txt +++ b/tests/unit/unittest/CMakeLists.txt @@ -155,8 +155,8 @@ extend_qtc_test(unittest "${QmlDesignerDir}/designercore" "${QmlDesignerDir}/designercore/include" "${QmlDesignerDir}/designercore/imagecache" - "${QmlDesignerDir}/../../../share/qtcreator/qml/qmlpuppet/interfaces" - "${QmlDesignerDir}/../../../share/qtcreator/qml/qmlpuppet/types" + "${QmlDesignerDir}/../../../src/libs/qmlpuppetcommunication/interfaces" + "${QmlDesignerDir}/../../../src/libs/qmlpuppetcommunication/types" DEFINES QMLDESIGNERCORE_STATIC_LIBRARY QMLDESIGNER_STATIC_LIBRARY SOURCES_PREFIX @@ -167,7 +167,7 @@ extend_qtc_test(unittest extend_qtc_test(unittest SOURCES_PREFIX "${QmlDesignerDir}/designercore" SOURCES - ../../../../share/qtcreator/qml/qmlpuppet/interfaces/commondefines.h + ../../../../src/libs/qmlpuppetcommunication/interfaces/commondefines.h ../components/listmodeleditor/listmodeleditormodel.cpp ../components/listmodeleditor/listmodeleditormodel.h exceptions/exception.cpp diff --git a/tests/unit/unittest/filesystemmock.h b/tests/unit/unittest/filesystemmock.h index 0c325d1bbbb..0af7eef8649 100644 --- a/tests/unit/unittest/filesystemmock.h +++ b/tests/unit/unittest/filesystemmock.h @@ -15,6 +15,7 @@ public: directoryEntries, (const QString &directoryPath), (const, override)); + MOCK_METHOD(QStringList, qmlFileNames, (const QString &directoryPath), (const, override)); MOCK_METHOD(long long, lastModified, (QmlDesigner::SourceId sourceId), (const, override)); MOCK_METHOD(QmlDesigner::FileStatus, fileStatus, (QmlDesigner::SourceId sourceId), (const, override)); MOCK_METHOD(void, remove, (const QmlDesigner::SourceIds &sourceIds), (override)); diff --git a/tests/unit/unittest/gtest-creator-printing.cpp b/tests/unit/unittest/gtest-creator-printing.cpp index c703b802ade..3eadd98e8fb 100644 --- a/tests/unit/unittest/gtest-creator-printing.cpp +++ b/tests/unit/unittest/gtest-creator-printing.cpp @@ -676,9 +676,12 @@ std::ostream &operator<<(std::ostream &out, ChangeLevel changeLevel) std::ostream &operator<<(std::ostream &out, const SynchronizationPackage &package) { - return out << "(" << package.imports << ", " << package.types << ", " - << package.updatedSourceIds << ", " << package.fileStatuses << ", " - << package.updatedFileStatusSourceIds << ", " << package.projectDatas << ")"; + return out << "(imports: " << package.imports << ", types: " << package.types + << ", updatedSourceIds: " << package.updatedSourceIds + << ", fileStatuses: " << package.fileStatuses + << ", updatedFileStatusSourceIds: " << package.updatedFileStatusSourceIds + << ", updatedProjectSourceIds: " << package.updatedProjectSourceIds + << ", projectDatas: " << package.projectDatas << ")"; } std::ostream &operator<<(std::ostream &out, const ProjectData &data) diff --git a/tests/unit/unittest/listmodeleditor-test.cpp b/tests/unit/unittest/listmodeleditor-test.cpp index 9b12adc0030..bde9b747003 100644 --- a/tests/unit/unittest/listmodeleditor-test.cpp +++ b/tests/unit/unittest/listmodeleditor-test.cpp @@ -175,7 +175,7 @@ public: protected: MockFunction<ModelNode(const ModelNode &)> mockGoIntoComponent; - std::unique_ptr<QmlDesigner::Model> designerModel{QmlDesigner::Model::create("QtQuick.Item", 1, 1)}; + QmlDesigner::ModelPointer designerModel{QmlDesigner::Model::create("QtQuick.Item", 1, 1)}; NiceMock<MockListModelEditorView> mockView; QmlDesigner::ListModelEditorModel model{ [&] { return mockView.createModelNode("QtQml.Models.ListModel", 2, 15); }, @@ -187,7 +187,7 @@ protected: ModelNode element1; ModelNode element2; ModelNode element3; - std::unique_ptr<QmlDesigner::Model> componentModel{ + QmlDesigner::ModelPointer componentModel{ QmlDesigner::Model::create("QtQml.Models.ListModel", 1, 1)}; NiceMock<MockListModelEditorView> mockComponentView; ModelNode componentElement; diff --git a/tests/unit/unittest/projectstorageupdater-test.cpp b/tests/unit/unittest/projectstorageupdater-test.cpp index 30f46081ffc..6d55565c1e2 100644 --- a/tests/unit/unittest/projectstorageupdater-test.cpp +++ b/tests/unit/unittest/projectstorageupdater-test.cpp @@ -103,7 +103,8 @@ MATCHER_P4(IsProjectData, const Storage::Synchronization::ProjectData &projectData = arg; return compareInvalidAreTrue(projectData.projectSourceId, projectSourceId) - && projectData.sourceId == sourceId && projectData.moduleId == moduleId + && projectData.sourceId == sourceId + && compareInvalidAreTrue(projectData.moduleId, moduleId) && projectData.fileType == fileType; } @@ -138,9 +139,17 @@ public: ON_CALL(projectStorageMock, fetchFileStatus(Eq(qmlDirPathSourceId))) .WillByDefault(Return(FileStatus{qmlDirPathSourceId, 2, 421})); + ON_CALL(fileSystemMock, fileStatus(Eq(directoryPathSourceId))) + .WillByDefault(Return(FileStatus{directoryPathSourceId, 2, 421})); + ON_CALL(projectStorageMock, fetchFileStatus(Eq(directoryPathSourceId))) + .WillByDefault(Return(FileStatus{directoryPathSourceId, 2, 421})); + ON_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/qmldir")))) .WillByDefault(Return(qmldirContent)); + ON_CALL(fileSystemMock, qmlFileNames(Eq(QString("/path")))) + .WillByDefault(Return(QStringList{"First.qml", "First2.qml", "Second.qml"})); + ON_CALL(fileSystemMock, fileStatus(Eq(qmlDocumentSourceId1))) .WillByDefault(Return(FileStatus{qmlDocumentSourceId1, 22, 12})); ON_CALL(projectStorageMock, fetchFileStatus(Eq(qmlDocumentSourceId1))) @@ -218,6 +227,7 @@ protected: SourceId qmltypesPathSourceId = sourcePathCache.sourceId("/path/example.qmltypes"); SourceId qmltypes2PathSourceId = sourcePathCache.sourceId("/path/types/example2.qmltypes"); SourceId qmlDirPathSourceId = sourcePathCache.sourceId("/path/qmldir"); + SourceId directoryPathSourceId = sourcePathCache.sourceId("/path/."); SourceId qmlDocumentSourceId1 = sourcePathCache.sourceId("/path/First.qml"); SourceId qmlDocumentSourceId2 = sourcePathCache.sourceId("/path/First2.qml"); SourceId qmlDocumentSourceId3 = sourcePathCache.sourceId("/path/Second.qml"); @@ -270,13 +280,13 @@ protected: QString qmldirContent{"module Example\ntypeinfo example.qmltypes\n"}; QString qmltypes1{"Module {\ndependencies: [module1]}"}; QString qmltypes2{"Module {\ndependencies: [module2]}"}; - QStringList qmlDirs = {"/path/qmldir"}; + QStringList directories = {"/path"}; }; TEST_F(ProjectStorageUpdater, GetContentForQmlDirPathsIfFileStatusIsDifferent) { SourceId qmlDir3PathSourceId = sourcePathCache.sourceId("/path/three/qmldir"); - QStringList qmlDirs = {"/path/one/qmldir", "/path/two/qmldir", "/path/three/qmldir"}; + QStringList directories = {"/path/one", "/path/two", "/path/three"}; ON_CALL(fileSystemMock, fileStatus(_)).WillByDefault([](auto sourceId) { return FileStatus{sourceId, 21, 421}; }); @@ -291,7 +301,7 @@ TEST_F(ProjectStorageUpdater, GetContentForQmlDirPathsIfFileStatusIsDifferent) EXPECT_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/one/qmldir")))); EXPECT_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/two/qmldir")))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, RequestFileStatusFromFileSystem) @@ -300,25 +310,27 @@ TEST_F(ProjectStorageUpdater, RequestFileStatusFromFileSystem) EXPECT_CALL(fileSystemMock, fileStatus(Eq(qmlDirPathSourceId))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, GetContentForQmlTypes) { QString qmldir{R"(module Example typeinfo example.qmltypes)"}; + ON_CALL(fileSystemMock, qmlFileNames(Eq(QString("/path")))).WillByDefault(Return(QStringList{})); EXPECT_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/qmldir")))) .WillRepeatedly(Return(qmldir)); EXPECT_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/example.qmltypes")))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, GetContentForQmlTypesIfProjectStorageFileStatusIsInvalid) { QString qmldir{R"(module Example typeinfo example.qmltypes)"}; + ON_CALL(fileSystemMock, qmlFileNames(Eq(QString("/path")))).WillByDefault(Return(QStringList{})); EXPECT_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/qmldir")))) .WillRepeatedly(Return(qmldir)); ON_CALL(projectStorageMock, fetchFileStatus(Eq(qmltypesPathSourceId))) @@ -326,20 +338,21 @@ TEST_F(ProjectStorageUpdater, GetContentForQmlTypesIfProjectStorageFileStatusIsI EXPECT_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/example.qmltypes")))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, DontGetContentForQmlTypesIfFileSystemFileStatusIsInvalid) { QString qmldir{R"(module Example typeinfo example.qmltypes)"}; + ON_CALL(fileSystemMock, qmlFileNames(Eq(QString("/path")))).WillByDefault(Return(QStringList{})); EXPECT_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/qmldir")))) .WillRepeatedly(Return(qmldir)); ON_CALL(fileSystemMock, fileStatus(Eq(qmltypesPathSourceId))).WillByDefault(Return(FileStatus{})); EXPECT_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/example.qmltypes")))).Times(0); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, ParseQmlTypes) @@ -360,7 +373,7 @@ TEST_F(ProjectStorageUpdater, ParseQmlTypes) EXPECT_CALL(qmlTypesParserMock, parse(qmltypes2, _, _, Field(&ProjectData::moduleId, exampleCppNativeModuleId))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, SynchronizeIsEmptyForNoChange) @@ -374,7 +387,7 @@ TEST_F(ProjectStorageUpdater, SynchronizeIsEmptyForNoChange) EXPECT_CALL(projectStorageMock, synchronize(PackageIsEmpty())); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, SynchronizeQmlTypes) @@ -383,6 +396,7 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmlTypes) Storage::Synchronization::Version{2, 3}, qmltypesPathSourceId}; QString qmltypes{"Module {\ndependencies: []}"}; + ON_CALL(fileSystemMock, qmlFileNames(Eq(QString("/path")))).WillByDefault(Return(QStringList{})); ON_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/example.qmltypes")))) .WillByDefault(Return(qmltypes)); ON_CALL(qmlTypesParserMock, parse(qmltypes, _, _, _)) @@ -411,7 +425,7 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmlTypes) Field(&SynchronizationPackage::updatedProjectSourceIds, UnorderedElementsAre(qmlDirPathSourceId))))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, SynchronizeQmlTypesAreEmptyIfFileDoesNotChanged) @@ -430,12 +444,14 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmlTypesAreEmptyIfFileDoesNotChanged) EXPECT_CALL(projectStorageMock, synchronize(PackageIsEmpty())); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, GetContentForQmlDocuments) { SourceId oldSecondSourceId3 = sourcePathCache.sourceId("/path/OldSecond.qml"); + ON_CALL(fileSystemMock, qmlFileNames(Eq(QString("/path")))) + .WillByDefault(Return(QStringList{"First.qml", "First2.qml", "OldSecond.qml", "Second.qml"})); ON_CALL(fileSystemMock, fileStatus(Eq(oldSecondSourceId3))) .WillByDefault(Return(FileStatus{oldSecondSourceId3, 22, 14})); ON_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/OldSecond.qml")))) @@ -453,7 +469,7 @@ TEST_F(ProjectStorageUpdater, GetContentForQmlDocuments) EXPECT_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/OldSecond.qml")))); EXPECT_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/Second.qml")))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, ParseQmlDocuments) @@ -477,7 +493,7 @@ TEST_F(ProjectStorageUpdater, ParseQmlDocuments) EXPECT_CALL(qmlDocumentParserMock, parse(qmlDocument2, _, _, _)); EXPECT_CALL(qmlDocumentParserMock, parse(qmlDocument3, _, _, _)); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, ParseQmlDocumentsWithNonExistingQmlDocumentThrows) @@ -486,7 +502,7 @@ TEST_F(ProjectStorageUpdater, ParseQmlDocumentsWithNonExistingQmlDocumentThrows) NonexitingType 1.0 NonexitingType.qml)"}; ON_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/qmldir")))).WillByDefault(Return(qmldir)); - ASSERT_THROW(updater.update(qmlDirs, {}), QmlDesigner::CannotParseQmlDocumentFile); + ASSERT_THROW(updater.update(directories, {}), QmlDesigner::CannotParseQmlDocumentFile); } TEST_F(ProjectStorageUpdater, SynchronizeQmlDocuments) @@ -501,188 +517,411 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmlDocuments) projectStorageMock, synchronize(AllOf( Field(&SynchronizationPackage::imports, UnorderedElementsAre(import1, import2, import3)), + Field( + &SynchronizationPackage::types, + UnorderedElementsAre( + AllOf(IsStorageType("First.qml", + Storage::Synchronization::ImportedType{"Object"}, + TypeTraits::Reference, + qmlDocumentSourceId1, + Storage::Synchronization::ChangeLevel::Full), + Field(&Storage::Synchronization::Type::exportedTypes, + UnorderedElementsAre(IsExportedType(exampleModuleId, "FirstType", 1, 0), + IsExportedType(pathModuleId, "First", -1, -1)))), + AllOf(IsStorageType("First2.qml", + Storage::Synchronization::ImportedType{"Object2"}, + TypeTraits::Reference, + qmlDocumentSourceId2, + Storage::Synchronization::ChangeLevel::Full), + Field(&Storage::Synchronization::Type::exportedTypes, + UnorderedElementsAre(IsExportedType(exampleModuleId, "FirstType", 2, 2), + IsExportedType(pathModuleId, "First2", -1, -1)))), + AllOf(IsStorageType("Second.qml", + Storage::Synchronization::ImportedType{"Object3"}, + TypeTraits::Reference, + qmlDocumentSourceId3, + Storage::Synchronization::ChangeLevel::Full), + Field(&Storage::Synchronization::Type::exportedTypes, + UnorderedElementsAre(IsExportedType(exampleModuleId, "SecondType", 2, 2), + IsExportedType(pathModuleId, "Second", -1, -1)))))), + Field(&SynchronizationPackage::updatedSourceIds, + UnorderedElementsAre(qmlDirPathSourceId, + qmlDocumentSourceId1, + qmlDocumentSourceId2, + qmlDocumentSourceId3)), + Field(&SynchronizationPackage::updatedFileStatusSourceIds, + UnorderedElementsAre(qmlDirPathSourceId, + qmlDocumentSourceId1, + qmlDocumentSourceId2, + qmlDocumentSourceId3)), + Field(&SynchronizationPackage::fileStatuses, + UnorderedElementsAre(IsFileStatus(qmlDirPathSourceId, 21, 421), + IsFileStatus(qmlDocumentSourceId1, 22, 12), + IsFileStatus(qmlDocumentSourceId2, 22, 13), + IsFileStatus(qmlDocumentSourceId3, 22, 14))), + Field(&SynchronizationPackage::updatedProjectSourceIds, + UnorderedElementsAre(qmlDirPathSourceId)), + Field(&SynchronizationPackage::projectDatas, + UnorderedElementsAre( + IsProjectData(qmlDirPathSourceId, qmlDocumentSourceId1, ModuleId{}, FileType::QmlDocument), + IsProjectData(qmlDirPathSourceId, qmlDocumentSourceId2, ModuleId{}, FileType::QmlDocument), + IsProjectData(qmlDirPathSourceId, + qmlDocumentSourceId3, + ModuleId{}, + FileType::QmlDocument)))))); + + updater.update(directories, {}); +} + +TEST_F(ProjectStorageUpdater, SynchronizeAddOnlyQmlDocumentInDirectory) +{ + QString qmldir{R"(module Example + FirstType 1.0 First.qml)"}; + ON_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/qmldir")))).WillByDefault(Return(qmldir)); + ON_CALL(fileSystemMock, fileStatus(Eq(qmlDocumentSourceId1))) + .WillByDefault(Return(FileStatus{qmlDocumentSourceId1, 22, 2})); + ON_CALL(fileSystemMock, qmlFileNames(Eq(QString("/path")))) + .WillByDefault(Return(QStringList{"First.qml", "First2.qml"})); + + EXPECT_CALL( + projectStorageMock, + synchronize(AllOf( + Field(&SynchronizationPackage::imports, UnorderedElementsAre(import1, import2, import3)), Field(&SynchronizationPackage::types, UnorderedElementsAre( AllOf(IsStorageType("First.qml", Storage::Synchronization::ImportedType{"Object"}, TypeTraits::Reference, qmlDocumentSourceId1, - Storage::Synchronization::ChangeLevel::Full), + Storage::Synchronization::ChangeLevel::Minimal), Field(&Storage::Synchronization::Type::exportedTypes, - ElementsAre(IsExportedType(exampleModuleId, "FirstType", 1, 0), - IsExportedType(pathModuleId, "First", -1, -1)))), + UnorderedElementsAre(IsExportedType(exampleModuleId, "FirstType", 1, 0), + IsExportedType(pathModuleId, "First", -1, -1)))), AllOf(IsStorageType("First2.qml", Storage::Synchronization::ImportedType{"Object2"}, TypeTraits::Reference, qmlDocumentSourceId2, Storage::Synchronization::ChangeLevel::Full), Field(&Storage::Synchronization::Type::exportedTypes, - ElementsAre(IsExportedType(exampleModuleId, "FirstType", 2, 2), - IsExportedType(pathModuleId, "First2", -1, -1)))), - AllOf(IsStorageType("Second.qml", - Storage::Synchronization::ImportedType{"Object3"}, - TypeTraits::Reference, - qmlDocumentSourceId3, - Storage::Synchronization::ChangeLevel::Full), - Field(&Storage::Synchronization::Type::exportedTypes, - ElementsAre(IsExportedType(exampleModuleId, "SecondType", 2, 2), - IsExportedType(pathModuleId, "Second", -1, -1)))))), + UnorderedElementsAre(IsExportedType(pathModuleId, "First2", -1, -1)))))), Field(&SynchronizationPackage::updatedSourceIds, - UnorderedElementsAre(qmlDirPathSourceId, - qmlDocumentSourceId1, - qmlDocumentSourceId2, - qmlDocumentSourceId3)), + UnorderedElementsAre(qmlDocumentSourceId1, qmlDocumentSourceId2)), Field(&SynchronizationPackage::updatedFileStatusSourceIds, - UnorderedElementsAre(qmlDirPathSourceId, - qmlDocumentSourceId1, - qmlDocumentSourceId2, - qmlDocumentSourceId3)), + UnorderedElementsAre(qmlDocumentSourceId2)), Field(&SynchronizationPackage::fileStatuses, - UnorderedElementsAre(IsFileStatus(qmlDirPathSourceId, 21, 421), - IsFileStatus(qmlDocumentSourceId1, 22, 12), - IsFileStatus(qmlDocumentSourceId2, 22, 13), - IsFileStatus(qmlDocumentSourceId3, 22, 14))), + UnorderedElementsAre(IsFileStatus(qmlDocumentSourceId2, 22, 13))), Field(&SynchronizationPackage::updatedProjectSourceIds, UnorderedElementsAre(qmlDirPathSourceId)), Field(&SynchronizationPackage::projectDatas, UnorderedElementsAre(IsProjectData(qmlDirPathSourceId, qmlDocumentSourceId1, - exampleModuleId, + ModuleId{}, FileType::QmlDocument), IsProjectData(qmlDirPathSourceId, qmlDocumentSourceId2, - exampleModuleId, - FileType::QmlDocument), - IsProjectData(qmlDirPathSourceId, - qmlDocumentSourceId3, - exampleModuleId, + ModuleId{}, FileType::QmlDocument)))))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } -TEST_F(ProjectStorageUpdater, SynchronizeRemoved) +TEST_F(ProjectStorageUpdater, SynchronizeRemovesQmlDocument) { QString qmldir{R"(module Example FirstType 1.0 First.qml FirstType 2.2 First2.qml - typeinfo example.qmltypes - typeinfo types/example2.qmltypes )"}; ON_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/qmldir")))).WillByDefault(Return(qmldir)); - ON_CALL(projectStorageMock, fetchFileStatus(Eq(qmlDocumentSourceId2))) - .WillByDefault(Return(FileStatus{qmlDocumentSourceId2, 22, 13})); - ON_CALL(projectStorageMock, fetchFileStatus(Eq(qmltypes2PathSourceId))) - .WillByDefault(Return(FileStatus{qmltypes2PathSourceId, 21, 421})); + ON_CALL(fileSystemMock, fileStatus(Eq(qmlDirPathSourceId))) + .WillByDefault(Return(FileStatus{qmlDirPathSourceId, 21, 422})); + ON_CALL(fileSystemMock, fileStatus(Eq(qmlDocumentSourceId1))) + .WillByDefault(Return(FileStatus{qmlDocumentSourceId1, 22, 2})); + ON_CALL(fileSystemMock, fileStatus(Eq(qmlDocumentSourceId2))) + .WillByDefault(Return(FileStatus{qmlDocumentSourceId2, 22, 2})); + ON_CALL(fileSystemMock, fileStatus(Eq(qmlDocumentSourceId3))) + .WillByDefault(Return(FileStatus{qmlDocumentSourceId3, -1, -1})); ON_CALL(projectStorageMock, fetchProjectDatas(Eq(qmlDirPathSourceId))) .WillByDefault(Return(QmlDesigner::Storage::Synchronization::ProjectDatas{ - {qmlDirPathSourceId, qmltypesPathSourceId, exampleModuleId, FileType::QmlTypes}, - {qmlDirPathSourceId, qmltypes2PathSourceId, exampleModuleId, FileType::QmlTypes}, - {qmlDirPathSourceId, qmlDocumentSourceId1, exampleModuleId, FileType::QmlDocument}, - {qmlDirPathSourceId, qmlDocumentSourceId2, exampleModuleId, FileType::QmlDocument}, - {qmlDirPathSourceId, qmlDocumentSourceId3, exampleModuleId, FileType::QmlDocument}})); + {qmlDirPathSourceId, qmlDocumentSourceId1, ModuleId{}, FileType::QmlDocument}, + {qmlDirPathSourceId, qmlDocumentSourceId2, ModuleId{}, FileType::QmlDocument}, + {qmlDirPathSourceId, qmlDocumentSourceId3, ModuleId{}, FileType::QmlDocument}})); + ON_CALL(fileSystemMock, qmlFileNames(Eq(QString("/path")))) + .WillByDefault(Return(QStringList{"First.qml", "First2.qml"})); + + EXPECT_CALL(projectStorageMock, + synchronize(AllOf( + Field(&SynchronizationPackage::imports, IsEmpty()), + Field(&SynchronizationPackage::types, + UnorderedElementsAre( + AllOf(IsStorageType("First.qml", + Storage::Synchronization::ImportedType{}, + TypeTraits::Reference, + qmlDocumentSourceId1, + Storage::Synchronization::ChangeLevel::Minimal), + Field(&Storage::Synchronization::Type::exportedTypes, + UnorderedElementsAre( + IsExportedType(exampleModuleId, "FirstType", 1, 0), + IsExportedType(pathModuleId, "First", -1, -1)))), + AllOf(IsStorageType("First2.qml", + Storage::Synchronization::ImportedType{}, + TypeTraits::Reference, + qmlDocumentSourceId2, + Storage::Synchronization::ChangeLevel::Minimal), + Field(&Storage::Synchronization::Type::exportedTypes, + UnorderedElementsAre( + IsExportedType(exampleModuleId, "FirstType", 2, 2), + IsExportedType(pathModuleId, "First2", -1, -1)))))), + Field(&SynchronizationPackage::updatedSourceIds, + UnorderedElementsAre(qmlDirPathSourceId, + qmlDocumentSourceId1, + qmlDocumentSourceId2, + qmlDocumentSourceId3)), + Field(&SynchronizationPackage::updatedFileStatusSourceIds, + UnorderedElementsAre(qmlDirPathSourceId, qmlDocumentSourceId3)), + Field(&SynchronizationPackage::fileStatuses, + UnorderedElementsAre(IsFileStatus(qmlDirPathSourceId, 21, 422))), + Field(&SynchronizationPackage::updatedProjectSourceIds, + UnorderedElementsAre(qmlDirPathSourceId)), + Field(&SynchronizationPackage::projectDatas, + UnorderedElementsAre(IsProjectData(qmlDirPathSourceId, + qmlDocumentSourceId1, + ModuleId{}, + FileType::QmlDocument), + IsProjectData(qmlDirPathSourceId, + qmlDocumentSourceId2, + ModuleId{}, + FileType::QmlDocument)))))); + + updater.update(directories, {}); +} + +TEST_F(ProjectStorageUpdater, SynchronizeRemovesQmlDocumentInQmldirOnly) +{ + QString qmldir{R"(module Example + FirstType 1.0 First.qml + )"}; + ON_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/qmldir")))).WillByDefault(Return(qmldir)); + ON_CALL(fileSystemMock, fileStatus(Eq(qmlDirPathSourceId))) + .WillByDefault(Return(FileStatus{qmlDirPathSourceId, 21, 422})); + ON_CALL(fileSystemMock, fileStatus(Eq(qmlDocumentSourceId1))) + .WillByDefault(Return(FileStatus{qmlDocumentSourceId1, 22, 2})); + ON_CALL(fileSystemMock, fileStatus(Eq(qmlDocumentSourceId2))) + .WillByDefault(Return(FileStatus{qmlDocumentSourceId2, 22, 2})); + ON_CALL(projectStorageMock, fetchProjectDatas(Eq(qmlDirPathSourceId))) + .WillByDefault(Return(QmlDesigner::Storage::Synchronization::ProjectDatas{ + {qmlDirPathSourceId, qmlDocumentSourceId1, ModuleId{}, FileType::QmlDocument}, + {qmlDirPathSourceId, qmlDocumentSourceId2, ModuleId{}, FileType::QmlDocument}})); + ON_CALL(fileSystemMock, qmlFileNames(Eq(QString("/path")))) + .WillByDefault(Return(QStringList{"First.qml", "First2.qml"})); EXPECT_CALL( projectStorageMock, synchronize(AllOf( - Field(&SynchronizationPackage::imports, UnorderedElementsAre(import1, import4)), + Field(&SynchronizationPackage::imports, IsEmpty()), Field(&SynchronizationPackage::types, UnorderedElementsAre( - Eq(objectType), AllOf(IsStorageType("First.qml", - Storage::Synchronization::ImportedType{"Object"}, + Storage::Synchronization::ImportedType{}, TypeTraits::Reference, qmlDocumentSourceId1, - Storage::Synchronization::ChangeLevel::Full), + Storage::Synchronization::ChangeLevel::Minimal), Field(&Storage::Synchronization::Type::exportedTypes, - ElementsAre(IsExportedType(exampleModuleId, "FirstType", 1, 0), - IsExportedType(pathModuleId, "First", -1, -1)))), + UnorderedElementsAre(IsExportedType(exampleModuleId, "FirstType", 1, 0), + IsExportedType(pathModuleId, "First", -1, -1)))), AllOf(IsStorageType("First2.qml", Storage::Synchronization::ImportedType{}, TypeTraits::Reference, qmlDocumentSourceId2, Storage::Synchronization::ChangeLevel::Minimal), Field(&Storage::Synchronization::Type::exportedTypes, - ElementsAre(IsExportedType(exampleModuleId, "FirstType", 2, 2), - IsExportedType(pathModuleId, "First2", -1, -1)))))), + UnorderedElementsAre(IsExportedType(pathModuleId, "First2", -1, -1)))))), Field(&SynchronizationPackage::updatedSourceIds, - UnorderedElementsAre(qmlDirPathSourceId, - qmltypesPathSourceId, - qmlDocumentSourceId1, - qmlDocumentSourceId2, - qmlDocumentSourceId3)), + UnorderedElementsAre(qmlDirPathSourceId, qmlDocumentSourceId1, qmlDocumentSourceId2)), Field(&SynchronizationPackage::updatedFileStatusSourceIds, - UnorderedElementsAre(qmlDirPathSourceId, - qmlDocumentSourceId1, - qmltypesPathSourceId, - qmlDocumentSourceId3)), + UnorderedElementsAre(qmlDirPathSourceId)), Field(&SynchronizationPackage::fileStatuses, - UnorderedElementsAre(IsFileStatus(qmlDirPathSourceId, 21, 421), - IsFileStatus(qmlDocumentSourceId1, 22, 12), - IsFileStatus(qmltypesPathSourceId, 21, 421))), + UnorderedElementsAre(IsFileStatus(qmlDirPathSourceId, 21, 422))), Field(&SynchronizationPackage::updatedProjectSourceIds, UnorderedElementsAre(qmlDirPathSourceId)), Field(&SynchronizationPackage::projectDatas, UnorderedElementsAre(IsProjectData(qmlDirPathSourceId, qmlDocumentSourceId1, - exampleModuleId, + ModuleId{}, FileType::QmlDocument), IsProjectData(qmlDirPathSourceId, qmlDocumentSourceId2, - exampleModuleId, + ModuleId{}, + FileType::QmlDocument)))))); + + updater.update(directories, {}); +} + +TEST_F(ProjectStorageUpdater, SynchronizeAddQmlDocumentToQmldir) +{ + QString qmldir{R"(module Example + FirstType 1.0 First.qml + FirstType 2.2 First2.qml + )"}; + ON_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/qmldir")))).WillByDefault(Return(qmldir)); + ON_CALL(fileSystemMock, fileStatus(Eq(qmlDirPathSourceId))) + .WillByDefault(Return(FileStatus{qmlDirPathSourceId, 21, 422})); + ON_CALL(fileSystemMock, fileStatus(Eq(qmlDocumentSourceId1))) + .WillByDefault(Return(FileStatus{qmlDocumentSourceId1, 22, 2})); + ON_CALL(fileSystemMock, fileStatus(Eq(qmlDocumentSourceId2))) + .WillByDefault(Return(FileStatus{qmlDocumentSourceId2, 22, 2})); + ON_CALL(projectStorageMock, fetchProjectDatas(Eq(qmlDirPathSourceId))) + .WillByDefault(Return(QmlDesigner::Storage::Synchronization::ProjectDatas{ + {qmlDirPathSourceId, qmlDocumentSourceId1, ModuleId{}, FileType::QmlDocument}, + {qmlDirPathSourceId, qmlDocumentSourceId2, ModuleId{}, FileType::QmlDocument}})); + ON_CALL(fileSystemMock, qmlFileNames(Eq(QString("/path")))) + .WillByDefault(Return(QStringList{"First.qml", "First2.qml"})); + + EXPECT_CALL( + projectStorageMock, + synchronize(AllOf( + Field(&SynchronizationPackage::imports, IsEmpty()), + Field( + &SynchronizationPackage::types, + UnorderedElementsAre( + AllOf(IsStorageType("First.qml", + Storage::Synchronization::ImportedType{}, + TypeTraits::Reference, + qmlDocumentSourceId1, + Storage::Synchronization::ChangeLevel::Minimal), + Field(&Storage::Synchronization::Type::exportedTypes, + UnorderedElementsAre(IsExportedType(exampleModuleId, "FirstType", 1, 0), + IsExportedType(pathModuleId, "First", -1, -1)))), + AllOf(IsStorageType("First2.qml", + Storage::Synchronization::ImportedType{}, + TypeTraits::Reference, + qmlDocumentSourceId2, + Storage::Synchronization::ChangeLevel::Minimal), + Field(&Storage::Synchronization::Type::exportedTypes, + UnorderedElementsAre(IsExportedType(exampleModuleId, "FirstType", 2, 2), + IsExportedType(pathModuleId, "First2", -1, -1)))))), + Field(&SynchronizationPackage::updatedSourceIds, + UnorderedElementsAre(qmlDirPathSourceId, qmlDocumentSourceId1, qmlDocumentSourceId2)), + Field(&SynchronizationPackage::updatedFileStatusSourceIds, + UnorderedElementsAre(qmlDirPathSourceId)), + Field(&SynchronizationPackage::fileStatuses, + UnorderedElementsAre(IsFileStatus(qmlDirPathSourceId, 21, 422))), + Field(&SynchronizationPackage::updatedProjectSourceIds, + UnorderedElementsAre(qmlDirPathSourceId)), + Field(&SynchronizationPackage::projectDatas, + UnorderedElementsAre(IsProjectData(qmlDirPathSourceId, + qmlDocumentSourceId1, + ModuleId{}, FileType::QmlDocument), IsProjectData(qmlDirPathSourceId, - qmltypesPathSourceId, - exampleCppNativeModuleId, - FileType::QmlTypes), - IsProjectData(qmlDirPathSourceId, - qmltypes2PathSourceId, - exampleCppNativeModuleId, - FileType::QmlTypes)))))); + qmlDocumentSourceId2, + ModuleId{}, + FileType::QmlDocument)))))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } -TEST_F(ProjectStorageUpdater, SynchronizeQmlDocumentsDontUpdateIfUpToDate) +TEST_F(ProjectStorageUpdater, SynchronizeAddQmlDocumentToDirectory) { QString qmldir{R"(module Example FirstType 1.0 First.qml - FirstType 2.2 First2.qml - SecondType 2.2 Second.qml)"}; + )"}; ON_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/qmldir")))).WillByDefault(Return(qmldir)); - ON_CALL(projectStorageMock, fetchFileStatus(Eq(qmlDocumentSourceId3))) - .WillByDefault(Return(FileStatus{qmlDocumentSourceId3, 22, 14})); + ON_CALL(fileSystemMock, fileStatus(Eq(qmlDirPathSourceId))) + .WillByDefault(Return(FileStatus{qmlDirPathSourceId, 21, 422})); + ON_CALL(fileSystemMock, fileStatus(Eq(qmlDocumentSourceId1))) + .WillByDefault(Return(FileStatus{qmlDocumentSourceId1, 22, 2})); + ON_CALL(fileSystemMock, fileStatus(Eq(qmlDocumentSourceId2))) + .WillByDefault(Return(FileStatus{qmlDocumentSourceId2, 22, 2})); + ON_CALL(projectStorageMock, fetchProjectDatas(Eq(qmlDirPathSourceId))) + .WillByDefault(Return(QmlDesigner::Storage::Synchronization::ProjectDatas{ + {qmlDirPathSourceId, qmlDocumentSourceId1, ModuleId{}, FileType::QmlDocument}, + {qmlDirPathSourceId, qmlDocumentSourceId2, ModuleId{}, FileType::QmlDocument}})); + ON_CALL(fileSystemMock, qmlFileNames(Eq(QString("/path")))) + .WillByDefault(Return(QStringList{"First.qml", "First2.qml"})); EXPECT_CALL( projectStorageMock, synchronize(AllOf( - Field(&SynchronizationPackage::imports, UnorderedElementsAre(import1, import2)), + Field(&SynchronizationPackage::imports, IsEmpty()), Field(&SynchronizationPackage::types, UnorderedElementsAre( AllOf(IsStorageType("First.qml", - Storage::Synchronization::ImportedType{"Object"}, + Storage::Synchronization::ImportedType{}, TypeTraits::Reference, qmlDocumentSourceId1, - Storage::Synchronization::ChangeLevel::Full), + Storage::Synchronization::ChangeLevel::Minimal), Field(&Storage::Synchronization::Type::exportedTypes, - ElementsAre(IsExportedType(exampleModuleId, "FirstType", 1, 0), - IsExportedType(pathModuleId, "First", -1, -1)))), + UnorderedElementsAre(IsExportedType(exampleModuleId, "FirstType", 1, 0), + IsExportedType(pathModuleId, "First", -1, -1)))), AllOf(IsStorageType("First2.qml", - Storage::Synchronization::ImportedType{"Object2"}, - TypeTraits::Reference, - qmlDocumentSourceId2, - Storage::Synchronization::ChangeLevel::Full), - Field(&Storage::Synchronization::Type::exportedTypes, - ElementsAre(IsExportedType(exampleModuleId, "FirstType", 2, 2), - IsExportedType(pathModuleId, "First2", -1, -1)))), - AllOf(IsStorageType("Second.qml", Storage::Synchronization::ImportedType{}, TypeTraits::Reference, - qmlDocumentSourceId3, + qmlDocumentSourceId2, Storage::Synchronization::ChangeLevel::Minimal), Field(&Storage::Synchronization::Type::exportedTypes, - ElementsAre(IsExportedType(exampleModuleId, "SecondType", 2, 2), - IsExportedType(pathModuleId, "Second", -1, -1)))))), + UnorderedElementsAre(IsExportedType(pathModuleId, "First2", -1, -1)))))), + Field(&SynchronizationPackage::updatedSourceIds, + UnorderedElementsAre(qmlDirPathSourceId, qmlDocumentSourceId1, qmlDocumentSourceId2)), + Field(&SynchronizationPackage::updatedFileStatusSourceIds, + UnorderedElementsAre(qmlDirPathSourceId)), + Field(&SynchronizationPackage::fileStatuses, + UnorderedElementsAre(IsFileStatus(qmlDirPathSourceId, 21, 422))), + Field(&SynchronizationPackage::updatedProjectSourceIds, + UnorderedElementsAre(qmlDirPathSourceId)), + Field(&SynchronizationPackage::projectDatas, + UnorderedElementsAre(IsProjectData(qmlDirPathSourceId, + qmlDocumentSourceId1, + ModuleId{}, + FileType::QmlDocument), + IsProjectData(qmlDirPathSourceId, + qmlDocumentSourceId2, + ModuleId{}, + FileType::QmlDocument)))))); + + updater.update(directories, {}); +} + +TEST_F(ProjectStorageUpdater, SynchronizeQmlDocumentsDontUpdateIfUpToDate) +{ + QString qmldir{R"(module Example + FirstType 1.0 First.qml + FirstType 2.2 First2.qml + SecondType 2.2 Second.qml)"}; + ON_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/qmldir")))).WillByDefault(Return(qmldir)); + ON_CALL(projectStorageMock, fetchFileStatus(Eq(qmlDocumentSourceId3))) + .WillByDefault(Return(FileStatus{qmlDocumentSourceId3, 22, 14})); + + EXPECT_CALL( + projectStorageMock, + synchronize(AllOf( + Field(&SynchronizationPackage::imports, UnorderedElementsAre(import1, import2)), + Field( + &SynchronizationPackage::types, + UnorderedElementsAre( + AllOf(IsStorageType("First.qml", + Storage::Synchronization::ImportedType{"Object"}, + TypeTraits::Reference, + qmlDocumentSourceId1, + Storage::Synchronization::ChangeLevel::Full), + Field(&Storage::Synchronization::Type::exportedTypes, + UnorderedElementsAre(IsExportedType(exampleModuleId, "FirstType", 1, 0), + IsExportedType(pathModuleId, "First", -1, -1)))), + AllOf(IsStorageType("First2.qml", + Storage::Synchronization::ImportedType{"Object2"}, + TypeTraits::Reference, + qmlDocumentSourceId2, + Storage::Synchronization::ChangeLevel::Full), + Field(&Storage::Synchronization::Type::exportedTypes, + UnorderedElementsAre(IsExportedType(exampleModuleId, "FirstType", 2, 2), + IsExportedType(pathModuleId, "First2", -1, -1)))), + AllOf(IsStorageType("Second.qml", + Storage::Synchronization::ImportedType{}, + TypeTraits::Reference, + qmlDocumentSourceId3, + Storage::Synchronization::ChangeLevel::Minimal), + Field(&Storage::Synchronization::Type::exportedTypes, + UnorderedElementsAre(IsExportedType(exampleModuleId, "SecondType", 2, 2), + IsExportedType(pathModuleId, "Second", -1, -1)))))), Field(&SynchronizationPackage::updatedSourceIds, UnorderedElementsAre(qmlDirPathSourceId, qmlDocumentSourceId1, @@ -697,20 +936,15 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmlDocumentsDontUpdateIfUpToDate) Field(&SynchronizationPackage::updatedProjectSourceIds, UnorderedElementsAre(qmlDirPathSourceId)), Field(&SynchronizationPackage::projectDatas, - UnorderedElementsAre(IsProjectData(qmlDirPathSourceId, - qmlDocumentSourceId1, - exampleModuleId, - FileType::QmlDocument), - IsProjectData(qmlDirPathSourceId, - qmlDocumentSourceId2, - exampleModuleId, - FileType::QmlDocument), - IsProjectData(qmlDirPathSourceId, - qmlDocumentSourceId3, - exampleModuleId, - FileType::QmlDocument)))))); - - updater.update(qmlDirs, {}); + UnorderedElementsAre( + IsProjectData(qmlDirPathSourceId, qmlDocumentSourceId1, ModuleId{}, FileType::QmlDocument), + IsProjectData(qmlDirPathSourceId, qmlDocumentSourceId2, ModuleId{}, FileType::QmlDocument), + IsProjectData(qmlDirPathSourceId, + qmlDocumentSourceId3, + ModuleId{}, + FileType::QmlDocument)))))); + + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, UpdateQmldirDocuments) @@ -744,7 +978,7 @@ TEST_F(ProjectStorageUpdater, AddSourceIdForForInvalidQmldirFileStatus) Field(&SynchronizationPackage::fileStatuses, IsEmpty()), Field(&SynchronizationPackage::updatedFileStatusSourceIds, IsEmpty()), Field(&SynchronizationPackage::projectDatas, IsEmpty())))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, SynchronizIfQmldirFileHasNotChanged) @@ -796,7 +1030,7 @@ TEST_F(ProjectStorageUpdater, SynchronizIfQmldirFileHasNotChanged) qmlDocumentSourceId2)), Field(&SynchronizationPackage::projectDatas, IsEmpty())))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, SynchronizIfQmldirFileHasNotChangedAndSomeUpdatedFiles) @@ -836,7 +1070,7 @@ TEST_F(ProjectStorageUpdater, SynchronizIfQmldirFileHasNotChangedAndSomeUpdatedF UnorderedElementsAre(qmltypesPathSourceId, qmlDocumentSourceId1)), Field(&SynchronizationPackage::projectDatas, IsEmpty())))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, UpdateQmlTypesFilesIsEmpty) @@ -913,39 +1147,39 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmlDocumentsWithDifferentVersionButSame FirstType 1.1 First.qml FirstType 6.0 First.qml)"}; ON_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/qmldir")))).WillByDefault(Return(qmldir)); + ON_CALL(fileSystemMock, qmlFileNames(Eq(QString("/path")))) + .WillByDefault(Return(QStringList{"First.qml"})); - EXPECT_CALL(projectStorageMock, - synchronize( - AllOf(Field(&SynchronizationPackage::imports, UnorderedElementsAre(import1)), - Field(&SynchronizationPackage::types, - UnorderedElementsAre(AllOf( - IsStorageType("First.qml", - Storage::Synchronization::ImportedType{"Object"}, - TypeTraits::Reference, - qmlDocumentSourceId1, - Storage::Synchronization::ChangeLevel::Full), - Field(&Storage::Synchronization::Type::exportedTypes, - UnorderedElementsAre( - IsExportedType(exampleModuleId, "FirstType", 1, 0), - IsExportedType(exampleModuleId, "FirstType", 1, 1), - IsExportedType(exampleModuleId, "FirstType", 6, 0), - IsExportedType(pathModuleId, "First", -1, -1)))))), - Field(&SynchronizationPackage::updatedSourceIds, - UnorderedElementsAre(qmlDirPathSourceId, qmlDocumentSourceId1)), - Field(&SynchronizationPackage::updatedFileStatusSourceIds, - UnorderedElementsAre(qmlDirPathSourceId, qmlDocumentSourceId1)), - Field(&SynchronizationPackage::fileStatuses, - UnorderedElementsAre(IsFileStatus(qmlDirPathSourceId, 21, 421), - IsFileStatus(qmlDocumentSourceId1, 22, 12))), - Field(&SynchronizationPackage::updatedProjectSourceIds, - UnorderedElementsAre(qmlDirPathSourceId)), - Field(&SynchronizationPackage::projectDatas, - UnorderedElementsAre(IsProjectData(qmlDirPathSourceId, - qmlDocumentSourceId1, - exampleModuleId, - FileType::QmlDocument)))))); + EXPECT_CALL( + projectStorageMock, + synchronize(AllOf( + Field(&SynchronizationPackage::imports, UnorderedElementsAre(import1)), + Field(&SynchronizationPackage::types, + UnorderedElementsAre(AllOf( + IsStorageType("First.qml", + Storage::Synchronization::ImportedType{"Object"}, + TypeTraits::Reference, + qmlDocumentSourceId1, + Storage::Synchronization::ChangeLevel::Full), + Field(&Storage::Synchronization::Type::exportedTypes, + UnorderedElementsAre(IsExportedType(exampleModuleId, "FirstType", 1, 0), + IsExportedType(exampleModuleId, "FirstType", 1, 1), + IsExportedType(exampleModuleId, "FirstType", 6, 0), + IsExportedType(pathModuleId, "First", -1, -1)))))), + Field(&SynchronizationPackage::updatedSourceIds, + UnorderedElementsAre(qmlDirPathSourceId, qmlDocumentSourceId1)), + Field(&SynchronizationPackage::updatedFileStatusSourceIds, + UnorderedElementsAre(qmlDirPathSourceId, qmlDocumentSourceId1)), + Field(&SynchronizationPackage::fileStatuses, + UnorderedElementsAre(IsFileStatus(qmlDirPathSourceId, 21, 421), + IsFileStatus(qmlDocumentSourceId1, 22, 12))), + Field(&SynchronizationPackage::updatedProjectSourceIds, + UnorderedElementsAre(qmlDirPathSourceId)), + Field(&SynchronizationPackage::projectDatas, + UnorderedElementsAre(IsProjectData( + qmlDirPathSourceId, qmlDocumentSourceId1, ModuleId{}, FileType::QmlDocument)))))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, SynchronizeQmlDocumentsWithDifferentTypeNameButSameVersionAndFileName) @@ -954,38 +1188,38 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmlDocumentsWithDifferentTypeNameButSam FirstType 1.0 First.qml FirstType2 1.0 First.qml)"}; ON_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/qmldir")))).WillByDefault(Return(qmldir)); + ON_CALL(fileSystemMock, qmlFileNames(Eq(QString("/path")))) + .WillByDefault(Return(QStringList{"First.qml"})); - EXPECT_CALL(projectStorageMock, - synchronize( - AllOf(Field(&SynchronizationPackage::imports, UnorderedElementsAre(import1)), - Field(&SynchronizationPackage::types, - UnorderedElementsAre(AllOf( - IsStorageType("First.qml", - Storage::Synchronization::ImportedType{"Object"}, - TypeTraits::Reference, - qmlDocumentSourceId1, - Storage::Synchronization::ChangeLevel::Full), - Field(&Storage::Synchronization::Type::exportedTypes, - UnorderedElementsAre( - IsExportedType(exampleModuleId, "FirstType", 1, 0), - IsExportedType(exampleModuleId, "FirstType2", 1, 0), - IsExportedType(pathModuleId, "First", -1, -1)))))), - Field(&SynchronizationPackage::updatedSourceIds, - UnorderedElementsAre(qmlDirPathSourceId, qmlDocumentSourceId1)), - Field(&SynchronizationPackage::updatedFileStatusSourceIds, - UnorderedElementsAre(qmlDirPathSourceId, qmlDocumentSourceId1)), - Field(&SynchronizationPackage::fileStatuses, - UnorderedElementsAre(IsFileStatus(qmlDirPathSourceId, 21, 421), - IsFileStatus(qmlDocumentSourceId1, 22, 12))), - Field(&SynchronizationPackage::updatedProjectSourceIds, - UnorderedElementsAre(qmlDirPathSourceId)), - Field(&SynchronizationPackage::projectDatas, - UnorderedElementsAre(IsProjectData(qmlDirPathSourceId, - qmlDocumentSourceId1, - exampleModuleId, - FileType::QmlDocument)))))); + EXPECT_CALL( + projectStorageMock, + synchronize(AllOf( + Field(&SynchronizationPackage::imports, UnorderedElementsAre(import1)), + Field(&SynchronizationPackage::types, + UnorderedElementsAre(AllOf( + IsStorageType("First.qml", + Storage::Synchronization::ImportedType{"Object"}, + TypeTraits::Reference, + qmlDocumentSourceId1, + Storage::Synchronization::ChangeLevel::Full), + Field(&Storage::Synchronization::Type::exportedTypes, + UnorderedElementsAre(IsExportedType(exampleModuleId, "FirstType", 1, 0), + IsExportedType(exampleModuleId, "FirstType2", 1, 0), + IsExportedType(pathModuleId, "First", -1, -1)))))), + Field(&SynchronizationPackage::updatedSourceIds, + UnorderedElementsAre(qmlDirPathSourceId, qmlDocumentSourceId1)), + Field(&SynchronizationPackage::updatedFileStatusSourceIds, + UnorderedElementsAre(qmlDirPathSourceId, qmlDocumentSourceId1)), + Field(&SynchronizationPackage::fileStatuses, + UnorderedElementsAre(IsFileStatus(qmlDirPathSourceId, 21, 421), + IsFileStatus(qmlDocumentSourceId1, 22, 12))), + Field(&SynchronizationPackage::updatedProjectSourceIds, + UnorderedElementsAre(qmlDirPathSourceId)), + Field(&SynchronizationPackage::projectDatas, + UnorderedElementsAre(IsProjectData( + qmlDirPathSourceId, qmlDocumentSourceId1, ModuleId{}, FileType::QmlDocument)))))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, DontSynchronizeSelectors) @@ -995,70 +1229,18 @@ TEST_F(ProjectStorageUpdater, DontSynchronizeSelectors) ON_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/qml/+First.qml")))) .WillByDefault(Return(qmlDocument1)); QString qmldir{R"(module Example - FirstType 1.0 +First.qml - FirstType2 1.0 qml/+First.qml)"}; + FirstType 1.0 +First.qml)"}; ON_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/qmldir")))).WillByDefault(Return(qmldir)); + ON_CALL(fileSystemMock, qmlFileNames(Eq(QString("/path")))) + .WillByDefault(Return(QStringList{"First.qml"})); EXPECT_CALL(projectStorageMock, - synchronize( - AllOf(Field(&SynchronizationPackage::imports, IsEmpty()), - Field(&SynchronizationPackage::types, IsEmpty()), - Field(&SynchronizationPackage::updatedSourceIds, - UnorderedElementsAre(qmlDirPathSourceId)), - Field(&SynchronizationPackage::fileStatuses, - UnorderedElementsAre(IsFileStatus(qmlDirPathSourceId, 21, 421))), - Field(&SynchronizationPackage::updatedFileStatusSourceIds, - UnorderedElementsAre(qmlDirPathSourceId)), - Field(&SynchronizationPackage::projectDatas, IsEmpty()), - Field(&SynchronizationPackage::updatedProjectSourceIds, - UnorderedElementsAre(qmlDirPathSourceId))))); - - updater.update(qmlDirs, {}); -} - -TEST_F(ProjectStorageUpdater, SynchronizeQmlDocumentsWithRelativeFilePath) -{ - SourceId qmlDocumentSourceId = sourcePathCache.sourceId("/path/First.qml"); - ON_CALL(fileSystemMock, fileStatus(Eq(qmlDocumentSourceId))) - .WillByDefault(Return(FileStatus{qmlDocumentSourceId, 22, 12})); - ON_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/First.qml")))) - .WillByDefault(Return(qmlDocument1)); - QString qmldir{R"(module Example - FirstType 1.0 First.qml - FirstType2 1.0 First.qml)"}; - ON_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/qmldir")))).WillByDefault(Return(qmldir)); - - EXPECT_CALL(projectStorageMock, - synchronize( - AllOf(Field(&SynchronizationPackage::imports, UnorderedElementsAre(import1)), - Field(&SynchronizationPackage::types, - UnorderedElementsAre(AllOf( - IsStorageType("First.qml", - Storage::Synchronization::ImportedType{"Object"}, - TypeTraits::Reference, - qmlDocumentSourceId, - Storage::Synchronization::ChangeLevel::Full), - Field(&Storage::Synchronization::Type::exportedTypes, - UnorderedElementsAre( - IsExportedType(exampleModuleId, "FirstType", 1, 0), - IsExportedType(exampleModuleId, "FirstType2", 1, 0), - IsExportedType(pathModuleId, "First", -1, -1)))))), - Field(&SynchronizationPackage::updatedSourceIds, - UnorderedElementsAre(qmlDirPathSourceId, qmlDocumentSourceId)), - Field(&SynchronizationPackage::updatedFileStatusSourceIds, - UnorderedElementsAre(qmlDirPathSourceId, qmlDocumentSourceId)), - Field(&SynchronizationPackage::fileStatuses, - UnorderedElementsAre(IsFileStatus(qmlDirPathSourceId, 21, 421), - IsFileStatus(qmlDocumentSourceId, 22, 12))), - Field(&SynchronizationPackage::updatedProjectSourceIds, - UnorderedElementsAre(qmlDirPathSourceId)), - Field(&SynchronizationPackage::projectDatas, - UnorderedElementsAre(IsProjectData(qmlDirPathSourceId, - qmlDocumentSourceId, - exampleModuleId, - FileType::QmlDocument)))))); + synchronize(Not(Field( + &SynchronizationPackage::types, + Contains(Field(&Storage::Synchronization::Type::exportedTypes, + Contains(IsExportedType(exampleModuleId, "FirstType", 1, 0)))))))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, SynchronizeQmldirDependencies) @@ -1089,7 +1271,7 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmldirDependencies) Field(&SynchronizationPackage::updatedModuleDependencySourceIds, UnorderedElementsAre(qmltypesPathSourceId, qmltypes2PathSourceId))))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, SynchronizeQmldirDependenciesWithDoubleEntries) @@ -1121,7 +1303,7 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmldirDependenciesWithDoubleEntries) Field(&SynchronizationPackage::updatedModuleDependencySourceIds, UnorderedElementsAre(qmltypesPathSourceId, qmltypes2PathSourceId))))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, SynchronizeQmldirDependenciesWithCollidingImports) @@ -1153,7 +1335,7 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmldirDependenciesWithCollidingImports) Field(&SynchronizationPackage::updatedModuleDependencySourceIds, UnorderedElementsAre(qmltypesPathSourceId, qmltypes2PathSourceId))))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, SynchronizeQmldirWithNoDependencies) @@ -1170,7 +1352,7 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmldirWithNoDependencies) Field(&SynchronizationPackage::updatedModuleDependencySourceIds, UnorderedElementsAre(qmltypesPathSourceId, qmltypes2PathSourceId))))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, SynchronizeQmldirImports) @@ -1212,7 +1394,7 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmldirImports) IsAutoVersion::No})), Field(&SynchronizationPackage::updatedModuleIds, ElementsAre(exampleModuleId))))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, SynchronizeQmldirWithNoImports) @@ -1226,7 +1408,7 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmldirWithNoImports) Field(&SynchronizationPackage::updatedModuleIds, ElementsAre(exampleModuleId))))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, SynchronizeQmldirImportsWithDoubleEntries) @@ -1269,7 +1451,7 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmldirImportsWithDoubleEntries) IsAutoVersion::No})), Field(&SynchronizationPackage::updatedModuleIds, ElementsAre(exampleModuleId))))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } TEST_F(ProjectStorageUpdater, SynchronizeQmldirOptionalImports) @@ -1311,7 +1493,7 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmldirOptionalImports) IsAutoVersion::No})), Field(&SynchronizationPackage::updatedModuleIds, ElementsAre(exampleModuleId))))); - updater.update(qmlDirs, {}); + updater.update(directories, {}); } } // namespace |