diff options
author | Charles Yin <charles.yin@nokia.com> | 2012-03-22 12:27:30 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-01 06:06:55 +0200 |
commit | 7cecad76b6a8beb31c74111b986be0e67bb2e15c (patch) | |
tree | 3db17684e3b0b29a11e75c206878a6b1fef708a1 /src/imports | |
parent | 0949071f13e7bcbc16a0f07f496e0b6a23b04edd (diff) |
Consolidate SignalSpy item
1. Add signalArguments to track emitted signal parameters
2. Add valid property to track signal connection status
3. Make count, valid, signalArguments read only properties
Task-number: QTBUG-18531
Change-Id: I08e99c1086786a0e5095bf0d04750dec33153fde
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Diffstat (limited to 'src/imports')
-rw-r--r-- | src/imports/testlib/SignalSpy.qml | 24 | ||||
-rw-r--r-- | src/imports/testlib/signalspy.qdoc | 22 |
2 files changed, 38 insertions, 8 deletions
diff --git a/src/imports/testlib/SignalSpy.qml b/src/imports/testlib/SignalSpy.qml index 539cb178f5..a3c5111c53 100644 --- a/src/imports/testlib/SignalSpy.qml +++ b/src/imports/testlib/SignalSpy.qml @@ -49,16 +49,17 @@ Item { TestUtil { id: util } - // Public API. - property var target: null property string signalName: "" - property int count: 0 + readonly property alias count: spy.qtest_count + readonly property alias valid:spy.qtest_valid + readonly property alias signalArguments:spy.qtest_signalArguments function clear() { - count = 0 + qtest_count = 0 qtest_expectedCount = 0 + qtest_signalArguments = [] } function wait(timeout) { @@ -66,11 +67,11 @@ Item { timeout = 5000 var expected = ++qtest_expectedCount var i = 0 - while (i < timeout && count < expected) { + while (i < timeout && qtest_count < expected) { qtest_results.wait(50) i += 50 } - var success = (count >= expected) + var success = (qtest_count >= expected) if (!qtest_results.verify(success, "wait for signal " + signalName, util.callerFile(), util.callerLine())) throw new Error("QtQuickTest::fail") } @@ -89,6 +90,9 @@ Item { property var qtest_prevTarget: null property string qtest_prevSignalName: "" property int qtest_expectedCount: 0 + property var qtest_signalArguments:[] + property int qtest_count: 0 + property bool qtest_valid:false function qtest_update() { if (qtest_prevTarget != null) { @@ -101,16 +105,22 @@ Item { if (target != null && signalName != "") { var func = target[signalName] if (func === undefined) { + spy.qtest_valid = false console.log("Signal '" + signalName + "' not found") } else { qtest_prevTarget = target qtest_prevSignalName = signalName func.connect(spy.qtest_activated) + spy.qtest_valid = true + spy.qtest_signalArguments = [] } + } else { + spy.qtest_valid = false } } function qtest_activated() { - ++count + ++qtest_count + spy.qtest_signalArguments[spy.qtest_signalArguments.length] = arguments } } diff --git a/src/imports/testlib/signalspy.qdoc b/src/imports/testlib/signalspy.qdoc index cdf6637918..504ab8de5e 100644 --- a/src/imports/testlib/signalspy.qdoc +++ b/src/imports/testlib/signalspy.qdoc @@ -94,18 +94,38 @@ */ /*! + \qmlproperty list SignalSpy::signalArguments + + This property holds a list of emitted signal arguments. Each emission of the signal will append one item to the list, containing the arguments of the signal. + When connecting to a new \l target or new \l signalName or calling the \l clear() method, the \l signalArguments will be reset to empty. + + \sa signalName, clear() + \readonly +*/ + +/*! + \qmlproperty bool SignalSpy::valid + + This property defines the current signal connection status. It will be true when the \l signalName of the \l target is connected successfully, otherwise it will be false. + + \sa count, target, signalName, clear() + \readonly +*/ + +/*! \qmlproperty int SignalSpy::count This property defines the number of times that \l signalName has been emitted from \l target since the last call to clear(). \sa target, signalName, clear() + \readonly */ /*! \qmlmethod SignalSpy::clear() - Clears \l count to 0. + Clears \l count to 0, resets \l valid to false and clears the \l signalArguments to empty. \sa count, wait() */ |