]> git.sur5r.net Git - i3/i3/blob - testcases/t/116-nestedcons.t
Merge branch 'master' into next
[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     nodes => $ignore,
51     window => undef,
52     name => 'root',
53     orientation => $ignore,
54     type => 0,
55     id => $ignore,
56     rect => $ignore,
57     window_rect => $ignore,
58     geometry => $ignore,
59     swallows => $ignore,
60     percent => undef,
61     layout => 'splith',
62     floating => 'auto_off',
63     last_split_layout => 'splith',
64     scratchpad_state => 'none',
65     focus => $ignore,
66     focused => JSON::XS::false,
67     urgent => JSON::XS::false,
68     border => 'normal',
69     'floating_nodes' => $ignore,
70     workspace_layout => 'default',
71     current_border_width => -1,
72 };
73
74 # a shallow copy is sufficient, since we only ignore values at the root
75 my $tree_copy = { %$tree };
76
77 for (keys %$expected) {
78     my $val = $expected->{$_};
79
80     # delete unwanted keys, so we can use is_deeply()
81     if (ref($val) eq 'SCALAR' and $val == $ignore) {
82         delete $tree_copy->{$_};
83         delete $expected->{$_};
84     }
85 }
86
87 is_deeply($tree_copy, $expected, 'root node OK');
88
89 my @nodes = @{$tree->{nodes}};
90
91 ok(@nodes > 0, 'root node has at least one leaf');
92
93 ok((all { $_->{type} == 1 } @nodes), 'all nodes are of type CT_OUTPUT');
94 ok((none { defined($_->{window}) } @nodes), 'no CT_OUTPUT contains a window');
95 ok((all { @{$_->{nodes}} > 0 } @nodes), 'all nodes have at least one leaf (workspace)');
96 my @workspaces;
97 for my $ws (@nodes) {
98     my $content = first { $_->{type} == 2 } @{$ws->{nodes}};
99     @workspaces = (@workspaces, @{$content->{nodes}});
100 }
101
102 ok((all { $_->{type} == 4 } @workspaces), 'all workspaces are of type CT_WORKSPACE');
103 #ok((all { @{$_->{nodes}} == 0 } @workspaces), 'all workspaces are empty yet');
104 ok((none { defined($_->{window}) } @workspaces), 'no CT_OUTPUT contains a window');
105
106 # TODO: get the focused container
107
108 $i3->command('open')->recv;
109
110 # TODO: get the focused container, check if it changed.
111 # TODO: get the old focused container, check if there is a new child
112
113 #diag(Dumper(\@workspaces));
114
115 #diag(Dumper($tree));
116
117
118 done_testing;