diff options
Diffstat (limited to 'src/interpreter/imports/qtsystemtest')
35 files changed, 3494 insertions, 0 deletions
diff --git a/src/interpreter/imports/qtsystemtest/qml/Application.qml b/src/interpreter/imports/qtsystemtest/qml/Application.qml new file mode 100644 index 0000000..36c9cdb --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/qml/Application.qml @@ -0,0 +1,162 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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 1.1 +import "../scripts/QstCore.js" as Core + +QtObject { + id: app + + property Remote remote + property variant pid: null + property variant __id + + function item(query) { + var matches = __queryProperties(query); + if ( matches.length !== 1 ) { + throw new Core.Qtt.Fail('Error: ' + matches.length + + ' items match query, expected a single match', 1); + } + return __handlerForObject(matches[0]); + } + + function items(query) { + var matches = __queryProperties(query); + var handlers = matches.map(function(obj) { + return __handlerForObject(obj); + }); + return handlers; + } + + function activeWidgetInfo() { return __sendQuery(arguments.callee.name); } + + function applicationData() { + return __sendQuery(arguments.callee.name).applicationdata; + } + + + function keyPress(key) { + __sendQuery(arguments.callee.name, { key: key }); + } + + function keyRelease(key) { + __sendQuery(arguments.callee.name, { key: key }); + } + + function keyClick(key) { + __sendQuery(arguments.callee.name, { key: key }); + } + + + function mousePress(pos, buttons) { + __inputEvent(arguments.callee.name, pos, buttons); + } + + function mouseRelease(pos, buttons) { + __inputEvent(arguments.callee.name, pos, buttons); + } + + function mouseClick(pos, buttons) { + __inputEvent(arguments.callee.name, pos, buttons); + } + + function mouseDoubleClick(pos, buttons) { + __inputEvent(arguments.callee.name, pos, buttons); + } + + function terminate() { + remote.runProcess( { program: "kill", arguments: [ pid ], timeout: 500 } ); + } + + function __queryProperties(query) { + // traverse the query object replacing any QstObject with its __internals + (function prepare(query) { + var prop, v; + for (prop in query) { + v = query[prop]; + if ( typeof(v) !== 'object' ) { continue; } + + if( v.__isQmlWrapper === true ) { + query[prop] = v.__internals; + } else { + prepare(v); + } + } + })(query); + + var items = __sendQuery("queryProperties", { + searchvalues: query + }).queryproperties; + return items || []; + } + + function __handlerForObject(obj) { + var ItemFactory = Core.ItemFactory; + var component = ItemFactory.handlerForObject(obj, {application: app}); + return component.createObject( + __runner.currentTestItem, { + application: app, + __internals: obj, + } + ); + + } + + + function __inheritanceTree(o) { + return __sendQuery('inheritance',{}, o).inheritance; + } + + function __inputEvent(event, pos, buttons) { + buttons = buttons || Qt.LeftButton; + + if (pos.__isQmlWrapper === true) { + return __sendQuery(event, {buttons: buttons}, pos.__internals); + } + + return remote.__sendPositionQuery(event, {buttons: buttons}, pos); + } + + + function __sendQuery() { + return remote.__sendQuery.apply(remote, arguments); + } +} diff --git a/src/interpreter/imports/qtsystemtest/qml/ApplicationObjectsCache.js b/src/interpreter/imports/qtsystemtest/qml/ApplicationObjectsCache.js new file mode 100644 index 0000000..15fdc67 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/qml/ApplicationObjectsCache.js @@ -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 QtSystemTest. +** +** $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$ +** +****************************************************************************/ + +.pragma library + +var __hosts = {}; + +function host(address) { + if ( __hosts[address] === undefined) { + __hosts[address] = new Host(address); + } + + return __hosts[address]; +} + +function Host(address) { + this.address = address; + this._store = {}; +} + +Host.prototype.store = function(appId, props) { + if ( !(appId in this._store) ){ + this._store[appId] = props; + return; + } + + var s = this._store[appId]; + for (var x in props) { + s[x] = props[x]; + } +} + +Host.prototype.data = function(appId) { + return appId in this._store + ? this._store[appId] + : null; +} diff --git a/src/interpreter/imports/qtsystemtest/qml/Js.qml b/src/interpreter/imports/qtsystemtest/qml/Js.qml new file mode 100644 index 0000000..703c564 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/qml/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 QtSystemTest. +** +** $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 1.1 +import '../scripts/QstCore.js' as Core + +QtObject { + function core() { + return Core; + } +} diff --git a/src/interpreter/imports/qtsystemtest/qml/Remote.qml b/src/interpreter/imports/qtsystemtest/qml/Remote.qml new file mode 100644 index 0000000..255a291 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/qml/Remote.qml @@ -0,0 +1,168 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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 1.1 +import '../scripts/QstCore.js' as Core +import 'ApplicationObjectsCache.js' as Cache + +QtObject { + id: remote + property string host + property int port: 5656 + property int applicationStartTimeout: 5000 + property int appStartRefreshInterval: 250 + + property bool __needToReconnect: true + property bool __debug_showMessageReceived: false + + onHostChanged: { __needToReconnect = true; } + onPortChanged: { __needToReconnect = true; } + + + function runProcess(params) { + return __sendQuery(arguments.callee.name, { cmd: params } ); + } + + function startApplication(app, args) { + args = args || [] + args.push("-style", "qtuitestd"); + var currentAppId = __currentAppId(); + var output = runProcess({ + program: app, + arguments: args, + detached: true + }); + + var timeout = 0; + while( __currentAppId() === currentAppId + && timeout < applicationStartTimeout) { + sleep(appStartRefreshInterval); + timeout += appStartRefreshInterval; + } + + var newAppId = __currentAppId(); + if (currentAppId === newAppId) { + throw new Core.Qtt.Fail('Application failed to start', 1); + } + Cache.host(host).store(newAppId, { + executable: app, + pid: output.pid, + }); + return applicationForId(newAppId) + } + + + + function currentApplication() { + var appId = __currentAppId(); + + if (appId === '') { + throw new Core.Qtt.Fail('No Current application', 1); + } + + return applicationForId(appId); + } + + function applicationForId(appId) { + // there should be data in the cache already + var cache = Cache.host(host); + var appData = cache.data(appId); + if (appData === null) { + throw new Core.Qtt.Fail('Application for Id not found', 1); + } + + if (appData.application !== undefined) { + return appData.application; + } + + var ApplicationRegistry = Core.ApplicationRegistry + var component = ApplicationRegistry.applicationForKey(appData.executable); + var app = component.createObject(__runner.currentTestItem, { + remote: remote, + __id: appId, + pid: appData.pid, + }); + if (app === null) { + throw new Core.Qtt.Error('Failed to create an application object for : ' + appId); + } + cache.store(appId, {application: app}); + return app; + } + + function applications() { + } + + function __connection() { + if (__needToReconnect == false) { + return __connection.object; + } + __connection.object = ConnectionManager.connectionForHost(host, port); + __connection.object.messageReceived.connect(__messageReceived); + var ok = __connection.object.connectToRemote(); + if ( !ok ) { + var e = new Core.Qtt.Fail('Error: Connection to : \ + host ' + host + 'port :' + port + ' failed', 2); + throw e; + } + __needToReconnect = false; + return __connection.object; + } + + function __sendQuery(event, params, widgetSpecifier) { + return __connection().sendQuery(event, params, widgetSpecifier); + } + + function __sendPositionQuery(event, params, position) { + return __connection().sendPositionQuery(event, params, position); + } + + function __currentAppId() { + return __sendQuery('currentApplication').currentapplication; + } + + function __messageReceived(event, context, data) { + if ( __debug_showMessageReceived ) { + console.log("Message received: ", + event, " context(" + context + ")", + 'data: ', Core.stringify(data)); + } + } +} diff --git a/src/interpreter/imports/qtsystemtest/qml/Test.qml b/src/interpreter/imports/qtsystemtest/qml/Test.qml new file mode 100644 index 0000000..df7f815 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/qml/Test.qml @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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 1.1 +import "../scripts/QstCore.js" as Core + +TestItem { + id: root + + property string __status: Core.Qtt.Status.Untested ///'' // passed, failed, skipped + property bool __isTest: true + property variant __mustHaves: ['name', 'description', 'run'] + + function __validate() { + var missingMustHave; + var allMustHaves = __mustHaves.every(function(k) { + missingMustHave =k; + return (k in root) && root[k] !== ''; + }); + + if (!allMustHaves) { + return __error('Test Item: ', root.name, ' does not define property or function', + '\'', missingMustHave, '\' the must haves are: ', __mustHaves); + } + + return __ok(); + } + +} + diff --git a/src/interpreter/imports/qtsystemtest/qml/TestCollection.qml b/src/interpreter/imports/qtsystemtest/qml/TestCollection.qml new file mode 100644 index 0000000..87e5b86 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/qml/TestCollection.qml @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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 1.1 +import "../scripts/QstCore.js" as Core + +TestItem { + id: root + property list<TestItem> __subset + default property alias children: root.__subset + + function __validate() { + var missingMustHave; + var allMustHaves = __mustHaves.every(function(k) { + missingMustHave =k; + return (k in root) && root[k] !== ''; + }); + + if (!allMustHaves) { + return __error('Test Item: ', root.name, ' does not define property', + '\'', missingMustHave, '\' the must haves are: ', __mustHaves); + } + + if( root.__subset.length > 0 && 'run' in root && typeof(root.run) === 'function' ) { + return __error('Invalid test: Cannot have sub test-sets and run() defined for ', root.name); + } + + if(__subset === null) { + return __ok(); + } + + for( var i = 0; i < __subset.length; i++) { + var s = __subset[i]; + var v = s.__validate(); + if( v.valid === false) { + return v; + } + } + + return __ok(); + } +} diff --git a/src/interpreter/imports/qtsystemtest/qml/TestItem.qml b/src/interpreter/imports/qtsystemtest/qml/TestItem.qml new file mode 100644 index 0000000..04fda39 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/qml/TestItem.qml @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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 1.1 +import "../scripts/QstCore.js" as Core + +TestMethod { + id: root + property string name:'' + property string description: '' + property bool enabled: true + + property list<Remote> remotes + + property variant __mustHaves: ['name', 'description'] + property bool __isTest: false + + function __ok() { + var path = Core.Js.__validationRoot__; + if ( path !== undefined) { + path.pop(); + if (path.length === 0) { + delete Core.Js.__validationRoot__; + } + } + return { + valid: true, + }; + } + + function __error() { + var runner = __runner, + msg = Array.prototype.slice.call(arguments).join(' '), + e = new Core.Qtt.Error(msg), + loc = runner.locationOf(root), + err; + + err = e.toString() + '\n' + + 'Location: ' + loc.url + '(' + loc.lineNumber + ')'; + return { + valid: false, + error : err + }; + } +} diff --git a/src/interpreter/imports/qtsystemtest/qml/TestMethod.qml b/src/interpreter/imports/qtsystemtest/qml/TestMethod.qml new file mode 100644 index 0000000..55cb64d --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/qml/TestMethod.qml @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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 1.1 +import QtSystemTest 1.0 +import '../scripts/QstCore.js' as Core + +QtObject { + // make core c++ stuff internal + property variant __core: CoreApi {} + function core() { return Core; } + + /*! + Causes the current test object to fail immediately + */ + function fail(message) { + var msg = Core.stringify.apply(null, arguments); + var e = new Core.Qtt.Fail(msg); + e.discardCallSites(); + throw e; + } + + function skip(message) { + var msg = Core.stringify.apply(null, arguments); + var e = new Core.Qtt.Skip(msg); + e.discardCallSites(); + throw e; + } + + function log() { + __runner.log.apply(__runner, arguments); + } + + function expect(o) { + return core().expect(o); + } + + function sleep(ms) { + // calls cpp method + __core.sleep(ms); + } +} diff --git a/src/interpreter/imports/qtsystemtest/qml/itemhandlers/QstObject.qml b/src/interpreter/imports/qtsystemtest/qml/itemhandlers/QstObject.qml new file mode 100644 index 0000000..6cbee20 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/qml/itemhandlers/QstObject.qml @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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 1.1 +import '..' +import "../../scripts/QstCore.js" as Core + +QtObject { + id: me + + property Application application + property variant __internals + property bool __isQmlWrapper: true + property string handles: 'QObject' + + function property(name) { + return __sendQuery('getProperty', {property: name}).getproperty; + } + + function setProperty(name, value) { + return __sendQuery('setProperty', { + property: name, + value: value, + }); + } + + function descendants(filter) { + filter = filter || {}; + filter.descendant_of = me; + return application.items(filter); + } + + function ancestors(filter) { + filter = filter || {}; + filter.ancestor_of = me; + return application.items(filter); + } + + function parent() { + return application.item({parent_of: me}); + } + + function isValid() { + try { + var x = type(); + } catch(e) { + return false; + } + return true; + + } + + function type() { + return __sendQuery('typeOf')['typeof']; + } + +// method: function(methodSignature) { +// return new QtUiTestMethod(this, methodSignature); +// }, + +// equals: function(other) { +// // FIXME other should be checked if it is a QtUiTestObject +// // but that test fails since for _prefetched_ objects the +// // type is set as Object and not QtUiTestWidget or QtUiTestObject +// // try: print(other.constructor.name) +// return other._signature_ !== undefined +// && this._signature_ === other._signature_; +// }, + + function toString() { + return this._signature_; + } + + function __sendQuery(event, params) { + params = params || {}; + return application.__sendQuery(event, params, __internals); + } + +} diff --git a/src/interpreter/imports/qtsystemtest/qml/itemhandlers/QstWidget.qml b/src/interpreter/imports/qtsystemtest/qml/itemhandlers/QstWidget.qml new file mode 100644 index 0000000..4eaa33f --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/qml/itemhandlers/QstWidget.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 QtSystemTest. +** +** $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 1.1 +import QtSystemTest 1.0 +import "../../scripts/QstCore.js" as Core + +QstObject { + id: me + handles: 'QWidget' +} diff --git a/src/interpreter/imports/qtsystemtest/qmldir b/src/interpreter/imports/qtsystemtest/qmldir new file mode 100644 index 0000000..06f9958 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/qmldir @@ -0,0 +1,11 @@ +plugin qtsystemtest +Application 1.0 qml/Application.qml +Remote 1.0 qml/Remote.qml +TestData 1.0 qml/TestData.qml +TestItem 1.0 qml/TestItem.qml +Test 1.0 qml/Test.qml +TestCollection 1.0 qml/TestCollection.qml +QstObject 1.0 qml/itemhandlers/QstObject.qml +QstWidget 1.0 qml/itemhandlers/QstWidget.qml +Js 1.0 qml/Js.qml +Core 1.0 scripts/QstCore.js diff --git a/src/interpreter/imports/qtsystemtest/qtsystemtest.json b/src/interpreter/imports/qtsystemtest/qtsystemtest.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/qtsystemtest.json @@ -0,0 +1 @@ +{} diff --git a/src/interpreter/imports/qtsystemtest/qtsystemtest.pro b/src/interpreter/imports/qtsystemtest/qtsystemtest.pro new file mode 100644 index 0000000..566a570 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/qtsystemtest.pro @@ -0,0 +1,74 @@ +TARGET = qtsystemtest +TARGETPATH = QtSystemTest + + +TEMPLATE = lib +CONFIG += no_clean qt plugin + +QT += declarative declarative-private testlib + +INCLUDEPATH += ../../../../include +LIBS += -L../../../../lib +LIBS += -lQstProtocol + +SOURCES += src/imports.cpp \ + src/qstcoreapi.cpp \ + src/qstutils.cpp \ + src/qstlocalprocess.cpp + +HEADERS += src/imports.h \ + src/qstcoreapi.h \ + src/qstutils.h \ + src/qstlocalprocess.h + +OTHER_FILES += \ + qtsystemtest.json \ + +target.path += $$[QT_INSTALL_IMPORTS]/QtSystemTest + +# public api +QML_IMPORT_FILES = \ + qml/TestMethod.qml \ + qml/TestItem.qml \ + qml/Test.qml \ + qml/TestCollection.qml \ + qml/Remote.qml \ + qml/Application.qml \ + qml/itemhandlers/QstObject.qml \ + qml/Js.qml \ + +qmlImportFiles.files += $$PWD/qml +qmlImportFiles.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH + +# scripts +SCRIPT_FILES = \ + scripts/api.js \ + scripts/Datatype.js \ + scripts/Functional.js \ + scripts/JsCore.js \ + scripts/SourceBuilder.js \ + scripts/Class.js \ + scripts/QstCore.js \ + scripts/Console.js \ + scripts/Expect.js \ + scripts/Exception.js \ + scripts/ComponentCacher.js \ + scripts/ApplicationRegistry.js \ + scripts/ItemFactory.js \ + +scriptFiles.files += $$SCRIPT_FILES +scriptFiles.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH/scripts + +# qmldir +QMLDIR_FILE = qmldir +qmldirFile.files += $$QMLDIR_FILE +qmldirFile.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH + +# show in QtCreator +OTHER_FILES += $$QML_IMPORT_FILES \ + $$SCRIPT_FILES \ + qmldir \ + + +INSTALLS += qmlImportFiles scriptFiles qmldirFile target + diff --git a/src/interpreter/imports/qtsystemtest/scripts/ApplicationRegistry.js b/src/interpreter/imports/qtsystemtest/scripts/ApplicationRegistry.js new file mode 100644 index 0000000..9566179 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/scripts/ApplicationRegistry.js @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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$ +** +****************************************************************************/ + +Js.include_check(ApplicationRegistry === undefined, 'ApplicationRegistry.js already included'); + +Js.require('ComponentCacher.js'); +Js.require('Exception.js'); + +// create a factory and make that singleton +var ApplicationRegistry = function() { + var Factory = ComponentCacher.extend(function() { + this._super(); + this.setDefaultItemFile('../qml/Application.qml'); + + function applicationForKey(key) { + var component = this.componentForKey(key); + if (component === null) { + throw new Qtt.Fail('Error creating an Application handler for: ' + key + + ' using file: ' + this.fileForKey(key) , 2); + } + return component; + } + + + return { + applicationForKey: applicationForKey + }; + }); + return new Factory(); +}(); diff --git a/src/interpreter/imports/qtsystemtest/scripts/Class.js b/src/interpreter/imports/qtsystemtest/scripts/Class.js new file mode 100644 index 0000000..e59c7f7 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/scripts/Class.js @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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$ +** +****************************************************************************/ + +Js.include_check(Class.isFn === undefined, 'Class.js already included'); + +function Class(){ }; + +Class.DebugEnabled = false; +//Class.DebugEnabled = true; +Class.debug = function debug() { + if (Class.DebugEnabled) { + var str = ''; + for (var i=0; i<arguments.length; i++) { + str += arguments[i]; + } + console.log(str); + } +} + +Class.isFn = function(fn) { return typeof fn === 'function'; }; +Class.isBothFn = function (fn, superFn) { + var debug = Class.debug; + debug('\t is fn ', (fn ? fn.name: undefined), ', superFn: ', (superFn ? superFn.name : undefined) , ' is a function'); + return Class.isFn(fn) && Class.isFn(superFn) +}; + +Class.create = function(superClass, constructor) { + // if 2 args are passed, then SuperClass is specified and else it is of the + // from X.extend(definition-of-y) + // SuperClass need not be specified in that case, SubClass definition will be + // in the SuperClass arg + var SuperClass, SubClass, + debug = Class.debug; + if( arguments.length == 1) { + SuperClass = this; + SubClass = superClass; // has the definition + + }else { + SubClass = constructor; + SuperClass = superClass; + } + debug('Superclass is ', SuperClass.name); + + // NOTE constructor.name for the object created using this is empty + var definition = function () { + // about to call the constructor of this object, so the super classes are already + // constructor and the prototype of this is already set. + var myProto = this; + debug('My Prototype already has : ', Object.keys(myProto)); + // define _super before calling the construtor + this._super = SuperClass; // _super from constructor should work + + // constructor returns the exported public members + var publicMembers = SubClass.apply(this, arguments); // returns the exported members + debug('Exported members are: ', Object.keys(publicMembers)); + + for (var name in publicMembers) { + debug('\t Testing if ', name, ' should be overridden'); + (function(member, superMember) { + // overide the definition in my proto if required + if ( Class.isFn(member) ) { + var s = Class.isFn(superMember) ? superMember : undefined; + myProto[name] = function() { + var tmp = this._super; + this._super = s; + var ret = member.apply(this, arguments); + this._super = tmp; + return ret; + } + } else { + myProto[name] = member; + } + + })(publicMembers[name], myProto[name]); + } + }; // definition + definition.prototype = new SuperClass; // establish prototype chain + definition.prototype.constructor = definition; // and the ctor + definition.extend = SuperClass.extend || Class.create + return definition; + +}; // Class.create + diff --git a/src/interpreter/imports/qtsystemtest/scripts/ComponentCacher.js b/src/interpreter/imports/qtsystemtest/scripts/ComponentCacher.js new file mode 100644 index 0000000..781914f --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/scripts/ComponentCacher.js @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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$ +** +****************************************************************************/ + +Js.include_check(ComponentCacher === undefined, 'ComponentCacher.js already included'); +Js.require('Exception.js'); +Js.require('Class.js'); + +var OriginalCallerDepth = 5; // explaination below +/* + the stack for factory.register(foo, bar) or this.setDefaultItemFile would lead to + 1. something.register() + 2. class.call (register) + 3. this.register + 3. absolutePathOf + 4. inside register + to get the file that called register, we would have to traverse back in stack 5 levels +*/ + + function absolutePathOf(path) { + if ( !Qt.qst.isRelativePath(path) ) { + return path; + } + // get the filename that called applicaton.register + var stack = Js.Engine.callSite(OriginalCallerDepth); + var callerFilePath = stack.last().fileName; + var lastSlash = callerFilePath.lastIndexOf('/'); + return callerFilePath.left(lastSlash + 1) + path; + } + + +var ComponentCacher = Class.create(function() { + var __registry = { + //key: qmlFile + }; + + var __componentsCache = { + //key: Component + }; + var __defaultItemFile; + var fallbackToDefault = true; + + function setDefaultItemFile(qmlFilePath) { + __defaultItemFile = absolutePathOf(qmlFilePath); + } + + function unregister(key) { + if (key in __registry) { + delete __registry[key]; + } + if (key in __componentsCache) { + delete __componentsCache[key]; + } + } + + function register(key, qmlFilePath) { + __registry[key] = absolutePathOf(qmlFilePath); + } + + function fileForKey(key) { + if (key in __registry) { + return __registry[key]; + } + if ( !fallbackToDefault) { + return null; + } + + if ( !__defaultItemFile) { + throw new Qtt.Error( 'Error: ComponentCacher - unable to find a file for ' + key); + } + return __defaultItemFile; + } + + function componentForKey(key) { + var qmlFile = this.fileForKey(key); + if (qmlFile === null) { + return null; + } + + var component = null; + if ( ! (qmlFile in __componentsCache)) { + + component = Qt.createComponent(qmlFile) + // HACK ... 1 means Component.Ready I want to access Component.Ready here... + if (component.status !== 1) { + // fix me ... Change error to accept msg and formatted msg, + throw new Qtt.Error('Component creation failed : ' + component.errorString(), 2); + } + __componentsCache[qmlFile] = component; + } else { + component = __componentsCache[qmlFile]; + } + + return component; + } + function setFallbackToDefault(value) { + fallbackToDefault = value; + } + + return { + + setFallbackToDefault: setFallbackToDefault, + setDefaultItemFile: setDefaultItemFile, + fileForKey: fileForKey, + register: register, + unregister: unregister, + componentForKey: componentForKey, + keys: function() { return Object.keys(__registry); }, + }; +}); diff --git a/src/interpreter/imports/qtsystemtest/scripts/Console.js b/src/interpreter/imports/qtsystemtest/scripts/Console.js new file mode 100644 index 0000000..3ddb6f5 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/scripts/Console.js @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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$ +** +****************************************************************************/ + +Js.include_check(Topic === undefined, 'Console.js already included'); +Js.require('Class.js'); + +var Topic = Class.create(function(name, parent) { + parent = parent || null; + var _subtopic = { + // name: Topic + }; + var loglevel = { + debug: {enabled: false, activate: false }, + warn: {enabled: false, activate: false }, + } + + var DebugEnabled = false; + function stringify() { + stringify.sb = stringify.sb || new SourceBuilder(); + var sb = stringify.sb; + var str = ''; + for (var i =0; i<arguments.length; ++i) { + str += sb.sourceFor(arguments[i]); + } + return str; + } + function _debug() { + if (DebugEnabled) { + print('Console[Debug]: ', stringify.apply(null, arguments)); + } + } + + function path() { + var parents = [name]; + for (var p = parent; p !== null; p = p.parent) { + _debug('....... type: ', typeof(p), ' ctor:', p.constructor.name ); + parents.unshift(p.name); + } + return parents; + } + + function debug(m) { + if ( loglevel.debug.activate) { + return; + } + + if (arguments.length === 0) { + return; + } + _debug('..................', name); + + function log() { + var parents = path(); + var location = Js.Engine.callSite(4).last(); + var filePath = location.fileName; + var file = filePath.right(filePath.length - filePath.lastIndexOf('/') -1); + console.log(' ', Date.timestamp(), ', ' // timestamp + + file + '(' + location.lineNumber + ') :', // file (linenumber) + parents.join('.'), ': ' + stringify.apply(null, arguments)); // topic.topic.... : msg + } +// log.apply(null, arguments); + } + + function topic(t) { + _debug('Already existing ones: ', Object.keys(_subtopic) ); + if ( t in _subtopic ){ + return _subtopic[t] + } + _debug('Creating a topic: ', name, '.' , t); + var sub = new Topic(t, this); + _subtopic[t] = sub; + _debug(Object.keys(_subtopic)); + return sub; + } + + function enable() { + + } + + return { + debug: debug, + topic: topic, + name: name, + parent: parent, + enable: enable, + }; +}); + + +var Console = new Topic('Console'); diff --git a/src/interpreter/imports/qtsystemtest/scripts/Datatype.js b/src/interpreter/imports/qtsystemtest/scripts/Datatype.js new file mode 100644 index 0000000..1b2fa7a --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/scripts/Datatype.js @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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$ +** +****************************************************************************/ + +.pragma library + +/// FIXME: Qt5, Error.stack can be enabled by calling prepareStack once +Object.defineProperties(Error.prototype, { + __addStack: { + value: function(level) { + if (this.stack) { + return; + } + + var stack = level === undefined ? Qt.qst.stack() : Qt.qst.stack(level); + // this function (top of the stack) with the right values from Error + stack[0] = { + fileName: this.fileName, + lineNumber: this.lineNumber, + functionName: '<unknown function>' + }; + this.stack = stack; + } + } +}); + + +Object.defineProperties(Array.prototype, { + isEmpty: { + value: function() { return this.length === 0; } + }, + + clear: { + value: function() { this.length = 0; } + }, + + last: { + value: function() { return this[this.length-1]; } + }, + + first: { + value: function() { return this[0]; } + }, + + contains: { + value: function(element) { + if (this === undefined || this === null) { + throw new TypeError(); + } + return this.indexOf(element) !== -1; + } + }, + + remove: { + value: function(from, to) { + var rest = this.slice((to || from) + 1 || this.length); + this.length = from < 0 ? this.length + from : from; + return this.push.apply(this, rest); + } + } +}); + + +Object.defineProperties(String.prototype, { + startsWith: { + value: function(prefix) { return this.indexOf(prefix) === 0; } + }, + + endsWith: { + value: function(suffix) { + return this.indexOf(suffix, this.length - suffix.length) !== -1; } + }, + + left: { + value: function(len) { return this.substring(0, len); } + }, + + right: { + value: function(len) { return this.substring(this.length- len); } + }, + + repeat: { + value: function( num ) { return new Array( num + 1 ).join(this); } + }, + trim: { + value: function() { return this.replace(/^\s+|\s+$/g, ""); } + } +}); + + +Date.timestamp = function() { + function pad(n, places) { + var str = ''+n; + if ( str.length >= places) { + return str; + } + return '0'.repeat(places - str.length) + str; + } + var now = new Date(); + var timestamp = pad(now.getHours(), 2) + ':' + + pad( now.getMinutes(), 2) + ':' + + pad( now.getSeconds(), 2) + ' - ' + + pad( now.getMilliseconds(), 3); + return timestamp; +} diff --git a/src/interpreter/imports/qtsystemtest/scripts/Exception.js b/src/interpreter/imports/qtsystemtest/scripts/Exception.js new file mode 100644 index 0000000..25fdafb --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/scripts/Exception.js @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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$ +** +****************************************************************************/ + +Js.include_check(Qtt === undefined, 'Exception.js already included'); +Js.require('Class.js'); +Js.require('Console.js'); + +var Qtt = function(){ + var QttDebug = Console.topic('Qtt'); + + var Status = { + Error: 'error', + Passed: 'passed', + Failed: 'failed', + Skipped: 'skipped', + Aborted: 'aborted', + Untested: 'untested', + }; + + var QttError = Class.create(function QttError(msg, discardLevel) { + discardLevel = (discardLevel || 0 ) + 2; + this.name = arguments.callee.name; + this.stack = Qt.qst.stack(); + Js.discardCallSites.call(this, discardLevel); + return { + status : Status.Error, + type: 'QttError', + message: msg, + __addStack : function(){}, + discardCallSites: Js.discardCallSites, + toString: function() { return this.message; } + }; + }); + + var Skip = QttError.extend(function Skip(msg, discardLevel) { + discardLevel = (discardLevel || 0 ) + 2; + this._super(msg, discardLevel); + this.type = 'Skip'; + this.status = Status.Skipped; + return { }; + }); + + var Abort = QttError.extend(function Abort(msg, discardLevel) { + discardLevel = (discardLevel || 0 ) + 2; + this._super(msg, discardLevel); + this.type = 'Abort'; + this.status = Status.Aborted; + return { }; + }); + + var Fail = QttError.extend(function Fail(msg, discardLevel) { + discardLevel = (discardLevel || 0 ) + 2; + this._super(msg, discardLevel); + this.type = 'Fail'; + this.status =Status.Failed; + return { }; + }); + + + return { + Error: QttError, + Skip: Skip, + Fail: Fail, + Abort: Abort, + Status: Status + }; +}(); diff --git a/src/interpreter/imports/qtsystemtest/scripts/Expect.js b/src/interpreter/imports/qtsystemtest/scripts/Expect.js new file mode 100644 index 0000000..fc7cee0 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/scripts/Expect.js @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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$ +** +****************************************************************************/ + +Js.include_check(Expectation === undefined, 'Expect.js already included'); +Js.require('Class.js'); +Js.require('Exception.js'); + +var Expectation = Class.create(function(actual, value){ + var ok = value === undefined ? true : value; + + function _not_() { + return ok === true? ' ' : ' not '; + } + + function toBeBetween(low, high){ + if ( ( low < actual && actual < high) !== ok) { + var msg = 'Expected actual value to be' + _not_() + 'between low and high value.'; + var formatted = 'Expected (' + actual + ') to be' + _not_() + + 'between (' + low + ', ' + high + ')'; + var e = new Qtt.Fail(msg, formatted, 2); + e.meta = { + actual: actual, + low: low, + high: high + }; + throw e; + } + } + + function toBe(expectation){ + if ( (actual === expectation) !== ok) { + var msg = 'Expected actual value to be' + _not_() + 'expected value.'; + var e = new Qtt.Fail(msg, 2); + e.meta = { + actual: actual, + expected: expectation + }; + e.formatted = 'Expected (' + actual + ') to be' + _not_() + + '(' + expectation + ')'; + throw e; + } + } + + function toThrow(expection){ + } + + function instanceOf(expectation){ + if( (actual instanceof expectation) !== ok) { + var msg = 'Expected actual value to be' + _not_() + 'an instance of expected type.'; + var e = new Qtt.Fail(msg, 2); + e.meta = { + actual: actual, + expected: expectation.name + }; + e.formated = 'Expected (' + actual + ') to be' + _not_() + + 'instance of (' + expectation.name + ')'; + throw e; + } + } + + + return { + toBe: toBe, + toBeBetween: toBeBetween, + instanceOf: instanceOf + } +}); + + +function expect(actual) { + var x = new Expectation(actual); + x.not = new Expectation(actual, false) + return x; +} diff --git a/src/interpreter/imports/qtsystemtest/scripts/Functional.js b/src/interpreter/imports/qtsystemtest/scripts/Functional.js new file mode 100644 index 0000000..ddce3f8 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/scripts/Functional.js @@ -0,0 +1,298 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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$ +** +****************************************************************************/ + +.pragma library + +/*! + Returns a function that suppresses throwing the expection when the + function \a being wrapped either fails or throws an exception. + + The exception generated is stored in an exception property. + The failed property indicates if the function threw an exception. + + Usage: + \code + var itemExists = findUniqueItem.nothrow(); + var item = itemExists({QMLTYPE: 'QQuickItem'}); + + if (!itemExists.failed) { + print(item.property('x')); + } else { + // item is undefined + fail(itemExists.exception.message); + } + \endcode +*/ +Function.prototype.nothrow = function nothrow() { + var fn = this; + function nothrow() { + try { + var result = fn.apply(this, arguments); + arguments.callee.failed = false; + return result; + } catch(e) { + arguments.callee.exception = e; + arguments.callee.failed = true; + } + return undefined; + } + + // reduce nothrow().nothrow() to a single nothrow + return fn.toString() === nothrow.toString() ? fn : nothrow; +} + +/*! + Returns a function that retries the \a fn after every \a interval milliseconds + until it doesn't result in a 'fail' or times out after \a timeout milliseconds. + + Usage: + \code + var item = findUniqueItem.retry({timeout: 1000, interval: 250}); + var obj = item({QMLTYPE: 'Button', QMLID: 'aButton'}) + \endcode + + is equal to writing + + \code + var obj; + var excp; + var timeout = 1000; + var poll = 250; + try { + expect( function() { + try { + obj = findUniqueItem({QMLTYPE: 'Button', QMLID: 'aButton'}) + return true; + }catch(e) { + excp = e; + } + return false; + }, timeout, Math.floor(timeout/poll)); + } catch(e) { + fail(excp.message, ' after ', timeout, 'ms' ); + } + \endcode + +*/ +//Function.prototype.retry = function(config) { +// if (!config){ +// throw new Error('Missing args: no timeout and interval specified. \n' +// + 'Usage retry({timeout: <timeout>, interval: <interval> })'); +// } + +// if (typeof(config.timeout) !== 'number') { +// throw new TypeError('timeout: not a number \n' +// + 'Usage retry({timeout: <timeout>, interval: <interval> })'); +// } +// if (typeof(config.interval) !== 'number') { +// throw new TypeError('interval: not a number \n' +// + 'Usage retry({timeout: <timeout>, interval: <interval> })'); +// } + +// var method = this.nothrow(); + +// function retry() { +// // store the original method +// retry.original = this; +// var result; +// var args = Private.Utils.makeArray(arguments) ; +// var passes = Private.Utils.poll(function autoPoll() { +// result = method.apply(this, args); +// return method.failed === false; +// }, config.timeout, config.interval); + +// if (!passes) { +// fail(method.exception.message, ' after ', config.timeout, ' ms'); +// } +// return result; +// } + +// // error on retry().retry(); +// if (this.toString() === retry.toString()) { +// var originalMethod = this.original.name === '' ? '[anonymous]' +// : this.original.name; +// return new Error('Cannot create a retry version of already retry version of method: ' +// + originalMethod); +// } +// return retry; +//} + +/*! + Partially intialize first few arguments of a function + + \code + function sum(a, b) { return a+b;}; + var add5 = sum.curry(5); + var x = add5(10); // x = 15 now + \endcode + +*/ +Function.prototype.bind = function(scope) { + var fn = this; + var toArray = Array.prototype.slice; + var args = toArray.call(arguments); + var scope = args.shift(); + return function() { + return fn.apply(scope, args.concat(toArray.call(arguments))); + }; +}; + +Function.prototype.curry = function() { + var fn = this; + var toArray = Array.prototype.slice; + var args = toArray.call(arguments); + return function() { + return fn.apply(this, args.concat( toArray.call(arguments))); + }; +}; + + +/*! + Partially intialize arguments of a function, using undefined as placeholders for + arguments to be filled in later. + + \code + function sum(a, b) { return a+b;}; + var add5 = sum.partial(undefined, 5); + + var x = add5(10); // x = 15 now + \endcode + +*/ +Function.prototype.partial = function(){ + var fn = this; + var toArray = Array.prototype.slice; + var partialArgs = toArray.call(arguments); + return function(){ + var args = partialArgs.slice(); // copy partial + var arg = 0; + for ( var i = 0; i < args.length && arg < arguments.length; i++ ) { + if ( args[i] === undefined ) { + args[i] = arguments[arg++]; + } + } + return fn.apply(this, args); + }; +} + +var FunctionHelper = function() { + /*! + Validate number of the arguments passed to a function \a fn, throws an exception + if the number of args passed to the \a fn is less than the minArgsRequired. + + if no minimumArgs is passed, uses the number of named arguments in \a fn + + Usage: + \code + var findItems = FunctionHelper.validateArgs(function findItems( filter, fetch, mode) { + }, 1); // ensures 1 arg is passed when findItems + \endcode + */ + function validateArgs(fn, minArgsRequired) { + if( typeof(fn) !== 'function' || fn.name === '' ) { + throw new Error('The first argument to validateArgs should be a named function'); + } + minArgsRequired = minArgsRequired || fn.length; + return function() { + if (arguments.length < minArgsRequired) { + fail(fn.name, ' expects atleast ', minArgsRequired, + ' arguments, whereas only ', arguments.length, ' passed'); + } + return fn.apply(this, arguments) + }; + } + + /*! + Deprecates a function with the name \a fnName and replaced by \a replacedBy. Would print of the + msg if one is passed or generates one. + + Usage: + \code + var findWidget = FunctionHelper.deprecate('findWidget', findItems); + or + var findWidget = FunctionHelper.deprecate('findWidget', findItems, + 'Usage of findWidget is deprecated, use findItems instead') + var findWidget = FunctionHelper.deprecate('findWidget', + {replacedBy: findItems, name: 'findItems'}); + \endcode + */ + function deprecate(fnName, replacedBy, msg, config) { + msg = msg || 'Usage of deprecated function: ' + fnName + ', use ' + replacedBy.name + ' instead.'; + config = config || { + FailOnInvoke : false + }; + return function() { + if ( config.FailOnInvoke ) { + throw new Error('Error: ' + msg); + } + warn(msg); + // use the function if replacedBy is a Function else if it an object, then use the replacedBy property + var fn = replacedBy instanceof Function ? replacedBy : replacedBy.replacedBy; + return fn.apply(this, arguments); + }; + } + + + /*! + Helper function that wraps an object of type anything other than function + inside an anonymous function, invoking which returns the object; + + Usage: + \code + var x = 10; + x = FunctionHelper.toFunction(x); + var y = x(); // y is 10; + \endcode + */ + function toFunction(x) { + return typeof(x) === 'function' ? x : function(){ return x;}; + } + + function isFunction(x) { + return typeof(x) === 'function'; + } + return { + validateArgs: validateArgs, + deprecate: deprecate, + toFunction: toFunction, + isFunction: isFunction + }; +} diff --git a/src/interpreter/imports/qtsystemtest/scripts/ItemFactory.js b/src/interpreter/imports/qtsystemtest/scripts/ItemFactory.js new file mode 100644 index 0000000..93c2a2f --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/scripts/ItemFactory.js @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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$ +** +****************************************************************************/ + +// create a factory and make that singleton +var ItemFactory = function() { + /// FIXME: itemshandlers can be resitered or unregistered at run time + /// so, the keyForObject.cache would get invalidated + var Factory = ComponentCacher.extend(function() { + this._super(); + this.setFallbackToDefault(false); + var _handlerForItemCache = {}; + + function keyForObject(obj, application) { + var key = obj._type_; + + function handlerExists(k) { + if ( this.fileForKey(k) !== null ) { + handlerExists.key = k; + return true; + } + return false; + } + + // perfect match + if ( handlerExists.call(this, key) ) { + return key; + } + + if ( key in _handlerForItemCache) { + return _handlerForItemCache[key]; + } + + var tree = application.__inheritanceTree(obj); + tree.shift(); + var ret = tree.some(handlerExists, this) + ? handlerExists.key + : null; + _handlerForItemCache[key] = ret; + return ret; + } + + function itemForKey(obj, props) { + if ( !('_type_' in obj ) ) { + throw new Qtt.Fail('Invalid object passed to handlerForObject: _type_ does not exist ', 2); + } + + var key = keyForObject.call(this, obj, props.application); + if (key === null) { + throw new Qtt.Fail('Error finding a Item handler for: ' + obj._type_ , 2); + } + var component = this.componentForKey(key); + if (component === null) { + throw new Qtt.Fail('Error creating an Item handler for: ' + obj._type_ , 2); + } + return component; + } + + function register(k, path) { + path = absolutePathOf(path); + this._super(k, path); + _handlerForItemCache = {}; + } + + function unregister(key) { + this._super(key); + _handlerForItemCache = {}; + } + + return { + handlerForObject: itemForKey, + register: register, + unregister: unregister + }; + }); + var singleton = new Factory(); + singleton.register('QObject', '../qml/itemhandlers/QstObject.qml'); + singleton.register('QWidget', '../qml/itemhandlers/QstWidget.qml'); + return singleton; +}(); diff --git a/src/interpreter/imports/qtsystemtest/scripts/JsCore.js b/src/interpreter/imports/qtsystemtest/scripts/JsCore.js new file mode 100644 index 0000000..30b3736 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/scripts/JsCore.js @@ -0,0 +1,215 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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$ +** +****************************************************************************/ + +if( typeof(Js) !== 'undefined') { + Js.include_check(Js === undefined, 'JsCore.js already included'); +} + +Qt.include('Datatype.js') +Qt.include('Functional.js'); + +var Js = function() { + + var Core = { + Error: { + maxStack: 17 + } + }; + +// var DebugEnabled = true; + var DebugEnabled = false; + function _debug() { + var str = '', + arg, + i, + now, + timestamp; + + if (!DebugEnabled) { + return; + } + + for (i =0; i<arguments.length; ++i) { + arg = arguments[i] + if (arg != null) { + str += arg.toString(); + } else { + str += 'undefined' + } + } + console.log(Date.timestamp(), 'JsCore[Debug]:', str); + } + + function discardCallSites(num) { + num = num || 1; + if (!this.stack) return; + var stack = this.stack; + if( stack.length < num ) { + _debug(' Error: insufficient stack depth'); + throw new Error('Insufficient stack depth'); + } + while ( num-- > 0 ) { + this.stack.shift(); + } + } + + var JsError = (function() { + function JsError(msg) { + Error.call(this); + this.message = msg; + this.name = arguments.callee.name; + this.stack = Qt.qst.stack(); + this._discardCallSites(); + } + JsError.prototype = new Error(); + JsError.prototype._discardCallSites = discardCallSites; + return JsError; + })(); + + var IncludeError = (function() { + function IncludeError(msg) { + JsError.call(this, msg); + _debug(' Creating include error :', this.message); + this.name = arguments.callee.name; + this._discardCallSites(); + } + + IncludeError.prototype = new JsError(); + IncludeError.prototype.constructor = IncludeError; + return IncludeError; + })(); + + function require(filename) { + require.level = require.level || 0; + + function repeat(c, t){ + var str = ''; + for(var i=0; i< t; ++i){ + str += c; + } + return str; + } + var spaces = repeat(' ', require.level*4); + _debug('including .... '+ spaces + (require.level !==0? '+--': '') + '[', filename, ']'); + + require.level++; + try { + var include = Qt.include(filename); + } catch(e) { + console.log('Exception caught loading', filename, e.message); + console.log('Stack', e.stack.join('\n')); + } + + if( include && include.status === include.EXCEPTION) { + var ex = include.exception; + if (!(ex instanceof IncludeError) ) { + console.log('Exception including : ', filename, ': ', ex.message, ex.filename); + if ( ex.stack instanceof Array) { + ex.stack.forEach( function(cs) { + console.log( cs.fileName, ':', s.lineNumber); + }); + } + throw ex; + } else { + _debug('Exception including : ', filename, " exception: ", ex); + } + } + // _debug('including .... [', filename, ']done'); + require.level--; + } + + function include_check(condition, msg) { + if(!condition) { + throw new IncludeError(msg); + } + } + + + var JsEngine = function() { + function callSite(depth) { + var stack = depth === undefined + ? Qt.qst.stack() + : Qt.qst.stack(depth++); + return stack; + } + + function currentFile() { + var cs = callSite(3); + return cs.last().fileName; + } + + function currentPath() { + var cs = callSite(3); + var filePath = cs.last().fileName; + var fileStart = filePath.lastIndexOf('/'); + return filePath.substring(fileStart + 1); + } + + function currentLine() { + var cs = callSite(3); + return cs.last().lineNumber; + } + + return { + currentPath: currentPath, + currentFile: currentFile, + currentLine: currentLine, + callSite: callSite + } + }(); + + return { + require: require, + include_check: include_check, + Core: Core, + Error: JsError, + discardCallSites: discardCallSites, + Engine: JsEngine, + _debug: _debug, + } +}(); + + +function assert(condition, msg) { + if (!condition) { + throw new JsError(msg); + } +} diff --git a/src/interpreter/imports/qtsystemtest/scripts/QstCore.js b/src/interpreter/imports/qtsystemtest/scripts/QstCore.js new file mode 100644 index 0000000..da422be --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/scripts/QstCore.js @@ -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 QtSystemTest. +** +** $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$ +** +****************************************************************************/ + +.pragma library + +Qt.include('JsCore.js'); +Js.require('SourceBuilder.js'); + +Js.require('Class.js'); +Js.require('Console.js'); +Js.require('Exception.js'); +Js.require('Expect.js'); +Js.require('ApplicationRegistry.js'); +Js.require('ItemFactory.js'); diff --git a/src/interpreter/imports/qtsystemtest/scripts/SourceBuilder.js b/src/interpreter/imports/qtsystemtest/scripts/SourceBuilder.js new file mode 100644 index 0000000..014f118 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/scripts/SourceBuilder.js @@ -0,0 +1,172 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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$ +** +****************************************************************************/ + +Js.include_check(SourceBuilder === undefined, 'SourceBuilder.js already included'); + +var SourceBuilder = function() { + var DebugEnabled = false; + function debug(enabled){ + if (enabled && DebugEnabled) { + console.log( msg(Array.prototype.slice.call(arguments)) ); + } + } + + function msg() { + var str = ''; + for (var i =0; i<arguments.length; i++) { + var arg = arguments[i]; + str += arg; + } + return str; + } + + // converters + function arrayToString(a, level) { + if (a.length === 0 ) { + return '[]'; + } + + var str = '['; + var quote; + for (var i =0; i < a.length; ++i) { + quote = typeOf(a[i]) === 'String' ? "'" : ''; + str += quote + stringify(a[i]) + quote; + str += i < (a.length -1) ? ', ' : ']' + } + return str; + } + + function objectToString(obj, level) { + debug(DebugEnabled && msg(arguments.callee.name)); + + // if toString for the object is overridden then, use that version + if ( obj.toString !== Object.prototype.toString) { + return obj.toString(); + } + + var indentation = indentText.repeat(level); + var propertyCount = Object.keys(obj).length; + var terminator = propertyCount > 1 ? '\n': '' + var propertyIndentation = propertyCount > 1 ? (indentation + indentText) : '' + var objectType = typeOf(obj) + + function stripObject(o) { + return o === 'Object' ? '' : o; + } + // don't print 'Object', if the type is Object + var str = stripObject(objectType) + '{' + terminator; + var contents = ''; + for (var prop in obj) { + // add a quote if the value is of type string + var quote = typeof(obj[prop]) == 'string' ? "'" : ''; + + contents += propertyIndentation + prop + ': ' + + quote + stringify(obj[prop], level+1) + quote + + ',' + terminator; + } + str += contents.slice(0, -(1 + terminator.length)); // remove the , at the end of contents + str += terminator + indentation + '}' + terminator; + return str; + } + + function typeOf(o) { + debug(DebugEnabled && msg(arguments.callee.name)); + if ( o === undefined ) return 'undefined'; + if ( o === null ) return 'null'; + + // we have a valid object + var ctor = o.constructor.name; + return ctor.length === 0 ? 'Object' // no Object for a generic object + : ctor; + } + + function sameObject(x){ return x; } + function toString(x){ return x.toString(); } + function qtuitestWidget(x){ return 'QtUiTestWidget( ' + x.toString() + ' )'; } + function qtuitestObject(x){ return 'QtUiTestObject( ' + x.toString() + ' )'; } + + // converts obj to string + function stringify(obj, level) { + debug(DebugEnabled && msg(arguments.callee.name)); + debug(DebugEnabled && msg('Finding type of :', obj) ); + level = level || 0; + + var typeConverters = { + 'null': typeOf, + 'undefined': typeOf, + 'Number': toString, + 'Boolean': toString, + 'Function': toString, + 'String': sameObject, + 'Array': arrayToString, + 'QtUiTestWidget': qtuitestWidget, + 'QtUiTestObject': qtuitestObject, + 'Object': objectToString + }; + + var type = typeOf(obj); + if ( type in typeConverters) { + debug(DebugEnabled && msg('Found converter for type: ' + type + + ', using converter :' + typeConverters[type].name)); + return typeConverters[type](obj, level); + } + debug(DebugEnabled && msg('No converters Found for type: ' + type) ); + // if no converters are registered, treat the type as an object and print it + return objectToString(obj, level); + } + + var indentText = ' ';// .repeat(4); // 4 spaces for each level + return { + sourceFor: function sourceFor(obj) { + return stringify(obj); + } + }; + +}// SourceBuilder + +function stringify() { + stringify.sb = stringify.sb || new SourceBuilder(); + var str = ''; + for (var i =0; i< arguments.length; ++i) { + str += stringify.sb.sourceFor(arguments[i]); + } + return str; +} diff --git a/src/interpreter/imports/qtsystemtest/scripts/api.js b/src/interpreter/imports/qtsystemtest/scripts/api.js new file mode 100644 index 0000000..f9cf7a1 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/scripts/api.js @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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$ +** +****************************************************************************/ + +.pragma library + +Qt.include('JsCore.js'); +Js.include_check(Private === undefined, 'api.js already included'); + + +function api() { + var component = Qt.createQmlObject( + 'import QtQuick 2.0;' + + 'import QtUiTest 1.0;' + + 'TestMethod {}', Js.__testRoot); + return component; +} + +Js._debug(' api.js ... loaded'); diff --git a/src/interpreter/imports/qtsystemtest/src/imports.cpp b/src/interpreter/imports/qtsystemtest/src/imports.cpp new file mode 100644 index 0000000..e8f1529 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/src/imports.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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 "imports.h" +#include "qstcoreapi.h" +#include "qstutils.h" +#include "qstlocalprocess.h" +#include <QtDeclarative> + +#include <QtSystemTest/QstConnection> +#include <QtSystemTest/QstConnectionManager> + +void QtSystemTestQmlModule::registerTypes(const char *uri) +{ + Q_ASSERT(QLatin1String(uri) == QLatin1String("QtSystemTest")); + qmlRegisterType<QstCoreApi>( uri, 1, 0, "CoreApi"); + qmlRegisterType<QstConnection>( uri, 1, 0, "Connection"); + qmlRegisterType<QstLocalProcess>( uri, 1, 0, "LocalProcess"); +} + +void QtSystemTestQmlModule::initializeEngine(QDeclarativeEngine *e, const char *uri) +{ + qDebug() << Q_FUNC_INFO << "Registering connection manager and Utils" << uri; + e->rootContext()->setContextProperty("ConnectionManager", new QstConnectionManager()); + e->rootContext()->setContextProperty("Utils", new QstUtils()); +} + +Q_EXPORT_PLUGIN2(qtsystemtestplugin, QtSystemTestQmlModule); diff --git a/src/interpreter/imports/qtsystemtest/src/imports.h b/src/interpreter/imports/qtsystemtest/src/imports.h new file mode 100644 index 0000000..4a41b48 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/src/imports.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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$ +** +****************************************************************************/ + +#ifndef IMPORTS_H +#define IMPORTS_H + +#include <QDeclarativeExtensionPlugin> + +class QDeclarativeEngine; + +class QtSystemTestQmlModule : public QDeclarativeExtensionPlugin +{ + Q_OBJECT + +public: + virtual void registerTypes(const char *uri); + void initializeEngine(QDeclarativeEngine *, const char *); +}; + +#endif // IMPORTS_H diff --git a/src/interpreter/imports/qtsystemtest/src/qstcoreapi.cpp b/src/interpreter/imports/qtsystemtest/src/qstcoreapi.cpp new file mode 100644 index 0000000..979070d --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/src/qstcoreapi.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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 "qstcoreapi.h" + +#include <QtCore/QDebug> +#include <QtTest/QTest> + +QstCoreApi::QstCoreApi(QObject *parent) : + QObject(parent) +{ +} + +void QstCoreApi::sleep(int ms) +{ + QTest::qSleep(ms); +} + diff --git a/src/interpreter/imports/qtsystemtest/src/qstcoreapi.h b/src/interpreter/imports/qtsystemtest/src/qstcoreapi.h new file mode 100644 index 0000000..4efc473 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/src/qstcoreapi.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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$ +** +****************************************************************************/ + +#ifndef QSTCOREAPI_H +#define QSTCOREAPI_H + +#include <QtCore/QObject> +#include <QtCore/QVariantMap> + +class QSystemTestMaster; + +class QstCoreApi : public QObject +{ + Q_OBJECT +public: + explicit QstCoreApi(QObject *parent = 0); + + static const QLatin1String signatureProperty; + static const QLatin1String appIdProperty; + static const QLatin1String widgetSpecifierProperty; + +signals: + +public slots: + void sleep(int ms); + bool connectApplication(const QString &host, int port); + + private: + + QSystemTestMaster *m_test_app; +}; + +#endif // QSTCOREAPI_H diff --git a/src/interpreter/imports/qtsystemtest/src/qstlocalprocess.cpp b/src/interpreter/imports/qtsystemtest/src/qstlocalprocess.cpp new file mode 100644 index 0000000..cf60379 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/src/qstlocalprocess.cpp @@ -0,0 +1,167 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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 "qstlocalprocess.h" + +#include <QtCore/QTextCodec> + +QstLocalProcess::QstLocalProcess(QObject *parent) : + QProcess(parent), + m_inputCodec(0), + m_outputCodec(0), + m_outputDecoder(0), + m_errorDecoder(0), + m_outputMode(DeviceOutput) +{ + m_inputCodec = QTextCodec::codecForLocale(); + m_outputCodec = QTextCodec::codecForLocale(); + + connect(this, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(forwardFinished(int, QProcess::ExitStatus))); +} + +void QstLocalProcess::start(const QString &program, const QStringList &arguments) +{ + QProcess::start(program, arguments, QIODevice::ReadWrite); +} + +bool QstLocalProcess::waitForStarted(int msecs) +{ + return QProcess::waitForStarted(msecs); +} + +bool QstLocalProcess::waitForFinished(int msecs) +{ + return QProcess::waitForFinished(msecs); +} + +bool QstLocalProcess::waitForReadyRead(int msecs) +{ + return QProcess::waitForReadyRead(msecs); +} + +void QstLocalProcess::closeWriteChannel() +{ + QProcess::closeWriteChannel(); +} + +QProcess::ProcessState QstLocalProcess::state() const +{ + return QProcess::state(); +} + +QProcess::ExitStatus QstLocalProcess::exitStatus() const +{ + return QProcess::exitStatus(); +} + +int QstLocalProcess::exitCode() const +{ + return QProcess::exitCode(); +} + +QString QstLocalProcess::inputCodec() const +{ + return QString::fromLatin1(m_inputCodec->name()); +} + +void QstLocalProcess::setInputCodec(const QString &name) +{ + m_inputCodec = QTextCodec::codecForName(name.toLatin1().constData()); +} + +QString QstLocalProcess::outputCodec() const +{ + return QString::fromLatin1(m_outputCodec->name()); +} + +void QstLocalProcess::setOutputCodec(const QString &name) +{ + if (name == outputCodec()) + return; + m_outputCodec = QTextCodec::codecForName(name.toLatin1().constData()); + delete m_outputDecoder; + delete m_errorDecoder; + m_outputDecoder = 0; + m_errorDecoder = 0; +} + +void QstLocalProcess::setOutputMode(OutputMode mode) +{ + if (mode == m_outputMode) + return; + m_outputMode = mode; + if (m_outputMode == DeviceOutput) { + disconnect(this, SIGNAL(readyReadStandardOutput()), this, SLOT(updateOutputBuffer())); + disconnect(this, SIGNAL(readyReadStandardError()), this, SLOT(updateErrorBuffer())); + } else { + setProcessChannelMode(SeparateChannels); + connect(this, SIGNAL(readyReadStandardOutput()), this, SLOT(updateOutputBuffer())); + connect(this, SIGNAL(readyReadStandardError()), this, SLOT(updateErrorBuffer())); + updateOutputBuffer(); + updateErrorBuffer(); + } +} +void QstLocalProcess::updateOutputBuffer() +{ + QByteArray bytes = readAllStandardOutput(); + if (!bytes.isEmpty()) { + if (!m_outputDecoder) + m_outputDecoder = m_outputCodec->makeDecoder(); + m_stdoutBuffer.append(m_outputDecoder->toUnicode((bytes))); + emit standardOutputChanged(m_stdoutBuffer); + } +} + +void QstLocalProcess::updateErrorBuffer() +{ + QByteArray bytes = readAllStandardOutput(); + if (!bytes.isEmpty()) { + if (!m_errorDecoder) + m_errorDecoder = m_outputCodec->makeDecoder(); + m_stderrBuffer.append(m_errorDecoder->toUnicode((bytes))); + emit standardErrorChanged(m_stderrBuffer); + } +} + +void QstLocalProcess::write(const QString &input) +{ + QProcess::write(m_inputCodec->fromUnicode(input)); +} diff --git a/src/interpreter/imports/qtsystemtest/src/qstlocalprocess.h b/src/interpreter/imports/qtsystemtest/src/qstlocalprocess.h new file mode 100644 index 0000000..215ee36 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/src/qstlocalprocess.h @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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$ +** +****************************************************************************/ + +#ifndef QSTLOCALPROCESS_H +#define QSTLOCALPROCESS_H + +#include <QtCore/QProcess> + +class QTextCodec; +class QTextDecoder; + +class QstLocalProcess : public QProcess +{ + Q_OBJECT + Q_ENUMS(ProcessState ExitStatus OutputMode) + + Q_PROPERTY(ProcessState state READ state NOTIFY stateChanged) + Q_PROPERTY(ExitStatus exitStatus READ exitStatus NOTIFY exitStatusChanged) + Q_PROPERTY(int exitCode READ exitCode NOTIFY exitCodeChanged) + + Q_PROPERTY(QString standardOutput READ standardOutput NOTIFY standardOutputChanged) + Q_PROPERTY(QString standardError READ standardError NOTIFY standardErrorChanged) + + Q_PROPERTY(QString inputCodec READ inputCodec WRITE setInputCodec) + Q_PROPERTY(QString outputCodec READ outputCodec WRITE setOutputCodec) + + Q_PROPERTY(OutputMode outputMode READ outputMode WRITE setOutputMode) + +public: + explicit QstLocalProcess(QObject *parent = 0); + + enum OutputMode { + DeviceOutput, + PropertyOutput + }; + + Q_INVOKABLE void start(const QString &program, const QStringList &arguments = QStringList()); + Q_INVOKABLE bool waitForStarted(int msecs); + Q_INVOKABLE bool waitForFinished(int msecs); + Q_INVOKABLE bool waitForReadyRead(int msecs); + Q_INVOKABLE void closeWriteChannel(); + + Q_INVOKABLE ProcessState state() const; + Q_INVOKABLE ExitStatus exitStatus() const; + Q_INVOKABLE int exitCode() const; + + Q_INVOKABLE void write(const QString &input); + + QString standardOutput() const { return m_stdoutBuffer; } + Q_INVOKABLE void clearStandardOutput() + { m_stdoutBuffer.clear(); emit standardOutputChanged(m_stdoutBuffer); } + + QString standardError() const { return m_stderrBuffer; } + Q_INVOKABLE void clearStandardError() + { m_stderrBuffer.clear(); emit standardErrorChanged(m_stderrBuffer); } + + QString inputCodec() const; + QString outputCodec() const; + void setInputCodec(const QString &); + void setOutputCodec(const QString &); + + OutputMode outputMode() const { return m_outputMode; } + void setOutputMode(OutputMode mode); + +signals: + void stateChanged(QProcess::ProcessState state); + void exitStatusChanged(QProcess::ExitStatus status); + void exitCodeChanged(int); + void standardOutputChanged(const QString &); + void standardErrorChanged(const QString &); + +private slots: + void forwardFinished(int code, QProcess::ExitStatus status) + { + emit exitStatusChanged(status); + emit exitCodeChanged(code); + } + + void updateOutputBuffer(); + void updateErrorBuffer(); + +private: + QTextCodec *m_inputCodec; + QTextCodec *m_outputCodec; + QTextDecoder *m_outputDecoder; + QTextDecoder *m_errorDecoder; + OutputMode m_outputMode; + + QString m_stdoutBuffer; + QString m_stderrBuffer; +}; + +#endif // QSTLOCALPROCESS_H diff --git a/src/interpreter/imports/qtsystemtest/src/qstutils.cpp b/src/interpreter/imports/qtsystemtest/src/qstutils.cpp new file mode 100644 index 0000000..c826094 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/src/qstutils.cpp @@ -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 QtSystemTest. +** +** $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 "qstutils.h" +#include <QtCore/QUrl> +#include <QtCore/QDir> + +QstUtils::QstUtils(QObject *parent) + : QObject(parent) +{ +} + diff --git a/src/interpreter/imports/qtsystemtest/src/qstutils.h b/src/interpreter/imports/qtsystemtest/src/qstutils.h new file mode 100644 index 0000000..46f68b3 --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/src/qstutils.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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$ +** +****************************************************************************/ + +#ifndef QSTUTILS_H +#define QSTUTILS_H + +#include <QObject> +class QUrl; +class QScriptValue; + +class QstUtils : public QObject +{ + Q_OBJECT +public: + explicit QstUtils(QObject *parent = 0); + +signals: + +public slots: + +}; + +#endif // QSTUTILS_H diff --git a/src/interpreter/imports/qtsystemtest/src/qtuitestglobal.h b/src/interpreter/imports/qtsystemtest/src/qtuitestglobal.h new file mode 100644 index 0000000..66a0cef --- /dev/null +++ b/src/interpreter/imports/qtsystemtest/src/qtuitestglobal.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of QtSystemTest. +** +** $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$ +** +****************************************************************************/ + + +#ifndef QTUITEST_GLOBAL_H +#define QTUITEST_GLOBAL_H + +#include <QtGlobal> + +#if defined(Q_OS_WIN32) +# if defined(QTUITEST_TARGET) +# define QTUITEST_EXPORT Q_DECL_EXPORT +# else +# define QTUITEST_EXPORT Q_DECL_IMPORT +# endif +# if defined(QTSLAVE_TARGET) +# define QTSLAVE_EXPORT Q_DECL_EXPORT +# else +# define QTSLAVE_EXPORT Q_DECL_IMPORT +# endif +#else +# define QTUITEST_EXPORT Q_DECL_EXPORT +# define QTSLAVE_EXPORT Q_DECL_EXPORT +#endif + +#if defined(Q_OS_WIN32) || defined(Q_OS_SYMBIAN) +# if defined(QSYSTEMTEST_TARGET) +# define QSYSTEMTEST_EXPORT Q_DECL_EXPORT +# else +# define QSYSTEMTEST_EXPORT Q_DECL_IMPORT +# endif +# if defined(QTUITESTRUNNER_TARGET) +# define QTUITESTRUNNER_EXPORT Q_DECL_EXPORT +# else +# define QTUITESTRUNNER_EXPORT Q_DECL_IMPORT +# endif +#else +# define QSYSTEMTEST_EXPORT Q_DECL_EXPORT +# define QTUITESTRUNNER_EXPORT Q_DECL_EXPORT +#endif + +#define xstr(s) str(s) +#define str(s) #s +#define QTUITEST_VERSION_STR xstr(QTUITEST_VERSION) + +#endif |