aboutsummaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/declarative/script/tst_script.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/benchmarks/declarative/script/tst_script.cpp')
-rw-r--r--tests/benchmarks/declarative/script/tst_script.cpp107
1 files changed, 106 insertions, 1 deletions
diff --git a/tests/benchmarks/declarative/script/tst_script.cpp b/tests/benchmarks/declarative/script/tst_script.cpp
index 4f4da8bd45..4321b09b75 100644
--- a/tests/benchmarks/declarative/script/tst_script.cpp
+++ b/tests/benchmarks/declarative/script/tst_script.cpp
@@ -70,6 +70,9 @@ private slots:
void property_qobject();
void property_qmlobject();
+ void setproperty_js();
+ void setproperty_qmlobject();
+
void function_js();
void function_cpp();
void function_qobject();
@@ -98,6 +101,10 @@ private slots:
void global_property_qml_js();
void scriptfile_property();
+
+ void enums();
+ void namespacedEnums();
+ void scriptCall();
};
inline QUrl TEST_FILE(const QString &filename)
@@ -108,12 +115,13 @@ inline QUrl TEST_FILE(const QString &filename)
class TestObject : public QObject
{
Q_OBJECT
- Q_PROPERTY(int x READ x)
+ Q_PROPERTY(int x READ x WRITE setX)
public:
TestObject(QObject *parent = 0);
int x();
+ void setX(int x) { m_x = x; }
void emitMySignal() { emit mySignal(); }
void emitMySignalWithArgs(int n) { emit mySignalWithArgs(n); }
@@ -323,6 +331,49 @@ void tst_script::property_qmlobject()
}
}
+#define SETPROPERTY_PROGRAM \
+ "(function(testObject) { return (function() { " \
+ " for (var ii = 0; ii < 10000; ++ii) { " \
+ " testObject.x = ii; " \
+ " } " \
+ "}); })"
+
+void tst_script::setproperty_js()
+{
+ QScriptEngine engine;
+
+ QScriptValue v = engine.newObject();
+ v.setProperty(QLatin1String("x"), 0);
+
+ QScriptValueList args;
+ args << v;
+ QScriptValue prog = engine.evaluate(SETPROPERTY_PROGRAM).call(engine.globalObject(), args);
+ prog.call();
+
+ QBENCHMARK {
+ prog.call();
+ }
+}
+
+void tst_script::setproperty_qmlobject()
+{
+ QDeclarativeEngine qmlengine;
+
+ QScriptEngine *engine = QDeclarativeEnginePrivate::getScriptEngine(&qmlengine);
+ TestObject to;
+
+ QScriptValue v = QDeclarativeEnginePrivate::get(&qmlengine)->objectClass->newQObject(&to);
+
+ QScriptValueList args;
+ args << v;
+ QScriptValue prog = engine->evaluate(SETPROPERTY_PROGRAM).call(engine->globalObject(), args);
+ prog.call();
+
+ QBENCHMARK {
+ prog.call();
+ }
+}
+
#define FUNCTION_PROGRAM \
"(function(testObject) { return (function() { " \
" var test = 0; " \
@@ -698,6 +749,60 @@ void tst_script::scriptfile_property()
delete rect;
}
+void tst_script::enums()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, TEST_FILE("enums.qml"));
+ QObject *o = component.create();
+ QVERIFY(o != 0);
+
+ int index = o->metaObject()->indexOfMethod("runtest()");
+ QVERIFY(index != -1);
+ QMetaMethod method = o->metaObject()->method(index);
+
+ QBENCHMARK {
+ method.invoke(o, Qt::DirectConnection);
+ }
+
+ delete o;
+}
+
+void tst_script::namespacedEnums()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, TEST_FILE("namespacedEnums.qml"));
+ QObject *o = component.create();
+ QVERIFY(o != 0);
+
+ int index = o->metaObject()->indexOfMethod("runtest()");
+ QVERIFY(index != -1);
+ QMetaMethod method = o->metaObject()->method(index);
+
+ QBENCHMARK {
+ method.invoke(o, Qt::DirectConnection);
+ }
+
+ delete o;
+}
+
+void tst_script::scriptCall()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, TEST_FILE("scriptCall.qml"));
+ QObject *o = component.create();
+ QVERIFY(o != 0);
+
+ int index = o->metaObject()->indexOfMethod("runtest()");
+ QVERIFY(index != -1);
+ QMetaMethod method = o->metaObject()->method(index);
+
+ QBENCHMARK {
+ method.invoke(o, Qt::DirectConnection);
+ }
+
+ delete o;
+}
+
QTEST_MAIN(tst_script)
#include "tst_script.moc"