on xenial help sign in
Introduce a findChildIn method, as some objects are not to be found in either children or data.
4be4517Michał Sawicz
tests/utils/modules/Unity/Test/UnityTestCase.qml+10−16
@@ -71,19 +71,8 @@ TestCase {
71
71
72
72
73 // Find an object with the given name in the children tree of "obj"
73 // Find an object with the given name in the children tree of "obj"
74− function findChild(obj,objectName) {
74+ function findChild(obj, objectName) {
75− var childs = new Array(0);
75+ return findChildIn(obj, "children", objectName);
76− childs.push(obj)
77− while (childs.length > 0) {
78− if (childs[0].objectName == objectName) {
79− return childs[0]
80− }
81− for (var i in childs[0].children) {
82− childs.push(childs[0].children[i])
83− }
84− childs.splice(0, 1);
85− }
86− return null;
87 }
76 }
88
77
89 // Find an object with the given name in the children tree of "obj"
78 // Find an object with the given name in the children tree of "obj"
@@ -91,15 +80,20 @@ TestCase {
91 // Note: you should use findChild if you're not sure you need this
80 // Note: you should use findChild if you're not sure you need this
92 // as this tree is much bigger and might contain stuff that goes
81 // as this tree is much bigger and might contain stuff that goes
93 // away randomly.
82 // away randomly.
94− function findInvisibleChild(obj,objectName) {
83+ function findInvisibleChild(obj, objectName) {
84+ return findChildIn(obj, "data", objectName);
85+ }
86+
87+ // Find a child in the named property
88+ function findChildIn(obj, prop, objectName) {
95 var childs = new Array(0);
89 var childs = new Array(0);
96 childs.push(obj)
90 childs.push(obj)
97 while (childs.length > 0) {
91 while (childs.length > 0) {
98 if (childs[0].objectName == objectName) {
92 if (childs[0].objectName == objectName) {
99 return childs[0]
93 return childs[0]
100 }
94 }
101− for (var i in childs[0].data) {
95+ for (var i in childs[0][prop]) {
102− childs.push(childs[0].data[i])
96+ childs.push(childs[0][prop][i])
103 }
97 }
104 childs.splice(0, 1);
98 childs.splice(0, 1);
105 }
99 }