X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=testcases%2Ft%2F122-split.t;h=6fd9b0e747313da53d43707c7601960f5c7d2e81;hb=8bfd06c3dd6e15b031c4a1bca82499e449f5121c;hp=0dfb99a37afb81f595db415c5e07b35af10bd6a7;hpb=1ddde16895f0eb8c4723d9609baa6011781a27ec;p=i3%2Fi3 diff --git a/testcases/t/122-split.t b/testcases/t/122-split.t index 0dfb99a3..6fd9b0e7 100644 --- a/testcases/t/122-split.t +++ b/testcases/t/122-split.t @@ -1,50 +1,73 @@ #!perl # vim:ts=4:sw=4:expandtab # +# Please read the following documents before working on tests: +# • http://build.i3wm.org/docs/testsuite.html +# (or docs/testsuite) +# +# • http://build.i3wm.org/docs/lib-i3test.html +# (alternatively: perldoc ./testcases/lib/i3test.pm) +# +# • http://build.i3wm.org/docs/ipc.html +# (or docs/ipc) +# +# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf +# (unless you are already familiar with Perl) +# # Tests splitting # use i3test; -use X11::XCB qw(:all); +use List::Util qw(first); -my $tmp = fresh_workspace; +my $tmp; +my $ws; -my $ws = get_ws($tmp); -is($ws->{orientation}, 'horizontal', 'orientation horizontal by default'); -cmd 'split v'; -$ws = get_ws($tmp); -is($ws->{orientation}, 'vertical', 'split v changes workspace orientation'); - -###################################################################### +################################################################################ # Open two containers, split, open another container. Then verify # the layout is like we expect it to be -###################################################################### -cmd 'open'; -cmd 'open'; -my $content = get_ws_content($tmp); +################################################################################ -is(@{$content}, 2, 'two containers on workspace level'); -my $first = $content->[0]; -my $second = $content->[1]; +sub verify_split_layout { + my (%args) = @_; -is(@{$first->{nodes}}, 0, 'first container has no children'); -is(@{$second->{nodes}}, 0, 'second container has no children (yet)'); -my $old_name = $second->{name}; + $tmp = fresh_workspace; + $ws = get_ws($tmp); + is($ws->{layout}, 'splith', 'orientation horizontal by default'); + cmd 'split v'; + $ws = get_ws($tmp); + is($ws->{layout}, 'splitv', 'split v changes workspace orientation'); -cmd 'split h'; -cmd 'open'; + cmd 'open'; + cmd 'open'; + my $content = get_ws_content($tmp); -$content = get_ws_content($tmp); + is(@{$content}, 2, 'two containers on workspace level'); + my $first = $content->[0]; + my $second = $content->[1]; -is(@{$content}, 2, 'two containers on workspace level'); -$first = $content->[0]; -$second = $content->[1]; + is(@{$first->{nodes}}, 0, 'first container has no children'); + is(@{$second->{nodes}}, 0, 'second container has no children (yet)'); + my $old_id = $second->{id}; -is(@{$first->{nodes}}, 0, 'first container has no children'); -isnt($second->{name}, $old_name, 'second container was replaced'); -is($second->{orientation}, 'horizontal', 'orientation is horizontal'); -is(@{$second->{nodes}}, 2, 'second container has 2 children'); -is($second->{nodes}->[0]->{name}, $old_name, 'found old second container'); + cmd $args{split_command}; + cmd 'open'; + + $content = get_ws_content($tmp); + + is(@{$content}, 2, 'two containers on workspace level'); + $first = $content->[0]; + $second = $content->[1]; + + is(@{$first->{nodes}}, 0, 'first container has no children'); + isnt($second->{id}, $old_id, 'second container was replaced'); + is($second->{layout}, 'splith', 'orientation is horizontal'); + is(@{$second->{nodes}}, 2, 'second container has 2 children'); + is($second->{nodes}->[0]->{id}, $old_id, 'found old second container'); +} + +verify_split_layout(split_command => 'split h'); +verify_split_layout(split_command => 'split horizontal'); # TODO: extend this test-case (test next/prev) # - wrapping (no horizontal switch possible, goes level-up) @@ -57,10 +80,10 @@ is($second->{nodes}->[0]->{name}, $old_name, 'found old second container'); $tmp = fresh_workspace; $ws = get_ws($tmp); -is($ws->{orientation}, 'horizontal', 'orientation horizontal by default'); +is($ws->{layout}, 'splith', 'orientation horizontal by default'); cmd 'split v'; $ws = get_ws($tmp); -is($ws->{orientation}, 'vertical', 'split v changes workspace orientation'); +is($ws->{layout}, 'splitv', 'split v changes workspace orientation'); cmd 'open'; my @content = @{get_ws_content($tmp)}; @@ -110,4 +133,79 @@ cmd 'open'; is(scalar @content, 1, 'Still one container on this ws'); is(scalar @{$content[0]->{nodes}}, 1, 'Stacked con still has one child node'); +################################################################################ +# When focusing the workspace, changing the layout should have an effect on the +# workspace, not on the parent (CT_CONTENT) container. +################################################################################ + +sub get_output_content { + my $tree = i3(get_socket_path())->get_tree->recv; + + my @outputs = grep { $_->{name} !~ /^__/ } @{$tree->{nodes}}; + is(scalar @outputs, 1, 'exactly one output (testcase not multi-monitor capable)'); + my $output = $outputs[0]; + # get the first (and only) CT_CON + return first { $_->{type} eq 'con' } @{$output->{nodes}}; +} + +$tmp = fresh_workspace; + +cmd 'open'; +cmd 'split v'; +cmd 'open'; +cmd 'focus parent'; +is(get_output_content()->{layout}, 'splith', 'content container layout ok'); +cmd 'layout stacked'; +is(get_output_content()->{layout}, 'splith', 'content container layout still ok'); + +###################################################################### +# Splitting a workspace that has more than one child +###################################################################### + +$tmp = fresh_workspace; + +cmd 'open'; +cmd 'open'; +cmd 'focus parent'; +cmd 'split v'; +cmd 'open'; + +my $content = get_ws_content($tmp); +my $fst = $content->[0]; +my $snd = $content->[1]; + +is(@{$content}, 2, 'two containers on workspace'); +is(@{$fst->{nodes}}, 2, 'first child has two children'); +is(@{$snd->{nodes}}, 0, 'second child has no children'); + +###################################################################### +# Test split toggle +###################################################################### + +$tmp = fresh_workspace; +cmd 'split h'; +cmd 'split toggle'; +$ws = get_ws($tmp); +is($ws->{layout}, 'splitv', 'toggled workspace split'); + +$tmp = fresh_workspace; +cmd 'split h'; +cmd 'split toggle'; +cmd 'split toggle'; +$ws = get_ws($tmp); +is($ws->{layout}, 'splith', 'toggled workspace back and forth'); + +cmd 'open'; +cmd 'open'; +cmd 'split toggle'; + +$content = get_ws_content($tmp); +my $second = $content->[1]; +is($second->{layout}, 'splitv', 'toggled container orientation to vertical'); + +cmd 'split toggle'; +$content = get_ws_content($tmp); +$second = $content->[1]; +is($second->{layout}, 'splith', 'toggled container orientation back to horizontal'); + done_testing;