diff options
Diffstat (limited to 'tests/auto/styleimports/tst_styleimports.cpp')
-rw-r--r-- | tests/auto/styleimports/tst_styleimports.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/styleimports/tst_styleimports.cpp b/tests/auto/styleimports/tst_styleimports.cpp index 04acbb21..7639db0e 100644 --- a/tests/auto/styleimports/tst_styleimports.cpp +++ b/tests/auto/styleimports/tst_styleimports.cpp @@ -59,6 +59,9 @@ private slots: void select(); void platformSelectors(); + + void importStyleWithoutControls_data(); + void importStyleWithoutControls(); }; void tst_StyleImports::initTestCase() @@ -200,6 +203,40 @@ void tst_StyleImports::platformSelectors() #endif } +void tst_StyleImports::importStyleWithoutControls_data() +{ + QTest::addColumn<QString>("style"); + + const auto builtInStyles = QQuickStylePrivate::builtInStyles(); + for (const auto &styleName : builtInStyles) + QTest::addRow(qPrintable(styleName)) << styleName; +} + +// Tests that warnings are printed when trying to import a specific style without first importing QtQuick.Controls. +void tst_StyleImports::importStyleWithoutControls() +{ + QFETCH(QString, style); + + QQmlApplicationEngine engine; + const QUrl url(testFileUrl(QString::fromLatin1("import%1StyleWithoutControls.qml").arg(style))); + bool success = false; + + // Two warnings, because Default is used as the fallback. + if (style != QLatin1String("Default")) + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("QtQuick.Controls must be imported before importing.*" + style)); + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("QtQuick.Controls must be imported before importing.*Default")); + + QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, + this, [url, &success](QObject *obj, const QUrl &objUrl) { + if (url == objUrl) + success = obj; + }, Qt::QueuedConnection); + + engine.load(url); + // It should load, but with warnings. + QTRY_VERIFY(success); +} + QTEST_MAIN(tst_StyleImports) #include "tst_styleimports.moc" |