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)
20 use List::Util qw(first);
25 ################################################################################
26 # Open two containers, split, open another container. Then verify
27 # the layout is like we expect it to be
28 ################################################################################
30 sub verify_split_layout {
33 $tmp = fresh_workspace;
36 is($ws->{layout}, 'splith', 'orientation horizontal by default');
39 is($ws->{layout}, 'splitv', 'split v changes workspace orientation');
43 my $content = get_ws_content($tmp);
45 is(@{$content}, 2, 'two containers on workspace level');
46 my $first = $content->[0];
47 my $second = $content->[1];
49 is(@{$first->{nodes}}, 0, 'first container has no children');
50 is(@{$second->{nodes}}, 0, 'second container has no children (yet)');
51 my $old_name = $second->{name};
53 cmd $args{split_command};
56 $content = get_ws_content($tmp);
58 is(@{$content}, 2, 'two containers on workspace level');
59 $first = $content->[0];
60 $second = $content->[1];
62 is(@{$first->{nodes}}, 0, 'first container has no children');
63 isnt($second->{name}, $old_name, 'second container was replaced');
64 is($second->{layout}, 'splith', 'orientation is horizontal');
65 is(@{$second->{nodes}}, 2, 'second container has 2 children');
66 is($second->{nodes}->[0]->{name}, $old_name, 'found old second container');
69 verify_split_layout(split_command => 'split h');
70 verify_split_layout(split_command => 'split horizontal');
72 # TODO: extend this test-case (test next/prev)
73 # - wrapping (no horizontal switch possible, goes level-up)
74 # - going level-up "manually"
76 ######################################################################
77 # Test splitting multiple times without actually creating windows
78 ######################################################################
80 $tmp = fresh_workspace;
83 is($ws->{layout}, 'splith', 'orientation horizontal by default');
86 is($ws->{layout}, 'splitv', 'split v changes workspace orientation');
89 my @content = @{get_ws_content($tmp)};
91 # recursively sums up all nodes and their children
95 return 0 if !@{$nodes};
97 my @children = (map { @{$_->{nodes}} } @{$nodes},
98 map { @{$_->{'floating_nodes'}} } @{$nodes});
100 return @{$nodes} + sum_nodes(\@children);
103 my $old_count = sum_nodes(\@content);
106 @content = @{get_ws_content($tmp)};
107 $old_count = sum_nodes(\@content);
111 @content = @{get_ws_content($tmp)};
112 my $count = sum_nodes(\@content);
113 is($count, $old_count, 'not more windows after splitting again');
115 ######################################################################
116 # In the special case of being inside a stacked or tabbed container, we don’t
117 # want this to happen.
118 ######################################################################
120 $tmp = fresh_workspace;
123 @content = @{get_ws_content($tmp)};
124 is(scalar @content, 1, 'Precisely one container on this ws');
125 cmd 'layout stacked';
126 @content = @{get_ws_content($tmp)};
127 is(scalar @content, 1, 'Still one container on this ws');
128 is(scalar @{$content[0]->{nodes}}, 1, 'Stacked con has one child node');
132 @content = @{get_ws_content($tmp)};
133 is(scalar @content, 1, 'Still one container on this ws');
134 is(scalar @{$content[0]->{nodes}}, 1, 'Stacked con still has one child node');
136 ################################################################################
137 # When focusing the workspace, changing the layout should have an effect on the
138 # workspace, not on the parent (CT_CONTENT) container.
139 ################################################################################
141 sub get_output_content {
142 my $tree = i3(get_socket_path())->get_tree->recv;
144 my @outputs = grep { $_->{name} !~ /^__/ } @{$tree->{nodes}};
145 is(scalar @outputs, 1, 'exactly one output (testcase not multi-monitor capable)');
146 my $output = $outputs[0];
147 # get the first (and only) CT_CON
148 return first { $_->{type} eq 'con' } @{$output->{nodes}};
151 $tmp = fresh_workspace;
157 is(get_output_content()->{layout}, 'splith', 'content container layout ok');
158 cmd 'layout stacked';
159 is(get_output_content()->{layout}, 'splith', 'content container layout still ok');
161 ######################################################################
162 # Splitting a workspace that has more than one child
163 ######################################################################
165 $tmp = fresh_workspace;
173 my $content = get_ws_content($tmp);
174 my $fst = $content->[0];
175 my $snd = $content->[1];
177 is(@{$content}, 2, 'two containers on workspace');
178 is(@{$fst->{nodes}}, 2, 'first child has two children');
179 is(@{$snd->{nodes}}, 0, 'second child has no children');