~helene-verhaeghe27/cairo-dock-core/bugfix

« back to all changes in this revision

Viewing changes to tests/TestDesklet.py

  • Committer: Fabrice Rey
  • Date: 2013-07-02 23:03:16 UTC
  • Revision ID: fabounet03@gmail.com-20130702230316-v9b46bclt08yq7q6
Tests: added a test case for Desklets

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from time import sleep
 
2
import os  # system, path
 
3
from Test import Test, key, set_param
 
4
from CairoDock import CairoDock
 
5
import config
 
6
import subprocess
 
7
 
 
8
# Test Launcher
 
9
class TestDesklet(Test):
 
10
        def __init__(self, dock):
 
11
                self.applet = 'clock'
 
12
                Test.__init__(self, "Test desklet", dock)
 
13
        
 
14
        def run(self):
 
15
                
 
16
                # ensure the applet is running
 
17
                props = self.d.GetProperties('module='+self.applet)
 
18
                if len(props) == 0:
 
19
                        conf_file = self.d.Add({'type':'Module-Instance', 'module':self.applet})
 
20
                else:
 
21
                        conf_file = props[0]['config-file']
 
22
                
 
23
                # detach the applet
 
24
                set_param (conf_file, "Desklet", "initially detached", "true")
 
25
                self.d.Reload('type=Module-Instance & config-file='+conf_file)
 
26
                sleep(.3)
 
27
                
 
28
                props = self.d.GetProperties('type=Desklet & name='+self.applet)  # check that the desklet has been created
 
29
                if len(props) == 0:
 
30
                        self.print_error ("Failed to create the desklet")
 
31
                
 
32
                x_ini = props[0]['x']
 
33
                w_ini = props[0]['width']
 
34
                
 
35
                
 
36
                # move the desklet from the config
 
37
                x = x_ini - 50 if x_ini > 50 else x_ini + 50
 
38
                set_param (conf_file, "Desklet", "x position", str(x))
 
39
                self.d.Reload('type=Module-Instance & config-file='+conf_file)
 
40
                sleep(.3)
 
41
                
 
42
                props = self.d.GetProperties('type=Desklet & name='+self.applet)  # check that the desklet's position is correct
 
43
                x2 = props[0]['x']
 
44
                if x2 != x:
 
45
                        self.print_error ("Failed to move the desklet (%d/%d)" % (x2, x))
 
46
                
 
47
                # move the desklet manually
 
48
                os.system('xdotool search --name '+self.applet+' windowmove 100 100')
 
49
                sleep(.8)  # wait until the desklet has moved and the desklet manager has written the new position in the config file
 
50
                
 
51
                props = self.d.GetProperties('type=Desklet & name='+self.applet)  # check that the desklet's position is correct
 
52
                x = props[0]['x']
 
53
                y = props[0]['y']
 
54
                if x != 100 or y != 100:
 
55
                        self.print_error ("Failed to move the desklet manually (%d/%d)" % (x, y))
 
56
                res = subprocess.call(['grep', 'x position *= *100', str(conf_file)])  # check that the new position has been written in conf
 
57
                if res != 0:
 
58
                        self.print_error ("Failed to move the desklet manually")
 
59
                
 
60
                
 
61
                # resize the desklet from the config
 
62
                w = w_ini + 10
 
63
                set_param (conf_file, "Desklet", "size", str(w)+';'+str(w))
 
64
                self.d.Reload('type=Module-Instance & config-file='+conf_file)
 
65
                sleep(1.0)  # wait until the desklet has resized and the desklet manager has updated the desklet
 
66
                
 
67
                props = self.d.GetProperties('type=Desklet & name='+self.applet)  # check that the desklet's size is correct
 
68
                w2 = props[0]['width']
 
69
                if w2 != w:
 
70
                        self.print_error ("Failed to resize the desklet (%d/%d)" % (w2, w))
 
71
                
 
72
                # resize the desklet manually
 
73
                os.system('xdotool search --name '+self.applet+' windowsize 100 100')
 
74
                sleep(1.0)  # wait until the desklet has resized and the desklet manager has written the new size in the config file
 
75
                
 
76
                props = self.d.GetProperties('type=Desklet & name='+self.applet)  # check that the desklet's size is correct
 
77
                w = props[0]['width']
 
78
                h = props[0]['height']
 
79
                if w != 100 or h != 100:
 
80
                        self.print_error ("Failed to resize the desklet manually (%d/%d)" % (w, h))
 
81
                res = subprocess.call(['grep', 'size *= *100;100', str(conf_file)])  # check that the new size has been written in conf
 
82
                if res != 0:
 
83
                        self.print_error ("Failed to resize the desklet manually")
 
84
                
 
85
                
 
86
                # just for fun ^^
 
87
                for i in range(0,361,15):
 
88
                        set_param(conf_file, 'Desklet', 'rotation', i)
 
89
                        self.d.Reload('type=Module-Instance & config-file='+conf_file)
 
90
                
 
91
                # re-attach the applet
 
92
                set_param (conf_file, "Desklet", "initially detached", "false")
 
93
                self.d.Reload('type=Module-Instance & config-file='+conf_file)
 
94
                
 
95
                props = self.d.GetProperties('type=Desklet & name='+self.applet)  # check that the desklet has been destroyed
 
96
                if len(props) != 0:
 
97
                        self.print_error ("Failed to destroy the desklet")
 
98
                
 
99
                self.end()