]> www.fi.muni.cz Git - evince.git/blob - test/test-print-combinations.py
[dualscreen] fix crash on ctrl+w and fix control window closing
[evince.git] / test / test-print-combinations.py
1 #!/usr/bin/python
2
3 # Test various print setting combinations
4 # To run this successfully you need to make some preparations. First of all,
5 # you need to open evince and make sure that:
6 #  * the printer is set to "Print to File"
7 # (I think) we are unable to select the "Print to File" line from the table
8
9 import os
10 # i'm note sure why this is required but it seems to break i18n if it is not commented out
11 # os.environ['LANG']='C'
12 homedir = os.environ["HOME"] + "/";
13
14 from dogtail.procedural import *
15 import dogtail.tree
16 import dogtail.predicate
17
18 #~ uncommenting the import and load below should enable you to run this on any language
19 #~ If you are testing a different language than English run the test like so:
20 #~ LANG=xx_XX.YYY ./test-print-combinations.py
21
22 # import dogtail.i18n
23 # dogtail.i18n.loadTranslationsFromPackageMoFiles('evince')
24
25 #~ test setting lists: customize these to your liking, the comment above each
26 #~ displays possible AND/OR default values
27
28 #~ copies = [1,2,3,4,....,n]  # does not need to be sequential
29 copies = [3,1]
30
31 #~ collate [0,1]
32 collate = [1,0]
33
34 #~ reverse = [0,1]
35 reverse = [1,0]
36
37 #~ pages_per_sheet = [1,2,4,6,9,16]
38 pages_per_sheet = [1,4,9]
39
40 #~ only_print = ["All sheets","Even sheets","Odd sheets"]
41 only_print = ["All sheets","Even sheets","Odd sheets"]
42
43 #~ output_type = ["pdf","ps"]
44 output_type = ["pdf"]
45
46 #~ if you prepare more test documents with different numbers of pages, 
47 #~ you can add them here, the test documents must be saved as n-page.pdf
48 #~ where n stands for the number of pages
49
50 #~ pages_in_document = [3,4]
51 pages_in_document = [3,4]
52
53 # all pages in a document, an even range, an odd range
54 #~ ranges = ["all","1-3,2-3,1","1-2,2-3,1-3"]
55 ranges = ["all","1-3,2-3,1","1-2,2-3,1-3"]
56
57 counter = 0
58 # estimate number of iterations the test will require, this will be lower because we don't run (col == 1 && cop == 1)
59 n_tests = len(copies) * len(collate) * len(reverse) * len(pages_per_sheet) * len(only_print) * len(output_type) * len(pages_in_document) * len(ranges)
60
61 #~ function: build_filename
62 def build_filename( pages, cop, pps, col, rev, rng, op, ot ):
63         result = "pid_" + str(pages) + "_cop_" + str(cop) + "_pps_" + str(pps) + "_col_" + str(col) + "_rev_" + str(rev)
64
65         result += "_sheets"             
66         if op == "All sheets":
67                 result += "_all"
68         elif op == "Even sheets":
69                 result += "_even"
70         else:
71                 result += "_odd"
72         
73         result += "_rng"        
74         if rng == "all":
75                 result += "_all"
76         elif rng == "1-3,2-3,1":
77                 result += "_even"
78         else:
79                 result += "_odd"
80
81         result += "."
82         result += str(ot)
83         return result
84 #~ ///function: build_filename
85
86
87
88 #~ function: run_test
89 def run_test( pages, cop, pps, col, rev, rng, op, ot ):
90         filename = build_filename( pages, cop, pps, col, rev, rng, op, ot )
91
92         #~ we don't want the "file exists" dialog to pop up:
93         #~ delete the file if it already exists, potentially dangerous if filename
94         #~ is zero so we check for nonzero length at least
95         if ( os.path.exists(homedir + filename) and (len(filename) != 0) ):
96                 os.unlink(homedir + filename)
97
98         evince = tree.root.application('evince')
99         
100         click('File', roleName='menu')
101         click('Print...', roleName='menu item')
102         
103         dlg = evince.dialog('Print')
104         
105         #~ This doesn't work, even if rewritten as in test6.py or test7.py
106         #~ click(name='Print to File', roleName='table cell', raw=True)
107         
108         focus.widget(roleName='page tab', name='General')
109         focus.widget.node.select()
110         
111         dlg.child( roleName='text' ).text = filename
112         
113         if ot == "pdf":
114                 click('PDF', roleName='radio button')
115         else:
116                 click('Postscript', roleName='radio button')
117                 
118         
119         if rng == "all":
120                 click('All Pages', roleName='radio button')
121         else:
122                 click('Pages:', roleName='radio button')
123                 dlg.child('Pages', roleName='text').text = rng
124         
125         
126         sb_copies = dlg.child( roleName='spin button' )
127         sb_copies.text = str(cop)
128         # activate must be called to actualize the new setting
129         sb_copies.doAction("activate")
130         
131         
132         cb_reverse = dlg.child('Reverse', roleName='check box')
133         if (rev == 1 and cb_reverse.checked == False):
134                 cb_reverse.click()
135         elif (rev == 0 and cb_reverse.checked == True):
136                 cb_reverse.click()
137         
138         cb_collate = dlg.child('Collate', roleName='check box')
139         if (col == 1 and cb_collate.checked == False):
140                 cb_collate.click()
141         elif (col == 0 and cb_collate.checked == True):
142                 cb_collate.click()
143                 
144         focus.widget(roleName='page tab', name='Page Setup')
145         focus.widget.node.select()
146         
147         #~ Set pages per sheet:
148         #~ This will break at some point if there is more than one numeric combo box
149         #~ it will also not work for languages with other numerals
150         #~ The for loops here are necessary because the name of these combo boxes
151         #~ is based on their current value and they have no 'label' attribute
152         
153         # Redefining this here so that changing pages_per_sheet above does not affect our search
154         local_pages_per_sheet = [1,2,4,6,9,16]
155         for x in local_pages_per_sheet:
156                 pred = dogtail.predicate.GenericPredicate( name = str(x), roleName='combo box' )
157                 if dlg.findChild( pred, retry=False, requireResult=False):
158                         # dlg.child( str(x), roleName='combo box').combovalue = str(pps)
159                         # we've found what we're looking for, no need to continue the loop
160                         break
161         
162         # Redefining this here so that changing only_print above does not affect our search
163         local_only_print = ["All sheets","Even sheets","Odd sheets"]
164         for x in local_only_print:      
165                 pred = dogtail.predicate.GenericPredicate( name = str(x), roleName='combo box' )
166                 if dlg.findChild( pred, retry=False, requireResult=False):
167                         dlg.child( str(x), roleName='combo box').combovalue = str(op)
168                         # we've found what we're looking for, no need to continue the loop
169                         break
170         
171         #~ We're done setting up, start the print job 
172         click('Print', roleName='push button')
173 #~ ///function: run_test
174
175
176
177
178 #~ The test loop. 
179 for ot in output_type:
180         for pages in pages_in_document:
181                 # the filename which is opened depends on 'pages'
182                 app = run('evince', arguments=' ' + str(pages) + "-page.pdf")
183                 for rev in reverse:
184                         for col in collate:
185                                 for cop in copies:
186                                         #no sense in testing collate with 1 copy! it is equivalent to 1 uncollated
187                                         if (cop == 1 and col == 1):
188                                                 continue
189                                         for rng in ranges:
190                                                 for pps in pages_per_sheet:
191                                                         for op in only_print:
192                                                                 counter += 1
193                                                                 print str(counter) + " of " + str(n_tests)
194                                                                 run_test( pages, cop, pps, col, rev, rng, op, ot )
195                 click('File',roleName='menu')
196                 click('Close',roleName='menu item')
197
198 #~ we should be done now.
199