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,
57 window_rect => $ignore,
62 floating => 'auto_off',
63 last_split_layout => 'splith',
64 scratchpad_state => 'none',
66 focused => JSON::XS::false,
67 urgent => JSON::XS::false,
69 'floating_nodes' => $ignore,
70 workspace_layout => 'default',
71 current_border_width => -1,
74 # a shallow copy is sufficient, since we only ignore values at the root
75 my $tree_copy = { %$tree };
77 for (keys %$expected) {
78 my $val = $expected->{$_};
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->{$_};
87 is_deeply($tree_copy, $expected, 'root node OK');
89 my @nodes = @{$tree->{nodes}};
91 ok(@nodes > 0, 'root node has at least one leaf');
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)');
98 my $content = first { $_->{type} == 2 } @{$ws->{nodes}};
99 @workspaces = (@workspaces, @{$content->{nodes}});
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');
106 # TODO: get the focused container
108 $i3->command('open')->recv;
110 # TODO: get the focused container, check if it changed.
111 # TODO: get the old focused container, check if there is a new child
113 #diag(Dumper(\@workspaces));
115 #diag(Dumper($tree));