From 759e05137467c6f768a3164de9fe783e1a37aece Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Tue, 19 Sep 2017 09:56:53 +0300 Subject: [PATCH] Move is_num_fullscreen to Test.pm --- testcases/lib/i3test/Test.pm | 20 ++++++++ testcases/t/100-fullscreen.t | 65 +++++++++++-------------- testcases/t/206-fullscreen-scratchpad.t | 17 ++----- testcases/t/291-swap.t | 21 +++----- 4 files changed, 60 insertions(+), 63 deletions(-) diff --git a/testcases/lib/i3test/Test.pm b/testcases/lib/i3test/Test.pm index 0253bc2d..552ae8b4 100644 --- a/testcases/lib/i3test/Test.pm +++ b/testcases/lib/i3test/Test.pm @@ -5,6 +5,7 @@ use base 'Test::Builder::Module'; our @EXPORT = qw( is_num_children + is_num_fullscreen cmp_float does_i3_live ); @@ -59,6 +60,25 @@ sub is_num_children { $tb->is_num($got_num_children, $num_children, $name); } +=head2 is_num_fullscreen($workspace, $expected, $test_name) + +Gets the number of fullscreen containers on the given workspace and verifies that +they match the expected amount. + + is_num_fullscreen('1', 0, 'no fullscreen containers on workspace 1'); + +=cut +sub is_num_fullscreen { + my ($workspace, $num_fullscreen, $name) = @_; + my $workspace_content = i3test::get_ws($workspace); + my $tb = $CLASS->builder; + + my $nodes = scalar grep { $_->{fullscreen_mode} != 0 } @{$workspace_content->{nodes}->[0]->{nodes}}; + my $cons = scalar grep { $_->{fullscreen_mode} != 0 } @{$workspace_content->{nodes}}; + my $floating = scalar grep { $_->{fullscreen_mode} != 0 } @{$workspace_content->{floating_nodes}->[0]->{nodes}}; + $tb->is_num($nodes + $cons + $floating, $num_fullscreen, $name); +} + =head2 cmp_float($a, $b) Compares floating point numbers C<$a> and C<$b> and returns true if they differ diff --git a/testcases/t/100-fullscreen.t b/testcases/t/100-fullscreen.t index f0d0b4c6..d817bee0 100644 --- a/testcases/t/100-fullscreen.t +++ b/testcases/t/100-fullscreen.t @@ -21,13 +21,6 @@ my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; -sub fullscreen_windows { - my $ws = $tmp; - $ws = shift if @_; - - scalar grep { $_->{fullscreen_mode} != 0 } @{get_ws_content($ws)} -} - # get the output of this workspace my $tree = $i3->get_tree->recv; my @outputs = @{$tree->{nodes}}; @@ -143,11 +136,11 @@ ok(!eq_hash($new_rect, $original_rect), "Window got repositioned"); $swindow->fullscreen(1); sync_with_i3; -is(fullscreen_windows(), 1, 'amount of fullscreen windows'); +is_num_fullscreen($tmp, 1, 'amount of fullscreen windows'); $window->fullscreen(0); sync_with_i3; -is(fullscreen_windows(), 1, 'amount of fullscreen windows'); +is_num_fullscreen($tmp, 1, 'amount of fullscreen windows'); ok($swindow->mapped, 'window mapped after other fullscreen ended'); @@ -160,15 +153,15 @@ ok($swindow->mapped, 'window mapped after other fullscreen ended'); $swindow->fullscreen(0); sync_with_i3; -is(fullscreen_windows(), 0, 'amount of fullscreen windows after disabling'); +is_num_fullscreen($tmp, 0, 'amount of fullscreen windows after disabling'); cmd 'fullscreen'; -is(fullscreen_windows(), 1, 'amount of fullscreen windows after fullscreen command'); +is_num_fullscreen($tmp, 1, 'amount of fullscreen windows after fullscreen command'); cmd 'fullscreen'; -is(fullscreen_windows(), 0, 'amount of fullscreen windows after fullscreen command'); +is_num_fullscreen($tmp, 0, 'amount of fullscreen windows after fullscreen command'); # clean up the workspace so that it will be cleaned when switching away cmd 'kill' for (@{get_ws_content($tmp)}); @@ -221,18 +214,18 @@ $swindow = open_window; cmd 'fullscreen'; -is(fullscreen_windows($tmp2), 1, 'one fullscreen window on second ws'); +is_num_fullscreen($tmp2, 1, 'one fullscreen window on second ws'); cmd "move workspace $tmp"; -is(fullscreen_windows($tmp2), 0, 'no fullscreen windows on second ws'); -is(fullscreen_windows($tmp), 1, 'one fullscreen window on first ws'); +is_num_fullscreen($tmp2, 0, 'no fullscreen windows on second ws'); +is_num_fullscreen($tmp, 1, 'one fullscreen window on first ws'); $swindow->fullscreen(0); sync_with_i3; # Verify that $swindow was the one that initially remained fullscreen. -is(fullscreen_windows($tmp), 0, 'no fullscreen windows on first ws'); +is_num_fullscreen($tmp, 0, 'no fullscreen windows on first ws'); ################################################################################ # Verify that opening a window with _NET_WM_STATE_FULLSCREEN unfullscreens any @@ -245,14 +238,14 @@ $window = open_window(); cmd "fullscreen"; -is(fullscreen_windows($tmp), 1, 'one fullscreen window on ws'); +is_num_fullscreen($tmp, 1, 'one fullscreen window on ws'); is($x->input_focus, $window->id, 'fullscreen window focused'); $swindow = open_window({ fullscreen => 1 }); -is(fullscreen_windows($tmp), 1, 'one fullscreen window on ws'); +is_num_fullscreen($tmp, 1, 'one fullscreen window on ws'); is($x->input_focus, $swindow->id, 'fullscreen window focused'); ################################################################################ @@ -263,19 +256,19 @@ $tmp = fresh_workspace; $window = open_window; is($x->input_focus, $window->id, 'window focused'); -is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace'); +is_num_fullscreen($tmp, 0, 'no fullscreen window on workspace'); cmd 'fullscreen enable'; is($x->input_focus, $window->id, 'window still focused'); -is(fullscreen_windows($tmp), 1, 'one fullscreen window on workspace'); +is_num_fullscreen($tmp, 1, 'one fullscreen window on workspace'); cmd 'fullscreen enable'; is($x->input_focus, $window->id, 'window still focused'); -is(fullscreen_windows($tmp), 1, 'still one fullscreen window on workspace'); +is_num_fullscreen($tmp, 1, 'still one fullscreen window on workspace'); $window->fullscreen(0); sync_with_i3; -is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace'); +is_num_fullscreen($tmp, 0, 'no fullscreen window on workspace'); ################################################################################ # Verify that command ‘fullscreen enable global’ works and is idempotent. @@ -285,19 +278,19 @@ $tmp = fresh_workspace; $window = open_window; is($x->input_focus, $window->id, 'window focused'); -is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace'); +is_num_fullscreen($tmp, 0, 'no fullscreen window on workspace'); cmd 'fullscreen enable global'; is($x->input_focus, $window->id, 'window still focused'); -is(fullscreen_windows($tmp), 1, 'one fullscreen window on workspace'); +is_num_fullscreen($tmp, 1, 'one fullscreen window on workspace'); cmd 'fullscreen enable global'; is($x->input_focus, $window->id, 'window still focused'); -is(fullscreen_windows($tmp), 1, 'still one fullscreen window on workspace'); +is_num_fullscreen($tmp, 1, 'still one fullscreen window on workspace'); $window->fullscreen(0); sync_with_i3; -is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace'); +is_num_fullscreen($tmp, 0, 'no fullscreen window on workspace'); ################################################################################ # Verify that command ‘fullscreen disable’ works and is idempotent. @@ -307,19 +300,19 @@ $tmp = fresh_workspace; $window = open_window; is($x->input_focus, $window->id, 'window focused'); -is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace'); +is_num_fullscreen($tmp, 0, 'no fullscreen window on workspace'); $window->fullscreen(1); sync_with_i3; -is(fullscreen_windows($tmp), 1, 'one fullscreen window on workspace'); +is_num_fullscreen($tmp, 1, 'one fullscreen window on workspace'); cmd 'fullscreen disable'; is($x->input_focus, $window->id, 'window still focused'); -is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace'); +is_num_fullscreen($tmp, 0, 'no fullscreen window on workspace'); cmd 'fullscreen disable'; is($x->input_focus, $window->id, 'window still focused'); -is(fullscreen_windows($tmp), 0, 'still no fullscreen window on workspace'); +is_num_fullscreen($tmp, 0, 'still no fullscreen window on workspace'); ################################################################################ # Verify that command ‘fullscreen toggle’ works. @@ -328,15 +321,15 @@ is(fullscreen_windows($tmp), 0, 'still no fullscreen window on workspace'); $tmp = fresh_workspace; $window = open_window; -is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace'); +is_num_fullscreen($tmp, 0, 'no fullscreen window on workspace'); cmd 'fullscreen toggle'; is($x->input_focus, $window->id, 'window still focused'); -is(fullscreen_windows($tmp), 1, 'one fullscreen window on workspace'); +is_num_fullscreen($tmp, 1, 'one fullscreen window on workspace'); cmd 'fullscreen toggle'; is($x->input_focus, $window->id, 'window still focused'); -is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace'); +is_num_fullscreen($tmp, 0, 'no fullscreen window on workspace'); ################################################################################ # Verify that a window’s fullscreen is disabled when another one is enabled @@ -349,15 +342,15 @@ $window = open_window; $other = open_window; is($x->input_focus, $other->id, 'other window focused'); -is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace'); +is_num_fullscreen($tmp, 0, 'no fullscreen window on workspace'); cmd 'fullscreen enable'; is($x->input_focus, $other->id, 'other window focused'); -is(fullscreen_windows($tmp), 1, 'one fullscreen window on workspace'); +is_num_fullscreen($tmp, 1, 'one fullscreen window on workspace'); cmd '[id="' . $window->id . '"] fullscreen enable'; is($x->input_focus, $window->id, 'window focused'); -is(fullscreen_windows($tmp), 1, 'one fullscreen window on workspace'); +is_num_fullscreen($tmp, 1, 'one fullscreen window on workspace'); ################################################################################ # Verify that when a global fullscreen is enabled the window is focused and diff --git a/testcases/t/206-fullscreen-scratchpad.t b/testcases/t/206-fullscreen-scratchpad.t index c098f23f..95245099 100644 --- a/testcases/t/206-fullscreen-scratchpad.t +++ b/testcases/t/206-fullscreen-scratchpad.t @@ -21,15 +21,6 @@ use i3test; my $tmp = fresh_workspace; -sub fullscreen_windows { - my $ws = $tmp; - $ws = shift if @_; - - my $nodes = scalar grep { $_->{fullscreen_mode} != 0 } @{get_ws_content($ws)->[0]->{nodes}}; - my $cons = scalar grep { $_->{fullscreen_mode} != 0 } @{get_ws_content($ws)}; - return $nodes + $cons; -} - ########################################################################################## # map two windows in one container, fullscreen one of them and then move it to scratchpad ########################################################################################## @@ -41,7 +32,7 @@ my $second_win = open_window; cmd 'fullscreen'; # see if the window really is in fullscreen mode -is(fullscreen_windows(), 1, 'amount of fullscreen windows after enabling fullscreen'); +is_num_fullscreen($tmp, 1, 'amount of fullscreen windows after enabling fullscreen'); # move window to scratchpad cmd 'move scratchpad'; @@ -57,7 +48,7 @@ cmd 'scratchpad show'; cmd 'floating toggle'; # see if no window is in fullscreen mode -is(fullscreen_windows(), 0, 'amount of fullscreen windows after showing previously fullscreened scratchpad window'); +is_num_fullscreen($tmp, 0, 'amount of fullscreen windows after showing previously fullscreened scratchpad window'); ######################################################################################## # move a window to scratchpad, focus parent container, make it fullscreen, focus a child @@ -79,7 +70,7 @@ cmd 'fullscreen'; cmd 'focus child'; # see if the window really is in fullscreen mode -is(fullscreen_windows(), 1, 'amount of fullscreen windows after enabling fullscreen on parent'); +is_num_fullscreen($tmp, 1, 'amount of fullscreen windows after enabling fullscreen on parent'); ########################################################################## # show a scratchpad window; no window should be in fullscreen mode anymore @@ -89,6 +80,6 @@ is(fullscreen_windows(), 1, 'amount of fullscreen windows after enabling fullscr cmd 'scratchpad show'; # see if no window is in fullscreen mode -is(fullscreen_windows(), 0, 'amount of fullscreen windows after showing a scratchpad window while a parent container was in fullscreen mode'); +is_num_fullscreen($tmp, 0, 'amount of fullscreen windows after showing a scratchpad window while a parent container was in fullscreen mode'); done_testing; diff --git a/testcases/t/291-swap.t b/testcases/t/291-swap.t index d4a43bfb..3b61fdab 100644 --- a/testcases/t/291-swap.t +++ b/testcases/t/291-swap.t @@ -30,12 +30,6 @@ my ($result); my @fullscreen_permutations = ([], ["A"], ["B"], ["A", "B"]); my @urgent; -sub fullscreen_windows { - my $ws = shift if @_; - - scalar grep { $_->{fullscreen_mode} != 0 } @{get_ws_content($ws)} -} - ############################################################################### # Invalid con_id should not crash i3 # See issue #2895. @@ -191,14 +185,14 @@ for my $fullscreen (@fullscreen_permutations){ $nodes = get_ws_content($ws1); $node = $nodes->[0]; is($node->{window}, $B->{id}, 'B is on ws1:left'); - is(fullscreen_windows($ws1), $A_fullscreen, 'amount of fullscreen windows in ws1'); + is_num_fullscreen($ws1, $A_fullscreen, 'amount of fullscreen windows in ws1'); is($node->{fullscreen_mode}, $A_fullscreen, 'B got A\'s fullscreen mode'); $nodes = get_ws_content($ws2); $node = $nodes->[1]; is($node->{window}, $A->{id}, 'A is on ws2:right'); is(get_focused($ws2), $expected_focus, 'A is focused'); - is(fullscreen_windows($ws2), $B_fullscreen, 'amount of fullscreen windows in ws2'); + is_num_fullscreen($ws2, $B_fullscreen, 'amount of fullscreen windows in ws2'); is($node->{fullscreen_mode}, $B_fullscreen, 'A got B\'s fullscreen mode'); kill_all_windows; @@ -232,7 +226,7 @@ cmd '[con_mark=B] swap container with mark A'; $nodes = get_ws_content($ws1); is($nodes->[0]->{window}, $B->{id}, 'B is on ws1:left'); -is(fullscreen_windows($ws1), 1, 'F still fullscreen in ws1'); +is_num_fullscreen($ws1, 1, 'F still fullscreen in ws1'); is(get_focused($ws1), $expected_focus, 'F is still focused'); $nodes = get_ws_content($ws2); @@ -258,7 +252,6 @@ cmd "split v"; open_window; cmd "focus parent"; cmd "fullscreen enable"; -$F = fullscreen_windows($ws1); $expected_focus = get_focused($ws1); $ws2 = fresh_workspace; @@ -274,11 +267,11 @@ does_i3_live; $nodes = get_ws_content($ws1); is($nodes->[1]->{nodes}->[0]->{window}, $B->{id}, 'B is on top right in ws1'); is(get_focused($ws1), $expected_focus, 'The container of the stacked windows remains focused in ws1'); -is(fullscreen_windows($ws1), $F, 'Same amount of fullscreen windows in ws1'); +is_num_fullscreen($ws1, 1, 'Same amount of fullscreen windows in ws1'); $nodes = get_ws_content($ws2); is($nodes->[0]->{window}, $A->{id}, 'A is on ws2'); -is(fullscreen_windows($ws2), 1, 'A is in fullscreen mode'); +is_num_fullscreen($ws2, 1, 'A is in fullscreen mode'); ############################################################################### # Swap two non-focused containers within the same workspace. @@ -351,13 +344,13 @@ for my $fullscreen (@fullscreen_permutations){ $nodes = get_ws_content($ws1); $node = $nodes->[0]; is($node->{window}, $B->{id}, 'B is on the first workspace'); - is(fullscreen_windows($ws1), $A_fullscreen, 'amount of fullscreen windows in ws1'); + is_num_fullscreen($ws1, $A_fullscreen, 'amount of fullscreen windows in ws1'); is($node->{fullscreen_mode}, $A_fullscreen, 'B got A\'s fullscreen mode'); $nodes = get_ws_content($ws2); $node = $nodes->[0]; is($node->{window}, $A->{id}, 'A is on the second workspace'); - is(fullscreen_windows($ws2), $B_fullscreen, 'amount of fullscreen windows in ws2'); + is_num_fullscreen($ws2, $B_fullscreen, 'amount of fullscreen windows in ws2'); is($node->{fullscreen_mode}, $B_fullscreen, 'A got B\'s fullscreen mode'); is(get_focused($ws3), $expected_focus, 'F is still focused'); -- 2.39.2