|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 #include <qtest.h> |
|
42 #include <qdir.h> |
|
43 #include <QtDeclarative/qdeclarativeengine.h> |
|
44 #include <QtDeclarative/qdeclarativecomponent.h> |
|
45 #include <QDebug> |
|
46 |
|
47 class tst_qdeclarativemoduleplugin : public QObject |
|
48 { |
|
49 Q_OBJECT |
|
50 public: |
|
51 tst_qdeclarativemoduleplugin() |
|
52 { |
|
53 } |
|
54 |
|
55 private slots: |
|
56 void importsPlugin(); |
|
57 }; |
|
58 |
|
59 #define VERIFY_ERRORS(errorfile) \ |
|
60 if (!errorfile) { \ |
|
61 if (qgetenv("DEBUG") != "" && !component.errors().isEmpty()) \ |
|
62 qWarning() << "Unexpected Errors:" << component.errors(); \ |
|
63 QVERIFY(!component.isError()); \ |
|
64 QVERIFY(component.errors().isEmpty()); \ |
|
65 } else { \ |
|
66 QFile file(QLatin1String("data/") + QLatin1String(errorfile)); \ |
|
67 QVERIFY(file.open(QIODevice::ReadOnly)); \ |
|
68 QByteArray data = file.readAll(); \ |
|
69 file.close(); \ |
|
70 QList<QByteArray> expected = data.split('\n'); \ |
|
71 expected.removeAll(QByteArray("")); \ |
|
72 QList<QDeclarativeError> errors = component.errors(); \ |
|
73 QList<QByteArray> actual; \ |
|
74 for (int ii = 0; ii < errors.count(); ++ii) { \ |
|
75 const QDeclarativeError &error = errors.at(ii); \ |
|
76 QByteArray errorStr = QByteArray::number(error.line()) + ":" + \ |
|
77 QByteArray::number(error.column()) + ":" + \ |
|
78 error.description().toUtf8(); \ |
|
79 actual << errorStr; \ |
|
80 } \ |
|
81 if (qgetenv("DEBUG") != "" && expected != actual) \ |
|
82 qWarning() << "Expected:" << expected << "Actual:" << actual; \ |
|
83 if (qgetenv("QDECLARATIVELANGUAGE_UPDATEERRORS") != "" && expected != actual) {\ |
|
84 QFile file(QLatin1String("data/") + QLatin1String(errorfile)); \ |
|
85 QVERIFY(file.open(QIODevice::WriteOnly)); \ |
|
86 for (int ii = 0; ii < actual.count(); ++ii) { \ |
|
87 file.write(actual.at(ii)); file.write("\n"); \ |
|
88 } \ |
|
89 file.close(); \ |
|
90 } else { \ |
|
91 QCOMPARE(expected, actual); \ |
|
92 } \ |
|
93 } |
|
94 |
|
95 inline QUrl TEST_FILE(const QString &filename) |
|
96 { |
|
97 QFileInfo fileInfo(__FILE__); |
|
98 return QUrl::fromLocalFile(fileInfo.absoluteDir().filePath(filename)); |
|
99 } |
|
100 |
|
101 |
|
102 void tst_qdeclarativemoduleplugin::importsPlugin() |
|
103 { |
|
104 QDeclarativeEngine engine; |
|
105 engine.addImportPath(QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("imports")); |
|
106 QTest::ignoreMessage(QtWarningMsg, "plugin created"); |
|
107 QTest::ignoreMessage(QtWarningMsg, "import worked"); |
|
108 QDeclarativeComponent component(&engine, TEST_FILE("data/works.qml")); |
|
109 foreach (QDeclarativeError err, component.errors()) |
|
110 qWarning() << err; |
|
111 VERIFY_ERRORS(0); |
|
112 QObject *object = component.create(); |
|
113 QVERIFY(object != 0); |
|
114 QCOMPARE(object->property("value").toInt(),123); |
|
115 } |
|
116 |
|
117 QTEST_MAIN(tst_qdeclarativemoduleplugin) |
|
118 |
|
119 #include "tst_qdeclarativemoduleplugin.moc" |