]> git.sur5r.net Git - i3/i3/blob - testcases/t/215-layout-restore-crash.t
Merge pull request #1621 from Airblader/feature-1416
[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 # • 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 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 diag('reply = ' . Dumper($reply));
135
136 does_i3_live;
137
138 ok(!$reply->[0]->{success}, 'IPC reply did not indicate success');
139
140 close($fh);
141
142 ################################################################################
143 # wrong percent key in a child node
144 ################################################################################
145
146 $ws = fresh_workspace;
147
148 @content = @{get_ws_content($ws)};
149 is(@content, 0, 'no nodes on the new workspace yet');
150
151 ($fh, $filename) = tempfile(UNLINK => 1);
152 print $fh <<'EOT';
153 // vim:ts=4:sw=4:et
154 {
155     "border": "pixel",
156     "floating": "auto_off",
157     "layout": "splitv",
158     "type": "con",
159     "nodes": [
160         {
161             "border": "pixel",
162             "floating": "auto_off",
163             "geometry": {
164                "height": 318,
165                "width": 566,
166                "x": 0,
167                "y": 0
168             },
169             "name": "zsh",
170             "percent": 0.833333,
171             "swallows": [
172                {
173                  "class": "^URxvt$",
174                  "instance": "^IRC$"
175                }
176             ],
177             "type": "con"
178         }
179     ]
180 }
181
182 EOT
183 $fh->flush;
184 cmd "append_layout $filename";
185
186 does_i3_live;
187
188 close($fh);
189
190
191 done_testing;