]> git.sur5r.net Git - i3/i3/blob - testcases/t/116-nestedcons.t
Merge branch 'next' into master
[i3/i3] / testcases / t / 116-nestedcons.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 use i3test;
18 use List::Util qw(first);
19
20 # to not depend on List::MoreUtils
21 sub all (&@) {
22     my $cb = shift;
23     for (@_) {
24         return 0 unless $cb->();
25     }
26     return 1;
27 }
28
29 sub none (&@) {
30     my $cb = shift;
31     for (@_) {
32         return 0 if $cb->();
33     }
34     return 1;
35 }
36
37 my $i3 = i3(get_socket_path());
38
39 ####################
40 # Request tree
41 ####################
42
43 my $tree = $i3->get_tree->recv;
44
45 # a unique value
46 my $ignore = \"";
47
48 my $expected = {
49     fullscreen_mode => 0,
50     sticky => $ignore,
51     nodes => $ignore,
52     window => undef,
53     name => 'root',
54     orientation => $ignore,
55     type => 'root',
56     id => $ignore,
57     rect => $ignore,
58     deco_rect => $ignore,
59     window_rect => $ignore,
60     geometry => $ignore,
61     swallows => $ignore,
62     percent => undef,
63     layout => 'splith',
64     floating => 'auto_off',
65     last_split_layout => 'splith',
66     scratchpad_state => 'none',
67     focus => $ignore,
68     focused => JSON::XS::false,
69     urgent => JSON::XS::false,
70     border => 'normal',
71     'floating_nodes' => $ignore,
72     workspace_layout => 'default',
73     current_border_width => -1,
74 };
75
76 # a shallow copy is sufficient, since we only ignore values at the root
77 my $tree_copy = { %$tree };
78
79 for (keys %$expected) {
80     my $val = $expected->{$_};
81
82     # delete unwanted keys, so we can use is_deeply()
83     if (ref($val) eq 'SCALAR' and $val == $ignore) {
84         delete $tree_copy->{$_};
85         delete $expected->{$_};
86     }
87 }
88
89 is_deeply($tree_copy, $expected, 'root node OK');
90
91 my @nodes = @{$tree->{nodes}};
92
93 ok(@nodes > 0, 'root node has at least one leaf');
94
95 ok((all { $_->{type} eq 'output' } @nodes), 'all nodes are of type CT_OUTPUT');
96 ok((none { defined($_->{window}) } @nodes), 'no CT_OUTPUT contains a window');
97 ok((all { @{$_->{nodes}} > 0 } @nodes), 'all nodes have at least one leaf (workspace)');
98 my @workspaces;
99 for my $ws (@nodes) {
100     my $content = first { $_->{type} eq 'con' } @{$ws->{nodes}};
101     @workspaces = (@workspaces, @{$content->{nodes}});
102 }
103
104 ok((all { $_->{type} eq 'workspace' } @workspaces), 'all workspaces are of type CT_WORKSPACE');
105 #ok((all { @{$_->{nodes}} == 0 } @workspaces), 'all workspaces are empty yet');
106 ok((none { defined($_->{window}) } @workspaces), 'no CT_OUTPUT contains a window');
107
108 # TODO: get the focused container
109
110 $i3->command('open')->recv;
111
112 # TODO: get the focused container, check if it changed.
113 # TODO: get the old focused container, check if there is a new child
114
115 #diag(Dumper(\@workspaces));
116
117 #diag(Dumper($tree));
118
119
120 done_testing;