]> git.sur5r.net Git - i3/i3/blob - testcases/t/304-ipc-workspace-init.t
Merge pull request #3614 from NilsIrl/next
[i3/i3] / testcases / t / 304-ipc-workspace-init.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • https://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # Test that the workspace init event is correctly sent.
18 # Ticket: #3631
19 # Bug still in: 4.16-85-g2d6e09a6
20
21 use i3test i3_config => <<EOT;
22 # i3 config file (v4)
23 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
24
25 # fake-1 under fake-0 to not interfere with left/right wraping
26 fake-outputs 1024x768+0+0,1024x768+0+1024
27 workspace X output fake-1
28 EOT
29
30 sub workspace_init_subtest {
31     my $cmd = shift;
32     my $num_events = shift;
33     my @events = events_for(sub { cmd $cmd }, 'workspace');
34
35     my @init = grep { $_->{change} eq 'init' } @events;
36     my $len = scalar @init;
37     is($len, $num_events, "Received $num_events workspace::init event");
38     $num_events = $len if $len < $num_events;
39     for my $idx (0 .. $num_events - 1) {
40         my $name = shift;
41         my $output = shift;
42         is($init[$idx]->{current}->{name}, $name, "workspace name $name matches");
43         is($init[$idx]->{current}->{output}, $output, "workspace output $output matches");
44     }
45 }
46
47 subtest 'focus outputs', \&workspace_init_subtest, 'focus output fake-1, focus output fake-0', 0;
48 subtest 'new workspaces', \&workspace_init_subtest,
49   'workspace a, workspace b, workspace a, workspace a', 3, 'a',
50   'fake-0', 'b', 'fake-0', 'a', 'fake-0';
51 open_window;    # Prevent workspace "a" from being deleted.
52 subtest 'return on existing workspace', \&workspace_init_subtest,
53   'workspace a, workspace b, workspace a', 1, 'b', 'fake-0';
54 subtest 'assigned workspace is already open', \&workspace_init_subtest,
55   'workspace X, workspace b, workspace a', 1, 'b', 'fake-1';
56 subtest 'assigned workspace was deleted and now is initialized again', \&workspace_init_subtest,
57   'workspace X, workspace b, workspace a', 2, 'X', 'fake-1', 'b', 'fake-1';
58 subtest 'move workspace to output', \&workspace_init_subtest,
59   'move workspace to output fake-1, move workspace to output fake-0', 2, '1', 'fake-0', 'X',
60   'fake-1';
61 subtest 'move window to workspace', \&workspace_init_subtest, 'move to workspace b', 1, 'b',
62   'fake-0';
63 subtest 'back_and_forth', \&workspace_init_subtest,
64   'workspace b, workspace back_and_forth, workspace b', 1,
65   'a', 'fake-0';
66 subtest 'move window to workspace back_and_forth', \&workspace_init_subtest,
67   'move window to workspace back_and_forth', 1, 'a', 'fake-0';
68
69 done_testing;