make testcases use AnyEvent::I3

This commit is contained in:
Michael Stapelberg 2010-03-27 15:20:38 +01:00
parent 5e2ab5be65
commit 8fb641cca4
12 changed files with 61 additions and 170 deletions

View File

@ -1,7 +1,7 @@
#!perl #!perl
# vim:ts=4:sw=4:expandtab # vim:ts=4:sw=4:expandtab
use Test::More tests => 4; use Test::More tests => 3;
use Test::Deep; use Test::Deep;
use X11::XCB qw(:all); use X11::XCB qw(:all);
use Data::Dumper; use Data::Dumper;
@ -9,6 +9,7 @@ use Time::HiRes qw(sleep);
use FindBin; use FindBin;
use lib "$FindBin::Bin/lib"; use lib "$FindBin::Bin/lib";
use i3test; use i3test;
use AnyEvent::I3;
BEGIN { BEGIN {
use_ok('IO::Socket::UNIX') or BAIL_OUT('Cannot load IO::Socket::UNIX'); use_ok('IO::Socket::UNIX') or BAIL_OUT('Cannot load IO::Socket::UNIX');
@ -17,19 +18,14 @@ BEGIN {
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock'); my $i3 = i3;
isa_ok($sock, 'IO::Socket::UNIX');
##################################################################### #####################################################################
# Ensure IPC works by switching workspaces # Ensure IPC works by switching workspaces
##################################################################### #####################################################################
# Switch to the first workspace to get a clean testing environment # Switch to the first workspace to get a clean testing environment
$sock->write(i3test::format_ipc_command("1")); $i3->command('1')->recv;
sleep(0.25);
# Create a window so we can get a focus different from NULL # Create a window so we can get a focus different from NULL
my $window = i3test::open_standard_window($x); my $window = i3test::open_standard_window($x);
@ -41,9 +37,7 @@ my $focus = $x->input_focus;
diag("old focus = $focus"); diag("old focus = $focus");
# Switch to the nineth workspace # Switch to the nineth workspace
$sock->write(i3test::format_ipc_command("9")); $i3->command('9')->recv;
sleep(0.25);
my $new_focus = $x->input_focus; my $new_focus = $x->input_focus;
isnt($focus, $new_focus, "Focus changed"); isnt($focus, $new_focus, "Focus changed");

View File

@ -4,7 +4,7 @@
# the workspace to be empty). # the workspace to be empty).
# TODO: skip it by default? # TODO: skip it by default?
use Test::More tests => 14; use Test::More tests => 13;
use Test::Deep; use Test::Deep;
use X11::XCB qw(:all); use X11::XCB qw(:all);
use Data::Dumper; use Data::Dumper;
@ -12,29 +12,25 @@ use Time::HiRes qw(sleep);
use FindBin; use FindBin;
use lib "$FindBin::Bin/lib"; use lib "$FindBin::Bin/lib";
use i3test; use i3test;
use AnyEvent::I3;
BEGIN { BEGIN {
use_ok('IO::Socket::UNIX') or BAIL_OUT('Cannot load IO::Socket::UNIX');
use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection'); use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
} }
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock'); my $i3 = i3;
isa_ok($sock, 'IO::Socket::UNIX');
# Switch to the nineth workspace # Switch to the nineth workspace
$sock->write(i3test::format_ipc_command("9")); $i3->command('9')->recv;
sleep(0.25);
##################################################################### #####################################################################
# Create two windows and make sure focus switching works # Create two windows and make sure focus switching works
##################################################################### #####################################################################
# Change mode of the container to "default" for following tests # Change mode of the container to "default" for following tests
$sock->write(i3test::format_ipc_command("d")); $i3->command('d')->recv;
sleep(0.25);
my $top = i3test::open_standard_window($x); my $top = i3test::open_standard_window($x);
my $mid = i3test::open_standard_window($x); my $mid = i3test::open_standard_window($x);
@ -52,8 +48,7 @@ diag("bottom id = " . $bottom->id);
sub focus_after { sub focus_after {
my $msg = shift; my $msg = shift;
$sock->write(i3test::format_ipc_command($msg)); $i3->command($msg)->recv;
sleep(0.5);
return $x->input_focus; return $x->input_focus;
} }
@ -81,8 +76,7 @@ is($focus, $top->id, "Top window focused (wrapping to the bottom works)");
############################################### ###############################################
# Switch to the 10. workspace # Switch to the 10. workspace
$sock->write(i3test::format_ipc_command("10")); $i3->command('10')->recv;
sleep 0.25;
$top = i3test::open_standard_window($x); $top = i3test::open_standard_window($x);
$bottom = i3test::open_standard_window($x); $bottom = i3test::open_standard_window($x);
@ -102,8 +96,7 @@ is($focus, $top->id, "Top window focused");
# Same thing, but left/right instead of top/bottom # Same thing, but left/right instead of top/bottom
# Switch to the 11. workspace # Switch to the 11. workspace
$sock->write(i3test::format_ipc_command("11")); $i3->command('11')->recv;
sleep 0.25;
my $left = i3test::open_standard_window($x); my $left = i3test::open_standard_window($x);
my $right = i3test::open_standard_window($x); my $right = i3test::open_standard_window($x);

View File

@ -4,7 +4,7 @@
# the workspace to be empty). # the workspace to be empty).
# TODO: skip it by default? # TODO: skip it by default?
use Test::More tests => 10; use Test::More tests => 8;
use Test::Deep; use Test::Deep;
use X11::XCB qw(:all); use X11::XCB qw(:all);
use Data::Dumper; use Data::Dumper;
@ -12,21 +12,18 @@ use Time::HiRes qw(sleep);
use FindBin; use FindBin;
use lib "$FindBin::Bin/lib"; use lib "$FindBin::Bin/lib";
use i3test; use i3test;
use AnyEvent::I3;
BEGIN { BEGIN {
use_ok('IO::Socket::UNIX') or BAIL_OUT('Cannot load IO::Socket::UNIX');
use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection'); use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
} }
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock'); my $i3 = i3;
isa_ok($sock, 'IO::Socket::UNIX');
# Switch to the nineth workspace # Switch to the nineth workspace
$sock->write(i3test::format_ipc_command("9")); $i3->command('9')->recv;
sleep(0.25);
##################################################################### #####################################################################
# Create two windows and make sure focus switching works # Create two windows and make sure focus switching works
@ -50,8 +47,7 @@ diag("bottom id = " . $bottom->id);
sub focus_after { sub focus_after {
my $msg = shift; my $msg = shift;
$sock->write(i3test::format_ipc_command($msg)); $i3->command($msg)->recv;
sleep(0.5);
return $x->input_focus; return $x->input_focus;
} }
@ -82,9 +78,7 @@ is($focus, $top->id, "Top window focused");
# Move window cross-workspace # Move window cross-workspace
##################################################################### #####################################################################
$sock->write(i3test::format_ipc_command("m12")); for my $cmd (qw(m12 t m13 12 13)) {
$sock->write(i3test::format_ipc_command("t")); $i3->command($cmd)->recv;
$sock->write(i3test::format_ipc_command("m13")); }
$sock->write(i3test::format_ipc_command("12"));
$sock->write(i3test::format_ipc_command("13"));
ok(1, "Still living"); ok(1, "Still living");

View File

@ -3,7 +3,7 @@
# Checks if the focus is correctly restored, when creating a floating client # Checks if the focus is correctly restored, when creating a floating client
# over an unfocused tiling client and destroying the floating one again. # over an unfocused tiling client and destroying the floating one again.
use Test::More tests => 6; use Test::More tests => 4;
use Test::Deep; use Test::Deep;
use X11::XCB qw(:all); use X11::XCB qw(:all);
use Data::Dumper; use Data::Dumper;
@ -11,28 +11,25 @@ use Time::HiRes qw(sleep);
use FindBin; use FindBin;
use lib "$FindBin::Bin/lib"; use lib "$FindBin::Bin/lib";
use i3test; use i3test;
use AnyEvent::I3;
BEGIN { BEGIN {
use_ok('IO::Socket::UNIX') or BAIL_OUT('Cannot load IO::Socket::UNIX');
use_ok('X11::XCB::Window') or BAIL_OUT('Could not load X11::XCB::Window'); use_ok('X11::XCB::Window') or BAIL_OUT('Could not load X11::XCB::Window');
} }
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock'); my $i3 = i3;
isa_ok($sock, 'IO::Socket::UNIX');
# Switch to the nineth workspace # Switch to the nineth workspace
$sock->write(i3test::format_ipc_command("9")); $i3->command('9')->recv;
sleep(0.25);
my $tiled_left = i3test::open_standard_window($x); my $tiled_left = i3test::open_standard_window($x);
my $tiled_right = i3test::open_standard_window($x); my $tiled_right = i3test::open_standard_window($x);
sleep(0.25); sleep(0.25);
$sock->write(i3test::format_ipc_command("ml")); $i3->command('ml')->recv;
# Get input focus before creating the floating window # Get input focus before creating the floating window
my $focus = $x->input_focus; my $focus = $x->input_focus;

View File

@ -4,7 +4,7 @@
# the workspace to be empty). # the workspace to be empty).
# TODO: skip it by default? # TODO: skip it by default?
use Test::More tests => 24; use Test::More tests => 22;
use Test::Deep; use Test::Deep;
use X11::XCB qw(:all); use X11::XCB qw(:all);
use Data::Dumper; use Data::Dumper;
@ -12,21 +12,18 @@ use Time::HiRes qw(sleep);
use FindBin; use FindBin;
use lib "$FindBin::Bin/lib"; use lib "$FindBin::Bin/lib";
use i3test; use i3test;
use AnyEvent::I3;
BEGIN { BEGIN {
use_ok('IO::Socket::UNIX') or BAIL_OUT('Cannot load IO::Socket::UNIX');
use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection'); use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
} }
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock'); my $i3 = i3;
isa_ok($sock, 'IO::Socket::UNIX');
# Switch to the nineth workspace # Switch to the nineth workspace
$sock->write(i3test::format_ipc_command("9")); $i3->command('9')->recv;
sleep(0.25);
##################################################################### #####################################################################
# Create two windows and make sure focus switching works # Create two windows and make sure focus switching works
@ -50,8 +47,7 @@ diag("bottom id = " . $bottom->id);
sub focus_after { sub focus_after {
my $msg = shift; my $msg = shift;
$sock->write(i3test::format_ipc_command($msg)); $i3->command($msg)->recv;
sleep(0.25);
return $x->input_focus; return $x->input_focus;
} }

View File

@ -12,7 +12,6 @@ use i3test;
use List::Util qw(first); use List::Util qw(first);
BEGIN { BEGIN {
#use_ok('IO::Socket::UNIX') or BAIL_OUT('Cannot load IO::Socket::UNIX');
use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection'); use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
} }

View File

@ -4,7 +4,7 @@
# the workspace to be empty). # the workspace to be empty).
# TODO: skip it by default? # TODO: skip it by default?
use Test::More tests => 9; use Test::More tests => 7;
use Test::Deep; use Test::Deep;
use X11::XCB qw(:all); use X11::XCB qw(:all);
use Data::Dumper; use Data::Dumper;
@ -13,21 +13,18 @@ use FindBin;
use Digest::SHA1 qw(sha1_base64); use Digest::SHA1 qw(sha1_base64);
use lib "$FindBin::Bin/lib"; use lib "$FindBin::Bin/lib";
use i3test; use i3test;
use AnyEvent::I3;
BEGIN { BEGIN {
use_ok('IO::Socket::UNIX') or BAIL_OUT('Cannot load IO::Socket::UNIX');
use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection'); use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
} }
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock'); my $i3 = i3;
isa_ok($sock, 'IO::Socket::UNIX');
# Switch to the nineth workspace # Switch to the nineth workspace
$sock->write(i3test::format_ipc_command("9")); $i3->command('9')->recv;
sleep(0.25);
##################################################################### #####################################################################
# Create two windows and make sure focus switching works # Create two windows and make sure focus switching works
@ -51,8 +48,7 @@ diag("bottom id = " . $bottom->id);
sub focus_after { sub focus_after {
my $msg = shift; my $msg = shift;
$sock->write(i3test::format_ipc_command($msg)); $i3->command($msg)->recv;
sleep(0.5);
return $x->input_focus; return $x->input_focus;
} }
@ -74,7 +70,7 @@ my $random_mark = sha1_base64(rand());
$focus = focus_after("goto $random_mark"); $focus = focus_after("goto $random_mark");
is($focus, $mid->id, "focus unchanged"); is($focus, $mid->id, "focus unchanged");
$sock->write(i3test::format_ipc_command("mark $random_mark")); $i3->command("mark $random_mark")->recv;
$focus = focus_after("k"); $focus = focus_after("k");
is($focus, $top->id, "Top window focused"); is($focus, $top->id, "Top window focused");

View File

@ -4,7 +4,7 @@
# the workspace to be empty). # the workspace to be empty).
# TODO: skip it by default? # TODO: skip it by default?
use Test::More tests => 17; use Test::More tests => 15;
use Test::Deep; use Test::Deep;
use X11::XCB qw(:all); use X11::XCB qw(:all);
use Data::Dumper; use Data::Dumper;
@ -13,21 +13,18 @@ use FindBin;
use Digest::SHA1 qw(sha1_base64); use Digest::SHA1 qw(sha1_base64);
use lib "$FindBin::Bin/lib"; use lib "$FindBin::Bin/lib";
use i3test; use i3test;
use AnyEvent::I3;
BEGIN { BEGIN {
use_ok('IO::Socket::UNIX') or BAIL_OUT('Cannot load IO::Socket::UNIX');
use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection'); use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
} }
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock'); my $i3 = i3;
isa_ok($sock, 'IO::Socket::UNIX');
# Switch to the nineth workspace # Switch to the nineth workspace
$sock->write(i3test::format_ipc_command("9")); $i3->command('9')->recv;
sleep 0.25;
##################################################################### #####################################################################
# Create a floating window and see if resizing works # Create a floating window and see if resizing works
@ -78,13 +75,11 @@ sub test_resize {
test_resize; test_resize;
# Test borderless # Test borderless
$sock->write(i3test::format_ipc_command("bb")); $i3->command('bb')->recv;
sleep 0.25;
test_resize; test_resize;
# Test with 1-px-border # Test with 1-px-border
$sock->write(i3test::format_ipc_command("bp")); $i3->command('bp')->recv;
sleep 0.25;
test_resize; test_resize;

View File

@ -4,7 +4,7 @@
# the workspace to be empty). # the workspace to be empty).
# TODO: skip it by default? # TODO: skip it by default?
use Test::More tests => 9; use Test::More tests => 7;
use Test::Deep; use Test::Deep;
use X11::XCB qw(:all); use X11::XCB qw(:all);
use Data::Dumper; use Data::Dumper;
@ -13,21 +13,18 @@ use FindBin;
use Digest::SHA1 qw(sha1_base64); use Digest::SHA1 qw(sha1_base64);
use lib "$FindBin::Bin/lib"; use lib "$FindBin::Bin/lib";
use i3test; use i3test;
use AnyEvent::I3;
BEGIN { BEGIN {
use_ok('IO::Socket::UNIX') or BAIL_OUT('Cannot load IO::Socket::UNIX');
use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection'); use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
} }
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock'); my $i3 = i3;
isa_ok($sock, 'IO::Socket::UNIX');
# Switch to the nineth workspace # Switch to the nineth workspace
$sock->write(i3test::format_ipc_command("9")); $i3->command('9')->recv;
sleep 0.25;
##################################################################### #####################################################################
# Create two windows and put them in stacking mode # Create two windows and put them in stacking mode
@ -38,8 +35,7 @@ sleep 0.25;
my $bottom = i3test::open_standard_window($x); my $bottom = i3test::open_standard_window($x);
sleep 0.25; sleep 0.25;
$sock->write(i3test::format_ipc_command("s")); $i3->command('s')->recv;
sleep 0.25;
##################################################################### #####################################################################
# Add the urgency hint, switch to a different workspace and back again # Add the urgency hint, switch to a different workspace and back again
@ -47,12 +43,9 @@ sleep 0.25;
$top->add_hint('urgency'); $top->add_hint('urgency');
sleep 1; sleep 1;
$sock->write(i3test::format_ipc_command("1")); $i3->command('1')->recv;
sleep 0.25; $i3->command('9')->recv;
$sock->write(i3test::format_ipc_command("9")); $i3->command('1')->recv;
sleep 0.25;
$sock->write(i3test::format_ipc_command("1"));
sleep 0.25;
my $std = i3test::open_standard_window($x); my $std = i3test::open_standard_window($x);
sleep 0.25; sleep 0.25;

View File

@ -4,7 +4,7 @@
# the workspace to be empty). # the workspace to be empty).
# TODO: skip it by default? # TODO: skip it by default?
use Test::More tests => 5; use Test::More tests => 3;
use Test::Deep; use Test::Deep;
use X11::XCB qw(:all); use X11::XCB qw(:all);
use Data::Dumper; use Data::Dumper;
@ -13,21 +13,17 @@ use FindBin;
use Digest::SHA1 qw(sha1_base64); use Digest::SHA1 qw(sha1_base64);
use lib "$FindBin::Bin/lib"; use lib "$FindBin::Bin/lib";
use i3test; use i3test;
use AnyEvent::I3;
BEGIN { BEGIN {
use_ok('IO::Socket::UNIX') or BAIL_OUT('Cannot load IO::Socket::UNIX');
use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection'); use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
} }
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
my $i3 = i3;
my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock');
isa_ok($sock, 'IO::Socket::UNIX');
# Switch to the nineth workspace # Switch to the nineth workspace
$sock->write(i3test::format_ipc_command("9")); $i3->command('9')->recv;
sleep 0.25;
##################################################################### #####################################################################
# Create a parent window # Create a parent window
@ -48,8 +44,7 @@ sleep 0.25;
# Switch workspace to 10 and open a child window. It should be positioned # Switch workspace to 10 and open a child window. It should be positioned
# on workspace 9. # on workspace 9.
######################################################################### #########################################################################
$sock->write(i3test::format_ipc_command("10")); $i3->command('10')->recv;
sleep 0.25;
my $child = $x->root->create_child( my $child = $x->root->create_child(
class => WINDOW_CLASS_INPUT_OUTPUT, class => WINDOW_CLASS_INPUT_OUTPUT,
@ -66,7 +61,6 @@ sleep 0.25;
isnt($x->input_focus, $child->id, "Child window focused"); isnt($x->input_focus, $child->id, "Child window focused");
# Switch back # Switch back
$sock->write(i3test::format_ipc_command("9")); $i3->command('9')->recv;
sleep 0.25;
is($x->input_focus, $child->id, "Child window focused"); is($x->input_focus, $child->id, "Child window focused");

View File

@ -1,52 +1,21 @@
#!perl #!perl
# vim:ts=4:sw=4:expandtab # vim:ts=4:sw=4:expandtab
use Test::More tests => 8; use Test::More tests => 3;
use Test::Exception; use Test::Exception;
use Data::Dumper;
use JSON::XS;
use List::MoreUtils qw(all); use List::MoreUtils qw(all);
use FindBin; use FindBin;
use lib "$FindBin::Bin/lib"; use lib "$FindBin::Bin/lib";
use i3test; use i3test;
use AnyEvent::I3;
BEGIN { my $i3 = i3;
use_ok('IO::Socket::UNIX') or BAIL_OUT('Cannot load IO::Socket::UNIX');
use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
}
my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock');
isa_ok($sock, 'IO::Socket::UNIX');
#################### ####################
# Request workspaces # Request workspaces
#################### ####################
# message type 1 is GET_WORKSPACES my $workspaces = $i3->get_workspaces->recv;
my $message = "i3-ipc" . pack("LL", 0, 1);
$sock->write($message);
#######################################
# Test the reply format for correctness
#######################################
# The following lines duplicate functionality from recv_ipc_command
# to have it included in the test-suite.
my $buffer;
$sock->read($buffer, length($message));
is(substr($buffer, 0, length("i3-ipc")), "i3-ipc", "ipc message received");
my ($len, $type) = unpack("LL", substr($buffer, 6));
is($type, 1, "correct reply type");
# read the payload
$sock->read($buffer, $len);
my $workspaces;
#########################
# Actually test the reply
#########################
lives_ok { $workspaces = decode_json($buffer) } 'JSON could be decoded';
ok(@{$workspaces} > 0, "More than zero workspaces found"); ok(@{$workspaces} > 0, "More than zero workspaces found");

View File

@ -29,33 +29,4 @@ sub open_standard_window {
return $window; return $window;
} }
sub format_ipc_command {
my $msg = shift;
my $len;
{ use bytes; $len = length($msg); }
my $message = "i3-ipc" . pack("LL", $len, 0) . $msg;
return $message;
}
sub recv_ipc_command {
my ($sock, $expected) = @_;
my $buffer;
# header is 14 bytes ("i3-ipc" + 32 bit + 32 bit)
$sock->read($buffer, 14);
return undef unless substr($buffer, 0, length("i3-ipc")) eq "i3-ipc";
my ($len, $type) = unpack("LL", substr($buffer, 6));
return undef unless $type == $expected;
# read the payload
$sock->read($buffer, $len);
decode_json($buffer)
}
1 1