2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
18 use List::Util qw(first);
20 # to not depend on List::MoreUtils
24 return 0 unless $cb->();
37 my $i3 = i3(get_socket_path());
43 my $tree = $i3->get_tree->recv;
53 orientation => $ignore,
55 split => JSON::XS::false,
58 window_rect => $ignore,
63 floating => 'auto_off',
64 last_split_layout => 'splith',
65 scratchpad_state => 'none',
67 focused => JSON::XS::false,
68 urgent => JSON::XS::false,
70 'floating_nodes' => $ignore,
73 # a shallow copy is sufficient, since we only ignore values at the root
74 my $tree_copy = { %$tree };
76 for (keys %$expected) {
77 my $val = $expected->{$_};
79 # delete unwanted keys, so we can use is_deeply()
80 if (ref($val) eq 'SCALAR' and $val == $ignore) {
81 delete $tree_copy->{$_};
82 delete $expected->{$_};
86 is_deeply($tree_copy, $expected, 'root node OK');
88 my @nodes = @{$tree->{nodes}};
90 ok(@nodes > 0, 'root node has at least one leaf');
92 ok((all { $_->{type} == 1 } @nodes), 'all nodes are of type CT_OUTPUT');
93 ok((none { defined($_->{window}) } @nodes), 'no CT_OUTPUT contains a window');
94 ok((all { @{$_->{nodes}} > 0 } @nodes), 'all nodes have at least one leaf (workspace)');
97 my $content = first { $_->{type} == 2 } @{$ws->{nodes}};
98 @workspaces = (@workspaces, @{$content->{nodes}});
101 ok((all { $_->{type} == 4 } @workspaces), 'all workspaces are of type CT_WORKSPACE');
102 #ok((all { @{$_->{nodes}} == 0 } @workspaces), 'all workspaces are empty yet');
103 ok((none { defined($_->{window}) } @workspaces), 'no CT_OUTPUT contains a window');
105 # TODO: get the focused container
107 $i3->command('open')->recv;
109 # TODO: get the focused container, check if it changed.
110 # TODO: get the old focused container, check if there is a new child
112 #diag(Dumper(\@workspaces));
114 #diag(Dumper($tree));