From b855240b782395f94315f43ea3e7e182299fac48 Mon Sep 17 00:00:00 2001 From: Matthew Vogt Date: Thu, 16 Feb 2012 14:43:03 +1000 Subject: Rename QDeclarative symbols to QQuick and QQml Symbols beginning with QDeclarative are already exported by the quick1 module. Users can apply the bin/rename-qtdeclarative-symbols.sh script to modify client code using the previous names of the renamed symbols. Task-number: QTBUG-23737 Change-Id: Ifaa482663767634931e8711a8e9bf6e404859e66 Reviewed-by: Martin Jones --- tests/benchmarks/qml/script/data/CustomObject.qml | 48 ++ tests/benchmarks/qml/script/data/block.qml | 75 ++ tests/benchmarks/qml/script/data/enums.qml | 51 ++ tests/benchmarks/qml/script/data/global.js | 54 ++ tests/benchmarks/qml/script/data/global_prop.qml | 53 ++ .../benchmarks/qml/script/data/namespacedEnums.qml | 52 ++ tests/benchmarks/qml/script/data/script.js | 1 + tests/benchmarks/qml/script/data/script2.js | 2 + tests/benchmarks/qml/script/data/scriptCall.qml | 54 ++ tests/benchmarks/qml/script/data/signal_args.qml | 47 ++ tests/benchmarks/qml/script/data/signal_qml.qml | 47 ++ .../qml/script/data/signal_unconnected.qml | 45 ++ .../qml/script/data/signal_unusedArgs.qml | 47 ++ tests/benchmarks/qml/script/data/slot_complex.qml | 57 ++ .../benchmarks/qml/script/data/slot_complex_js.js | 8 + .../benchmarks/qml/script/data/slot_complex_js.qml | 49 ++ tests/benchmarks/qml/script/data/slot_simple.qml | 50 ++ tests/benchmarks/qml/script/data/slot_simple_js.js | 3 + .../benchmarks/qml/script/data/slot_simple_js.qml | 48 ++ tests/benchmarks/qml/script/script.pro | 10 + tests/benchmarks/qml/script/tst_script.cpp | 803 +++++++++++++++++++++ 21 files changed, 1604 insertions(+) create mode 100644 tests/benchmarks/qml/script/data/CustomObject.qml create mode 100644 tests/benchmarks/qml/script/data/block.qml create mode 100644 tests/benchmarks/qml/script/data/enums.qml create mode 100644 tests/benchmarks/qml/script/data/global.js create mode 100644 tests/benchmarks/qml/script/data/global_prop.qml create mode 100644 tests/benchmarks/qml/script/data/namespacedEnums.qml create mode 100644 tests/benchmarks/qml/script/data/script.js create mode 100644 tests/benchmarks/qml/script/data/script2.js create mode 100644 tests/benchmarks/qml/script/data/scriptCall.qml create mode 100644 tests/benchmarks/qml/script/data/signal_args.qml create mode 100644 tests/benchmarks/qml/script/data/signal_qml.qml create mode 100644 tests/benchmarks/qml/script/data/signal_unconnected.qml create mode 100644 tests/benchmarks/qml/script/data/signal_unusedArgs.qml create mode 100644 tests/benchmarks/qml/script/data/slot_complex.qml create mode 100644 tests/benchmarks/qml/script/data/slot_complex_js.js create mode 100644 tests/benchmarks/qml/script/data/slot_complex_js.qml create mode 100644 tests/benchmarks/qml/script/data/slot_simple.qml create mode 100644 tests/benchmarks/qml/script/data/slot_simple_js.js create mode 100644 tests/benchmarks/qml/script/data/slot_simple_js.qml create mode 100644 tests/benchmarks/qml/script/script.pro create mode 100644 tests/benchmarks/qml/script/tst_script.cpp (limited to 'tests/benchmarks/qml/script') diff --git a/tests/benchmarks/qml/script/data/CustomObject.qml b/tests/benchmarks/qml/script/data/CustomObject.qml new file mode 100644 index 0000000000..485f8a1354 --- /dev/null +++ b/tests/benchmarks/qml/script/data/CustomObject.qml @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +QtObject { + property real prop1: 0 + property real prop2: 1 + property real prop3: 0 +} diff --git a/tests/benchmarks/qml/script/data/block.qml b/tests/benchmarks/qml/script/data/block.qml new file mode 100644 index 0000000000..3816b9f64b --- /dev/null +++ b/tests/benchmarks/qml/script/data/block.qml @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + width: 200; height: 200 + CustomObject { id: theObject } + function doSomethingDirect() { + theObject.prop1 = 0; + + for (var i = 0; i < 1000; ++i) + theObject.prop1 += theObject.prop2; + + theObject.prop3 = theObject.prop1; + } + + function doSomethingLocalObj() { + theObject.prop1 = 0; + + var incrementObj = theObject; + for (var i = 0; i < 1000; ++i) + incrementObj.prop1 += incrementObj.prop2; + + incrementObj.prop3 = incrementObj.prop1; + } + + function doSomethingLocal() { + theObject.prop1 = 0; + + var increment = theObject.prop2; + for (var i = 0; i < 1000; ++i) + theObject.prop1 += increment; + + theObject.prop3 = theObject.prop1; + } +} diff --git a/tests/benchmarks/qml/script/data/enums.qml b/tests/benchmarks/qml/script/data/enums.qml new file mode 100644 index 0000000000..8450b15732 --- /dev/null +++ b/tests/benchmarks/qml/script/data/enums.qml @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the Declarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Item { + function runtest() { + var a = 0; + for (var ii = 0; ii < 100000; ++ii) + a += Text.RichText; + return a; + } +} diff --git a/tests/benchmarks/qml/script/data/global.js b/tests/benchmarks/qml/script/data/global.js new file mode 100644 index 0000000000..4e3a4780f9 --- /dev/null +++ b/tests/benchmarks/qml/script/data/global.js @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +var incVar = 1; +var total; + +function doSomething() { + for (var i = 0; i < 10000; ++i) + Math.sin(90); +} + +function doIncrement() { + total = 0; + for (var i = 0; i < 100000; ++i) + total += incVar; +} diff --git a/tests/benchmarks/qml/script/data/global_prop.qml b/tests/benchmarks/qml/script/data/global_prop.qml new file mode 100644 index 0000000000..c77faaf9f4 --- /dev/null +++ b/tests/benchmarks/qml/script/data/global_prop.qml @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import "global.js" as Program + +Rectangle { + width: 200; height: 200 + + signal triggered + signal incrementTriggered + + onTriggered: Program.doSomething(); + onIncrementTriggered: Program.doIncrement(); +} diff --git a/tests/benchmarks/qml/script/data/namespacedEnums.qml b/tests/benchmarks/qml/script/data/namespacedEnums.qml new file mode 100644 index 0000000000..e49bf7e1ad --- /dev/null +++ b/tests/benchmarks/qml/script/data/namespacedEnums.qml @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the Declarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 as QtQuick + +QtQuick.Item { + function runtest() { + var a = 0; + for (var ii = 0; ii < 100000; ++ii) + a += QtQuick.Text.RichText; + return a; + } +} + diff --git a/tests/benchmarks/qml/script/data/script.js b/tests/benchmarks/qml/script/data/script.js new file mode 100644 index 0000000000..9f46570004 --- /dev/null +++ b/tests/benchmarks/qml/script/data/script.js @@ -0,0 +1 @@ +function func() { return 1; } diff --git a/tests/benchmarks/qml/script/data/script2.js b/tests/benchmarks/qml/script/data/script2.js new file mode 100644 index 0000000000..102f081140 --- /dev/null +++ b/tests/benchmarks/qml/script/data/script2.js @@ -0,0 +1,2 @@ +function func() { return 2; } + diff --git a/tests/benchmarks/qml/script/data/scriptCall.qml b/tests/benchmarks/qml/script/data/scriptCall.qml new file mode 100644 index 0000000000..420f621dfc --- /dev/null +++ b/tests/benchmarks/qml/script/data/scriptCall.qml @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the Declarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import "script.js" as Script +import "script2.js" as OtherScript + +Item { + function runtest() { + var a = 0; + for (var ii = 0; ii < 1000000; ++ii) + a += Script.func(); + return a; + } +} + diff --git a/tests/benchmarks/qml/script/data/signal_args.qml b/tests/benchmarks/qml/script/data/signal_args.qml new file mode 100644 index 0000000000..757ac1a1f9 --- /dev/null +++ b/tests/benchmarks/qml/script/data/signal_args.qml @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt.test 1.0 + +TestObject { + onMySignalWithArgs: { var a = n; return a; } +} + diff --git a/tests/benchmarks/qml/script/data/signal_qml.qml b/tests/benchmarks/qml/script/data/signal_qml.qml new file mode 100644 index 0000000000..c7314a6b1e --- /dev/null +++ b/tests/benchmarks/qml/script/data/signal_qml.qml @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt.test 1.0 + +TestObject { + onMySignal: { var a = 1; return a; } +} + diff --git a/tests/benchmarks/qml/script/data/signal_unconnected.qml b/tests/benchmarks/qml/script/data/signal_unconnected.qml new file mode 100644 index 0000000000..a33942dd2d --- /dev/null +++ b/tests/benchmarks/qml/script/data/signal_unconnected.qml @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt.test 1.0 + +TestObject { +} diff --git a/tests/benchmarks/qml/script/data/signal_unusedArgs.qml b/tests/benchmarks/qml/script/data/signal_unusedArgs.qml new file mode 100644 index 0000000000..52b4e1a54f --- /dev/null +++ b/tests/benchmarks/qml/script/data/signal_unusedArgs.qml @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt.test 1.0 + +TestObject { + onMySignalWithArgs: { var a = 1; return a; } +} + diff --git a/tests/benchmarks/qml/script/data/slot_complex.qml b/tests/benchmarks/qml/script/data/slot_complex.qml new file mode 100644 index 0000000000..4763146c65 --- /dev/null +++ b/tests/benchmarks/qml/script/data/slot_complex.qml @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt.test 1.0 + +TestObject { + function myCustomFunction(b) { + var n = b; + var a = 1; + while (n > 0) { + a = a * n; + n--; + } + return a; + } + + onMySignal: { for (var ii = 0; ii < 10000; ++ii) { myCustomFunction(10); } } +} + diff --git a/tests/benchmarks/qml/script/data/slot_complex_js.js b/tests/benchmarks/qml/script/data/slot_complex_js.js new file mode 100644 index 0000000000..64a1f65daa --- /dev/null +++ b/tests/benchmarks/qml/script/data/slot_complex_js.js @@ -0,0 +1,8 @@ +function myCustomFunction(n) { + var a = 1; + while (n > 0) { + a = a * n; + n--; + } + return a; +} diff --git a/tests/benchmarks/qml/script/data/slot_complex_js.qml b/tests/benchmarks/qml/script/data/slot_complex_js.qml new file mode 100644 index 0000000000..e44fc73f8e --- /dev/null +++ b/tests/benchmarks/qml/script/data/slot_complex_js.qml @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt.test 1.0 +import "slot_complex_js.js" as Logic + +TestObject { + onMySignal: { for (var ii = 0; ii < 10000; ++ii) { Logic.myCustomFunction(10); } } +} + + diff --git a/tests/benchmarks/qml/script/data/slot_simple.qml b/tests/benchmarks/qml/script/data/slot_simple.qml new file mode 100644 index 0000000000..b788970d12 --- /dev/null +++ b/tests/benchmarks/qml/script/data/slot_simple.qml @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt.test 1.0 + +TestObject { + function myCustomFunction() { + return 0; + } + + onMySignal: { for (var ii = 0; ii < 10000; ++ii) { myCustomFunction(); } } +} diff --git a/tests/benchmarks/qml/script/data/slot_simple_js.js b/tests/benchmarks/qml/script/data/slot_simple_js.js new file mode 100644 index 0000000000..d6e60608da --- /dev/null +++ b/tests/benchmarks/qml/script/data/slot_simple_js.js @@ -0,0 +1,3 @@ +function myCustomFunction() { + return 0; +} diff --git a/tests/benchmarks/qml/script/data/slot_simple_js.qml b/tests/benchmarks/qml/script/data/slot_simple_js.qml new file mode 100644 index 0000000000..5af1b0868f --- /dev/null +++ b/tests/benchmarks/qml/script/data/slot_simple_js.qml @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt.test 1.0 +import "slot_simple_js.js" as Logic + +TestObject { + onMySignal: { for (var ii = 0; ii < 10000; ++ii) { Logic.myCustomFunction(); } } +} + diff --git a/tests/benchmarks/qml/script/script.pro b/tests/benchmarks/qml/script/script.pro new file mode 100644 index 0000000000..88e8d9b33d --- /dev/null +++ b/tests/benchmarks/qml/script/script.pro @@ -0,0 +1,10 @@ +CONFIG += testcase +TEMPLATE = app +TARGET = tst_script +QT += qml qml-private testlib v8-private core-private +macx:CONFIG -= app_bundle +CONFIG += release + +SOURCES += tst_script.cpp + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/benchmarks/qml/script/tst_script.cpp b/tests/benchmarks/qml/script/tst_script.cpp new file mode 100644 index 0000000000..204fb945eb --- /dev/null +++ b/tests/benchmarks/qml/script/tst_script.cpp @@ -0,0 +1,803 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +class tst_script : public QObject +{ + Q_OBJECT +public: + tst_script() {} + +private slots: + void initTestCase(); + + void property_js(); + void property_getter(); + void property_getter_js(); + void property_getter_qobject(); + void property_getter_qmetaproperty(); + void property_qobject(); + void property_qmlobject(); + + void setproperty_js(); + void setproperty_qmlobject(); + + void function_js(); + void function_cpp(); + void function_qobject(); + void function_qmlobject(); + + void function_args_js(); + void function_args_cpp(); + void function_args_qobject(); + void function_args_qmlobject(); + + void signal_unconnected(); + void signal_qml(); + void signal_args(); + void signal_unusedArgs(); + + void slot_simple(); + void slot_simple_js(); + void slot_complex(); + void slot_complex_js(); + + void block_data(); + void block(); + + void global_property_js(); + void global_property_qml(); + void global_property_qml_js(); + + void scriptfile_property(); + + void enums(); + void namespacedEnums(); + void scriptCall(); +}; + +inline QUrl TEST_FILE(const QString &filename) +{ + return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename); +} + +class TestObject : public QObject +{ + Q_OBJECT + 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); } + +signals: + void mySignal(); + void mySignalWithArgs(int n); + +public slots: + int method() { + return x(); + } + + int methodArgs(int val) { + return val + x(); + } + +private: + int m_x; +}; +QML_DECLARE_TYPE(TestObject); + +TestObject::TestObject(QObject *parent) +: QObject(parent), m_x(0) +{ +} + +int TestObject::x() +{ + return m_x++; +} + +void tst_script::initTestCase() +{ + qmlRegisterType("Qt.test", 1, 0, "TestObject"); +} + + +#define PROPERTY_PROGRAM \ + "(function(testObject) { return (function() { " \ + " var test = 0; " \ + " for (var ii = 0; ii < 10000; ++ii) { " \ + " test += testObject.x; " \ + " } " \ + " return test; " \ + "}); })" + +void tst_script::property_js() +{ + QScriptEngine engine; + + QScriptValue v = engine.newObject(); + v.setProperty(QLatin1String("x"), 10); + + QScriptValueList args; + args << v; + QScriptValue prog = engine.evaluate(PROPERTY_PROGRAM).call(engine.globalObject(), args); + prog.call(); + + QBENCHMARK { + prog.call().toNumber(); + } +} + +static QScriptValue property_getter_method(QScriptContext *, QScriptEngine *engine) +{ + static int x = 0; + return QScriptValue(engine,x++); +} + +void tst_script::property_getter() +{ + QScriptEngine engine; + + QScriptValue v = engine.newObject(); + v.setProperty(QLatin1String("x"), engine.newFunction(property_getter_method), + QScriptValue::PropertyGetter); + + QScriptValueList args; + args << v; + QScriptValue prog = engine.evaluate(PROPERTY_PROGRAM).call(engine.globalObject(), args); + prog.call(); + + QBENCHMARK { + prog.call(); + } +} + +static TestObject *property_getter_qobject_object = 0; +static QScriptValue property_getter_qobject_method(QScriptContext *, QScriptEngine *) +{ + static int idx = -1; + if (idx == -1) + idx = TestObject::staticMetaObject.indexOfProperty("x"); + + int value = 0; + void *args[] = { &value, 0 }; + QMetaObject::metacall(property_getter_qobject_object, QMetaObject::ReadProperty, idx, args); + + return QScriptValue(value); +} + +static QScriptValue property_getter_qmetaproperty_method(QScriptContext *, QScriptEngine *) +{ + static int idx = -1; + if (idx == -1) + idx = TestObject::staticMetaObject.indexOfProperty("x"); + + int value = 0; + value = property_getter_qobject_object->metaObject()->property(idx).read(property_getter_qobject_object).toInt(); + + return QScriptValue(value); +} + +void tst_script::property_getter_qobject() +{ + QScriptEngine engine; + + TestObject to; + property_getter_qobject_object = &to; + QScriptValue v = engine.newObject(); + v.setProperty(QLatin1String("x"), engine.newFunction(property_getter_qobject_method), + QScriptValue::PropertyGetter); + + QScriptValueList args; + args << v; + QScriptValue prog = engine.evaluate(PROPERTY_PROGRAM).call(engine.globalObject(), args); + prog.call(); + + QBENCHMARK { + prog.call(); + } + property_getter_qobject_object = 0; +} + +void tst_script::property_getter_qmetaproperty() +{ + QScriptEngine engine; + + TestObject to; + property_getter_qobject_object = &to; + QScriptValue v = engine.newObject(); + v.setProperty(QLatin1String("x"), engine.newFunction(property_getter_qmetaproperty_method), + QScriptValue::PropertyGetter); + + QScriptValueList args; + args << v; + QScriptValue prog = engine.evaluate(PROPERTY_PROGRAM).call(engine.globalObject(), args); + prog.call(); + + QBENCHMARK { + prog.call(); + } + property_getter_qobject_object = 0; +} + + +void tst_script::property_getter_js() +{ + QScriptEngine engine; + + QScriptValue v = engine.evaluate("(function() { var o = new Object; o._x = 0; o.__defineGetter__(\"x\", function() { return this._x++; }); return o; })").call(); + + QScriptValueList args; + args << v; + QScriptValue prog = engine.evaluate(PROPERTY_PROGRAM).call(engine.globalObject(), args); + prog.call(); + + QBENCHMARK { + prog.call(); + } +} + +void tst_script::property_qobject() +{ + QScriptEngine engine; + + TestObject to; + QScriptValue v = engine.newQObject(&to); + + QScriptValueList args; + args << v; + QScriptValue prog = engine.evaluate(PROPERTY_PROGRAM).call(engine.globalObject(), args); + prog.call(); + + QBENCHMARK { + prog.call(); + } +} + +void tst_script::property_qmlobject() +{ + QQmlEngine qmlengine; + + QScriptEngine *engine = QQmlEnginePrivate::getScriptEngine(&qmlengine); + TestObject to; + + QScriptValue v = QQmlEnginePrivate::get(&qmlengine)->objectClass->newQObject(&to); + + QScriptValueList args; + args << v; + QScriptValue prog = engine->evaluate(PROPERTY_PROGRAM).call(engine->globalObject(), args); + prog.call(); + + QBENCHMARK { + prog.call(); + } +} + +#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() +{ + QQmlEngine qmlengine; + + QScriptEngine *engine = QQmlEnginePrivate::getScriptEngine(&qmlengine); + TestObject to; + + QScriptValue v = QQmlEnginePrivate::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; " \ + " for (var ii = 0; ii < 10000; ++ii) { " \ + " test += testObject.method(); " \ + " } " \ + " return test; " \ + "}); })" + +void tst_script::function_js() +{ + QScriptEngine engine; + + QScriptValue v = engine.evaluate("(function() { var o = new Object; o._x = 0; o.method = (function() { return this._x++; }); return o; })").call(); + + QScriptValueList args; + args << v; + QScriptValue prog = engine.evaluate(FUNCTION_PROGRAM).call(engine.globalObject(), args); + prog.call(); + + QBENCHMARK { + prog.call(); + } +} + +static QScriptValue function_method(QScriptContext *, QScriptEngine *) +{ + static int x = 0; + return QScriptValue(x++); +} + +void tst_script::function_cpp() +{ + QScriptEngine engine; + + QScriptValue v = engine.newObject(); + v.setProperty(QLatin1String("method"), engine.newFunction(function_method)); + + QScriptValueList args; + args << v; + QScriptValue prog = engine.evaluate(FUNCTION_PROGRAM).call(engine.globalObject(), args); + prog.call(); + + QBENCHMARK { + prog.call(); + } +} + +void tst_script::function_qobject() +{ + QScriptEngine engine; + + TestObject to; + QScriptValue v = engine.newQObject(&to); + + QScriptValueList args; + args << v; + QScriptValue prog = engine.evaluate(FUNCTION_PROGRAM).call(engine.globalObject(), args); + prog.call(); + + QBENCHMARK { + prog.call(); + } +} + +void tst_script::function_qmlobject() +{ + QQmlEngine qmlengine; + + QScriptEngine *engine = QQmlEnginePrivate::getScriptEngine(&qmlengine); + TestObject to; + + QScriptValue v = QQmlEnginePrivate::get(&qmlengine)->objectClass->newQObject(&to); + + QScriptValueList args; + args << v; + QScriptValue prog = engine->evaluate(FUNCTION_PROGRAM).call(engine->globalObject(), args); + prog.call(); + + QBENCHMARK { + prog.call(); + } +} + +#define FUNCTION_ARGS_PROGRAM \ + "(function(testObject) { return (function() { " \ + " var test = 0; " \ + " for (var ii = 0; ii < 10000; ++ii) { " \ + " test += testObject.methodArgs(ii); " \ + " } " \ + " return test; " \ + "}); })" + +void tst_script::function_args_js() +{ + QScriptEngine engine; + + QScriptValue v = engine.evaluate("(function() { var o = new Object; o._x = 0; o.methodArgs = (function(a) { return a + this._x++; }); return o; })").call(); + + QScriptValueList args; + args << v; + QScriptValue prog = engine.evaluate(FUNCTION_ARGS_PROGRAM).call(engine.globalObject(), args); + prog.call(); + + QBENCHMARK { + prog.call(); + } +} + +static QScriptValue function_args_method(QScriptContext *ctxt, QScriptEngine *) +{ + static int x = 0; + return QScriptValue(ctxt->argument(0).toNumber() + x++); +} + +void tst_script::function_args_cpp() +{ + QScriptEngine engine; + + QScriptValue v = engine.newObject(); + v.setProperty(QLatin1String("methodArgs"), engine.newFunction(function_args_method)); + + QScriptValueList args; + args << v; + QScriptValue prog = engine.evaluate(FUNCTION_ARGS_PROGRAM).call(engine.globalObject(), args); + prog.call(); + + QBENCHMARK { + prog.call(); + } +} + +void tst_script::function_args_qobject() +{ + QScriptEngine engine; + + TestObject to; + QScriptValue v = engine.newQObject(&to); + + QScriptValueList args; + args << v; + QScriptValue prog = engine.evaluate(FUNCTION_ARGS_PROGRAM).call(engine.globalObject(), args); + prog.call(); + + QBENCHMARK { + prog.call(); + } +} + +void tst_script::function_args_qmlobject() +{ + QQmlEngine qmlengine; + + QScriptEngine *engine = QQmlEnginePrivate::getScriptEngine(&qmlengine); + TestObject to; + + QScriptValue v = QQmlEnginePrivate::get(&qmlengine)->objectClass->newQObject(&to); + + QScriptValueList args; + args << v; + QScriptValue prog = engine->evaluate(FUNCTION_ARGS_PROGRAM).call(engine->globalObject(), args); + prog.call(); + + QBENCHMARK { + prog.call(); + } +} + +void tst_script::signal_unconnected() +{ + QQmlEngine engine; + QQmlComponent component(&engine, TEST_FILE("signal_unconnected.qml")); + TestObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QBENCHMARK { + object->emitMySignal(); + } + + delete object; +} + +void tst_script::signal_qml() +{ + QQmlEngine engine; + QQmlComponent component(&engine, TEST_FILE("signal_qml.qml")); + TestObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QBENCHMARK { + object->emitMySignal(); + } + + delete object; +} + +void tst_script::signal_args() +{ + QQmlEngine engine; + QQmlComponent component(&engine, TEST_FILE("signal_args.qml")); + TestObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QBENCHMARK { + object->emitMySignalWithArgs(11); + } + + delete object; +} + +void tst_script::signal_unusedArgs() +{ + QQmlEngine engine; + QQmlComponent component(&engine, TEST_FILE("signal_unusedArgs.qml")); + TestObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QBENCHMARK { + object->emitMySignalWithArgs(11); + } + + delete object; +} + +void tst_script::slot_simple() +{ + QQmlEngine engine; + QQmlComponent component(&engine, TEST_FILE("slot_simple.qml")); + TestObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QBENCHMARK { + object->emitMySignal(); + } + + delete object; +} + +void tst_script::slot_simple_js() +{ + QQmlEngine engine; + QQmlComponent component(&engine, TEST_FILE("slot_simple_js.qml")); + TestObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QBENCHMARK { + object->emitMySignal(); + } + + delete object; +} + +void tst_script::slot_complex() +{ + QQmlEngine engine; + QQmlComponent component(&engine, TEST_FILE("slot_complex.qml")); + TestObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QBENCHMARK { + object->emitMySignal(); + } + + delete object; +} + +void tst_script::slot_complex_js() +{ + QQmlEngine engine; + QQmlComponent component(&engine, TEST_FILE("slot_complex_js.qml")); + TestObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QBENCHMARK { + object->emitMySignal(); + } + + delete object; +} + +void tst_script::block_data() +{ + QTest::addColumn("methodName"); + QTest::newRow("direct") << "doSomethingDirect()"; + QTest::newRow("localObj") << "doSomethingLocalObj()"; + QTest::newRow("local") << "doSomethingLocal()"; +} + +void tst_script::block() +{ + QFETCH(QString, methodName); + QQmlEngine engine; + QQmlComponent component(&engine, TEST_FILE("block.qml")); + QQuickRectangle *rect = qobject_cast(component.create()); + QVERIFY(rect != 0); + + int index = rect->metaObject()->indexOfMethod(methodName.toUtf8()); + QVERIFY(index != -1); + QMetaMethod method = rect->metaObject()->method(index); + + QBENCHMARK { + method.invoke(rect, Qt::DirectConnection); + } + + delete rect; +} + +#define GLOBALPROPERTY_PROGRAM \ + "(function() { " \ + " for (var ii = 0; ii < 10000; ++ii) { " \ + " Math.sin(90); " \ + " } " \ + "})" + +void tst_script::global_property_js() +{ + QScriptEngine engine; + + QScriptValue prog = engine.evaluate(GLOBALPROPERTY_PROGRAM); + prog.call(); + + QBENCHMARK { + prog.call(); + } +} + +void tst_script::global_property_qml() +{ + QQmlEngine qmlengine; + + QScriptEngine *engine = QQmlEnginePrivate::getScriptEngine(&qmlengine); + QScriptValue prog = engine->evaluate(GLOBALPROPERTY_PROGRAM); + prog.call(); + + QBENCHMARK { + prog.call(); + } +} + +void tst_script::global_property_qml_js() +{ + QQmlEngine engine; + QQmlComponent component(&engine, TEST_FILE("global_prop.qml")); + QQuickRectangle *rect = qobject_cast(component.create()); + QVERIFY(rect != 0); + + int index = rect->metaObject()->indexOfMethod("triggered()"); + QVERIFY(index != -1); + QMetaMethod method = rect->metaObject()->method(index); + + QBENCHMARK { + method.invoke(rect, Qt::DirectConnection); + } + + delete rect; +} + +void tst_script::scriptfile_property() +{ + QQmlEngine engine; + QQmlComponent component(&engine, TEST_FILE("global_prop.qml")); + QQuickRectangle *rect = qobject_cast(component.create()); + QVERIFY(rect != 0); + + int index = rect->metaObject()->indexOfMethod("incrementTriggered()"); + QVERIFY(index != -1); + QMetaMethod method = rect->metaObject()->method(index); + + QBENCHMARK { + method.invoke(rect, Qt::DirectConnection); + } + + delete rect; +} + +void tst_script::enums() +{ + QQmlEngine engine; + QQmlComponent 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() +{ + QQmlEngine engine; + QQmlComponent 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() +{ + QQmlEngine engine; + QQmlComponent 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" -- cgit v1.2.3