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