2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
17 # Tests all kinds of matching methods
20 use X11::XCB qw(PROP_MODE_REPLACE);
22 my $tmp = fresh_workspace;
24 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
27 my $window = open_window;
28 my $content = get_ws_content($tmp);
29 ok(@{$content} == 1, 'window mapped');
30 my $win = $content->[0];
32 ######################################################################
33 # first test that matches which should not match this window really do
35 ######################################################################
36 # TODO: specify more match types
37 # we can match on any (non-empty) class here since that window does not have
39 cmd q|[class=".*"] kill|;
40 cmd q|[con_id="99999"] kill|;
42 is_num_children($tmp, 1, 'window still there');
45 cmd 'nop now killing the window';
47 cmd qq|[con_id="$id"] kill|;
49 wait_for_unmap $window;
51 cmd 'nop checking if its gone';
52 is_num_children($tmp, 0, 'window killed');
54 # TODO: same test, but with pcre expressions
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
60 ######################################################################
62 $tmp = fresh_workspace;
64 # TODO: move to X11::XCB
66 my ($id, $class, $instance) = @_;
68 # Add a _NET_WM_STRUT_PARTIAL hint
69 my $atomname = $x->atom(name => 'WM_CLASS');
70 my $atomtype = $x->atom(name => 'STRING');
78 length($class) + length($instance) + 2,
79 "$instance\x00$class\x00"
85 my $wm_class = delete($args{wm_class}) || 'special';
89 before_map => sub { set_wm_class($_->id, $wm_class, $wm_class) },
93 my $left = open_special(name => 'left');
94 ok($left->mapped, 'left window mapped');
96 my $right = open_special(name => 'right');
97 ok($right->mapped, 'right window mapped');
99 # two windows should be here
100 is_num_children($tmp, 2, 'two windows opened');
102 cmd '[class="special" title="left"] kill';
106 is_num_children($tmp, 1, 'one window still there');
108 ######################################################################
109 # check that regular expressions work
110 ######################################################################
112 $tmp = fresh_workspace;
114 $left = open_special(name => 'left', wm_class => 'special7');
115 ok($left->mapped, 'left window mapped');
116 is_num_children($tmp, 1, 'window opened');
118 cmd '[class="^special[0-9]$"] kill';
119 wait_for_unmap $left;
120 is_num_children($tmp, 0, 'window killed');
122 ######################################################################
123 # check that UTF-8 works when matching
124 ######################################################################
126 $tmp = fresh_workspace;
128 $left = open_special(name => 'ä 3', wm_class => 'special7');
129 ok($left->mapped, 'left window mapped');
130 is_num_children($tmp, 1, 'window opened');
132 cmd '[title="^\w [3]$"] kill';
133 wait_for_unmap $left;
134 is_num_children($tmp, 0, 'window killed');