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 # checks if mark and unmark work correctly
19 use List::Util qw(first);
21 my ($con, $first, $second);
24 return i3(get_socket_path())->get_marks->recv;
27 sub get_mark_for_window_on_workspace {
30 my $current = first { $_->{window} == $con->{id} } @{get_ws_content($ws)};
31 return $current->{marks};
34 ##############################################################
35 # 1: check that there are no marks set yet
36 ##############################################################
38 my $tmp = fresh_workspace;
42 is_deeply(get_marks(), [], 'no marks set yet');
44 ##############################################################
45 # 2: mark a con, check that it's marked, unmark it, check that
46 ##############################################################
48 my $one = open_window;
51 is_deeply(get_marks(), ["foo"], 'mark foo set');
55 is_deeply(get_marks(), [], 'mark foo removed');
57 ##############################################################
58 # 3: mark three cons, check that they are marked
59 # unmark one con, check that it's unmarked
60 # unmark all cons, check that they are unmarked
61 ##############################################################
63 my $left = open_window;
64 my $middle = open_window;
65 my $right = open_window;
74 # get_marks replys an array of marks, whose order is undefined,
75 # so we use sort to be able to compare the output
78 is_deeply(sort(get_marks()), ["left","middle","right"], 'all three marks set');
82 is_deeply(sort(get_marks()), ["left","middle"], 'mark right removed');
86 is_deeply(get_marks(), [], 'all marks removed');
88 ##############################################################
89 # 4: mark a con, use same mark to mark another con,
90 # check that only the latter is marked
91 ##############################################################
94 $second = open_window;
100 is_deeply(get_mark_for_window_on_workspace($tmp, $first), [ 'important' ], 'first container now has the mark');
101 ok(!get_mark_for_window_on_workspace($tmp, $second), 'second container lost the mark');
103 ##############################################################
104 # 5: mark a con, toggle the mark, check that the mark is gone
105 ##############################################################
108 cmd 'mark important';
109 cmd 'mark --toggle important';
110 ok(!get_mark_for_window_on_workspace($tmp, $con), 'container no longer has the mark');
112 ##############################################################
113 # 6: toggle a mark on an unmarked con, check it is marked
114 ##############################################################
117 cmd 'mark --toggle important';
118 is_deeply(get_mark_for_window_on_workspace($tmp, $con), [ 'important' ], 'container now has the mark');
120 ##############################################################
121 # 7: mark a con, toggle a different mark, check it is marked
123 ##############################################################
127 cmd 'mark --replace --toggle important';
128 is_deeply(get_mark_for_window_on_workspace($tmp, $con), [ 'important' ], 'container has the most recent mark');
130 ##############################################################
131 # 8: mark a con, toggle the mark on another con,
132 # check only the latter has the mark
133 ##############################################################
135 $first = open_window;
136 $second = open_window;
138 cmd 'mark important';
140 cmd 'mark --toggle important';
142 is_deeply(get_mark_for_window_on_workspace($tmp, $first), [ 'important' ], 'left container has the mark now');
143 ok(!get_mark_for_window_on_workspace($tmp, $second), 'second containr no longer has the mark');
145 ##############################################################
146 # 9: try to mark two cons with the same mark and check that
148 ##############################################################
150 $first = open_window(wm_class => 'iamnotunique');
151 $second = open_window(wm_class => 'iamnotunique');
153 my $result = cmd "[instance=iamnotunique] mark important";
155 is($result->[0]->{success}, 0, 'command was unsuccessful');
156 is($result->[0]->{error}, 'A mark must not be put onto more than one window', 'correct error is returned');
157 ok(!get_mark_for_window_on_workspace($tmp, $first), 'first container is not marked');
158 ok(!get_mark_for_window_on_workspace($tmp, $second), 'second containr is not marked');
160 ##############################################################