]> 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 use i3test;
5 use List::Util qw(first);
6
7 # to not depend on List::MoreUtils
8 sub all (&@) {
9     my $cb = shift;
10     for (@_) {
11         return 0 unless $cb->();
12     }
13     return 1;
14 }
15
16 sub none (&@) {
17     my $cb = shift;
18     for (@_) {
19         return 0 if $cb->();
20     }
21     return 1;
22 }
23
24 my $i3 = i3(get_socket_path());
25
26 ####################
27 # Request tree
28 ####################
29
30 my $tree = $i3->get_tree->recv;
31
32 # a unique value
33 my $ignore = \"";
34
35 my $expected = {
36     fullscreen_mode => 0,
37     nodes => $ignore,
38     window => undef,
39     name => 'root',
40     orientation => $ignore,
41     type => 0,
42     id => $ignore,
43     rect => $ignore,
44     window_rect => $ignore,
45     geometry => $ignore,
46     swallows => $ignore,
47     percent => undef,
48     layout => 'default',
49     scratchpad_state => 'none',
50     focus => $ignore,
51     focused => JSON::XS::false,
52     urgent => JSON::XS::false,
53     border => 'normal',
54     'floating_nodes' => $ignore,
55 };
56
57 # a shallow copy is sufficient, since we only ignore values at the root
58 my $tree_copy = { %$tree };
59
60 for (keys %$expected) {
61     my $val = $expected->{$_};
62
63     # delete unwanted keys, so we can use is_deeply()
64     if (ref($val) eq 'SCALAR' and $val == $ignore) {
65         delete $tree_copy->{$_};
66         delete $expected->{$_};
67     }
68 }
69
70 is_deeply($tree_copy, $expected, 'root node OK');
71
72 my @nodes = @{$tree->{nodes}};
73
74 ok(@nodes > 0, 'root node has at least one leaf');
75
76 ok((all { $_->{type} == 1 } @nodes), 'all nodes are of type CT_OUTPUT');
77 ok((none { defined($_->{window}) } @nodes), 'no CT_OUTPUT contains a window');
78 ok((all { @{$_->{nodes}} > 0 } @nodes), 'all nodes have at least one leaf (workspace)');
79 my @workspaces;
80 for my $ws (@nodes) {
81     my $content = first { $_->{type} == 2 } @{$ws->{nodes}};
82     @workspaces = (@workspaces, @{$content->{nodes}});
83 }
84
85 ok((all { $_->{type} == 4 } @workspaces), 'all workspaces are of type CT_WORKSPACE');
86 #ok((all { @{$_->{nodes}} == 0 } @workspaces), 'all workspaces are empty yet');
87 ok((none { defined($_->{window}) } @workspaces), 'no CT_OUTPUT contains a window');
88
89 # TODO: get the focused container
90
91 $i3->command('open')->recv;
92
93 # TODO: get the focused container, check if it changed.
94 # TODO: get the old focused container, check if there is a new child
95
96 #diag(Dumper(\@workspaces));
97
98 #diag(Dumper($tree));
99
100
101 done_testing;