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;
54 orientation => $ignore,
59 window_rect => $ignore,
64 floating => 'auto_off',
65 last_split_layout => 'splith',
66 scratchpad_state => 'none',
68 focused => JSON::XS::false,
69 urgent => JSON::XS::false,
71 'floating_nodes' => $ignore,
72 workspace_layout => 'default',
73 current_border_width => -1,
76 # a shallow copy is sufficient, since we only ignore values at the root
77 my $tree_copy = { %$tree };
79 for (keys %$expected) {
80 my $val = $expected->{$_};
82 # delete unwanted keys, so we can use is_deeply()
83 if (ref($val) eq 'SCALAR' and $val == $ignore) {
84 delete $tree_copy->{$_};
85 delete $expected->{$_};
89 is_deeply($tree_copy, $expected, 'root node OK');
91 my @nodes = @{$tree->{nodes}};
93 ok(@nodes > 0, 'root node has at least one leaf');
95 ok((all { $_->{type} eq 'output' } @nodes), 'all nodes are of type CT_OUTPUT');
96 ok((none { defined($_->{window}) } @nodes), 'no CT_OUTPUT contains a window');
97 ok((all { @{$_->{nodes}} > 0 } @nodes), 'all nodes have at least one leaf (workspace)');
100 my $content = first { $_->{type} eq 'con' } @{$ws->{nodes}};
101 @workspaces = (@workspaces, @{$content->{nodes}});
104 ok((all { $_->{type} eq 'workspace' } @workspaces), 'all workspaces are of type CT_WORKSPACE');
105 #ok((all { @{$_->{nodes}} == 0 } @workspaces), 'all workspaces are empty yet');
106 ok((none { defined($_->{window}) } @workspaces), 'no CT_OUTPUT contains a window');
108 # TODO: get the focused container
110 $i3->command('open')->recv;
112 # TODO: get the focused container, check if it changed.
113 # TODO: get the old focused container, check if there is a new child
115 #diag(Dumper(\@workspaces));
117 #diag(Dumper($tree));