]> git.sur5r.net Git - i3/i3/blob - testcases/t/210-mark-unmark.t
Merge branch 'master' into next
[i3/i3] / testcases / t / 210-mark-unmark.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # checks if mark and unmark work correctly
18 use i3test;
19 use List::Util qw(first);
20
21 sub get_marks {
22     return i3(get_socket_path())->get_marks->recv;
23 }
24
25 sub get_mark_for_window_on_workspace {
26     my ($ws, $con) = @_;
27
28     my $current = first { $_->{window} == $con->{id} } @{get_ws_content($ws)};
29     return $current->{mark};
30 }
31
32 ##############################################################
33 # 1: check that there are no marks set yet
34 ##############################################################
35
36 my $tmp = fresh_workspace;
37
38 cmd 'split h';
39
40 is_deeply(get_marks(), [], 'no marks set yet');
41
42
43 ##############################################################
44 # 2: mark a con, check that it's marked, unmark it, check that
45 ##############################################################
46
47 my $one = open_window;
48 cmd 'mark foo';
49
50 is_deeply(get_marks(), ["foo"], 'mark foo set');
51
52 cmd 'unmark foo';
53
54 is_deeply(get_marks(), [], 'mark foo removed');
55
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 ##############################################################
61
62 my $left = open_window;
63 my $middle = open_window;
64 my $right = open_window;
65
66 cmd 'mark right';
67 cmd 'focus left';
68 cmd 'mark middle';
69 cmd 'focus left';
70 cmd 'mark left';
71
72 #
73 # get_marks replys an array of marks, whose order is undefined,
74 # so we use sort to be able to compare the output
75 #
76
77 is_deeply(sort(get_marks()), ["left","middle","right"], 'all three marks set');
78
79 cmd 'unmark right';
80
81 is_deeply(sort(get_marks()), ["left","middle"], 'mark right removed');
82
83 cmd 'unmark';
84
85 is_deeply(get_marks(), [], 'all marks removed');
86
87 ##############################################################
88 # 4: mark a con, use same mark to mark another con,
89 #    check that only the latter is marked
90 ##############################################################
91
92 my $first = open_window;
93 my $second = open_window;
94
95 cmd 'mark important';
96 cmd 'focus left';
97 cmd 'mark important';
98
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');
101
102 ##############################################################
103 # 5: mark a con, toggle the mark, check that the mark is gone
104 ##############################################################
105
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');
110
111 ##############################################################
112 # 6: toggle a mark on an unmarked con, check it is marked
113 ##############################################################
114
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');
118
119 ##############################################################
120 # 7: mark a con, toggle a different mark, check it is marked
121 #    with the new mark
122 ##############################################################
123
124 my $con = open_window;
125 cmd 'mark boring';
126 cmd 'mark --toggle important';
127 is(get_mark_for_window_on_workspace($tmp, $con), 'important', 'container has the most recent mark');
128
129 ##############################################################
130 # 8: mark a con, toggle the mark on another con,
131 #    check only the latter has the mark
132 ##############################################################
133
134 my $first = open_window;
135 my $second = open_window;
136
137 cmd 'mark important';
138 cmd 'focus left';
139 cmd 'mark --toggle important';
140
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');
143
144 ##############################################################
145 # 9: try to mark two cons with the same mark and check that
146 #    it fails
147 ##############################################################
148
149 my $first = open_window(wm_class => 'iamnotunique');
150 my $second = open_window(wm_class => 'iamnotunique');
151
152 my $result = cmd "[instance=iamnotunique] mark important";
153
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');
158
159 ##############################################################
160
161 done_testing;