aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/imports/testlib/SignalSpy.qml24
-rw-r--r--src/imports/testlib/signalspy.qdoc22
-rw-r--r--tests/auto/qmltest/buttonclick/Button.qml4
-rw-r--r--tests/auto/qmltest/buttonclick/tst_buttonclick.qml12
4 files changed, 51 insertions, 11 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()
*/
diff --git a/tests/auto/qmltest/buttonclick/Button.qml b/tests/auto/qmltest/buttonclick/Button.qml
index e5adb9dfd9..723f1c6bee 100644
--- a/tests/auto/qmltest/buttonclick/Button.qml
+++ b/tests/auto/qmltest/buttonclick/Button.qml
@@ -46,7 +46,7 @@ Rectangle {
property string text: "Button"
- signal clicked
+ signal clicked(int x, int y)
width: buttonLabel.width + 20; height: buttonLabel.height + 5
border { width: 1; color: "black" }
@@ -62,7 +62,7 @@ Rectangle {
MouseArea {
id: mouseArea
anchors.fill: parent
- onClicked: container.clicked();
+ onClicked: container.clicked(mouse.x, mouse.y);
}
Text {
diff --git a/tests/auto/qmltest/buttonclick/tst_buttonclick.qml b/tests/auto/qmltest/buttonclick/tst_buttonclick.qml
index 6ecbfea450..840a7fd927 100644
--- a/tests/auto/qmltest/buttonclick/tst_buttonclick.qml
+++ b/tests/auto/qmltest/buttonclick/tst_buttonclick.qml
@@ -58,9 +58,19 @@ Button {
function test_click() {
compare(spy.count, 0)
- button.clicked();
+ button.clicked(1, 2);
compare(button.text, "Clicked");
compare(spy.count, 1)
+ compare(spy.signalArguments.length, 1)
+ compare(spy.signalArguments[0][0], 1)
+ compare(spy.signalArguments[0][1], 2)
+ verify(spy.valid)
+ spy.clear()
+ compare(spy.count, 0)
+ verify(spy.valid)
+ compare(spy.signalArguments.length, 0)
+ spy.signalName = ""
+ verify(!spy.valid)
}
}
}