1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the test suite of the Qt Toolkit.
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
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #include <QtDeclarative/qdeclarativecomponent.h>
43 #include <QtDeclarative/qdeclarativeengine.h>
44 #include <QtDeclarative/qdeclarativeitem.h>
45 #include <QtDeclarative/qdeclarativecontext.h>
46 #include <QtCore/QDir>
47 #include <QtScript/QScriptEngineAgent>
48 #include <private/qdeclarativeengine_p.h>
50 class MyTestObject : public QObject {
52 Q_PROPERTY(QString someProperty READ someProperty WRITE setSomeProperty NOTIFY somePropertyChanged)
55 QString someProperty() { return _someProperty; }
56 void setSomeProperty(const QString &p) { _someProperty = p; }
57 QString _someProperty;
59 void emitSignal(const QString &value) { emit signaled(value); }
62 void signaled(const QString &value);
63 void somePropertyChanged();
67 class BtAgent : public QScriptEngineAgent {
69 BtAgent(QScriptEngine *engine) : QScriptEngineAgent(engine)
70 { count = 0; engine->setAgent(this); }
75 void positionChange(qint64 , int lineNumber, int )
77 if(lineNumber == breakpoint) {
79 bt = engine()->currentContext()->backtrace();
87 This test covers evaluation of ECMAScript expressions and bindings from within
88 QML. This does not include static QML language issues.
90 Static QML language issues are covered in qmllanguage
92 inline QUrl TEST_FILE(const QString &filename)
94 QFileInfo fileInfo(__FILE__);
95 return QUrl::fromLocalFile(fileInfo.absoluteDir().filePath("data/" + filename));
98 inline QUrl TEST_FILE(const char *filename)
100 return TEST_FILE(QLatin1String(filename));
103 class tst_qdeclarativescriptdebugging : public QObject
107 tst_qdeclarativescriptdebugging() {}
114 void tst_qdeclarativescriptdebugging::initTestCase()
116 qmlRegisterType<MyTestObject>("Qt.test", 1,0, "MyTestObject");
119 void tst_qdeclarativescriptdebugging::backtrace1()
122 QDeclarativeEngine engine;
123 QUrl file = TEST_FILE("backtrace1.qml");
124 QDeclarativeComponent component(&engine, file);
125 QDeclarativeItem *item = qobject_cast<QDeclarativeItem *>(component.create());
127 MyTestObject *obj = item->findChild<MyTestObject *>();
129 QCOMPARE(obj->someProperty(), QString("Hello Default"));
131 QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(&engine);
132 BtAgent agent(&ep->scriptEngine);
133 agent.breakpoint = 16;
135 obj->emitSignal("blah");
136 QCOMPARE(obj->someProperty(), QString("Hello blahb"));
137 QCOMPARE(agent.count, 1);
139 QStringList expected;
140 expected << "append(a = 'Hello', b = 'blahb') at @PREFIX@/backtrace1.qml:16"
141 << "$someProperty() at @PREFIX@/backtrace1.qml:21"
142 << "function2InScript(a = 'blahb') at @PREFIX@/backtrace1.js:4"
143 << "functionInScript(a = 'blah', b = 'b') at @PREFIX@/backtrace1.js:10"
144 << "onSignaled() at @PREFIX@/backtrace1.qml:24"
145 << "<global>() at -1";
146 expected.replaceInStrings("@PREFIX@", file.toString().section('/', 0, -2));
147 QCOMPARE(agent.bt, expected);
152 QTEST_MAIN(tst_qdeclarativescriptdebugging)
154 #include "tst_qdeclarativescriptdebugging.moc"