~paulliu/unity8/lp1378469_MessageMenu

« back to all changes in this revision

Viewing changes to tests/qmltests/Greeter/tst_Clock.qml

  • Committer: Michał Sawicz
  • Date: 2013-06-05 22:03:08 UTC
  • Revision ID: michal.sawicz@canonical.com-20130605220308-yny8fv3futtr04fg
Inital unity8 commit.

Previous history can be found at https://code.launchpad.net/~unity-team/unity/phablet

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 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 General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU 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 ".."
 
20
import "../../../Greeter"
 
21
import Ubuntu.Components 0.1
 
22
import Unity.Test 0.1 as UT
 
23
 
 
24
Rectangle {
 
25
    width: units.gu(60)
 
26
    height: units.gu(40)
 
27
    color: "black"
 
28
 
 
29
    Clock {
 
30
        id: clock
 
31
        anchors {
 
32
            top: parent.top
 
33
            topMargin: units.gu(2)
 
34
            horizontalCenter: parent.horizontalCenter
 
35
        }
 
36
    }
 
37
 
 
38
    UT.UnityTestCase {
 
39
        name: "Clock"
 
40
 
 
41
        function test_customDate() {
 
42
            var dateObj = new Date("October 13, 1975 11:13:00")
 
43
            var dateString = Qt.formatDate(dateObj, Qt.DefaultLocaleLongDate)
 
44
            var timeString = Qt.formatTime(dateObj)
 
45
 
 
46
            clock.__timerInterval = 60000
 
47
            clock.__date = dateObj
 
48
            var dateLabel = findChild(clock, "dateLabel")
 
49
            compare(dateLabel.text, dateString, "Not the expected date")
 
50
            var timeLabel = findChild(clock, "timeLabel")
 
51
            compare(timeLabel.text, timeString, "Not the expected time")
 
52
        }
 
53
 
 
54
        function test_dateUpdate() {
 
55
            var dateObj = new Date("October 13, 1975 11:13:00")
 
56
            var dateString = Qt.formatDate(dateObj, Qt.DefaultLocaleLongDate)
 
57
            var timeString = Qt.formatTime(dateObj)
 
58
 
 
59
            clock.enabled = false
 
60
            compare(clock.__timerRunning, false, "Timer should not be running")
 
61
            clock.__date = dateObj
 
62
            clock.__timerInterval = 5
 
63
            wait(5) // spin event loop (only that would trigger the timer and reveal eventual bugs)
 
64
            var dateLabel = findChild(clock, "dateLabel")
 
65
            compare(dateLabel.text, dateString, "Not the expected date")
 
66
            var timeLabel = findChild(clock, "timeLabel")
 
67
            compare(timeLabel.text, timeString, "Not the expected time")
 
68
 
 
69
            clock.enabled = true
 
70
            compare(clock.__timerRunning, true, "Timer should be running")
 
71
            wait(0) // spin event loop to trigger the timer
 
72
            verify(dateLabel.text !== dateString)
 
73
            if (timeLabel.text == "11:13") wait(60000) // next test will fail at 11:13, wait 1 minute
 
74
            verify(timeLabel.text !== timeString)
 
75
        }
 
76
 
 
77
        function test_timerRunning() {
 
78
            // tests for clock.enabled property are already in test_dateUpdate()
 
79
            clock.opacity = 0.0
 
80
            compare(clock.__timerRunning, false, "Timer should not be running")
 
81
            clock.opacity = 1.0
 
82
            compare(clock.__timerRunning, true, "Timer should be running")
 
83
            clock.visible = false
 
84
            compare(clock.__timerRunning, false, "Timer should not be running")
 
85
            clock.visible = true
 
86
            compare(clock.__timerRunning, true, "Timer should be running")
 
87
        }
 
88
    }
 
89
}