X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=testcases%2Ft%2F119-match.t;h=0aaeddd732ddfc676380cc451f0c2f28fd666fe3;hb=7e424b2d71e4c3dbdb314aad03479fc8ee5480ff;hp=e2e553f439b372c52cabcf3ee5c579c7a47bec1a;hpb=f7f1ec5dab85e934de8220fb48dee861e1097e35;p=i3%2Fi3 diff --git a/testcases/t/119-match.t b/testcases/t/119-match.t index e2e553f4..0aaeddd7 100644 --- a/testcases/t/119-match.t +++ b/testcases/t/119-match.t @@ -1,10 +1,22 @@ #!perl # vim:ts=4:sw=4:expandtab # +# Please read the following documents before working on tests: +# • http://build.i3wm.org/docs/testsuite.html +# (or docs/testsuite) +# +# • http://build.i3wm.org/docs/lib-i3test.html +# (alternatively: perldoc ./testcases/lib/i3test.pm) +# +# • http://build.i3wm.org/docs/ipc.html +# (or docs/ipc) +# +# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf +# (unless you are already familiar with Perl) +# # Tests all kinds of matching methods # use i3test; -use X11::XCB qw(PROP_MODE_REPLACE WINDOW_CLASS_INPUT_OUTPUT); my $tmp = fresh_workspace; @@ -26,8 +38,7 @@ my $win = $content->[0]; cmd q|[class=".*"] kill|; cmd q|[con_id="99999"] kill|; -$content = get_ws_content($tmp); -ok(@{$content} == 1, 'window still there'); +is_num_children($tmp, 1, 'window still there'); # now kill the window cmd 'nop now killing the window'; @@ -37,8 +48,7 @@ cmd qq|[con_id="$id"] kill|; wait_for_unmap $window; cmd 'nop checking if its gone'; -$content = get_ws_content($tmp); -ok(@{$content} == 0, 'window killed'); +is_num_children($tmp, 0, 'window killed'); # TODO: same test, but with pcre expressions @@ -50,61 +60,20 @@ ok(@{$content} == 0, 'window killed'); $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($left), '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($right), 'right window mapped'); +my $left = open_window(wm_class => 'special', name => 'left'); +ok($left->mapped, 'left window mapped'); + +my $right = open_window(wm_class => 'special', name => 'right'); +ok($right->mapped, 'right window mapped'); # two windows should be here -$content = get_ws_content($tmp); -ok(@{$content} == 2, 'two windows opened'); +is_num_children($tmp, 2, 'two windows opened'); cmd '[class="special" title="left"] kill'; -sync_with_i3($x); +sync_with_i3; -$content = get_ws_content($tmp); -is(@{$content}, 1, 'one window still there'); +is_num_children($tmp, 1, 'one window still there'); ###################################################################### # check that regular expressions work @@ -112,29 +81,13 @@ is(@{$content}, 1, 'one window still there'); $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($left), 'left window mapped'); - -# two windows should be here -$content = get_ws_content($tmp); -ok(@{$content} == 1, 'window opened'); +$left = open_window(name => 'left', wm_class => 'special7'); +ok($left->mapped, 'left window mapped'); +is_num_children($tmp, 1, 'window opened'); cmd '[class="^special[0-9]$"] kill'; - wait_for_unmap $left; - -$content = get_ws_content($tmp); -is(@{$content}, 0, 'window killed'); +is_num_children($tmp, 0, 'window killed'); ###################################################################### # check that UTF-8 works when matching @@ -142,28 +95,12 @@ is(@{$content}, 0, 'window killed'); $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($left), 'left window mapped'); - -# two windows should be here -$content = get_ws_content($tmp); -ok(@{$content} == 1, 'window opened'); +$left = open_window(name => 'ä 3', wm_class => 'special7'); +ok($left->mapped, 'left window mapped'); +is_num_children($tmp, 1, 'window opened'); cmd '[title="^\w [3]$"] kill'; - wait_for_unmap $left; - -$content = get_ws_content($tmp); -is(@{$content}, 0, 'window killed'); +is_num_children($tmp, 0, 'window killed'); done_testing;