From a6b6bb670a373b632c84bcf9998793ceb2a24099 Mon Sep 17 00:00:00 2001 From: Francesco Mazzoli Date: Sat, 3 Nov 2012 11:17:33 +0000 Subject: [PATCH] workspace events test --- testcases/t/115-ipc-workspaces.t | 58 +++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/testcases/t/115-ipc-workspaces.t b/testcases/t/115-ipc-workspaces.t index ec2ec9d2..1dd12417 100644 --- a/testcases/t/115-ipc-workspaces.t +++ b/testcases/t/115-ipc-workspaces.t @@ -18,20 +18,62 @@ use i3test; my $i3 = i3(get_socket_path()); -#################### -# Request workspaces -#################### - -SKIP: { - skip "IPC API not yet stabilized", 2; +################################ +# Workspaces requests and events +################################ my $workspaces = $i3->get_workspaces->recv; ok(@{$workspaces} > 0, "More than zero workspaces found"); -#my $name_exists = all { defined($_->{name}) } @{$workspaces}; -#ok($name_exists, "All workspaces have a name"); +# my $name_exists = all { defined($_->{name}) } @{$workspaces}; +# ok($name_exists, "All workspaces have a name"); +# Focused workspace +my $focused; +foreach (@{$workspaces}) { + $focused = $_ if $_->{focused}; } +ok($focused, "At least one workspace is focused"); + +# Events + +# We are switching to an empty workpspace from an empty workspace, so we expect +# to receive "init", "focus", and "empty". +my $init = AnyEvent->condvar; +my $focus = AnyEvent->condvar; +my $empty = AnyEvent->condvar; +$i3->subscribe({ + workspace => sub { + my ($event) = @_; + if ($event->{change} eq 'init') { + $init->send(1); + } elsif ($event->{change} eq 'focus') { + # Check that we have the old and new workspace + $focus->send( + $event->{current}->{name} == '2' && + $event->{old}->{name} == $focused->{name} + ); + } elsif ($event->{change} eq 'empty') { + $empty->send(1); + } + } +})->recv; + +cmd 'workspace 2'; + +my $t; +$t = AnyEvent->timer( + after => 0.5, + cb => sub { + $init->send(0); + $focus->send(0); + $empty->send(0); + } +); + +ok($init->recv, 'Workspace "init" event received'); +ok($focus->recv, 'Workspace "focus" event received'); +ok($empty->recv, 'Workspace "empty" event received'); done_testing; -- 2.39.5