2023-03-30 13:14:17 +02:00
|
|
|
// Copyright (C) 2023 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
|
|
|
|
2023-04-26 14:07:54 +02:00
|
|
|
#include "externaldependenciesmock.h"
|
2023-03-30 13:14:17 +02:00
|
|
|
#include "googletest.h"
|
|
|
|
|
|
|
|
|
|
#include <projectstorage/modulescanner.h>
|
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
2023-04-26 14:07:54 +02:00
|
|
|
QLatin1String qmlModulesPath(TESTDATA_DIR "/qml");
|
|
|
|
|
|
2023-03-30 13:14:17 +02:00
|
|
|
template<typename Matcher>
|
|
|
|
|
auto UrlProperty(const Matcher &matcher)
|
|
|
|
|
{
|
|
|
|
|
return Property(&QmlDesigner::Import::url, matcher);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-18 11:51:09 +02:00
|
|
|
template<typename Matcher>
|
|
|
|
|
auto VersionProperty(const Matcher &matcher)
|
|
|
|
|
{
|
|
|
|
|
return Property(&QmlDesigner::Import::version, matcher);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-26 14:07:54 +02:00
|
|
|
template<typename Matcher>
|
|
|
|
|
auto CorePropertiesHave(const Matcher &matcher)
|
|
|
|
|
{
|
|
|
|
|
return AllOf(Contains(AllOf(UrlProperty("QtQuick"), matcher)),
|
|
|
|
|
Contains(AllOf(UrlProperty("QtQuick.Controls"), matcher)),
|
|
|
|
|
Contains(AllOf(UrlProperty("QtQuick3D"), matcher)),
|
|
|
|
|
Contains(AllOf(UrlProperty("QtQuick3D.Helpers"), matcher)),
|
|
|
|
|
Contains(AllOf(UrlProperty("QtQuick3D.Particles3D"), matcher)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Matcher>
|
|
|
|
|
auto NonCorePropertiesHave(const Matcher &matcher)
|
|
|
|
|
{
|
|
|
|
|
return Not(Contains(AllOf(UrlProperty(AnyOf(Eq("QtQuick"),
|
|
|
|
|
Eq("QtQuick.Controls"),
|
|
|
|
|
Eq("QtQuick3D"),
|
|
|
|
|
Eq("QtQuick3D.Helpers"),
|
|
|
|
|
Eq("QtQuick3D.Particles3D"))),
|
|
|
|
|
matcher)));
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-21 15:47:50 +02:00
|
|
|
MATCHER(HasDuplicates, std::string(negation ? "hasn't duplicates" : "has dublicates"))
|
|
|
|
|
{
|
|
|
|
|
auto values = arg;
|
|
|
|
|
std::sort(values.begin(), values.begin());
|
|
|
|
|
auto found = std::adjacent_find(values.begin(), values.end());
|
|
|
|
|
|
|
|
|
|
return found != values.end();
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-30 13:14:17 +02:00
|
|
|
class ModuleScanner : public testing::Test
|
|
|
|
|
{
|
|
|
|
|
protected:
|
2023-04-26 14:07:54 +02:00
|
|
|
NiceMock<ExternalDependenciesMock> externalDependenciesMock;
|
2023-04-18 11:51:09 +02:00
|
|
|
QmlDesigner::ModuleScanner scanner{[](QStringView moduleName) {
|
|
|
|
|
return moduleName.endsWith(u"impl");
|
|
|
|
|
},
|
2023-04-26 14:07:54 +02:00
|
|
|
QmlDesigner::VersionScanning::No,
|
|
|
|
|
externalDependenciesMock};
|
2023-03-30 13:14:17 +02:00
|
|
|
};
|
|
|
|
|
|
2023-05-08 16:30:08 +02:00
|
|
|
TEST_F(ModuleScanner, ReturnEmptyOptionalForEmptyPath)
|
2023-03-30 13:14:17 +02:00
|
|
|
{
|
|
|
|
|
scanner.scan(QStringList{""});
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(scanner.modules(), IsEmpty());
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-08 16:30:08 +02:00
|
|
|
TEST_F(ModuleScanner, ReturnEmptyOptionalForNullStringPath)
|
|
|
|
|
{
|
|
|
|
|
scanner.scan(QStringList{QString{}});
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(scanner.modules(), IsEmpty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ModuleScanner, ReturnEmptyOptionalForEmptyPaths)
|
|
|
|
|
{
|
|
|
|
|
scanner.scan(QStringList{});
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(scanner.modules(), IsEmpty());
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-30 13:14:17 +02:00
|
|
|
TEST_F(ModuleScanner, GetQtQuick)
|
|
|
|
|
{
|
2023-04-26 14:07:54 +02:00
|
|
|
scanner.scan(QStringList{qmlModulesPath});
|
2023-03-30 13:14:17 +02:00
|
|
|
|
|
|
|
|
ASSERT_THAT(scanner.modules(), Contains(UrlProperty("QtQuick")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ModuleScanner, SkipEmptyModules)
|
|
|
|
|
{
|
2023-04-26 14:07:54 +02:00
|
|
|
scanner.scan(QStringList{qmlModulesPath});
|
2023-03-30 13:14:17 +02:00
|
|
|
|
|
|
|
|
ASSERT_THAT(scanner.modules(), Not(Contains(UrlProperty(IsEmpty()))));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ModuleScanner, UseSkipFunction)
|
|
|
|
|
{
|
2023-04-26 14:07:54 +02:00
|
|
|
scanner.scan(QStringList{qmlModulesPath});
|
2023-03-30 13:14:17 +02:00
|
|
|
|
|
|
|
|
ASSERT_THAT(scanner.modules(), Not(Contains(UrlProperty(EndsWith(QStringView{u"impl"})))));
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-18 11:51:09 +02:00
|
|
|
TEST_F(ModuleScanner, Version)
|
|
|
|
|
{
|
|
|
|
|
QmlDesigner::ModuleScanner scanner{[](QStringView moduleName) {
|
|
|
|
|
return moduleName.endsWith(u"impl");
|
|
|
|
|
},
|
2023-04-26 14:07:54 +02:00
|
|
|
QmlDesigner::VersionScanning::Yes,
|
|
|
|
|
externalDependenciesMock};
|
2023-04-18 11:51:09 +02:00
|
|
|
|
|
|
|
|
scanner.scan(QStringList{TESTDATA_DIR "/modulescanner"});
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(scanner.modules(), ElementsAre(AllOf(UrlProperty("Example"), VersionProperty("1.3"))));
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-25 11:30:58 +02:00
|
|
|
TEST_F(ModuleScanner, NoVersion)
|
|
|
|
|
{
|
|
|
|
|
QmlDesigner::ModuleScanner scanner{[](QStringView moduleName) {
|
|
|
|
|
return moduleName.endsWith(u"impl");
|
|
|
|
|
},
|
2023-04-26 14:07:54 +02:00
|
|
|
QmlDesigner::VersionScanning::No,
|
|
|
|
|
externalDependenciesMock};
|
2023-04-25 11:30:58 +02:00
|
|
|
|
|
|
|
|
scanner.scan(QStringList{TESTDATA_DIR "/modulescanner"});
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(scanner.modules(),
|
|
|
|
|
ElementsAre(AllOf(UrlProperty("Example"), VersionProperty(QString{}))));
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-21 15:47:50 +02:00
|
|
|
TEST_F(ModuleScanner, Duplicates)
|
|
|
|
|
{
|
2023-04-26 14:07:54 +02:00
|
|
|
scanner.scan(QStringList{qmlModulesPath});
|
2023-04-21 15:47:50 +02:00
|
|
|
|
|
|
|
|
ASSERT_THAT(scanner.modules(), Not(HasDuplicates()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ModuleScanner, DontAddModulesAgain)
|
|
|
|
|
{
|
2023-04-26 14:07:54 +02:00
|
|
|
scanner.scan(QStringList{qmlModulesPath});
|
2023-04-21 15:47:50 +02:00
|
|
|
|
2023-04-26 14:07:54 +02:00
|
|
|
scanner.scan(QStringList{qmlModulesPath});
|
2023-04-21 15:47:50 +02:00
|
|
|
|
|
|
|
|
ASSERT_THAT(scanner.modules(), Not(HasDuplicates()));
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-26 14:07:54 +02:00
|
|
|
TEST_F(ModuleScanner, SetNoVersionForQtQuickVersion)
|
|
|
|
|
{
|
|
|
|
|
scanner.scan(QStringList{qmlModulesPath});
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(scanner.modules(), CorePropertiesHave(VersionProperty(QString{})));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ModuleScanner, SetVersionForQtQuickVersion)
|
|
|
|
|
{
|
|
|
|
|
ON_CALL(externalDependenciesMock, qtQuickVersion()).WillByDefault(Return(QString{"6.4"}));
|
|
|
|
|
|
|
|
|
|
scanner.scan(QStringList{qmlModulesPath});
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(scanner.modules(), CorePropertiesHave(VersionProperty(u"6.4")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ModuleScanner, DontSetVersionForNonQtQuickVersion)
|
|
|
|
|
{
|
|
|
|
|
ON_CALL(externalDependenciesMock, qtQuickVersion()).WillByDefault(Return(QString{"6.4"}));
|
|
|
|
|
|
|
|
|
|
scanner.scan(QStringList{qmlModulesPath});
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(scanner.modules(), NonCorePropertiesHave(VersionProperty(QString{})));
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-30 13:14:17 +02:00
|
|
|
} // namespace
|