]> git.sur5r.net Git - i3/i3/blob - testcases/t/119-match.t
Merge branch 'master' into next
[i3/i3] / testcases / t / 119-match.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://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 # Tests all kinds of matching methods
18 #
19 use i3test;
20 use X11::XCB qw(PROP_MODE_REPLACE);
21
22 my $tmp = fresh_workspace;
23
24 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
25
26 # Open a new window
27 my $window = open_window;
28 my $content = get_ws_content($tmp);
29 ok(@{$content} == 1, 'window mapped');
30 my $win = $content->[0];
31
32 ######################################################################
33 # first test that matches which should not match this window really do
34 # not match it
35 ######################################################################
36 # TODO: specify more match types
37 # we can match on any (non-empty) class here since that window does not have
38 # WM_CLASS set
39 cmd q|[class=".*"] kill|;
40 cmd q|[con_id="99999"] kill|;
41
42 is_num_children($tmp, 1, 'window still there');
43
44 # now kill the window
45 cmd 'nop now killing the window';
46 my $id = $win->{id};
47 cmd qq|[con_id="$id"] kill|;
48
49 wait_for_unmap $window;
50
51 cmd 'nop checking if its gone';
52 is_num_children($tmp, 0, 'window killed');
53
54 # TODO: same test, but with pcre expressions
55
56 ######################################################################
57 # check that multiple criteria work are checked with a logical AND,
58 # not a logical OR (that is, matching is not cancelled after the first
59 # criterion matches).
60 ######################################################################
61
62 $tmp = fresh_workspace;
63
64 # TODO: move to X11::XCB
65 sub set_wm_class {
66     my ($id, $class, $instance) = @_;
67
68     # Add a _NET_WM_STRUT_PARTIAL hint
69     my $atomname = $x->atom(name => 'WM_CLASS');
70     my $atomtype = $x->atom(name => 'STRING');
71
72     $x->change_property(
73         PROP_MODE_REPLACE,
74         $id,
75         $atomname->id,
76         $atomtype->id,
77         8,
78         length($class) + length($instance) + 2,
79         "$instance\x00$class\x00"
80     );
81 }
82
83 sub open_special {
84     my %args = @_;
85     my $wm_class = delete($args{wm_class}) || 'special';
86
87     return open_window(
88         %args,
89         before_map => sub { set_wm_class($_->id, $wm_class, $wm_class) },
90     );
91 }
92
93 my $left = open_special(name => 'left');
94 ok($left->mapped, 'left window mapped');
95
96 my $right = open_special(name => 'right');
97 ok($right->mapped, 'right window mapped');
98
99 # two windows should be here
100 is_num_children($tmp, 2, 'two windows opened');
101
102 cmd '[class="special" title="left"] kill';
103
104 sync_with_i3;
105
106 is_num_children($tmp, 1, 'one window still there');
107
108 ######################################################################
109 # check that regular expressions work
110 ######################################################################
111
112 $tmp = fresh_workspace;
113
114 $left = open_special(name => 'left', wm_class => 'special7');
115 ok($left->mapped, 'left window mapped');
116 is_num_children($tmp, 1, 'window opened');
117
118 cmd '[class="^special[0-9]$"] kill';
119 wait_for_unmap $left;
120 is_num_children($tmp, 0, 'window killed');
121
122 ######################################################################
123 # check that UTF-8 works when matching
124 ######################################################################
125
126 $tmp = fresh_workspace;
127
128 $left = open_special(name => 'ä 3', wm_class => 'special7');
129 ok($left->mapped, 'left window mapped');
130 is_num_children($tmp, 1, 'window opened');
131
132 cmd '[title="^\w [3]$"] kill';
133 wait_for_unmap $left;
134 is_num_children($tmp, 0, 'window killed');
135
136 done_testing;