From 0cd7250f4177ac192f4b97b9ddfab96cbf2e6366 Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Mon, 14 Oct 2019 02:28:09 +0300 Subject: [PATCH] Add testcases/t/308-focus_wrapping.t These tests pass with and without the following refactoring. --- testcases/t/308-focus_wrapping.t | 255 +++++++++++++++++++++++++++++++ 1 file changed, 255 insertions(+) create mode 100644 testcases/t/308-focus_wrapping.t diff --git a/testcases/t/308-focus_wrapping.t b/testcases/t/308-focus_wrapping.t new file mode 100644 index 00000000..7053b5ae --- /dev/null +++ b/testcases/t/308-focus_wrapping.t @@ -0,0 +1,255 @@ +#!perl +# vim:ts=4:sw=4:expandtab +# +# Please read the following documents before working on tests: +# • https://build.i3wm.org/docs/testsuite.html +# (or docs/testsuite) +# +# • https://build.i3wm.org/docs/lib-i3test.html +# (alternatively: perldoc ./testcases/lib/i3test.pm) +# +# • https://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 focus_wrapping yes|no|force|workspace with cmp_tree +# Tickets: #2352 +use i3test i3_autostart => 0; + +my $pid = 0; +sub focus_wrapping { + my ($setting) = @_; + + print "--------------------------------------------------------------------------------\n"; + print " focus_wrapping $setting\n"; + print "--------------------------------------------------------------------------------\n"; + exit_gracefully($pid) if $pid > 0; + + my $config = <<"EOT"; +# i3 config file (v4) +font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1 + +fake-outputs 1024x768+0+0,1024x768+1024+0,1024x768+1024+768,1024x768+0+768 +workspace left-top output fake-0 +workspace right-top output fake-1 +workspace right-bottom output fake-2 +workspace left-bottom output fake-3 + +focus_wrapping $setting +EOT + $pid = launch_with_config($config); +} + +############################################################################### +focus_wrapping('yes'); +############################################################################### + +cmp_tree( + msg => 'Normal focus up - should work for all options', + layout_before => 'S[a b*] V[c d T[e f g]]', + layout_after => 'S[a* b] V[c d T[e f g]]', + ws => 'left-top', + cb => sub { + cmd 'focus up'; + }); +cmp_tree( + msg => 'Normal focus right - should work for all options', + layout_before => 'S[a b] V[c d T[e* f g]]', + layout_after => 'S[a b] V[c d T[e f* g]]', + ws => 'left-top', + cb => sub { + cmd 'focus right'; + }); +cmp_tree( + msg => 'Focus leaves workspace vertically', + layout_before => 'S[a b*] V[c d T[e f g]]', + layout_after => 'S[a b] V[c d T[e f g]]', + ws => 'left-top', + cb => sub { + cmd 'focus down'; + is(focused_ws, 'left-bottom', 'Correct workspace focused'); + }); +cmp_tree( + msg => 'Focus wraps vertically', + layout_before => 'S[a* b] V[c d T[e f g]]', + layout_after => 'S[a b*] V[c d T[e f g]]', + ws => 'left-top', + cb => sub { + cmd 'focus up'; + }); +cmp_tree( + msg => 'Focus wraps horizontally', + layout_before => 'S[a b*] V[c d T[e f g]]', + layout_after => 'S[a b] V[c d T[e f g*]]', + ws => 'left-top', + cb => sub { + cmd 'focus left'; + }); +cmp_tree( + msg => 'Directional focus in the orientation of the parent does not wrap', + layout_before => 'S[a b] V[c d T[e* f g]]', + layout_after => 'S[a b*] V[c d T[e f g]]', + ws => 'left-top', + cb => sub { + cmd 'focus left'; + }); +cmp_tree( + msg => 'Focus leaves workspace horizontally', + layout_before => 'S[a b] V[c d* T[e f g*]]', + layout_after => 'S[a b] V[c d T[e f g]]', + ws => 'left-top', + cb => sub { + cmd 'focus right'; + is(focused_ws, 'right-top', 'Correct workspace focused'); + }); + +############################################################################### +focus_wrapping('no'); +# See issue #2352 +############################################################################### + +cmp_tree( + msg => 'Normal focus up - should work for all options', + layout_before => 'S[a b*] V[c d T[e f g]]', + layout_after => 'S[a* b] V[c d T[e f g]]', + ws => 'left-top', + cb => sub { + cmd 'focus up'; + }); +cmp_tree( + msg => 'Normal focus right - should work for all options', + layout_before => 'S[a b] V[c d T[e* f g]]', + layout_after => 'S[a b] V[c d T[e f* g]]', + ws => 'left-top', + cb => sub { + cmd 'focus right'; + }); +cmp_tree( + msg => 'Focus leaves workspace vertically', + layout_before => 'S[a b*] V[c d T[e f g]]', + layout_after => 'S[a b] V[c d T[e f g]]', + ws => 'left-top', + cb => sub { + cmd 'focus down'; + is(focused_ws, 'left-bottom', 'Correct workspace focused'); + }); +cmp_tree( + msg => 'Focus does not wrap vertically', + layout_before => 'S[a* b] V[c d T[e f g]]', + layout_after => 'S[a* b] V[c d T[e f g]]', + ws => 'left-top', + cb => sub { + cmd 'focus up'; + }); +cmp_tree( + msg => 'Focus does not wrap horizontally', + layout_before => 'S[a b*] V[c d T[e f g]]', + layout_after => 'S[a b*] V[c d T[e f g]]', + ws => 'left-top', + cb => sub { + cmd 'focus left'; + }); +cmp_tree( + msg => 'Directional focus in the orientation of the parent does not wrap', + layout_before => 'S[a b] V[c d T[e* f g]]', + layout_after => 'S[a b*] V[c d T[e f g]]', + ws => 'left-top', + cb => sub { + cmd 'focus left'; + }); +cmp_tree( + msg => 'Focus leaves workspace horizontally', + layout_before => 'S[a b] V[c d* T[e f g]]', + layout_after => 'S[a b] V[c d T[e f g]]', + ws => 'left-top', + cb => sub { + cmd 'focus right'; + is(focused_ws, 'right-top', 'Correct workspace focused'); + }); + +############################################################################### +focus_wrapping('force'); +############################################################################### + +cmp_tree( + msg => 'Normal focus up - should work for all options', + layout_before => 'S[a b*] V[c d T[e f g]]', + layout_after => 'S[a* b] V[c d T[e f g]]', + ws => 'left-top', + cb => sub { + cmd 'focus up'; + }); +cmp_tree( + msg => 'Normal focus right - should work for all options', + layout_before => 'S[a b] V[c d T[e* f g]]', + layout_after => 'S[a b] V[c d T[e f* g]]', + ws => 'left-top', + cb => sub { + cmd 'focus right'; + }); +cmp_tree( + msg => 'Focus does not leave workspace vertically', + layout_before => 'S[a b*] V[c d T[e f g]]', + layout_after => 'S[a* b] V[c d T[e f g]]', + ws => 'left-top', + cb => sub { + cmd 'focus down'; + is(focused_ws, 'left-top', 'Correct workspace focused'); + }); +cmp_tree( + msg => 'Focus wraps vertically', + layout_before => 'S[a* b] V[c d T[e f g]]', + layout_after => 'S[a b*] V[c d T[e f g]]', + ws => 'left-top', + cb => sub { + cmd 'focus up'; + }); +cmp_tree( + msg => 'Focus wraps horizontally (focus direction different than parent\'s orientation)', + layout_before => 'S[a b*] V[c d T[e f g]]', + layout_after => 'S[a b] V[c d T[e f g*]]', + ws => 'left-top', + cb => sub { + cmd 'focus left'; + }); +cmp_tree( + msg => 'Directional focus in the orientation of the parent wraps', + layout_before => 'S[a b] V[c d T[e* f g]]', + layout_after => 'S[a b] V[c d T[e f g*]]', + ws => 'left-top', + cb => sub { + cmd 'focus left'; + }); +cmp_tree( # 'focus_wrapping force' exclusive test + msg => 'But leaves when selecting parent', + layout_before => 'S[a b] V[c d T[e* f g]]', + layout_after => 'S[a b*] V[c d T[e f g]]', + ws => 'left-top', + cb => sub { + cmd 'focus parent, focus right'; + }); +cmp_tree( + msg => 'Focus does not leave workspace horizontally', + layout_before => 'S[a b] V[c d* T[e f g]]', + layout_after => 'S[a b*] V[c d T[e f g]]', + ws => 'left-top', + cb => sub { + cmd 'focus right'; + is(focused_ws, 'left-top', 'Correct workspace focused'); + }); +cmp_tree( # 'focus_wrapping force|workspace' exclusive test + msg => 'But leaves when selecting parent x2', + layout_before => 'S[a b] V[c d* T[e f g]]', + layout_after => 'S[a b] V[c d T[e f g]]', + ws => 'left-top', + cb => sub { + cmd 'focus parent, focus parent, focus right'; + is(focused_ws, 'right-top', 'Correct workspace focused'); + }); + +exit_gracefully($pid); + + +done_testing;