public
Description: Dissertacao de mestrado
Homepage:
Clone URL: git://github.com/briglia/dissertacao.git
Anderson Briglia (author)
Tue Apr 28 17:36:53 -0700 2009
dissertacao / utilities / test-canola.py
100644 150 lines (129 sloc) 4.089 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin.python
#
# Copyright (c) 2009 - Anderson Farias Briglia
# <anderson.briglia@gmail.com>
#
# This file is part of carman-python.
#
# carman-python is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# carman-python is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
 
import time
from os import system
 
 
BT_Y = 222 # Since they are in horizontal, y is the same
BT_OFFSET = 150 # Position offset
 
'''
Positions for main buttons when they are in even layout
'''
EV_FIRST_BT_X = 170 # X position for first bt
AUDIO_BT = 0
PHOTOS_BT = 1
VIDEOS_BT = 2
SETT_BT = 3
MY_PHOTOS_BT = 1
MY_VIDEOS_BT = 1
 
'''
Positions for buttons when they are in uneven layout
'''
UNEV_FIRST_BT_X = 248
MY_MUSIC_BT = 0
PODCASTS_BT = 1
RADIO_BT = 2
 
class TestCanola:
 
    def __init__(self):
        self.__steps = []
 
    def click(self, pos, sleep):
        cmd = ("xte -x :0.0 'mousemove " + str(pos[0]) + " " + str(pos[1]) + "' 'mouseclick 1'", sleep)
        self.add_step(cmd)
 
    def click_back(self):
        '''
        Click back button.
        '''
        self.click((45, 455), 3)
 
    def click_bt(self, button, first_bt_pos):
        '''
        Click buttons presented in main window.
        '''
        x = (button * BT_OFFSET) + first_bt_pos
        self.click((x, BT_Y), 3)
 
    def click_list(self, pos):
        '''
        Click in a list position
        Since just seven elements are showed each time, pos must be
        checked against these values. This method does not implement
        list rolling.
        '''
        if (pos >= 0) and (pos < 7):
            self.click((160, 68 + (pos * 63)), 3)
 
    def play_pause_music(self):
        self.click((759, 227), 2);
 
    def photo_click(self, photo):
        '''
        photo = photo number, starting in 0.
        '''
        x1 = 58
        y1 = 118
        x_offset = 146
        y_offset = 115
        if photo < 5:
            self.click(x1 + (photo * x_offset), y1)
        elif (photo >= 5) and (photo < 10):
            self.click((x1 + ((photo - 6) * x_offset), y1 + y_offset), 4)
        elif (photo >= 10) and (photo < 15):
            self.click((x1 + ((photo - 11) * x_offset), y1 + (2 * y_offset)), 4)
 
    def click_yes(self):
        self.click((508, 297), 2)
 
    def add_delay(self, delay):
        self.add_step(('', delay))
 
    def add_step(self, cmd):
        self.__steps.append(cmd)
 
    def play_steps(self):
        '''
        Run each command stored in self.__steps.
        Uses time.sleep() to make an interval between each command.
        '''
        for cmd in self.__steps:
            #print cmd
            if cmd[0] != '':
                system(cmd[0])
            time.sleep(cmd[1])
 
    def begin_test(self):
        # Playing a music
        self.click_bt(AUDIO_BT, EV_FIRST_BT_X)
        self.click_bt(MY_MUSIC_BT, UNEV_FIRST_BT_X)
        self.click_list(0)
        self.click_list(1)
        self.add_delay(10)
        self.play_pause_music()
        self.click_back()
        self.click_back()
        self.click_back()
        self.click_back()
        #Opening a photo
        self.click_bt(PHOTOS_BT, EV_FIRST_BT_X)
        self.click_bt(MY_PHOTOS_BT, EV_FIRST_BT_X)
        self.click_list(0)
        self.photo_click(6)
        self.click_back()
        self.click_back()
        self.click_back()
        self.click_back()
        # End
        self.click_back()
        self.click_yes()
        self.play_steps()
 
if __name__ == '__main__':
    print 'Initializing tests...'
    test = TestCanola()
    test.begin_test()
    print 'Test finished...'