1import os
2import sys
3import time
4import test_utils
5import test_constants
6
7def get_test_header():
8
9    notes =  "*          Studio Toolbar Tests                       *\n"
10    notes += "*                                                     *\n"
11    notes += "* Test grid and snap setting dialog                   *\n"
12    notes += "* Test grid and snap function                         *\n"
13    notes += "* Test toolbar button before project open             *\n"
14    notes += "* Test following toolbar buttons:                     *\n"
15    notes += "*   align left                                        *\n"
16    notes += "*   align right                                       *\n"
17    notes += "*   align top                                         *\n"
18    notes += "*   align bottom                                      *\n"
19    notes += "*   vertical space equally                            *\n"
20    notes += "*   horizontal space equally                          *\n"
21    notes += "*   equal width                                       *\n"
22    notes += "*   equal height                                      *\n"
23    notes += "*   move to front                                     *\n"
24    notes += "*   move to back                                      *\n"
25    notes += "*   zoom in                                           *\n"
26    notes += "*   zoom out                                          *\n"
27    return notes
28
29def run_drag_resize():
30    # drag left
31    widget_name = 'text_input_2'
32    test_utils.select_project_tree_node(widget_name)
33    test_utils.drag_left(widget_name, -13)
34    test_utils.drag_left(widget_name, 2)
35    test_utils.drag_right(widget_name, 12)
36    test_utils.drag_right(widget_name, -3)
37    test_utils.drag_top(widget_name, -13)
38    test_utils.drag_top(widget_name, 1)
39    test_utils.drag_bottom(widget_name, 12)
40    test_utils.drag_bottom(widget_name, -5)
41
42    widget_name = 'prompt_2'
43    test_utils.select_project_tree_node(widget_name)
44    test_utils.drag_left_top(widget_name, -5, -8)
45    test_utils.drag_left_top(widget_name, 1, 1)
46    test_utils.drag_right_top(widget_name, 11, -10)
47    test_utils.drag_right_top(widget_name, -3, 3)
48    test_utils.drag_left_bottom(widget_name, -5, 8)
49    test_utils.drag_left_bottom(widget_name, 5, -6)
50    test_utils.drag_right_bottom(widget_name, 19, 19)
51    test_utils.drag_right_bottom(widget_name, -9, -9)
52
53    test_utils.compare_result()
54
55#test toolbar button click when no widget been selected
56def run_toolbar_button_click():
57    test_utils.toolbar_cut()
58    test_utils.toolbar_copy()
59    test_utils.toolbar_paste()
60    test_utils.toolbar_align_left()
61    test_utils.toolbar_align_right()
62    test_utils.toolbar_align_top()
63    test_utils.toolbar_align_bottom()
64    test_utils.toolbar_vspace_equally()
65    test_utils.toolbar_hspace_equally()
66    test_utils.toolbar_equal_width()
67    test_utils.toolbar_equal_height()
68    test_utils.toolbar_move_to_front()
69    test_utils.toolbar_move_to_back()
70    test_utils.toolbar_size_to_fit()
71    test_utils.toolbar_zoom_in()
72    test_utils.toolbar_zoom_out()
73    test_utils.toolbar_record_macro()
74    test_utils.close_dialog(test_utils.RECORD_MACRO_DIALOG)
75    test_utils.toolbar_playback_macro()
76    test_utils.close_dialog(test_utils.PLAYBACK_MACRO_DIALOG)
77
78def run_toolbar_function():
79
80    #move widget that already in back
81    test_utils.select_project_tree_node('window')
82    test_utils.toolbar_move_to_back()
83
84    #move widget that already in front
85    test_utils.select_project_tree_node("window")
86    test_utils.toolbar_move_to_front()
87
88    test_utils.zoom_in(100)
89    test_utils.zoom_in(200)
90    test_utils.zoom_in(300)
91    test_utils.zoom_in(400)
92    test_utils.zoom_in(300)
93    test_utils.zoom_in(200)
94    test_utils.zoom_in(100)
95
96    # click zoom in button 5 times
97    test_utils.toolbar_zoom_in()
98    test_utils.toolbar_zoom_in()
99    test_utils.toolbar_zoom_in()
100    test_utils.toolbar_zoom_in()
101    test_utils.toolbar_zoom_in()
102
103    # click zoom out button 5 times
104    test_utils.toolbar_zoom_out()
105    test_utils.toolbar_zoom_out()
106    test_utils.toolbar_zoom_out()
107    test_utils.toolbar_zoom_out()
108    test_utils.toolbar_zoom_out()
109
110    # select 2 widgets
111    test_utils.select_multi_widgets('window_1')
112    test_utils.select_multi_widgets('prompt_1')
113    test_utils.toolbar_align_left()
114
115    test_utils.select_multi_widgets('window_1')
116    test_utils.select_multi_widgets('prompt_1')
117    test_utils.toolbar_align_right()
118
119    test_utils.select_multi_widgets('window_1')
120    test_utils.select_multi_widgets('prompt_1')
121    test_utils.toolbar_align_bottom()
122
123    test_utils.select_multi_widgets('window_1')
124    test_utils.select_multi_widgets('prompt_1')
125    test_utils.toolbar_align_top()
126
127    test_utils.select_multi_widgets('window_1')
128    test_utils.select_multi_widgets('prompt_1')
129    test_utils.toolbar_equal_width()
130
131    test_utils.select_multi_widgets('window_1')
132    test_utils.select_multi_widgets('prompt_1')
133    test_utils.toolbar_equal_height()
134
135    # select 3 wigets
136    test_utils.select_multi_widgets('prompt_2')
137    test_utils.select_multi_widgets('text_input_2')
138    test_utils.select_multi_widgets('button_2')
139    test_utils.toolbar_vspace_equally()
140
141    test_utils.select_multi_widgets('prompt_2')
142    test_utils.select_multi_widgets('text_input_2')
143    test_utils.select_multi_widgets('text_view_1')
144    test_utils.toolbar_hspace_equally()
145
146    test_utils.select_project_tree_node('prompt_1')
147    test_utils.toolbar_move_to_back()
148
149    test_utils.select_project_tree_node("window_1")
150    test_utils.select_project_tree_node('prompt_1')
151    test_utils.toolbar_move_to_front()
152
153    test_utils.select_project_tree_node("window_1")
154    test_utils.select_project_tree_node('prompt_1')
155    test_utils.toolbar_size_to_fit()
156
157    test_utils.select_project_tree_node("window_1")
158    test_utils.select_project_tree_node('text_input_1')
159    test_utils.toolbar_size_to_fit()
160
161    test_utils.select_project_tree_node("window_1")
162    test_utils.select_project_tree_node('prompt_2')
163    test_utils.toolbar_size_to_fit()
164
165    test_utils.select_project_tree_node("window_1")
166    test_utils.select_project_tree_node('button_1')
167    test_utils.toolbar_size_to_fit()
168
169    test_utils.select_project_tree_node("window_1")
170    test_utils.select_project_tree_node('button_2')
171    test_utils.toolbar_size_to_fit()
172
173    test_utils.select_project_tree_node("window_1")
174    test_utils.select_project_tree_node('multi_line_button_1')
175    test_utils.toolbar_size_to_fit()
176
177    test_utils.select_project_tree_node("window_1")
178    test_utils.select_project_tree_node('checkbox_1')
179    test_utils.toolbar_size_to_fit()
180
181    test_utils.select_project_tree_node("window_1")
182    test_utils.select_project_tree_node('checkbox_2')
183    test_utils.toolbar_size_to_fit()
184
185    test_utils.select_project_tree_node("window_1")
186    test_utils.select_project_tree_node('text_view_1')
187    test_utils.toolbar_size_to_fit()
188
189    test_utils.select_project_tree_node("window_1")
190    test_utils.select_project_tree_node('progress_bar_1')
191    test_utils.toolbar_size_to_fit()
192
193    test_utils.select_project_tree_node("window_1")
194    test_utils.select_project_tree_node('pixelmap_slider_1')
195    test_utils.toolbar_size_to_fit()
196
197    test_utils.select_project_tree_node("window_1")
198    test_utils.select_project_tree_node('pixelmap_slider_2')
199    test_utils.toolbar_size_to_fit()
200
201    test_utils.select_project_tree_node("window_1")
202    test_utils.select_project_tree_node('icon_button_1')
203    test_utils.toolbar_size_to_fit()
204
205    test_utils.select_project_tree_node("window_1")
206    test_utils.select_project_tree_node('sprite_1')
207    test_utils.toolbar_size_to_fit()
208
209    test_utils.select_project_tree_node("window_1")
210    test_utils.select_project_tree_node('horizontal_list_1')
211    test_utils.toolbar_size_to_fit()
212
213    test_utils.select_project_tree_node("window_1")
214    test_utils.select_project_tree_node('drop_list_1')
215    test_utils.toolbar_size_to_fit()
216
217    test_utils.select_project_tree_node("window_1")
218    test_utils.select_project_tree_node('vertical_list_1')
219    test_utils.toolbar_size_to_fit()
220
221    test_utils.select_project_tree_node("window_1")
222    test_utils.select_project_tree_node('radio_button_1')
223    test_utils.toolbar_size_to_fit()
224
225def run_toolbar_tests(generate, screenshot):
226
227    test_utils.output_test_header(get_test_header())
228    test_utils.setup(generate, screenshot, 'test_toolbar_golden_file')
229
230    test_utils.close_project()
231    print('run toolbar button click')
232    run_toolbar_button_click()
233
234    test_utils.open_project('generic_16bpp.gxp')
235
236    print('run drag resize function')
237    run_drag_resize()
238
239    # open grid and snap setting dialog
240    test_utils.grid_snap_setting()
241    test_utils.check_show_grid(1)
242    test_utils.check_snap(1)
243    test_utils.save_grid_snap_setting()
244    run_drag_resize()
245
246    test_utils.grid_snap_setting()
247    test_utils.set_grid_spacing(13)
248    test_utils.set_snap_spacing(13)
249    test_utils.save_grid_snap_setting()
250    run_drag_resize()
251
252    test_utils.zoom_in(200)
253    run_drag_resize()
254
255    print('run toolbar function')
256    run_toolbar_function()
257
258    test_utils.write_end('Toolbar Tests')
259