From e84fa22bb80d606ee7e57ebbb1fe9e2095d23ecf Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 9 Apr 2014 21:47:32 +0200 Subject: [PATCH] Fix t/158-wm_take_focus, it was not properly verifying events (Thanks TonyC) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See also http://cr.i3wm.org/patch/500 for TonyC’s patch. This version reduces code duplication. --- testcases/lib/i3test.pm | 2 ++ testcases/t/158-wm_take_focus.t | 27 +++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/testcases/lib/i3test.pm b/testcases/lib/i3test.pm index d71a6e86..5dd96acd 100644 --- a/testcases/lib/i3test.pm +++ b/testcases/lib/i3test.pm @@ -714,6 +714,8 @@ sub sync_with_i3 { # event mask, it will get the ClientMessage. $x->send_event(0, $root, EVENT_MASK_SUBSTRUCTURE_REDIRECT, $msg); + return $myrnd if $args{dont_wait_for_event}; + # now wait until the reply is here return wait_for_event 2, sub { my ($event) = @_; diff --git a/testcases/t/158-wm_take_focus.t b/testcases/t/158-wm_take_focus.t index 222c93e4..b9bc6100 100644 --- a/testcases/t/158-wm_take_focus.t +++ b/testcases/t/158-wm_take_focus.t @@ -22,10 +22,29 @@ subtest 'Window without WM_TAKE_FOCUS', sub { fresh_workspace; my $window = open_window; - # sync_with_i3 will send a ClientMessage to i3 and receive one targeted to - # $window->id. If it receives WM_TAKE_FOCUS instead, it will return 0, thus - # the test will fail. - ok(sync_with_i3(window_id => $window->id), 'did not receive ClientMessage'); + # sync_with_i3 will send a ClientMessage to i3 and i3 will send the same + # payload back to $window->id. + my $myrnd = sync_with_i3( + window_id => $window->id, + dont_wait_for_event => 1, + ); + + # We check whether the first received message has the correct payload — if + # not, the received message was a WM_TAKE_FOCUS message. + my $first_event_is_clientmessage; + wait_for_event 2, sub { + my ($event) = @_; + # TODO: const + return 0 unless $event->{response_type} == 161; + + my ($win, $rnd) = unpack "LL", $event->{data}; + if (!defined($first_event_is_clientmessage)) { + $first_event_is_clientmessage = ($rnd == $myrnd); + } + return ($rnd == $myrnd); + }; + + ok($first_event_is_clientmessage, 'did not receive ClientMessage'); done_testing; };