]> git.sur5r.net Git - i3/i3/blob - testcases/t/215-layout-restore-crash.t
Merge branch 'next' into master
[i3/i3] / testcases / t / 215-layout-restore-crash.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • https://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 i3 does not crash when a layout is partially loadable.
18 # ticket #1145, bug still present in commit b109b1b20dd51401dc929407453d3acdd8ff5566
19 use i3test;
20 use File::Temp qw(tempfile);
21 use IO::Handle;
22
23 ################################################################################
24 # empty layout file.
25 ################################################################################
26
27 my ($fh, $filename) = tempfile(UNLINK => 1);
28 cmd "append_layout $filename";
29
30 does_i3_live;
31
32 close($fh);
33
34 ################################################################################
35 # file with a superfluous trailing comma
36 ################################################################################
37
38 my $ws = fresh_workspace;
39
40 my @content = @{get_ws_content($ws)};
41 is(@content, 0, 'no nodes on the new workspace yet');
42
43 ($fh, $filename) = tempfile(UNLINK => 1);
44 print $fh <<'EOT';
45 // vim:ts=4:sw=4:et
46 {
47     "border": "pixel",
48     "floating": "auto_off",
49     "geometry": {
50        "height": 777,
51        "width": 199,
52        "x": 0,
53        "y": 0
54     },
55     "name": "Buddy List",
56     "percent": 0.116145833333333,
57     "swallows": [
58        {
59        "class": "^Pidgin$",
60        "window_role": "^buddy_list$"
61        }
62     ],
63     "type": "con"
64 }
65
66 {
67     // splitv split container with 1 children
68     "border": "pixel",
69     "floating": "auto_off",
70     "layout": "splitv",
71     "percent": 0.883854166666667,
72     "swallows": [
73        {}
74     ],
75     "type": "con",
76     "nodes": [
77         {
78             // splitv split container with 2 children
79             "border": "pixel",
80             "floating": "auto_off",
81             "layout": "splitv",
82             "percent": 1,
83             "swallows": [
84                {}
85             ],
86             "type": "con",
87             "nodes": [
88                 {
89                     "border": "pixel",
90                     "floating": "auto_off",
91                     "geometry": {
92                        "height": 318,
93                        "width": 566,
94                        "x": 0,
95                        "y": 0
96                     },
97                     "name": "zsh",
98                     "percent": 0.5,
99                     "swallows": [
100                        {
101                          "class": "^URxvt$",
102                          "instance": "^IRC$",
103                        }
104                     ],
105                     "type": "con"
106                 },
107                 {
108                     "border": "pixel",
109                     "floating": "auto_off",
110                     "geometry": {
111                        "height": 1057,
112                        "width": 636,
113                        "x": 0,
114                        "y": 0
115                     },
116                     "name": "Michael Stapelberg",
117                     "percent": 0.5,
118                     "swallows": [
119                        {
120                          "class": "^Pidgin$",
121                          "window_role": "^conversation$"
122                        }
123                     ],
124                     "type": "con"
125                 }
126             ]
127         }
128     ]
129 }
130
131 EOT
132 $fh->flush;
133 my $reply = cmd "append_layout $filename";
134 ok(!$reply->[0]->{success}, 'IPC reply did not indicate success');
135
136 does_i3_live;
137
138
139 close($fh);
140
141 ################################################################################
142 # another file with a superfluous trailing comma (issue #2755)
143 ################################################################################
144
145 subtest 'issue 2755' => sub {
146     plan tests => 4;
147     $ws = fresh_workspace;
148
149     @content = @{get_ws_content($ws)};
150     is(@content, 0, 'no nodes on the new workspace yet');
151
152     ($fh, $filename) = tempfile(UNLINK => 1);
153     print $fh <<'EOT';
154 // vim:ts=4:sw=4:et
155 {
156     // splith split container with 2 children
157     "border": "normal",
158     "floating": "auto_off",
159     "layout": "splith",
160     "percent": null,
161     "type": "con",
162     "nodes": [
163         {
164             "border": "normal",
165             "current_border_width": 2,
166             "floating": "auto_off",
167             "geometry": {
168                "height": 860,
169                "width": 1396,
170                "x": 1922,
171                "y": 38
172             },
173             "name": "Chromium1",
174             "percent": 0.5,
175             "swallows": [
176                {
177                   "class": "^Chromium$",
178                // "instance": "^chromium$",
179                // "title": "^Git\\ Tutorial\\ \\-\\ corp\\ \\-\\ Chromium$",
180                // "transient_for": "^$",
181                // "window_role": "^browser$"
182                }
183             ],
184             "type": "con"
185         },
186         {
187             "border": "normal",
188             "current_border_width": 2,
189             "floating": "auto_off",
190             "geometry": {
191                "height": 1040,
192                "width": 956,
193                "x": 2,
194                "y": 38
195             },
196             "name": "Chromium2",
197             "percent": 0.5,
198             "swallows": [
199                {
200                   "class": "^Chromium$",
201                // "instance": "^chromium$",
202                // "title": "^Nutanix\\ \\-\\ Prod\\ \\-\\ Sign\\ In\\ \\-\\ Chromium$",
203                // "transient_for": "^$",
204                // "window_role": "^browser$"
205                }
206             ],
207             "type": "con"
208         }
209     ]
210 }
211
212 EOT
213     $fh->flush;
214     $reply = cmd "append_layout $filename";
215     ok(!$reply->[0]->{success}, 'IPC reply indicated success');
216
217     does_i3_live;
218
219     # Move to a different workspace rendered the half-attached con’s con->parent
220     # invalid.
221     fresh_workspace;
222
223     cmd '[urgent=latest] focus';
224     $reply = cmd 'scratchpad show';
225
226     does_i3_live;
227
228     close($fh);
229 };
230
231 ################################################################################
232 # wrong percent key in a child node
233 ################################################################################
234
235 $ws = fresh_workspace;
236
237 @content = @{get_ws_content($ws)};
238 is(@content, 0, 'no nodes on the new workspace yet');
239
240 ($fh, $filename) = tempfile(UNLINK => 1);
241 print $fh <<'EOT';
242 // vim:ts=4:sw=4:et
243 {
244     "border": "pixel",
245     "floating": "auto_off",
246     "layout": "splitv",
247     "type": "con",
248     "nodes": [
249         {
250             "border": "pixel",
251             "floating": "auto_off",
252             "geometry": {
253                "height": 318,
254                "width": 566,
255                "x": 0,
256                "y": 0
257             },
258             "name": "zsh",
259             "percent": 0.833333,
260             "swallows": [
261                {
262                  "class": "^URxvt$",
263                  "instance": "^IRC$"
264                }
265             ],
266             "type": "con"
267         }
268     ]
269 }
270
271 EOT
272 $fh->flush;
273 cmd "append_layout $filename";
274
275 does_i3_live;
276
277 close($fh);
278
279
280 done_testing;