]> git.sur5r.net Git - i3/i3/blob - testcases/t/234-layout-restore-output.t
Merge branch 'master' into next
[i3/i3] / testcases / t / 234-layout-restore-output.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 # Verifies that entire outputs can be saved and restored properly by i3.
18 # Ticket: #1306
19 # Bug still in: 4.8-26-gf96ec19
20 use i3test;
21 use File::Temp qw(tempfile);
22 use IO::Handle;
23
24 my $ws = fresh_workspace;
25
26 ################################################################################
27 # Append a new workspace with a name.
28 ################################################################################
29
30 ok(!workspace_exists('ws_new'), 'workspace "ws_new" does not exist yet');
31
32 my ($fh, $filename) = tempfile(UNLINK => 1);
33 print $fh <<'EOT';
34 // vim:ts=4:sw=4:et
35 {
36     // workspace with 1 children
37     "border": "pixel",
38     "floating": "auto_off",
39     "layout": "splith",
40     "percent": null,
41     "type": "workspace",
42     "name": "ws_new",
43     "nodes": [
44         {
45             "border": "pixel",
46             "floating": "auto_off",
47             "geometry": {
48                "height": 268,
49                "width": 484,
50                "x": 0,
51                "y": 0
52             },
53             "name": "vals@w00t: ~",
54             "percent": 1,
55             "swallows": [
56                {
57                // "class": "^URxvt$",
58                // "instance": "^urxvt$",
59                // "title": "^vals\\@w00t\\:\\ \\~$"
60                }
61             ],
62             "type": "con"
63         }
64     ]
65 }
66 EOT
67 $fh->flush;
68 cmd "append_layout $filename";
69
70 ok(workspace_exists('ws_new'), 'workspace "ws_new" exists now');
71
72 does_i3_live;
73
74 close($fh);
75
76 ################################################################################
77 # Append a new workspace with a name that clashes with an existing workspace.
78 ################################################################################
79
80 my @old_workspaces = @{get_workspace_names()};
81
82 cmd "append_layout $filename";
83
84 my @new_workspaces = @{get_workspace_names()};
85 cmp_ok(scalar @new_workspaces, '>', scalar @old_workspaces, 'more workspaces than before');
86
87 my %created_workspaces = map { ($_, 1) } @new_workspaces;
88 delete $created_workspaces{$_} for @old_workspaces;
89 diag('created workspaces = ' . Dumper(keys %created_workspaces));
90 cmp_ok(scalar keys %created_workspaces, '>', 0, 'new workspaces appeared');
91
92 ################################################################################
93 # Append a new workspace without a name.
94 ################################################################################
95
96 ok(!workspace_exists('unnamed'), 'workspace "unnamed" does not exist yet');
97
98 ($fh, $filename) = tempfile(UNLINK => 1);
99 print $fh <<'EOT';
100 // vim:ts=4:sw=4:et
101 {
102     // workspace with 1 children
103     "border": "pixel",
104     "floating": "auto_off",
105     "layout": "splith",
106     "percent": null,
107     "type": "workspace",
108     "nodes": [
109         {
110             "border": "pixel",
111             "floating": "auto_off",
112             "geometry": {
113                "height": 268,
114                "width": 484,
115                "x": 0,
116                "y": 0
117             },
118             "name": "vals@w00t: ~",
119             "percent": 1,
120             "swallows": [
121                {
122                // "class": "^URxvt$",
123                // "instance": "^urxvt$",
124                // "title": "^vals\\@w00t\\:\\ \\~$"
125                }
126             ],
127             "type": "con"
128         }
129     ]
130 }
131 EOT
132 $fh->flush;
133 cmd "append_layout $filename";
134
135 ok(workspace_exists('unnamed'), 'workspace "unnamed" exists now');
136
137 ################################################################################
138 # Append a workspace with a numeric name, ensure it has ->num set.
139 ################################################################################
140
141 ok(!workspace_exists('4'), 'workspace "4" does not exist yet');
142
143 ($fh, $filename) = tempfile(UNLINK => 1);
144 print $fh <<'EOT';
145 // vim:ts=4:sw=4:et
146 {
147     // workspace with 1 children
148     "border": "pixel",
149     "floating": "auto_off",
150     "layout": "splith",
151     "percent": null,
152     "type": "workspace",
153     "name": "4",
154     "nodes": [
155         {
156             "border": "pixel",
157             "floating": "auto_off",
158             "geometry": {
159                "height": 268,
160                "width": 484,
161                "x": 0,
162                "y": 0
163             },
164             "name": "vals@w00t: ~",
165             "percent": 1,
166             "swallows": [
167                {
168                // "class": "^URxvt$",
169                // "instance": "^urxvt$",
170                // "title": "^vals\\@w00t\\:\\ \\~$"
171                }
172             ],
173             "type": "con"
174         }
175     ]
176 }
177 EOT
178 $fh->flush;
179 cmd "append_layout $filename";
180
181 ok(workspace_exists('4'), 'workspace "4" exists now');
182 $ws = get_ws("4");
183 is($ws->{num}, 4, 'workspace number is 4');
184
185 ################################################################################
186 # Append a workspace with a numeric name, with the “type” property at the end
187 # of the JSON blurb (which is valid and sometimes happens).
188 ################################################################################
189
190 ok(!workspace_exists('5'), 'workspace "5" does not exist yet');
191
192 ($fh, $filename) = tempfile(UNLINK => 1);
193 print $fh <<'EOT';
194 // vim:ts=4:sw=4:et
195 {
196     // workspace with 1 children
197     "border": "pixel",
198     "floating": "auto_off",
199     "layout": "splith",
200     "percent": null,
201     "name": "5",
202     "nodes": [
203         {
204             "border": "pixel",
205             "floating": "auto_off",
206             "geometry": {
207                "height": 268,
208                "width": 484,
209                "x": 0,
210                "y": 0
211             },
212             "name": "vals@w00t: ~",
213             "percent": 1,
214             "swallows": [
215                {
216                // "class": "^URxvt$",
217                // "instance": "^urxvt$",
218                // "title": "^vals\\@w00t\\:\\ \\~$"
219                }
220             ],
221             "type": "con"
222         }
223     ],
224     "type": "workspace"
225 }
226 EOT
227 $fh->flush;
228 cmd "append_layout $filename";
229
230 ok(workspace_exists('5'), 'workspace "5" exists now');
231 $ws = get_ws("5");
232 is($ws->{num}, 5, 'workspace number is 5');
233
234 done_testing;