]> git.sur5r.net Git - i3/i3/blob - testcases/t/213-layout-restore-simple.t
d681b8d63e12aca1da1f040483ac47a71e0f6a38
[i3/i3] / testcases / t / 213-layout-restore-simple.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 # Restores a simple layout from a JSON file.
18 use i3test;
19 use File::Temp qw(tempfile);
20 use IO::Handle;
21
22 ################################################################################
23 # empty layout file.
24 ################################################################################
25
26 my ($fh, $filename) = tempfile(UNLINK => 1);
27 cmd "append_layout $filename";
28
29 does_i3_live;
30
31 close($fh);
32
33 ################################################################################
34 # simple vsplit layout
35 ################################################################################
36
37 my $ws = fresh_workspace;
38
39 my @content = @{get_ws_content($ws)};
40 is(@content, 0, 'no nodes on the new workspace yet');
41
42 ($fh, $filename) = tempfile(UNLINK => 1);
43 print $fh <<EOT;
44 {
45     "layout": "splitv",
46     "nodes": [
47         {
48         },
49         {
50         }
51     ]
52 }
53 EOT
54 $fh->flush;
55 cmd "append_layout $filename";
56
57 does_i3_live;
58
59 @content = @{get_ws_content($ws)};
60 is(@content, 1, 'one node on the workspace now');
61 is($content[0]->{layout}, 'splitv', 'node has splitv layout');
62 is(@{$content[0]->{nodes}}, 2, 'node has two children');
63
64 close($fh);
65
66 ################################################################################
67 # two simple vsplit containers in the same file
68 ################################################################################
69
70 $ws = fresh_workspace;
71
72 @content = @{get_ws_content($ws)};
73 is(@content, 0, 'no nodes on the new workspace yet');
74
75 ($fh, $filename) = tempfile(UNLINK => 1);
76 print $fh <<EOT;
77 {
78     "layout": "splitv",
79     "nodes": [
80         {
81         },
82         {
83         }
84     ]
85 }
86
87 {
88     "layout": "splitv"
89 }
90 EOT
91 $fh->flush;
92 cmd "append_layout $filename";
93
94 does_i3_live;
95
96 @content = @{get_ws_content($ws)};
97 is(@content, 2, 'one node on the workspace now');
98 is($content[0]->{layout}, 'splitv', 'first node has splitv layout');
99 is(@{$content[0]->{nodes}}, 2, 'first node has two children');
100 is($content[1]->{layout}, 'splitv', 'second node has splitv layout');
101 is(@{$content[1]->{nodes}}, 0, 'first node has no children');
102
103 close($fh);
104
105 ################################################################################
106 # simple vsplit layout with swallow specifications
107 ################################################################################
108
109 $ws = fresh_workspace;
110
111 @content = @{get_ws_content($ws)};
112 is(@content, 0, 'no nodes on the new workspace yet');
113
114 ($fh, $filename) = tempfile(UNLINK => 1);
115 print $fh <<EOT;
116 {
117     "layout": "splitv",
118     "nodes": [
119         {
120             "swallows": [
121                 {
122                     "class": "top"
123                 }
124             ]
125         },
126         {
127             "swallows": [
128                 {
129                     "class": "bottom"
130                 }
131             ]
132         }
133     ]
134 }
135 EOT
136 $fh->flush;
137 cmd "append_layout $filename";
138
139 does_i3_live;
140
141 @content = @{get_ws_content($ws)};
142 is(@content, 1, 'one node on the workspace now');
143
144 my $top = open_window(
145     name => 'top window',
146     wm_class => 'top',
147     instance => 'top',
148 );
149
150 my $bottom = open_window(
151     name => 'bottom window',
152     wm_class => 'bottom',
153     instance => 'bottom',
154 );
155
156 @content = @{get_ws_content($ws)};
157 is(@content, 1, 'still one node on the workspace now');
158 my @nodes = @{$content[0]->{nodes}};
159 is($nodes[0]->{name}, 'top window', 'top window on top');
160
161 close($fh);
162
163 done_testing;