on xenial help sign in
Make tests a bit more stable

findChild is now stubborn and will try for a bit more before returning a null child Approved by: Andrea Cimitan, Unity8 CI Bot

commitb3acd66a56002daf3a99a8623142d365e48334ba authorAlbert Astals Cid <albert.astals@canonical.com> dateFri 27 May 2016, 13:54 (10 years ago) parent7da665e80b1544
11 files changed+40−19
tests/mocks/GSettings.1.0/fake_gsettings.cpp+1 tests/mocks/IntegratedLightDM/liblightdm/GreeterPrivate.h−1 tests/mocks/Ubuntu/Payments/MockPayments.cpp+1 tests/mocks/Unity/Application/MirSurfaceItem.cpp+1 tests/mocks/libusermetrics/UserMetrics.cpp+1−1 tests/plugins/Unity/Indicators/MenuContentActivatorTest.cpp+1 tests/qmltests/Dash/Previews/tst_PreviewWidgetFactory.qml+1−1 tests/qmltests/Dash/tst_Card.qml+10−10 tests/qmltests/Dash/tst_CardTool.qml+1−1 tests/uqmlscene/main.cpp−1 tests/utils/modules/Unity/Test/UnityTestCase.qml+23−4
tests/mocks/GSettings.1.0/fake_gsettings.cpp+1
@@ -22,6 +22,7 @@ GSettingsControllerQml* GSettingsControllerQml::s_controllerInstance = 0;
2222
2323GSettingsControllerQml::GSettingsControllerQml()
2424 : m_disableHeight(false)
25+ , m_lockedOutTime(0)
2526 , m_usageMode("Staged")
2627 , m_autohideLauncher(false)
2728 , m_launcherWidth(8)
tests/mocks/IntegratedLightDM/liblightdm/GreeterPrivate.h−1
@@ -41,7 +41,6 @@ public:
4141 void handleRespond(const QString &response);
4242
4343protected:
44− GreeterImpl *m_impl; // if the backend needs more private data
4544 Greeter * const q_ptr;
4645
4746private:
tests/mocks/Ubuntu/Payments/MockPayments.cpp+1
@@ -21,6 +21,7 @@
2121
2222MockPayments::MockPayments(QObject *parent)
2323 : QObject(parent)
24+ , m_price(0)
2425{
2526}
2627
tests/mocks/Unity/Application/MirSurfaceItem.cpp+1
@@ -40,6 +40,7 @@ using namespace unity::shell::application;
4040MirSurfaceItem::MirSurfaceItem(QQuickItem *parent)
4141 : MirSurfaceItemInterface(parent)
4242 , m_qmlSurface(nullptr)
43+ , m_qmlContentComponent(nullptr)
4344 , m_qmlItem(nullptr)
4445 , m_consumesInput(false)
4546 , m_surfaceWidth(0)
tests/mocks/libusermetrics/UserMetrics.cpp+1−1
@@ -220,7 +220,7 @@ int UserMetricsData::length() const
220220}
221221
222222UserMetricsPrivate::UserMetricsPrivate(UserMetrics *parent) :
223− q_ptr(parent), m_firstColor(this), m_secondColor(this)
223+ q_ptr(parent), m_firstColor(this), m_secondColor(this), m_currentDay(0)
224224{
225225 m_fakeData.insert("", UserMetricsDataPtr(new UserMetricsData(this)));
226226}
tests/plugins/Unity/Indicators/MenuContentActivatorTest.cpp+1
@@ -28,6 +28,7 @@ class FakeTimer : public UnityIndicators::AbstractTimer
2828public:
2929 FakeTimer(QObject *parent = 0)
3030 : UnityIndicators::AbstractTimer(parent)
31+ , m_duration(0)
3132 {}
3233
3334 int interval() const override { return m_duration; }
tests/qmltests/Dash/Previews/tst_PreviewWidgetFactory.qml+1−1
@@ -43,7 +43,7 @@ Rectangle {
4343 name: "PreviewWidgetFactory"
4444 when: windowShown
4545
46− property Item mockWidget: findChild(factory, "mockPreviewWidget")
46+ property Item mockWidget: findChild(factory, "mockPreviewWidget", 0 /*timeout*/)
4747
4848 function cleanup() {
4949 factory.source = Qt.binding(function() { return factory.widgetSource });
tests/qmltests/Dash/tst_Card.qml+10−10
@@ -226,16 +226,16 @@ Rectangle {
226226
227227 when: windowShown
228228
229− property Item title: findChild(loader, "titleLabel")
230− property Item subtitle: findChild(loader, "subtitleLabel")
231− property var headerRow: findChild(loader, "outerRow")
232− property var art: findChild(loader, "artShape")
233− property Item artImage: findChild(loader, "artImage")
234− property Item summary: findChild(loader, "summaryLabel")
235− property Item background: findChild(loader, "background")
236− property Item backgroundLoader: findChild(loader, "backgroundLoader")
237− property Item backgroundImage: findChild(loader, "backgroundImage")
238− property Item mascotImage: findChild(loader, "mascotImage");
229+ property Item title: findChild(loader, "titleLabel", 0 /*timeout*/)
230+ property Item subtitle: findChild(loader, "subtitleLabel", 0 /*timeout*/)
231+ property var headerRow: findChild(loader, "outerRow", 0 /*timeout*/)
232+ property var art: findChild(loader, "artShape", 0 /*timeout*/)
233+ property Item artImage: findChild(loader, "artImage", 0 /*timeout*/)
234+ property Item summary: findChild(loader, "summaryLabel", 0 /*timeout*/)
235+ property Item background: findChild(loader, "background", 0 /*timeout*/)
236+ property Item backgroundLoader: findChild(loader, "backgroundLoader", 0 /*timeout*/)
237+ property Item backgroundImage: findChild(loader, "backgroundImage", 0 /*timeout*/)
238+ property Item mascotImage: findChild(loader, "mascotImage", 0 /*timeout*/)
239239
240240 function init() {
241241 cardTool.components = Qt.binding(function() { return Helpers.update(JSON.parse(Helpers.defaultLayout), Helpers.tryParse(layoutArea.text, layoutError))['components']; });
tests/qmltests/Dash/tst_CardTool.qml+1−1
@@ -240,7 +240,7 @@ Rectangle {
240240 id: testCase
241241 name: "CardTool"
242242
243− property var internalCard: findChild(cardTool, "cardToolCard")
243+ property var internalCard: findChild(cardTool, "cardToolCard", 0 /*timeout*/)
244244
245245 when: windowShown
246246
tests/uqmlscene/main.cpp−1
@@ -159,7 +159,6 @@ struct Options
159159 bool maximized;
160160 bool fullscreen;
161161 bool transparent;
162− bool scenegraphOnGraphicsview;
163162 bool clip;
164163 bool versionDetection;
165164 bool quitImmediately;
tests/utils/modules/Unity/Test/UnityTestCase.qml+23−4
@@ -176,11 +176,11 @@ TestCase {
176176
177177
178178 // Find an object with the given name in the children tree of "obj"
179− function findChild(obj, objectName) {
179+ function findChild(obj, objectName, timeout) {
180180 if (!obj)
181181 qtest_fail("no obj given", 1);
182182
183− return findChildIn(obj, "children", objectName);
183+ return findChildInWithTimeout(obj, "children", objectName, timeout);
184184 }
185185
186186 // Find an object with the given name in the children tree of "obj"
@@ -188,11 +188,30 @@ TestCase {
188188 // Note: you should use findChild if you're not sure you need this
189189 // as this tree is much bigger and might contain stuff that goes
190190 // away randomly.
191− function findInvisibleChild(obj, objectName) {
191+ function findInvisibleChild(obj, objectName, timeout) {
192192 if (!obj)
193193 qtest_fail("no obj given", 1);
194194
195− return findChildIn(obj, "data", objectName);
195+ return findChildInWithTimeout(obj, "data", objectName, timeout);
196+ }
197+
198+ // Find a child in the named property with timeout
199+ function findChildInWithTimeout(obj, prop, objectName, timeout) {
200+ if (!obj)
201+ qtest_fail("no obj given", 1);
202+
203+ var timeSpent = 0
204+ if (timeout === undefined)
205+ timeout = 5000;
206+
207+ var child = findChildIn(obj, prop, objectName);
208+
209+ while (timeSpent < timeout && !child) {
210+ wait(50)
211+ timeSpent += 50
212+ child = findChildIn(obj, prop, objectName);
213+ }
214+ return child;
196215 }
197216
198217 // Find a child in the named property