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