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);
22 return i3(get_socket_path())->get_marks->recv;
25 sub get_mark_for_window_on_workspace {
28 my $current = first { $_->{window} == $con->{id} } @{get_ws_content($ws)};
29 return $current->{mark};
32 ##############################################################
33 # 1: check that there are no marks set yet
34 ##############################################################
36 my $tmp = fresh_workspace;
40 is_deeply(get_marks(), [], 'no marks set yet');
43 ##############################################################
44 # 2: mark a con, check that it's marked, unmark it, check that
45 ##############################################################
47 my $one = open_window;
50 is_deeply(get_marks(), ["foo"], 'mark foo set');
54 is_deeply(get_marks(), [], 'mark foo removed');
56 ##############################################################
57 # 3: mark three cons, check that they are marked
58 # unmark one con, check that it's unmarked
59 # unmark all cons, check that they are unmarked
60 ##############################################################
62 my $left = open_window;
63 my $middle = open_window;
64 my $right = open_window;
73 # get_marks replys an array of marks, whose order is undefined,
74 # so we use sort to be able to compare the output
77 is_deeply(sort(get_marks()), ["left","middle","right"], 'all three marks set');
81 is_deeply(sort(get_marks()), ["left","middle"], 'mark right removed');
85 is_deeply(get_marks(), [], 'all marks removed');
87 ##############################################################
88 # 4: mark a con, use same mark to mark another con,
89 # check that only the latter is marked
90 ##############################################################
92 my $first = open_window;
93 my $second = open_window;
99 is(get_mark_for_window_on_workspace($tmp, $first), 'important', 'first container now has the mark');
100 ok(!get_mark_for_window_on_workspace($tmp, $second), 'second container lost the mark');
102 ##############################################################
103 # 5: mark a con, toggle the mark, check that the mark is gone
104 ##############################################################
106 my $con = open_window;
107 cmd 'mark important';
108 cmd 'mark --toggle important';
109 ok(!get_mark_for_window_on_workspace($tmp, $con), 'container no longer has the mark');
111 ##############################################################
112 # 6: toggle a mark on an unmarked con, check it is marked
113 ##############################################################
115 my $con = open_window;
116 cmd 'mark --toggle important';
117 is(get_mark_for_window_on_workspace($tmp, $con), 'important', 'container now has the mark');
119 ##############################################################
120 # 7: mark a con, toggle a different mark, check it is marked
122 ##############################################################
124 my $con = open_window;
126 cmd 'mark --toggle important';
127 is(get_mark_for_window_on_workspace($tmp, $con), 'important', 'container has the most recent mark');
129 ##############################################################
130 # 8: mark a con, toggle the mark on another con,
131 # check only the latter has the mark
132 ##############################################################
134 my $first = open_window;
135 my $second = open_window;
137 cmd 'mark important';
139 cmd 'mark --toggle important';
141 is(get_mark_for_window_on_workspace($tmp, $first), 'important', 'left container has the mark now');
142 ok(!get_mark_for_window_on_workspace($tmp, $second), 'second containr no longer has the mark');
144 ##############################################################
145 # 9: try to mark two cons with the same mark and check that
147 ##############################################################
149 my $first = open_window(wm_class => 'iamnotunique');
150 my $second = open_window(wm_class => 'iamnotunique');
152 my $result = cmd "[instance=iamnotunique] mark important";
154 is($result->[0]->{success}, 0, 'command was unsuccessful');
155 is($result->[0]->{error}, 'A mark must not be put onto more than one window', 'correct error is returned');
156 ok(!get_mark_for_window_on_workspace($tmp, $first), 'first container is not marked');
157 ok(!get_mark_for_window_on_workspace($tmp, $second), 'second containr is not marked');
159 ##############################################################