]> git.sur5r.net Git - i3/i3/blob - testcases/t/11-goto.t
tests: clean up/beautify all tests (code style / test style)
[i3/i3] / testcases / t / 11-goto.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3
4 use i3test tests => 6;
5 use X11::XCB qw(:all);
6 use Digest::SHA1 qw(sha1_base64);
7
8 BEGIN {
9     use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
10 }
11
12 my $x = X11::XCB::Connection->new;
13
14 my $i3 = i3("/tmp/nestedcons");
15 fresh_workspace;
16
17 cmd 'split h';
18
19 #####################################################################
20 # Create two windows and make sure focus switching works
21 #####################################################################
22
23 my $top = open_standard_window($x);
24 sleep 0.25;
25 my $mid = open_standard_window($x);
26 sleep 0.25;
27 my $bottom = open_standard_window($x);
28 sleep 0.25;
29
30 diag("top id = " . $top->id);
31 diag("mid id = " . $mid->id);
32 diag("bottom id = " . $bottom->id);
33
34 #
35 # Returns the input focus after sending the given command to i3 via IPC
36 # end sleeping for half a second to make sure i3 reacted
37 #
38 sub focus_after {
39     my $msg = shift;
40
41     cmd $msg;
42     return $x->input_focus;
43 }
44
45 $focus = $x->input_focus;
46 is($focus, $bottom->id, "Latest window focused");
47
48 $focus = focus_after("prev h");
49 is($focus, $mid->id, "Middle window focused");
50
51 #####################################################################
52 # Now goto a mark which does not exist
53 #####################################################################
54
55 my $random_mark = sha1_base64(rand());
56
57 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
58 is($focus, $mid->id, "focus unchanged");
59
60 $i3->command("mark $random_mark")->recv;
61
62 $focus = focus_after("prev h");
63 is($focus, $top->id, "Top window focused");
64
65 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
66 is($focus, $mid->id, "goto worked");
67
68 done_testing;