2010-04-16 14:24:29 +02:00
|
|
|
|
#!perl
|
|
|
|
|
# vim:ts=4:sw=4:expandtab
|
|
|
|
|
#
|
2012-09-10 14:09:01 +02:00
|
|
|
|
# Please read the following documents before working on tests:
|
|
|
|
|
# • http://build.i3wm.org/docs/testsuite.html
|
|
|
|
|
# (or docs/testsuite)
|
|
|
|
|
#
|
|
|
|
|
# • http://build.i3wm.org/docs/lib-i3test.html
|
|
|
|
|
# (alternatively: perldoc ./testcases/lib/i3test.pm)
|
|
|
|
|
#
|
|
|
|
|
# • http://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)
|
|
|
|
|
#
|
2010-04-16 14:24:29 +02:00
|
|
|
|
# Tests whether we can switch to a non-existant workspace
|
|
|
|
|
# (necessary for further tests)
|
|
|
|
|
#
|
2011-06-10 16:03:59 +02:00
|
|
|
|
use List::Util qw(first);
|
2011-03-09 20:25:17 +01:00
|
|
|
|
use i3test;
|
2010-04-16 14:24:29 +02:00
|
|
|
|
|
2011-07-27 14:35:40 +02:00
|
|
|
|
# to ensure that workspace 1 stays open
|
|
|
|
|
cmd 'open';
|
|
|
|
|
|
2011-03-09 20:25:17 +01:00
|
|
|
|
my $tmp = fresh_workspace;
|
2010-04-16 14:24:29 +02:00
|
|
|
|
ok(workspace_exists($tmp), 'workspace created');
|
2010-04-16 15:03:27 +02:00
|
|
|
|
# if the workspace could not be created, we cannot run any other test
|
|
|
|
|
# (every test starts by creating its workspace)
|
|
|
|
|
if (!workspace_exists($tmp)) {
|
|
|
|
|
BAIL_OUT('Cannot create workspace, further tests make no sense');
|
|
|
|
|
}
|
2010-04-16 14:24:29 +02:00
|
|
|
|
|
2011-03-09 20:25:17 +01:00
|
|
|
|
my $otmp = fresh_workspace;
|
2010-04-16 14:24:29 +02:00
|
|
|
|
diag("Other temporary workspace name: $otmp\n");
|
|
|
|
|
|
|
|
|
|
# As the old workspace was empty, it should get
|
|
|
|
|
# cleaned up as we switch away from it
|
2011-03-09 20:25:17 +01:00
|
|
|
|
cmd "workspace $otmp";
|
2010-04-16 14:24:29 +02:00
|
|
|
|
ok(!workspace_exists($tmp), 'old workspace cleaned up');
|
|
|
|
|
|
2010-05-09 23:20:49 +02:00
|
|
|
|
# Switch to the same workspace again to make sure it doesn’t get cleaned up
|
2011-03-09 20:25:17 +01:00
|
|
|
|
cmd "workspace $otmp";
|
|
|
|
|
cmd "workspace $otmp";
|
2010-05-09 23:20:49 +02:00
|
|
|
|
ok(workspace_exists($otmp), 'other workspace still exists');
|
|
|
|
|
|
2011-06-10 16:03:59 +02:00
|
|
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
|
# check if the workspace next / prev commands work
|
|
|
|
|
#####################################################################
|
|
|
|
|
|
|
|
|
|
cmd 'workspace next';
|
|
|
|
|
|
|
|
|
|
ok(!workspace_exists('next'), 'workspace "next" does not exist');
|
|
|
|
|
|
|
|
|
|
cmd "workspace $tmp";
|
|
|
|
|
cmd 'open';
|
|
|
|
|
|
|
|
|
|
ok(workspace_exists($tmp), 'workspace created');
|
|
|
|
|
|
|
|
|
|
cmd "workspace $otmp";
|
|
|
|
|
cmd 'open';
|
|
|
|
|
|
|
|
|
|
ok(workspace_exists($tmp), 'workspace tmp still exists');
|
|
|
|
|
ok(workspace_exists($otmp), 'workspace otmp created');
|
|
|
|
|
|
|
|
|
|
is(focused_ws(), $otmp, 'focused workspace is otmp');
|
|
|
|
|
|
|
|
|
|
cmd 'workspace prev';
|
|
|
|
|
is(focused_ws(), $tmp, 'focused workspace is tmp after workspace prev');
|
|
|
|
|
|
|
|
|
|
cmd 'workspace next';
|
|
|
|
|
is(focused_ws(), $otmp, 'focused workspace is otmp after workspace next');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
|
# check that wrapping works
|
|
|
|
|
#####################################################################
|
|
|
|
|
|
|
|
|
|
cmd 'workspace next';
|
|
|
|
|
is(focused_ws(), '1', 'focused workspace is 1 after workspace next');
|
|
|
|
|
|
|
|
|
|
cmd 'workspace next';
|
|
|
|
|
is(focused_ws(), $tmp, 'focused workspace is tmp after workspace next');
|
|
|
|
|
|
|
|
|
|
cmd 'workspace next';
|
|
|
|
|
is(focused_ws(), $otmp, 'focused workspace is otmp after workspace next');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmd 'workspace prev';
|
|
|
|
|
is(focused_ws(), $tmp, 'focused workspace is tmp after workspace prev');
|
|
|
|
|
|
|
|
|
|
cmd 'workspace prev';
|
|
|
|
|
is(focused_ws(), '1', 'focused workspace is tmp after workspace prev');
|
|
|
|
|
|
|
|
|
|
cmd 'workspace prev';
|
|
|
|
|
is(focused_ws(), $otmp, 'focused workspace is otmp after workspace prev');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
|
# check if we can change to "next" / "prev"
|
|
|
|
|
#####################################################################
|
|
|
|
|
|
|
|
|
|
cmd 'workspace "next"';
|
|
|
|
|
|
|
|
|
|
ok(workspace_exists('next'), 'workspace "next" exists');
|
|
|
|
|
is(focused_ws(), 'next', 'now on workspace next');
|
|
|
|
|
|
|
|
|
|
cmd 'workspace "prev"';
|
|
|
|
|
|
|
|
|
|
ok(workspace_exists('prev'), 'workspace "prev" exists');
|
|
|
|
|
is(focused_ws(), 'prev', 'now on workspace prev');
|
|
|
|
|
|
2011-09-05 22:24:28 +02:00
|
|
|
|
#####################################################################
|
|
|
|
|
# check that the numbers are assigned/recognized correctly
|
|
|
|
|
#####################################################################
|
|
|
|
|
|
|
|
|
|
cmd "workspace 3: $tmp";
|
|
|
|
|
my $ws = get_ws("3: $tmp");
|
|
|
|
|
ok(defined($ws), "workspace 3: $tmp was created");
|
|
|
|
|
is($ws->{num}, 3, 'workspace number is 3');
|
|
|
|
|
|
|
|
|
|
cmd "workspace 0: $tmp";
|
2011-11-21 21:04:00 +01:00
|
|
|
|
$ws = get_ws("0: $tmp");
|
2011-09-05 22:24:28 +02:00
|
|
|
|
ok(defined($ws), "workspace 0: $tmp was created");
|
|
|
|
|
is($ws->{num}, 0, 'workspace number is 0');
|
|
|
|
|
|
|
|
|
|
cmd "workspace aa: $tmp";
|
2011-11-21 23:44:20 +01:00
|
|
|
|
$ws = get_ws("aa: $tmp");
|
2011-09-05 22:24:28 +02:00
|
|
|
|
ok(defined($ws), "workspace aa: $tmp was created");
|
|
|
|
|
is($ws->{num}, -1, 'workspace number is -1');
|
|
|
|
|
|
2012-04-08 19:17:46 +02:00
|
|
|
|
################################################################################
|
|
|
|
|
# Check that we can go to workspace "4: foo" with the command
|
|
|
|
|
# "workspace number 4".
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
|
ok(!workspace_exists('4'), 'workspace 4 does not exist');
|
|
|
|
|
ok(!workspace_exists('4: foo'), 'workspace 4: foo does not exist yet');
|
|
|
|
|
cmd 'workspace 4: foo';
|
|
|
|
|
ok(workspace_exists('4: foo'), 'workspace 4: foo was created');
|
|
|
|
|
cmd 'open';
|
|
|
|
|
|
|
|
|
|
cmd 'workspace 3';
|
|
|
|
|
ok(workspace_exists('4: foo'), 'workspace 4: foo still open');
|
|
|
|
|
cmd 'workspace number 4';
|
|
|
|
|
is(focused_ws(), '4: foo', 'now on workspace 4: foo');
|
|
|
|
|
ok(!workspace_exists('4'), 'workspace 4 still does not exist');
|
|
|
|
|
|
2012-05-09 20:33:11 +02:00
|
|
|
|
################################################################################
|
|
|
|
|
# Check that we "workspace number 5" will create workspace 5 if it does not yet
|
|
|
|
|
# exist.
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
|
ok(!workspace_exists('5'), 'workspace 5 does not exist');
|
|
|
|
|
cmd 'workspace number 5';
|
|
|
|
|
ok(workspace_exists('5'), 'workspace 5 was created');
|
|
|
|
|
|
2012-08-31 20:19:27 +02:00
|
|
|
|
################################################################################
|
|
|
|
|
# Check that we can go to workspace "7: foo" with the command
|
|
|
|
|
# "workspace number 7: bar", i.e. the additional workspace name is ignored.
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
|
ok(!workspace_exists('7'), 'workspace 7 does not exist');
|
|
|
|
|
ok(!workspace_exists('7: bar'), 'workspace 7: bar does not exist');
|
|
|
|
|
ok(!workspace_exists('7: foo'), 'workspace 7: foo does not exist yet');
|
|
|
|
|
cmd 'workspace 7: foo';
|
|
|
|
|
ok(workspace_exists('7: foo'), 'workspace 7: foo was created');
|
|
|
|
|
cmd 'open';
|
|
|
|
|
|
|
|
|
|
cmd 'workspace 6';
|
|
|
|
|
ok(workspace_exists('7: foo'), 'workspace 7: foo still open');
|
|
|
|
|
cmd 'workspace number 7: bar';
|
|
|
|
|
is(focused_ws(), '7: foo', 'now on workspace 7: foo');
|
|
|
|
|
ok(!workspace_exists('7'), 'workspace 7 still does not exist');
|
|
|
|
|
ok(!workspace_exists('7: bar'), 'workspace 7: bar still does not exist');
|
|
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
# Check that "workspace number 8: foo" will create workspace "8: foo" if it
|
|
|
|
|
# does not yet exist (just like "workspace 8: foo" would).
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
|
ok(!workspace_exists('8: foo'), 'workspace 8: foo does not exist');
|
|
|
|
|
cmd 'workspace number 8: foo';
|
|
|
|
|
ok(workspace_exists('8: foo'), 'workspace 8: foo was created');
|
|
|
|
|
|
2012-04-08 20:34:31 +02:00
|
|
|
|
################################################################################
|
|
|
|
|
# Verify that renaming workspaces works.
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
|
sub workspace_numbers_sorted {
|
|
|
|
|
my ($name) = @_;
|
|
|
|
|
my $i3 = i3(get_socket_path());
|
|
|
|
|
my $tree = $i3->get_tree->recv;
|
|
|
|
|
|
|
|
|
|
my @outputs = @{$tree->{nodes}};
|
|
|
|
|
my @workspaces;
|
|
|
|
|
for my $output (@outputs) {
|
2013-12-14 14:50:44 +01:00
|
|
|
|
my $content = first { $_->{type} eq 'con' } @{$output->{nodes}};
|
2012-04-08 20:34:31 +02:00
|
|
|
|
@workspaces = (@workspaces, @{$content->{nodes}});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my @numbers = grep { $_ != -1 } map { $_->{num} } @workspaces;
|
|
|
|
|
is_deeply(
|
|
|
|
|
[ sort { $a <=> $b } @numbers ],
|
|
|
|
|
\@numbers,
|
|
|
|
|
'workspace numbers sorted');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 1: numbered workspace
|
|
|
|
|
cmd 'workspace 10';
|
|
|
|
|
cmd 'open';
|
|
|
|
|
cmd 'workspace 13';
|
|
|
|
|
cmd 'open';
|
|
|
|
|
|
|
|
|
|
workspace_numbers_sorted();
|
|
|
|
|
|
|
|
|
|
cmd 'workspace 9';
|
|
|
|
|
is(focused_ws(), '9', 'now on workspace 9');
|
|
|
|
|
|
|
|
|
|
ok(!workspace_exists('12'), 'workspace 12 does not exist yet');
|
|
|
|
|
cmd 'rename workspace 9 to 12';
|
|
|
|
|
ok(!workspace_exists('9'), 'workspace 9 does not exist anymore');
|
|
|
|
|
is(focused_ws(), '12', 'now on workspace 12');
|
|
|
|
|
$ws = get_ws('12');
|
|
|
|
|
is($ws->{num}, 12, 'number correctly changed');
|
|
|
|
|
|
|
|
|
|
workspace_numbers_sorted();
|
|
|
|
|
|
|
|
|
|
# 2: numbered + named workspace
|
|
|
|
|
cmd 'workspace 9: foo';
|
|
|
|
|
is(focused_ws(), '9: foo', 'now on workspace 9: foo');
|
|
|
|
|
|
|
|
|
|
ok(!workspace_exists('11: bar'), 'workspace 11: bar does not exist yet');
|
|
|
|
|
cmd 'rename workspace "9: foo" to "11: bar"';
|
|
|
|
|
ok(!workspace_exists('9: foo'), 'workspace 9 does not exist anymore');
|
|
|
|
|
is(focused_ws(), '11: bar', 'now on workspace 10');
|
|
|
|
|
$ws = get_ws('11: bar');
|
|
|
|
|
is($ws->{num}, 11, 'number correctly changed');
|
|
|
|
|
workspace_numbers_sorted();
|
|
|
|
|
# keep that one open, we need it later
|
|
|
|
|
cmd 'open';
|
|
|
|
|
|
|
|
|
|
# 3: named workspace
|
|
|
|
|
cmd 'workspace bleh';
|
|
|
|
|
is(focused_ws(), 'bleh', 'now on workspace bleh');
|
|
|
|
|
|
|
|
|
|
ok(!workspace_exists('qux'), 'workspace qux does not exist yet');
|
|
|
|
|
cmd 'rename workspace bleh to qux';
|
|
|
|
|
ok(!workspace_exists('bleh'), 'workspace 9 does not exist anymore');
|
|
|
|
|
is(focused_ws(), 'qux', 'now on workspace qux');
|
|
|
|
|
$ws = get_ws('qux');
|
|
|
|
|
is($ws->{num}, -1, 'number correctly changed');
|
|
|
|
|
workspace_numbers_sorted();
|
|
|
|
|
|
2012-10-29 22:42:20 +01:00
|
|
|
|
# 4: rename current workspace
|
|
|
|
|
cmd 'workspace 4711';
|
|
|
|
|
is(focused_ws(), '4711', 'now on workspace 4711');
|
|
|
|
|
|
|
|
|
|
ok(!workspace_exists('42'), 'workspace 42 does not exist yet');
|
|
|
|
|
cmd 'rename workspace to 42';
|
|
|
|
|
ok(!workspace_exists('4711'), 'workspace 4711 does not exist anymore');
|
|
|
|
|
is(focused_ws(), '42', 'now on workspace 42');
|
|
|
|
|
$ws = get_ws('42');
|
|
|
|
|
is($ws->{num}, 42, 'number correctly changed');
|
|
|
|
|
workspace_numbers_sorted();
|
|
|
|
|
|
|
|
|
|
# 5: special cases
|
|
|
|
|
cmd 'workspace bla';
|
|
|
|
|
is(focused_ws(), 'bla', 'now on workspace to');
|
|
|
|
|
|
|
|
|
|
ok(!workspace_exists('to'), 'workspace to does not exist yet');
|
|
|
|
|
cmd 'rename workspace bla to to';
|
|
|
|
|
ok(!workspace_exists('bla'), 'workspace bla does not exist anymore');
|
|
|
|
|
is(focused_ws(), 'to', 'now on workspace to');
|
|
|
|
|
cmd 'rename workspace to to bla';
|
|
|
|
|
ok(!workspace_exists('to'), 'workspace to does not exist anymore');
|
|
|
|
|
is(focused_ws(), 'bla', 'now on workspace bla');
|
|
|
|
|
cmd 'rename workspace to to';
|
|
|
|
|
ok(!workspace_exists('bla'), 'workspace bla does not exist anymore');
|
|
|
|
|
is(focused_ws(), 'to', 'now on workspace to');
|
|
|
|
|
|
|
|
|
|
# 6: already existing workspace
|
2012-04-08 20:34:31 +02:00
|
|
|
|
my $result = cmd 'rename workspace qux to 11: bar';
|
|
|
|
|
ok(!$result->[0]->{success}, 'renaming workspace to an already existing one failed');
|
|
|
|
|
|
2012-10-29 22:42:20 +01:00
|
|
|
|
# 7: non-existing old workspace (verify command result)
|
2012-04-08 20:34:31 +02:00
|
|
|
|
$result = cmd 'rename workspace notexistant to bleh';
|
|
|
|
|
ok(!$result->[0]->{success}, 'renaming workspace which does not exist failed');
|
|
|
|
|
|
2016-02-15 08:34:03 +01:00
|
|
|
|
# 8: change case
|
|
|
|
|
ok(!workspace_exists('11: BAR'), 'workspace 11: BAR does not exist yet');
|
|
|
|
|
$result = cmd 'rename workspace "11: bar" to "11: BAR"';
|
|
|
|
|
ok($result->[0]->{success}, 'renaming workspace from 11: bar to 11: BAR worked');
|
|
|
|
|
ok(workspace_exists('11: BAR'), 'workspace 11: BAR now exists');
|
2012-04-08 20:34:31 +02:00
|
|
|
|
|
2011-03-09 20:25:17 +01:00
|
|
|
|
done_testing;
|