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