2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
17 # Test that movement of a con into a branch will place the moving con at the
18 # correct position within the branch.
20 # If the direction of movement is the same as the orientation of the branch
21 # container, append or prepend the container to the branch in the obvious way.
22 # If the movement is to the right or downward, insert the moving container in
23 # the first position (i.e., the leftmost or top position resp.) If the movement
24 # is to the left or upward, insert the moving container in the last position
25 # (i.e., the rightmost or bottom position resp.)
27 # If the direction of movement is different from the orientation of the branch
28 # container, insert the container into the branch after the focused-inactive
31 # For testing purposes, we will demonstrate the behavior for tabbed containers
32 # to represent the case of split-horizontal branches and stacked containers to
33 # represent the case of split-vertical branches.
36 # Bug still in: 4.6-109-g18cfc36
40 # Opens tabs on the presently focused branch and adds several additional
41 # windows. Shifts focus to somewhere in the middle of the tabs so the most
42 # general case can be assumed.
49 cmd 'focus left; focus left'
52 # Likewise for a stack
54 cmd 'layout stacking';
59 cmd 'focus up; focus up'
62 # Gets the position of the given leaf within the given branch. The first
63 # position is one (1). Returns negative one (-1) if the leaf cannot be found
65 sub get_leaf_position {
66 my ($branch, $leaf) = @_;
68 for my $i (0 .. @{$branch->{nodes}}) {
69 if ($branch->{nodes}[$i]->{id} == $leaf) {
77 # convenience function to focus a con by id to avoid having to type an ugly
80 my $con_id = shift @_;
81 cmd "[con_id=\"$con_id\"] focus";
84 # Places a leaf into a branch and focuses the leaf. The newly created branch
85 # will have orientation specified by the second parameter.
87 my ($con_id, $orientation) = @_;
89 $orientation eq 'horizontal' ? cmd 'splith' : cmd 'splitv';
94 ##############################################################################
95 # When moving a con right into tabs, the moving con should be placed as the
96 # first tab in the branch
97 ##############################################################################
98 my $ws = fresh_workspace;
100 # create the target leaf
102 my $target_leaf = get_focused($ws);
104 # create the tabbed branch container
109 # move the target leaf into the tabbed branch
110 focus_con($target_leaf);
113 # the target leaf should be the first in the branch
114 my $branch = shift @{get_ws_content($ws)};
115 is($branch->{nodes}[0]->{id}, $target_leaf, 'moving con right into tabs placed it as the first tab in the branch');
117 # repeat the test when the target is in a branch
118 cmd 'move up; move left';
119 branchify($target_leaf, 'vertical');
122 $branch = pop @{get_ws_content($ws)};
123 is($branch->{nodes}[0]->{id}, $target_leaf, 'moving con right into tabs from a branch placed it as the first tab in the branch');
125 ##############################################################################
126 # When moving a con right into a stack, the moving con should be placed
127 # below the focused-inactive leaf
128 ##############################################################################
129 $ws = fresh_workspace;
131 # create the target leaf
133 $target_leaf = get_focused($ws);
135 # create the stacked branch container and find the focused leaf
139 my $secondary_leaf = get_focused($ws);
141 # move the target leaf into the stacked branch
142 focus_con($target_leaf);
145 # the secondary focus leaf should be below the target
146 $branch = shift @{get_ws_content($ws)};
147 my $target_leaf_position = get_leaf_position($branch, $target_leaf);
148 my $secondary_leaf_position = get_leaf_position($branch, $secondary_leaf);
150 is($target_leaf_position, $secondary_leaf_position + 1, 'moving con right into a stack placed it below the focused-inactive leaf');
152 # repeat the test when the target is in a branch
153 cmd 'move up; move left';
154 branchify($target_leaf, 'vertical');
157 $branch = pop @{get_ws_content($ws)};
158 $target_leaf_position = get_leaf_position($branch, $target_leaf);
159 $secondary_leaf_position = get_leaf_position($branch, $secondary_leaf);
161 is($target_leaf_position, $secondary_leaf_position + 1, 'moving con right into a stack from a branch placed it below the focused-inactive leaf');
163 ##############################################################################
164 # When moving a con down into a stack, the moving con should be placed at the
166 ##############################################################################
167 $ws = fresh_workspace;
170 # create the target leaf
172 $target_leaf = get_focused($ws);
174 # create the stacked branch container
179 # move the target leaf into the stacked branch
180 focus_con($target_leaf);
183 # the target leaf should be on the top of the stack
184 $branch = shift @{get_ws_content($ws)};
185 is($branch->{nodes}[0]->{id}, $target_leaf, 'moving con down into a stack placed it on the top of the stack');
187 # repeat the test when the target is in a branch
188 cmd 'move right; move up';
189 branchify($target_leaf, 'horizontal');
192 $branch = pop @{get_ws_content($ws)};
193 is($branch->{nodes}[0]->{id}, $target_leaf, 'moving con down into a stack from a branch placed it on the top of the stack');
195 ##############################################################################
196 # When moving a con down into tabs, the moving con should be placed after the
197 # focused-inactive tab
198 ##############################################################################
199 $ws = fresh_workspace;
202 # create the target leaf
204 $target_leaf = get_focused($ws);
206 # create the tabbed branch container and find the focused tab
210 $secondary_leaf = get_focused($ws);
212 # move the target leaf into the tabbed branch
213 focus_con($target_leaf);
216 # the secondary focus tab should be to the right
217 $branch = shift @{get_ws_content($ws)};
218 $target_leaf_position = get_leaf_position($branch, $target_leaf);
219 $secondary_leaf_position = get_leaf_position($branch, $secondary_leaf);
221 is($target_leaf_position, $secondary_leaf_position + 1, 'moving con down into tabs placed it after the focused-inactive tab');
223 # repeat the test when the target is in a branch
224 cmd 'move right; move up';
225 branchify($target_leaf, 'horizontal');
228 $branch = pop @{get_ws_content($ws)};
229 $target_leaf_position = get_leaf_position($branch, $target_leaf);
230 $secondary_leaf_position = get_leaf_position($branch, $secondary_leaf);
232 is($target_leaf_position, $secondary_leaf_position + 1, 'moving con down into tabs from a branch placed it after the focused-inactive tab');
234 ##############################################################################
235 # When moving a con left into tabs, the moving con should be placed as the last
237 ##############################################################################
238 $ws = fresh_workspace;
240 # create the tabbed branch container
245 # create the target leaf
248 $target_leaf = get_focused($ws);
250 # move the target leaf into the tabbed branch
253 # the target leaf should be last in the branch
254 $branch = shift @{get_ws_content($ws)};
256 is($branch->{nodes}->[-1]->{id}, $target_leaf, 'moving con left into tabs placed it as the last tab in the branch');
258 # repeat the test when the target leaf is in a branch
259 cmd 'move up; move right';
260 branchify($target_leaf, 'vertical');
263 $branch = shift @{get_ws_content($ws)};
264 is($branch->{nodes}->[-1]->{id}, $target_leaf, 'moving con left into tabs from a branch placed it as the last tab in the branch');
266 ##############################################################################
267 # When moving a con left into a stack, the moving con should be placed below
268 # the focused-inactive leaf
269 ##############################################################################
270 $ws = fresh_workspace;
272 # create the stacked branch container and find the focused leaf
275 $secondary_leaf = get_focused($ws);
277 # create the target leaf to the right
280 $target_leaf = get_focused($ws);
282 # move the target leaf into the stacked branch
285 # the secondary focus leaf should be below
286 $branch = shift @{get_ws_content($ws)};
287 $target_leaf_position = get_leaf_position($branch, $target_leaf);
288 $secondary_leaf_position = get_leaf_position($branch, $secondary_leaf);
290 is($target_leaf_position, $secondary_leaf_position + 1, 'moving con left into a stack placed it below the focused-inactive leaf');
292 # repeat the test when the target leaf is in a branch
293 cmd 'move up; move right';
294 branchify($target_leaf, 'vertical');
297 $branch = shift @{get_ws_content($ws)};
298 $target_leaf_position = get_leaf_position($branch, $target_leaf);
299 $secondary_leaf_position = get_leaf_position($branch, $secondary_leaf);
301 is($target_leaf_position, $secondary_leaf_position + 1, 'moving con left into a stack from a branch placed it below the focused-inactive leaf');
303 ##############################################################################
304 # When moving a con up into a stack, the moving con should be placed last in
306 ##############################################################################
307 $ws = fresh_workspace;
310 # create the stacked branch container
315 # create the target leaf
318 $target_leaf = get_focused($ws);
320 # move the target leaf into the stacked branch
323 # the target leaf should be on the bottom of the stack
324 $branch = shift @{get_ws_content($ws)};
326 is($branch->{nodes}->[-1]->{id}, $target_leaf, 'moving con up into stack placed it on the bottom of the stack');
328 # repeat the test when the target leaf is in a branch
329 cmd 'move right; move down';
330 branchify($target_leaf, 'horizontal');
333 $branch = shift @{get_ws_content($ws)};
335 is($branch->{nodes}->[-1]->{id}, $target_leaf, 'moving con up into stack from a branch placed it on the bottom of the stack');
337 ##############################################################################
338 # When moving a con up into tabs, the moving con should be placed after the
339 # focused-inactive tab
340 ##############################################################################
341 $ws = fresh_workspace;
344 # create the tabbed branch container and find the focused leaf
348 $secondary_leaf = get_focused($ws);
350 # create the target leaf below
353 $target_leaf = get_focused($ws);
355 # move the target leaf into the tabbed branch
358 # the secondary focus tab should be to the right
359 $branch = shift @{get_ws_content($ws)};
360 $target_leaf_position = get_leaf_position($branch, $target_leaf);
361 $secondary_leaf_position = get_leaf_position($branch, $secondary_leaf);
363 is($target_leaf_position, $secondary_leaf_position + 1, 'moving con up into tabs placed it after the focused-inactive tab');
365 # repeat the test when the target leaf is in a branch
366 cmd 'move right; move down';
367 branchify($target_leaf, 'horizontal');
370 $branch = shift @{get_ws_content($ws)};
371 $target_leaf_position = get_leaf_position($branch, $target_leaf);
372 $secondary_leaf_position = get_leaf_position($branch, $secondary_leaf);
374 is($target_leaf_position, $secondary_leaf_position + 1, 'moving con up into tabs from a branch placed it after the focused-inactive tab');