aboutsummaryrefslogtreecommitdiff
path: root/testcases/t/116-nestedcons.t
blob: 7b15c5f0e59951247bd1a12943ec1f02ccb3f611 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!perl
# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
# • https://build.i3wm.org/docs/testsuite.html
#   (or docs/testsuite)
#
# • https://build.i3wm.org/docs/lib-i3test.html
#   (alternatively: perldoc ./testcases/lib/i3test.pm)
#
# • https://build.i3wm.org/docs/ipc.html
#   (or docs/ipc)
#
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
#   (unless you are already familiar with Perl)

use i3test;
use List::Util qw(first);

# to not depend on List::MoreUtils
sub all (&@) {
    my $cb = shift;
    for (@_) {
        return 0 unless $cb->();
    }
    return 1;
}

sub none (&@) {
    my $cb = shift;
    for (@_) {
        return 0 if $cb->();
    }
    return 1;
}

my $i3 = i3(get_socket_path());

####################
# Request tree
####################

my $tree = $i3->get_tree->recv;

# a unique value
my $ignore = \"";

my $expected = {
    fullscreen_mode => 0,
    sticky => $ignore,
    nodes => $ignore,
    window => undef,
    name => 'root',
    orientation => $ignore,
    type => 'root',
    window_type => undef,
    id => $ignore,
    rect => $ignore,
    deco_rect => $ignore,
    window_rect => $ignore,
    geometry => $ignore,
    swallows => $ignore,
    percent => undef,
    layout => 'splith',
    floating => 'auto_off',
    last_split_layout => 'splith',
    scratchpad_state => 'none',
    focus => $ignore,
    focused => JSON::XS::false,
    urgent => JSON::XS::false,
    border => 'normal',
    'floating_nodes' => $ignore,
    workspace_layout => 'default',
    current_border_width => -1,
    marks => $ignore,
    window_icon_padding => -1,
};

# a shallow copy is sufficient, since we only ignore values at the root
my $tree_copy = { %$tree };

for (keys %$expected) {
    my $val = $expected->{$_};

    # delete unwanted keys, so we can use is_deeply()
    if (ref($val) eq 'SCALAR' and $val == $ignore) {
        delete $tree_copy->{$_};
        delete $expected->{$_};
    }
}

is_deeply($tree_copy, $expected, 'root node OK');

my @nodes = @{$tree->{nodes}};

ok(@nodes > 0, 'root node has at least one leaf');

ok((all { $_->{type} eq 'output' } @nodes), 'all nodes are of type CT_OUTPUT');
ok((none { defined($_->{window}) } @nodes), 'no CT_OUTPUT contains a window');
ok((all { @{$_->{nodes}} > 0 } @nodes), 'all nodes have at least one leaf (workspace)');
my @workspaces;
for my $ws (@nodes) {
    my $content = first { $_->{type} eq 'con' } @{$ws->{nodes}};
    @workspaces = (@workspaces, @{$content->{nodes}});
}

ok((all { $_->{type} eq 'workspace' } @workspaces), 'all workspaces are of type CT_WORKSPACE');
#ok((all { @{$_->{nodes}} == 0 } @workspaces), 'all workspaces are empty yet');
ok((none { defined($_->{window}) } @workspaces), 'no CT_OUTPUT contains a window');

# TODO: get the focused container

$i3->command('open')->recv;

# TODO: get the focused container, check if it changed.
# TODO: get the old focused container, check if there is a new child

#diag(Dumper(\@workspaces));

#diag(Dumper($tree));


done_testing;