]> git.sur5r.net Git - i3/i3/blobdiff - testcases/t/19-match.t
Merge branch 'master' into next
[i3/i3] / testcases / t / 19-match.t
index bfeda815315b89270e75ce4e8ec657ecb43a03c3..8b9d21d3e0da46fbc422bda5041cd9365fcbbb61 100644 (file)
@@ -3,32 +3,16 @@
 #
 # Tests all kinds of matching methods
 #
-use i3test tests => 4;
+use i3test;
 use X11::XCB qw(:all);
 
-my $i3 = i3("/tmp/nestedcons");
-
-my $tmp = get_unused_workspace();
-$i3->command("workspace $tmp")->recv;
+my $tmp = fresh_workspace;
 
 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
 
 # Open a new window
 my $x = X11::XCB::Connection->new;
-my $window = $x->root->create_child(
-    class => WINDOW_CLASS_INPUT_OUTPUT,
-    rect => [ 0, 0, 30, 30 ],
-    background_color => '#C0C0C0',
-);
-
-$window->map;
-# give it some time to be picked up by the window manager
-# TODO: better check for $window->mapped or something like that?
-# maybe we can even wait for getting mapped?
-my $c = 0;
-while (@{get_ws_content($tmp)} == 0 and $c++ < 5) {
-    sleep 0.25;
-}
+my $window = open_window($x);
 my $content = get_ws_content($tmp);
 ok(@{$content} == 1, 'window mapped');
 my $win = $content->[0];
@@ -37,10 +21,11 @@ my $win = $content->[0];
 # first test that matches which should not match this window really do
 # not match it
 ######################################################################
-# TODO: use PCRE expressions
 # TODO: specify more match types
-$i3->command(q|[class="*"] kill|)->recv;
-$i3->command(q|[con_id="99999"] kill|)->recv;
+# we can match on any (non-empty) class here since that window does not have
+# WM_CLASS set
+cmd q|[class=".*"] kill|;
+cmd q|[con_id="99999"] kill|;
 
 $content = get_ws_content($tmp);
 ok(@{$content} == 1, 'window still there');
@@ -48,10 +33,9 @@ ok(@{$content} == 1, 'window still there');
 # now kill the window
 cmd 'nop now killing the window';
 my $id = $win->{id};
-$i3->command(qq|[con_id="$id"] kill|)->recv;
+cmd qq|[con_id="$id"] kill|;
 
-# give i3 some time to pick up the UnmapNotify event
-sleep 0.25;
+wait_for_unmap $x;
 
 cmd 'nop checking if its gone';
 $content = get_ws_content($tmp);
@@ -59,4 +43,128 @@ ok(@{$content} == 0, 'window killed');
 
 # TODO: same test, but with pcre expressions
 
-diag( "Testing i3, Perl $], $^X" );
+######################################################################
+# check that multiple criteria work are checked with a logical AND,
+# not a logical OR (that is, matching is not cancelled after the first
+# criterion matches).
+######################################################################
+
+$tmp = fresh_workspace;
+
+# TODO: move to X11::XCB
+sub set_wm_class {
+    my ($id, $class, $instance) = @_;
+
+    # Add a _NET_WM_STRUT_PARTIAL hint
+    my $atomname = $x->atom(name => 'WM_CLASS');
+    my $atomtype = $x->atom(name => 'STRING');
+
+    $x->change_property(
+        PROP_MODE_REPLACE,
+        $id,
+        $atomname->id,
+        $atomtype->id,
+        8,
+        length($class) + length($instance) + 2,
+        "$instance\x00$class\x00"
+    );
+}
+
+my $left = $x->root->create_child(
+    class => WINDOW_CLASS_INPUT_OUTPUT,
+    rect => [ 0, 0, 30, 30 ],
+    background_color => '#0000ff',
+    event_mask => [ 'structure_notify' ],
+);
+
+$left->_create;
+set_wm_class($left->id, 'special', 'special');
+$left->name('left');
+$left->map;
+ok(wait_for_map($x), 'left window mapped');
+
+my $right = $x->root->create_child(
+    class => WINDOW_CLASS_INPUT_OUTPUT,
+    rect => [ 0, 0, 30, 30 ],
+    background_color => '#0000ff',
+    event_mask => [ 'structure_notify' ],
+);
+
+$right->_create;
+set_wm_class($right->id, 'special', 'special');
+$right->name('right');
+$right->map;
+ok(wait_for_map($x), 'right window mapped');
+
+# two windows should be here
+$content = get_ws_content($tmp);
+ok(@{$content} == 2, 'two windows opened');
+
+cmd '[class="special" title="left"] kill';
+
+sync_with_i3($x);
+
+$content = get_ws_content($tmp);
+is(@{$content}, 1, 'one window still there');
+
+######################################################################
+# check that regular expressions work
+######################################################################
+
+$tmp = fresh_workspace;
+
+$left = $x->root->create_child(
+    class => WINDOW_CLASS_INPUT_OUTPUT,
+    rect => [ 0, 0, 30, 30 ],
+    background_color => '#0000ff',
+    event_mask => [ 'structure_notify' ],
+);
+
+$left->_create;
+set_wm_class($left->id, 'special7', 'special7');
+$left->name('left');
+$left->map;
+ok(wait_for_map($x), 'left window mapped');
+
+# two windows should be here
+$content = get_ws_content($tmp);
+ok(@{$content} == 1, 'window opened');
+
+cmd '[class="^special[0-9]$"] kill';
+
+wait_for_unmap $x;
+
+$content = get_ws_content($tmp);
+is(@{$content}, 0, 'window killed');
+
+######################################################################
+# check that UTF-8 works when matching
+######################################################################
+
+$tmp = fresh_workspace;
+
+$left = $x->root->create_child(
+    class => WINDOW_CLASS_INPUT_OUTPUT,
+    rect => [ 0, 0, 30, 30 ],
+    background_color => '#0000ff',
+    event_mask => [ 'structure_notify' ],
+);
+
+$left->_create;
+set_wm_class($left->id, 'special7', 'special7');
+$left->name('รค 3');
+$left->map;
+ok(wait_for_map($x), 'left window mapped');
+
+# two windows should be here
+$content = get_ws_content($tmp);
+ok(@{$content} == 1, 'window opened');
+
+cmd '[title="^\w [3]$"] kill';
+
+wait_for_unmap $x;
+
+$content = get_ws_content($tmp);
+is(@{$content}, 0, 'window killed');
+
+done_testing;