]> git.sur5r.net Git - i3/i3/blobdiff - testcases/t/115-ipc-workspaces.t
Merge branch 'next' into master
[i3/i3] / testcases / t / 115-ipc-workspaces.t
index cffcc45584832a0505dbd004a959fc44860f98f0..b0c4354ec10fe7385e41ed5a95d7dd06b3e01051 100644 (file)
@@ -2,13 +2,13 @@
 # vim:ts=4:sw=4:expandtab
 #
 # Please read the following documents before working on tests:
-# • http://build.i3wm.org/docs/testsuite.html
+# • https://build.i3wm.org/docs/testsuite.html
 #   (or docs/testsuite)
 #
-# • http://build.i3wm.org/docs/lib-i3test.html
+# • https://build.i3wm.org/docs/lib-i3test.html
 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
 #
-# • http://build.i3wm.org/docs/ipc.html
+# • https://build.i3wm.org/docs/ipc.html
 #   (or docs/ipc)
 #
 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
 
 use i3test;
 
-my $i3 = i3(get_socket_path());
-
-################################
-# Workspaces requests and events
-################################
-
-my $focused = get_ws(focused_ws());
-
-# Events
+my $old_ws = get_ws(focused_ws());
 
 # 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;
+my @events = events_for(
+    sub { cmd 'workspace 2' },
+    'workspace');
+
+my $current_ws = get_ws(focused_ws());
 
-cmd 'workspace 2';
+is(scalar @events, 3, 'Received 3 events');
+is($events[0]->{change}, 'init', 'First event has change = init');
+is($events[0]->{current}->{id}, $current_ws->{id}, 'the "current" property contains the initted workspace con');
 
-my $t;
-$t = AnyEvent->timer(
-    after => 0.5,
-    cb => sub {
-        $init->send(0);
-        $focus->send(0);
-        $empty->send(0);
-    }
-);
+is($events[1]->{change}, 'focus', 'Second event has change = focus');
+is($events[1]->{current}->{id}, $current_ws->{id}, 'the "current" property should contain the focused workspace con');
+is($events[1]->{old}->{id}, $old_ws->{id}, 'the "old" property should contain the workspace con that was focused last');
 
-ok($init->recv, 'Workspace "init" event received');
-ok($focus->recv, 'Workspace "focus" event received');
-ok($empty->recv, 'Workspace "empty" event received');
+is($events[2]->{change}, 'empty', 'Third event has change = empty');
+is($events[2]->{current}->{id}, $old_ws->{id}, 'the "current" property should contain the emptied workspace con');
 
 done_testing;