From 56499d8374c6c6064eebbe8c6a8c535854a8d543 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 2 Aug 2011 19:21:09 +0200 Subject: [PATCH 1/3] tests: make t/65-for-window.t use separate i3 instances --- testcases/i3-test.config | 4 --- testcases/t/65-for_window.t | 69 ++++++++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 5 deletions(-) diff --git a/testcases/i3-test.config b/testcases/i3-test.config index 4f59205e..513dda36 100644 --- a/testcases/i3-test.config +++ b/testcases/i3-test.config @@ -1,7 +1,3 @@ -for_window [class="borderless"] border none -for_window [title="special borderless title"] border none -for_window [title="special mark title"] border none, mark bleh - # ISO 10646 = Unicode font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1 diff --git a/testcases/t/65-for_window.t b/testcases/t/65-for_window.t index d2952540..f6765175 100644 --- a/testcases/t/65-for_window.t +++ b/testcases/t/65-for_window.t @@ -1,14 +1,19 @@ #!perl # vim:ts=4:sw=4:expandtab +# !NO_I3_INSTANCE! will prevent complete-run.pl from starting i3 # # use X11::XCB qw(:all); use X11::XCB::Connection; use i3test; +use Cwd qw(abs_path); +use Proc::Background; +use File::Temp qw(tempfile tempdir); my $x = X11::XCB::Connection->new; -my $tmp = fresh_workspace; +# assuming we are run by complete-run.pl +my $i3_path = abs_path("../i3"); ############################################################## # 1: test the following directive: @@ -18,6 +23,25 @@ my $tmp = fresh_workspace; # "borderless" (should get no border) ############################################################## +my $socketpath = File::Temp::tempnam('/tmp', 'i3-test-socket-'); + +my ($fh, $tmpfile) = tempfile(); +say $fh "# i3 config file (v4)"; +say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1"; +say $fh "ipc-socket $socketpath"; +say $fh q|for_window [class="borderless"] border none|; +close($fh); + +diag("Starting i3"); +my $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null"; +my $process = Proc::Background->new($i3cmd); +sleep 1; + +# force update of the cached socket path in lib/i3test +get_socket_path(0); + +my $tmp = fresh_workspace; + my $window = $x->root->create_child( class => WINDOW_CLASS_INPUT_OUTPUT, rect => [ 0, 0, 30, 30 ], @@ -81,11 +105,31 @@ sleep 0.25; @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 0, 'no more nodes'); +exit_gracefully($process->pid); + ############################################################## # 2: match on the title, check if for_window is really executed # only once ############################################################## +($fh, $tmpfile) = tempfile(); +say $fh "# i3 config file (v4)"; +say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1"; +say $fh "ipc-socket $socketpath"; +say $fh q|for_window [class="borderless"] border none|; +say $fh q|for_window [title="special borderless title"] border none|; +close($fh); + +diag("Starting i3"); +my $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null"; +my $process = Proc::Background->new($i3cmd); +sleep 1; + +# force update of the cached socket path in lib/i3test +get_socket_path(0); + +$tmp = fresh_workspace; + $window = $x->root->create_child( class => WINDOW_CLASS_INPUT_OUTPUT, rect => [ 0, 0, 30, 30 ], @@ -126,10 +170,31 @@ sleep 0.25; @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 0, 'no more nodes'); +exit_gracefully($process->pid); + ############################################################## # 3: match on the title, set border style *and* a mark ############################################################## +($fh, $tmpfile) = tempfile(); +say $fh "# i3 config file (v4)"; +say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1"; +say $fh "ipc-socket $socketpath"; +say $fh q|for_window [class="borderless"] border none|; +say $fh q|for_window [title="special borderless title"] border none|; +say $fh q|for_window [title="special mark title"] border none, mark bleh|; +close($fh); + +diag("Starting i3"); +my $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null"; +my $process = Proc::Background->new($i3cmd); +sleep 1; + +# force update of the cached socket path in lib/i3test +get_socket_path(0); + +$tmp = fresh_workspace; + $window = $x->root->create_child( class => WINDOW_CLASS_INPUT_OUTPUT, rect => [ 0, 0, 30, 30 ], @@ -157,4 +222,6 @@ cmd qq|[con_mark="bleh"] focus|; @content = @{get_ws_content($tmp)}; ok($content[0]->{focused}, 'first node focused'); +exit_gracefully($process->pid); + done_testing; From b57e8570c9183f7fc4ac0342675b58b9700aab25 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 2 Aug 2011 19:37:04 +0200 Subject: [PATCH 2/3] t/65-for_window: add a testcase for multiple criteria --- testcases/t/65-for_window.t | 56 +++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/testcases/t/65-for_window.t b/testcases/t/65-for_window.t index f6765175..26ccb7cf 100644 --- a/testcases/t/65-for_window.t +++ b/testcases/t/65-for_window.t @@ -222,6 +222,62 @@ cmd qq|[con_mark="bleh"] focus|; @content = @{get_ws_content($tmp)}; ok($content[0]->{focused}, 'first node focused'); +exit_gracefully($process->pid); + +############################################################## +# 4: multiple criteria for the for_window command +############################################################## + +($fh, $tmpfile) = tempfile(); +say $fh "# i3 config file (v4)"; +say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1"; +say $fh "ipc-socket $socketpath"; +say $fh q|for_window [class="borderless" title="usethis"] border none|; +close($fh); + +diag("Starting i3"); +my $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/tmp/a 2>/dev/null"; +my $process = Proc::Background->new($i3cmd); +sleep 1; + +# force update of the cached socket path in lib/i3test +get_socket_path(0); + +$tmp = fresh_workspace; + +$window = $x->root->create_child( + class => WINDOW_CLASS_INPUT_OUTPUT, + rect => [ 0, 0, 30, 30 ], + background_color => '#00ff00', +); + +$window->_create; + +set_wm_class($window->id, 'borderless', 'borderless'); +$window->name('usethis'); +$window->map; +sleep 0.25; + +@content = @{get_ws_content($tmp)}; +cmp_ok(@content, '==', 1, 'one node on this workspace now'); +is($content[0]->{border}, 'none', 'no border'); + +$window->unmap; +sleep 0.25; + +@content = @{get_ws_content($tmp)}; +cmp_ok(@content, '==', 0, 'no nodes on this workspace now'); + +set_wm_class($window->id, 'borderless', 'borderless'); +$window->name('notthis'); +$window->map; +sleep 0.25; + +@content = @{get_ws_content($tmp)}; +cmp_ok(@content, '==', 1, 'one node on this workspace now'); +is($content[0]->{border}, 'normal', 'no border'); + + exit_gracefully($process->pid); done_testing; From 554a43ca4a7bc028255adc5d159cb32ac02aef36 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 2 Aug 2011 19:44:44 +0200 Subject: [PATCH 3/3] Bugfix: Make the criteria rules recursive in src/cfgparse.y, too (Thanks f8l) --- src/cfgparse.y | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cfgparse.y b/src/cfgparse.y index ae789576..53b08cda 100644 --- a/src/cfgparse.y +++ b/src/cfgparse.y @@ -685,6 +685,11 @@ matchend: ; criteria: + criteria criterion + | criterion + ; + +criterion: TOK_CLASS '=' STR { printf("criteria: class = %s\n", $3);