~ubuntu-sdk-team/ubuntu-ui-toolkit/orientationManual

« back to all changes in this revision

Viewing changes to tests/unit_x11/tst_components/tst_stress_alarmmodel.qml

  • Committer: CI Train Bot
  • Author(s): Leo Arias, Christian Dywan, Nekhelesh Ramananthan, Tim Peeters, Zoltán Balogh
  • Date: 2015-03-27 12:35:52 UTC
  • mfrom: (1000.433.19 last_bugfix_vivid)
  • Revision ID: ci-train-bot@canonical.com-20150327123552-mdwg6mecr05akf0q
The very last bugfix landing for Vivid

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.0
 
18
import QtTest 1.0
 
19
import Ubuntu.Test 1.0
 
20
import Ubuntu.Components 1.2
 
21
 
 
22
MainView {
 
23
    width: units.gu(40)
 
24
    height: units.gu(71)
 
25
 
 
26
    AlarmModel {
 
27
        id: model
 
28
    }
 
29
 
 
30
    Alarm {
 
31
        id: testAlarm
 
32
    }
 
33
 
 
34
    UbuntuTestCase {
 
35
        name: "AlarmModelStressTest"
 
36
        when: windowShown
 
37
 
 
38
        SignalSpy {
 
39
            id: modelSpy
 
40
            signalName: "modelReset"
 
41
            target: model
 
42
        }
 
43
 
 
44
        property string testAlarmMessage: "test_"
 
45
 
 
46
        function createAlarm(pattern, idx) {
 
47
            testAlarm.reset();
 
48
            testAlarm.message = pattern + idx;
 
49
            var dt = new Date();
 
50
            dt.setMinutes(dt.getMinutes() + 10);
 
51
            testAlarm.date = dt;
 
52
            modelSpy.signalName = "rowsInserted";
 
53
            testAlarm.save();
 
54
            modelSpy.wait();
 
55
        }
 
56
 
 
57
        function clearTestAlarms(pattern) {
 
58
            var i = 0;
 
59
            modelSpy.signalName = "rowsRemoved";
 
60
            while (i < model.count) {
 
61
                var alarm = model.get(i);
 
62
                // this will fail if get() returns NULL
 
63
                if (alarm.message.indexOf(pattern) == 0) {
 
64
                    alarm.cancel();
 
65
                    modelSpy.wait();
 
66
                    modelSpy.clear();
 
67
                    i = 0;
 
68
                } else {
 
69
                    i++;
 
70
                }
 
71
            }
 
72
        }
 
73
 
 
74
        // need to create a huge amount of alarms then cleanone part of it
 
75
        function initTestCase() {
 
76
            for (var i = 0; i < 20; i++) {
 
77
                createAlarm(testAlarmMessage, i)
 
78
            }
 
79
            for (var i = 0; i < 40; i++) {
 
80
                createAlarm("testAlarm_", i)
 
81
            }
 
82
        }
 
83
        function cleanupTestCase() {
 
84
            clearTestAlarms(testAlarmMessage);
 
85
        }
 
86
 
 
87
        function test_remove_alarms()
 
88
        {
 
89
            clearTestAlarms("testAlarm_");
 
90
        }
 
91
    }
 
92
}