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,
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,
71 workspace_layout => 'default',
72 current_border_width => -1,
75 # a shallow copy is sufficient, since we only ignore values at the root
76 my $tree_copy = { %$tree };
78 for (keys %$expected) {
79 my $val = $expected->{$_};
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->{$_};
88 is_deeply($tree_copy, $expected, 'root node OK');
90 my @nodes = @{$tree->{nodes}};
92 ok(@nodes > 0, 'root node has at least one leaf');
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)');
99 my $content = first { $_->{type} eq 'con' } @{$ws->{nodes}};
100 @workspaces = (@workspaces, @{$content->{nodes}});
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');
107 # TODO: get the focused container
109 $i3->command('open')->recv;
111 # TODO: get the focused container, check if it changed.
112 # TODO: get the old focused container, check if there is a new child
114 #diag(Dumper(\@workspaces));
116 #diag(Dumper($tree));