i3 - improved tiling WM


Test workspace empty event semantics

Patch status: merged

Patch by Marco Hunsicker

Long description:

This patchs provides testcases for the workspace "empty" event.

To apply this patch, use:
curl http://cr.i3wm.org/patch/501/raw.patch | git am

b/testcases/t/223-ipc-workspace-empty.t

16
@@ -0,0 +1,123 @@
17
+#!perl
18
+# vim:ts=4:sw=4:expandtab
19
+#
20
+# Please read the following documents before working on tests:
21
+# • http://build.i3wm.org/docs/testsuite.html
22
+#   (or docs/testsuite)
23
+#
24
+# • http://build.i3wm.org/docs/lib-i3test.html
25
+#   (alternatively: perldoc ./testcases/lib/i3test.pm)
26
+#
27
+# • http://build.i3wm.org/docs/ipc.html
28
+#   (or docs/ipc)
29
+#
30
+# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
31
+#   (unless you are already familiar with Perl)
32
+#
33
+# Checks the workspace "empty" event semantics.
34
+#
35
+use i3test;
36
+
37
+SKIP: {
38
+
39
+    skip "AnyEvent::I3 too old (need >= 0.15)", 1 if $AnyEvent::I3::VERSION < 0.15;
40
+
41
+################################################################################
42
+# check that the workspace empty event is send upon workspace switch when the
43
+# old workspace is empty
44
+################################################################################
45
+subtest 'Workspace empty event upon switch', sub {
46
+    my $ws2 = fresh_workspace;
47
+    my $w2 = open_window();
48
+    my $ws1 = fresh_workspace;
49
+    my $w1 = open_window();
50
+
51
+    cmd '[id="' . $w1->id . '"] kill';
52
+
53
+    my $cond = AnyEvent->condvar;
54
+    my $client = i3(get_socket_path(0));
55
+    $client->connect()->recv;
56
+    $client->subscribe({
57
+        workspace => sub {
58
+            my ($event) = @_;
59
+            $cond->send($event);
60
+        }
61
+    })->recv;
62
+
63
+    cmd "workspace $ws2";
64
+
65
+    sync_with_i3;
66
+
67
+    my $event = $cond->recv;
68
+    is($event->{change}, 'empty', '"Empty" event received upon workspace switch');
69
+};
70
+
71
+################################################################################
72
+# check that no workspace empty event is send upon workspace switch if the
73
+# workspace is not empty
74
+################################################################################
75
+subtest 'No workspace empty event', sub {
76
+    my $ws2 = fresh_workspace;
77
+    my $w2 = open_window();
78
+    my $ws1 = fresh_workspace;
79
+    my $w1 = open_window();
80
+
81
+    my @events;
82
+    my $cond = AnyEvent->condvar;
83
+    my $client = i3(get_socket_path(0));
84
+    $client->connect()->recv;
85
+    $client->subscribe({
86
+        workspace => sub {
87
+            my ($event) = @_;
88
+            push @events, $event;
89
+        }
90
+    })->recv;
91
+
92
+    # Wait for the workspace event on a new connection. Events will be delivered
93
+    # to older connections earlier, so by the time it arrives here, it should be
94
+    # in @events already.
95
+    my $ws_event_block_conn = i3(get_socket_path(0));
96
+    $ws_event_block_conn->connect()->recv;
97
+    $ws_event_block_conn->subscribe({ workspace => sub { $cond->send(1) }});
98
+
99
+    cmd "workspace $ws2";
100
+
101
+    sync_with_i3;
102
+
103
+    my @expected_events = grep { $_->{change} eq 'focus' } @events;
104
+    my @empty_events = grep { $_->{change} eq 'empty' } @events;
105
+    is(@expected_events, 1, '"Focus" event received');
106
+    is(@empty_events, 0, 'No "empty" events received');
107
+};
108
+
109
+################################################################################
110
+# check that workspace empty event is send when the last window has been closed
111
+# on invisible workspace
112
+################################################################################
113
+subtest 'Workspace empty event upon window close', sub {
114
+    my $ws1 = fresh_workspace;
115
+    my $w1 = open_window();
116
+    my $ws2 = fresh_workspace;
117
+    my $w2 = open_window();
118
+
119
+    my $cond = AnyEvent->condvar;
120
+    my $client = i3(get_socket_path(0));
121
+    $client->connect()->recv;
122
+    $client->subscribe({
123
+        workspace => sub {
124
+            my ($event) = @_;
125
+            $cond->send($event);
126
+        }
127
+    })->recv;
128
+
129
+    cmd '[id="' . $w1->id . '"] kill';
130
+
131
+    sync_with_i3;
132
+
133
+    my $event = $cond->recv;
134
+    is($event->{change}, 'empty', '"Empty" event received upon window close');
135
+};
136
+
137
+}
138
+
139
+done_testing;