2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2011-11-15 11:02:32 +01:00
|
|
|
|
|
|
|
|
#include "qmljstoolsplugin.h"
|
|
|
|
|
|
|
|
|
|
#include <QLatin1String>
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <qmljs/qmljslink.h>
|
2015-03-04 16:46:23 +01:00
|
|
|
#include <qmljs/qmljsvalueowner.h>
|
2011-11-15 11:02:32 +01:00
|
|
|
#include <qmljstools/qmljsmodelmanager.h>
|
|
|
|
|
|
|
|
|
|
#include <QtTest>
|
|
|
|
|
|
|
|
|
|
using namespace QmlJS;
|
|
|
|
|
|
2015-02-03 23:48:57 +02:00
|
|
|
namespace QmlJSTools {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
void QmlJSToolsPlugin::test_basic()
|
2011-11-15 11:02:32 +01:00
|
|
|
{
|
2015-02-03 23:48:57 +02:00
|
|
|
ModelManagerInterface *modelManager = ModelManagerInterface::instance();
|
2011-11-15 11:02:32 +01:00
|
|
|
|
2022-06-20 12:35:13 +02:00
|
|
|
const Utils::FilePath qmlFilePath = Core::ICore::resourcePath(
|
|
|
|
|
"qmldesigner/itemLibraryQmlSources/ItemDelegate.qml");
|
|
|
|
|
modelManager->updateSourceFiles(QList<Utils::FilePath>({qmlFilePath}), false);
|
2020-05-10 16:00:31 +02:00
|
|
|
modelManager->test_joinAllThreads();
|
2011-11-15 11:02:32 +01:00
|
|
|
|
|
|
|
|
Snapshot snapshot = modelManager->snapshot();
|
2017-04-19 11:07:15 +02:00
|
|
|
Document::Ptr doc = snapshot.document(qmlFilePath);
|
2011-11-15 11:02:32 +01:00
|
|
|
QVERIFY(doc && doc->isQmlDocument());
|
|
|
|
|
|
2013-10-16 15:08:27 +02:00
|
|
|
ContextPtr context = Link(snapshot, ViewerContext(), LibraryInfo())();
|
2011-11-15 11:02:32 +01:00
|
|
|
QVERIFY(context);
|
|
|
|
|
|
|
|
|
|
const CppComponentValue *rectangleValue = context->valueOwner()->cppQmlTypes().objectByQualifiedName(
|
2020-07-28 13:03:53 +02:00
|
|
|
QLatin1String("QtQuick"), QLatin1String("QDeclarativeRectangle"), LanguageUtils::ComponentVersion(2, 15));
|
2011-11-15 11:02:32 +01:00
|
|
|
QVERIFY(rectangleValue);
|
2012-11-22 11:35:34 +01:00
|
|
|
QVERIFY(!rectangleValue->isWritable(QLatin1String("border")));
|
|
|
|
|
QVERIFY(rectangleValue->hasProperty(QLatin1String("border")));
|
|
|
|
|
QVERIFY(rectangleValue->isPointer(QLatin1String("border")));
|
|
|
|
|
QVERIFY(rectangleValue->isWritable(QLatin1String("color")));
|
|
|
|
|
QVERIFY(!rectangleValue->isPointer(QLatin1String("color")));
|
2011-11-15 11:02:32 +01:00
|
|
|
|
2012-11-22 11:35:34 +01:00
|
|
|
const ObjectValue *ovItem = context->lookupType(doc.data(), QStringList(QLatin1String("Item")));
|
2011-11-15 11:02:32 +01:00
|
|
|
QVERIFY(ovItem);
|
2012-11-22 11:35:34 +01:00
|
|
|
QCOMPARE(ovItem->className(), QLatin1String("Item"));
|
|
|
|
|
QCOMPARE(context->imports(doc.data())->info(QLatin1String("Item"), context.data()).name(), QLatin1String("QtQuick"));
|
2011-11-15 11:02:32 +01:00
|
|
|
|
2012-11-22 11:35:34 +01:00
|
|
|
const ObjectValue *ovProperty = context->lookupType(doc.data(), QStringList() << QLatin1String("Item") << QLatin1String("states"));
|
2011-11-15 11:02:32 +01:00
|
|
|
QVERIFY(ovProperty);
|
2012-11-22 11:35:34 +01:00
|
|
|
QCOMPARE(ovProperty->className(), QLatin1String("State"));
|
2011-11-15 11:02:32 +01:00
|
|
|
|
2012-11-22 11:35:34 +01:00
|
|
|
const CppComponentValue *qmlItemValue = value_cast<CppComponentValue>(ovItem);
|
2011-11-15 11:02:32 +01:00
|
|
|
QVERIFY(qmlItemValue);
|
2012-11-22 11:35:34 +01:00
|
|
|
QCOMPARE(qmlItemValue->defaultPropertyName(), QLatin1String("data"));
|
|
|
|
|
QCOMPARE(qmlItemValue->propertyType(QLatin1String("state")), QLatin1String("string"));
|
2011-11-15 11:02:32 +01:00
|
|
|
|
2012-11-22 11:35:34 +01:00
|
|
|
const ObjectValue *ovState = context->lookupType(doc.data(), QStringList(QLatin1String("State")));
|
|
|
|
|
const CppComponentValue *qmlState2Value = value_cast<CppComponentValue>(ovState);
|
|
|
|
|
QCOMPARE(qmlState2Value->className(), QLatin1String("State"));
|
2011-11-15 11:02:32 +01:00
|
|
|
|
2012-11-22 11:35:34 +01:00
|
|
|
const ObjectValue *ovImage = context->lookupType(doc.data(), QStringList(QLatin1String("Image")));
|
|
|
|
|
const CppComponentValue *qmlImageValue = value_cast<CppComponentValue>(ovImage);
|
|
|
|
|
QCOMPARE(qmlImageValue->className(), QLatin1String("Image"));
|
|
|
|
|
QCOMPARE(qmlImageValue->propertyType(QLatin1String("source")), QLatin1String("QUrl"));
|
2011-11-15 11:02:32 +01:00
|
|
|
}
|
2015-02-03 23:48:57 +02:00
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlJSTools
|