]> git.sur5r.net Git - i3/i3/blob - testcases/t/11-goto.t
tests: lib/i3test: Use //= instead of unless exists $args{key} (Thanks mxf)
[i3/i3] / testcases / t / 11-goto.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3
4 use i3test;
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 $tmp = fresh_workspace;
15
16 cmd 'split h';
17
18 #####################################################################
19 # Create two windows and make sure focus switching works
20 #####################################################################
21
22 my $top = open_window($x);
23 my $mid = open_window($x);
24 my $bottom = open_window($x);
25
26 #
27 # Returns the input focus after sending the given command to i3 via IPC
28 # end sleeping for half a second to make sure i3 reacted
29 #
30 sub focus_after {
31     my $msg = shift;
32
33     cmd $msg;
34     sync_with_i3($x);
35     return $x->input_focus;
36 }
37
38 $focus = $x->input_focus;
39 is($focus, $bottom->id, "Latest window focused");
40
41 $focus = focus_after('focus left');
42 is($focus, $mid->id, "Middle window focused");
43
44 #####################################################################
45 # Now goto a mark which does not exist
46 #####################################################################
47
48 my $random_mark = sha1_base64(rand());
49
50 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
51 is($focus, $mid->id, "focus unchanged");
52
53 cmd "mark $random_mark";
54
55 $focus = focus_after('focus left');
56 is($focus, $top->id, "Top window focused");
57
58 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
59 is($focus, $mid->id, "goto worked");
60
61 # check that we can specify multiple criteria
62
63 $focus = focus_after('focus left');
64 is($focus, $top->id, "Top window focused");
65
66 $focus = focus_after(qq|[con_mark="$random_mark" con_mark="$random_mark"] focus|);
67 is($focus, $mid->id, "goto worked");
68
69 #####################################################################
70 # Check whether the focus command will switch to a different
71 # workspace if necessary
72 #####################################################################
73
74 my $tmp2 = fresh_workspace;
75
76 is(focused_ws(), $tmp2, 'tmp2 now focused');
77
78 cmd qq|[con_mark="$random_mark"] focus|;
79
80 is(focused_ws(), $tmp, 'tmp now focused');
81
82 done_testing;