1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
|
/*
* Copyright 2013-2016 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QtCore/QString>
#include <QtQml/QQmlEngine>
#include <QtQml/QQmlContext>
#include <QtQml/QQmlComponent>
#include <QtQuick/private/qquicktext_p.h>
#include <QtTest/QtTest>
#include <LomiriToolkit/lomiritoolkitmodule.h>
#include <LomiriToolkit/private/ucdeprecatedtheme_p.h>
#include <LomiriToolkit/private/uctheme_p.h>
#include "uctestcase.h"
UT_USE_NAMESPACE
Q_DECLARE_METATYPE(QList<QQmlError>)
class ThemeTestCase : public LomiriTestCase
{
Q_OBJECT
public:
ThemeTestCase(const QString& file, QWindow* parent = 0)
: LomiriTestCase(file, QQuickView::SizeViewToRootObject, true, parent)
{
}
~ThemeTestCase()
{
// restore theme before quitting
if (!rootContext()) {
return;
}
UCDeprecatedTheme *theme = rootContext()->contextProperty("Theme").value<UCDeprecatedTheme*>();
if (theme) {
theme->resetName();
} else {
qWarning() << "No theme instance found!";
}
}
void setTheme(const QString &theme)
{
rootObject()->setProperty("themeName", theme);
QCoreApplication::processEvents();
}
void setStyle(const QString &style)
{
rootObject()->setProperty("styleDocument", style);
QCoreApplication::processEvents();
}
};
class tst_UCDeprecatedTheme : public QObject
{
Q_OBJECT
private:
QString m_xdgDataPath;
UCDeprecatedTheme *instance(QQmlEngine &engine)
{
return engine.rootContext()->contextProperty("Theme").value<UCDeprecatedTheme*>();
}
void initDeprecatedTheme(QQmlEngine &engine)
{
LomiriToolkitModule::initializeContextProperties(&engine);
}
private Q_SLOTS:
void initTestCase();
void cleanupTestCase();
void testNameDefault();
void testNameSet();
void testCreateStyleComponent();
void testCreateStyleComponent_data();
void testThemesRelativePath();
void testThemesRelativePathWithParent();
void testThemesRelativePathWithParentXDGDATA();
void testThemesRelativePathWithParentNoVariablesSet();
void testThemesRelativePathWithParentOneXDGPathSet();
void testNoImportPathSet();
void testBogusImportPathSet();
void testMultipleImportPathsSet();
void testPaletteUsed_bug1549830();
};
void tst_UCDeprecatedTheme::initTestCase()
{
m_xdgDataPath = QLatin1String(getenv("XDG_DATA_DIRS"));
qputenv("SUPPRESS_DEPRECATED_NOTE", "yes");
}
void tst_UCDeprecatedTheme::cleanupTestCase()
{
qputenv("XDG_DATA_DIRS", m_xdgDataPath.toLocal8Bit());
}
void tst_UCDeprecatedTheme::testNameDefault()
{
QQmlEngine engine;
initDeprecatedTheme(engine);
QCOMPARE(instance(engine)->name(), QString("Lomiri.Components.Themes.Ambiance"));
}
void tst_UCDeprecatedTheme::testNameSet()
{
QTest::ignoreMessage(QtWarningMsg, "Theme not found: \"MyBeautifulTheme\"");
QQmlEngine engine;
initDeprecatedTheme(engine);
instance(engine)->setName("MyBeautifulTheme");
QCOMPARE(instance(engine)->name(), QString("MyBeautifulTheme"));
}
void tst_UCDeprecatedTheme::testCreateStyleComponent()
{
QFETCH(QString, styleName);
QFETCH(QString, parentName);
QFETCH(bool, success);
if (parentName == "SimpleItem.qml")
QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready");
else if (styleName == "NotExistingTestStyle.qml")
ThemeTestCase::ignoreWarning(parentName, 20, 1, "QML Parent: Warning: Style NotExistingTestStyle.qml not found in theme TestModule.TestTheme");
qputenv("LOMIRI_UI_TOOLKIT_THEMES_PATH", ".");
QScopedPointer<ThemeTestCase> view(new ThemeTestCase(parentName));
QVERIFY(view);
view->setTheme("TestModule.TestTheme");
view->setStyle(styleName);
QQmlComponent *style = view->rootObject()->property("style").value<QQmlComponent*>();
QCOMPARE(style != NULL, success);
}
void tst_UCDeprecatedTheme::testCreateStyleComponent_data() {
QTest::addColumn<QString>("styleName");
QTest::addColumn<QString>("parentName");
QTest::addColumn<bool>("success");
QTest::newRow("Existing style") << "TestStyle.qml" << "Parent.qml" << true;
QTest::newRow("Non existing style") << "NotExistingTestStyle.qml" << "Parent.qml" << false;
}
void tst_UCDeprecatedTheme::testThemesRelativePath()
{
qputenv("LOMIRI_UI_TOOLKIT_THEMES_PATH", "../tst_theme_engine");
QScopedPointer<ThemeTestCase> view(new ThemeTestCase("Parent.qml"));
QVERIFY(view);
view->setTheme("TestModule.TestTheme");
view->setStyle("TestStyle.qml");
QQmlComponent *style = view->rootObject()->property("style").value<QQmlComponent*>();
QCOMPARE(style != NULL, true);
}
void tst_UCDeprecatedTheme::testThemesRelativePathWithParent()
{
qputenv("LOMIRI_UI_TOOLKIT_THEMES_PATH", "./themes:./themes/TestModule");
QScopedPointer<ThemeTestCase> view(new ThemeTestCase("Parent.qml"));
QVERIFY(view);
view->setTheme("CustomTheme");
view->setStyle("TestStyle.qml");
QQmlComponent *style = view->rootObject()->property("style").value<QQmlComponent*>();
QCOMPARE(style != NULL, true);
}
void tst_UCDeprecatedTheme::testThemesRelativePathWithParentXDGDATA()
{
qputenv("LOMIRI_UI_TOOLKIT_THEMES_PATH", "");
qputenv("XDG_DATA_DIRS", "./themes:./themes/TestModule");
QScopedPointer<ThemeTestCase> view(new ThemeTestCase("Parent.qml"));
QVERIFY(view);
view->setTheme("CustomTheme");
view->setStyle("TestStyle.qml");
QQmlComponent *style = view->rootObject()->property("style").value<QQmlComponent*>();
QCOMPARE(style != NULL, true);
}
void tst_UCDeprecatedTheme::testThemesRelativePathWithParentNoVariablesSet()
{
ThemeTestCase::ignoreWarning("Parent.qml", 20, 1, "QML Parent: Warning: Style TestStyle.qml not found in theme Lomiri.Components.Themes.Ambiance");
qputenv("LOMIRI_UI_TOOLKIT_THEMES_PATH", "");
qputenv("XDG_DATA_DIRS", "");
QScopedPointer<ThemeTestCase> view(new ThemeTestCase("Parent.qml"));
QVERIFY(view);
view->setStyle("TestStyle.qml");
}
void tst_UCDeprecatedTheme::testThemesRelativePathWithParentOneXDGPathSet()
{
qputenv("LOMIRI_UI_TOOLKIT_THEMES_PATH", "");
qputenv("XDG_DATA_DIRS", "../tst_theme_engine");
QScopedPointer<ThemeTestCase> view(new ThemeTestCase("Parent.qml"));
QVERIFY(view);
view->setTheme("TestModule.TestTheme");
view->setStyle("TestStyle.qml");
QQmlComponent *style = view->rootObject()->property("style").value<QQmlComponent*>();
QCOMPARE(style != NULL, true);
}
void tst_UCDeprecatedTheme::testNoImportPathSet()
{
if (!QFile(QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath) + "/Lomiri/Components").exists())
QSKIP("This can only be tested if the UITK is installed");
qputenv("LOMIRI_UI_TOOLKIT_THEMES_PATH", "");
qputenv("XDG_DATA_DIRS", "");
qputenv("QML2_IMPORT_PATH", "");
QQmlEngine engine;
initDeprecatedTheme(engine);
QCOMPARE(instance(engine)->name(), QString("Lomiri.Components.Themes.Ambiance"));
}
void tst_UCDeprecatedTheme::testBogusImportPathSet()
{
if (!QFile(QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath) + "/Lomiri/Components").exists())
QSKIP("This can only be tested if the UITK is installed");
qputenv("LOMIRI_UI_TOOLKIT_THEMES_PATH", "");
qputenv("XDG_DATA_DIRS", "");
qputenv("QML2_IMPORT_PATH", "/no/plugins/here");
QQmlEngine engine;
initDeprecatedTheme(engine);
QCOMPARE(instance(engine)->name(), QString("Lomiri.Components.Themes.Ambiance"));
}
void tst_UCDeprecatedTheme::testMultipleImportPathsSet()
{
if (!QFile(QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath) + "/Lomiri/Components").exists())
QSKIP("This can only be tested if the UITK is installed");
qputenv("LOMIRI_UI_TOOLKIT_THEMES_PATH", "");
qputenv("XDG_DATA_DIRS", "");
qputenv("QML2_IMPORT_PATH", "/no/plugins/here:.");
QScopedPointer<ThemeTestCase> view(new ThemeTestCase("Parent.qml"));
QVERIFY(view);
view->setTheme("TestModule.TestTheme");
}
void tst_UCDeprecatedTheme::testPaletteUsed_bug1549830()
{
ThemeTestCase::ignoreWarning("ErroneousPaletteUse.qml", 29, 13, "Unable to assign [undefined] to QColor", 3);
QScopedPointer<ThemeTestCase> view(new ThemeTestCase("ErroneousPaletteUse.qml"));
}
QTEST_MAIN(tst_UCDeprecatedTheme)
#include "tst_deprecated_theme_engine.moc"
|