aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@digia.com>2014-07-02 09:53:00 +0200
committerLiang Qi <liang.qi@digia.com>2014-07-04 23:10:32 +0200
commit97cd2af9ac4c9b516ddf7ed19041041444b5f5e0 (patch)
treeb737817f91d558bcf96098bf65313ad7cd5b8055 /src
parent92658ebb755bda136a7e4fa455b8d116c2dd0c6f (diff)
Add findChild to TestCase.
This is useful for auto tests where it's necessary to have access to dynamically created child items. For example: property Component threeItemDelegate: Text { objectName: "delegate" + styleData.index text: styleData.value } ... function test_stuff() { ... var delegate0 = findChild(item, "delegate0"); // check delegate0 for some condition... } [ChangeLog][QtTest][TestCase] Added findChild function to TestCase. Change-Id: I04a8b07c9904768c07ec12f4b03f1afb1989e054 Reviewed-by: Liang Qi <liang.qi@digia.com> Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/imports/testlib/TestCase.qml15
-rw-r--r--src/qmltest/quicktestresult.cpp6
-rw-r--r--src/qmltest/quicktestresult_p.h2
3 files changed, 23 insertions, 0 deletions
diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml
index 37addd1d7d..f946a4eef3 100644
--- a/src/imports/testlib/TestCase.qml
+++ b/src/imports/testlib/TestCase.qml
@@ -638,6 +638,21 @@ Item {
}
/*!
+ \since 5.4
+ \qmlmethod QtObject TestCase::findChild(parent, objectName)
+
+ Returns the first child of \a parent with \a objectName,
+ or \c null if no such item exists. Children are searched recursively.
+
+ \code
+ compare(findChild(item, "childObject"), expectedChildObject);
+ \endcode
+ */
+ function findChild(parent, objectName) {
+ return qtest_results.findChild(parent, objectName);
+ }
+
+ /*!
\qmlmethod TestCase::tryCompare(obj, property, expected, timeout = 5000, message = "")
Fails the current test case if the specified \a property on \a obj
diff --git a/src/qmltest/quicktestresult.cpp b/src/qmltest/quicktestresult.cpp
index a1686459a5..ab37be3c95 100644
--- a/src/qmltest/quicktestresult.cpp
+++ b/src/qmltest/quicktestresult.cpp
@@ -694,6 +694,12 @@ QObject *QuickTestResult::grabImage(QQuickItem *item)
}
return 0;
}
+
+QObject *QuickTestResult::findChild(QObject *parent, const QString &objectName)
+{
+ return parent ? parent->findChild<QObject*>(objectName) : 0;
+}
+
namespace QTest {
void qtest_qParseArgs(int argc, char *argv[], bool qml);
};
diff --git a/src/qmltest/quicktestresult_p.h b/src/qmltest/quicktestresult_p.h
index 4639c1b776..45165ca295 100644
--- a/src/qmltest/quicktestresult_p.h
+++ b/src/qmltest/quicktestresult_p.h
@@ -147,6 +147,8 @@ public Q_SLOTS:
QObject *grabImage(QQuickItem *item);
+ QObject *findChild(QObject *parent, const QString &objectName);
+
public:
// Helper functions for the C++ main() shell.
static void parseArgs(int argc, char *argv[]);