#!perl
# vim:ts=4:sw=4:expandtab
-use Test::More tests => 4;
+use Test::More tests => 3;
use Test::Deep;
use X11::XCB qw(:all);
use Data::Dumper;
use FindBin;
use lib "$FindBin::Bin/lib";
use i3test;
+use AnyEvent::I3;
BEGIN {
use_ok('IO::Socket::UNIX') or BAIL_OUT('Cannot load IO::Socket::UNIX');
my $x = X11::XCB::Connection->new;
-my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock');
-
-isa_ok($sock, 'IO::Socket::UNIX');
-
+my $i3 = i3;
#####################################################################
# Ensure IPC works by switching workspaces
#####################################################################
# Switch to the first workspace to get a clean testing environment
-$sock->write(i3test::format_ipc_command("1"));
-
-sleep(0.25);
+$i3->command('1')->recv;
# Create a window so we can get a focus different from NULL
my $window = i3test::open_standard_window($x);
diag("old focus = $focus");
# Switch to the nineth workspace
-$sock->write(i3test::format_ipc_command("9"));
-
-sleep(0.25);
+$i3->command('9')->recv;
my $new_focus = $x->input_focus;
isnt($focus, $new_focus, "Focus changed");
# the workspace to be empty).
# TODO: skip it by default?
-use Test::More tests => 14;
+use Test::More tests => 13;
use Test::Deep;
use X11::XCB qw(:all);
use Data::Dumper;
use FindBin;
use lib "$FindBin::Bin/lib";
use i3test;
+use AnyEvent::I3;
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');
}
my $x = X11::XCB::Connection->new;
-my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock');
-isa_ok($sock, 'IO::Socket::UNIX');
+my $i3 = i3;
# Switch to the nineth workspace
-$sock->write(i3test::format_ipc_command("9"));
-
-sleep(0.25);
+$i3->command('9')->recv;
#####################################################################
# Create two windows and make sure focus switching works
#####################################################################
# Change mode of the container to "default" for following tests
-$sock->write(i3test::format_ipc_command("d"));
-sleep(0.25);
+$i3->command('d')->recv;
my $top = i3test::open_standard_window($x);
my $mid = i3test::open_standard_window($x);
sub focus_after {
my $msg = shift;
- $sock->write(i3test::format_ipc_command($msg));
- sleep(0.5);
+ $i3->command($msg)->recv;
return $x->input_focus;
}
###############################################
# Switch to the 10. workspace
-$sock->write(i3test::format_ipc_command("10"));
-sleep 0.25;
+$i3->command('10')->recv;
$top = i3test::open_standard_window($x);
$bottom = i3test::open_standard_window($x);
# Same thing, but left/right instead of top/bottom
# Switch to the 11. workspace
-$sock->write(i3test::format_ipc_command("11"));
-sleep 0.25;
+$i3->command('11')->recv;
my $left = i3test::open_standard_window($x);
my $right = i3test::open_standard_window($x);
# the workspace to be empty).
# TODO: skip it by default?
-use Test::More tests => 10;
+use Test::More tests => 8;
use Test::Deep;
use X11::XCB qw(:all);
use Data::Dumper;
use FindBin;
use lib "$FindBin::Bin/lib";
use i3test;
+use AnyEvent::I3;
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');
}
my $x = X11::XCB::Connection->new;
-my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock');
-isa_ok($sock, 'IO::Socket::UNIX');
+my $i3 = i3;
# Switch to the nineth workspace
-$sock->write(i3test::format_ipc_command("9"));
-
-sleep(0.25);
+$i3->command('9')->recv;
#####################################################################
# Create two windows and make sure focus switching works
sub focus_after {
my $msg = shift;
- $sock->write(i3test::format_ipc_command($msg));
- sleep(0.5);
+ $i3->command($msg)->recv;
return $x->input_focus;
}
# Move window cross-workspace
#####################################################################
-$sock->write(i3test::format_ipc_command("m12"));
-$sock->write(i3test::format_ipc_command("t"));
-$sock->write(i3test::format_ipc_command("m13"));
-$sock->write(i3test::format_ipc_command("12"));
-$sock->write(i3test::format_ipc_command("13"));
+for my $cmd (qw(m12 t m13 12 13)) {
+ $i3->command($cmd)->recv;
+}
ok(1, "Still living");
# Checks if the focus is correctly restored, when creating a floating client
# 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 X11::XCB qw(:all);
use Data::Dumper;
use FindBin;
use lib "$FindBin::Bin/lib";
use i3test;
+use AnyEvent::I3;
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');
}
my $x = X11::XCB::Connection->new;
-my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock');
-isa_ok($sock, 'IO::Socket::UNIX');
+my $i3 = i3;
# Switch to the nineth workspace
-$sock->write(i3test::format_ipc_command("9"));
-
-sleep(0.25);
+$i3->command('9')->recv;
my $tiled_left = i3test::open_standard_window($x);
my $tiled_right = i3test::open_standard_window($x);
sleep(0.25);
-$sock->write(i3test::format_ipc_command("ml"));
+$i3->command('ml')->recv;
# Get input focus before creating the floating window
my $focus = $x->input_focus;
# the workspace to be empty).
# TODO: skip it by default?
-use Test::More tests => 24;
+use Test::More tests => 22;
use Test::Deep;
use X11::XCB qw(:all);
use Data::Dumper;
use FindBin;
use lib "$FindBin::Bin/lib";
use i3test;
+use AnyEvent::I3;
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');
}
my $x = X11::XCB::Connection->new;
-my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock');
-isa_ok($sock, 'IO::Socket::UNIX');
+my $i3 = i3;
# Switch to the nineth workspace
-$sock->write(i3test::format_ipc_command("9"));
-
-sleep(0.25);
+$i3->command('9')->recv;
#####################################################################
# Create two windows and make sure focus switching works
sub focus_after {
my $msg = shift;
- $sock->write(i3test::format_ipc_command($msg));
- sleep(0.25);
+ $i3->command($msg)->recv;
return $x->input_focus;
}
use List::Util qw(first);
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');
}
# the workspace to be empty).
# TODO: skip it by default?
-use Test::More tests => 9;
+use Test::More tests => 7;
use Test::Deep;
use X11::XCB qw(:all);
use Data::Dumper;
use Digest::SHA1 qw(sha1_base64);
use lib "$FindBin::Bin/lib";
use i3test;
+use AnyEvent::I3;
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');
}
my $x = X11::XCB::Connection->new;
-my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock');
-isa_ok($sock, 'IO::Socket::UNIX');
+my $i3 = i3;
# Switch to the nineth workspace
-$sock->write(i3test::format_ipc_command("9"));
-
-sleep(0.25);
+$i3->command('9')->recv;
#####################################################################
# Create two windows and make sure focus switching works
sub focus_after {
my $msg = shift;
- $sock->write(i3test::format_ipc_command($msg));
- sleep(0.5);
+ $i3->command($msg)->recv;
return $x->input_focus;
}
$focus = focus_after("goto $random_mark");
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");
is($focus, $top->id, "Top window focused");
# the workspace to be empty).
# TODO: skip it by default?
-use Test::More tests => 17;
+use Test::More tests => 15;
use Test::Deep;
use X11::XCB qw(:all);
use Data::Dumper;
use Digest::SHA1 qw(sha1_base64);
use lib "$FindBin::Bin/lib";
use i3test;
+use AnyEvent::I3;
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');
}
my $x = X11::XCB::Connection->new;
-my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock');
-isa_ok($sock, 'IO::Socket::UNIX');
+my $i3 = i3;
# Switch to the nineth workspace
-$sock->write(i3test::format_ipc_command("9"));
-
-sleep 0.25;
+$i3->command('9')->recv;
#####################################################################
# Create a floating window and see if resizing works
test_resize;
# Test borderless
-$sock->write(i3test::format_ipc_command("bb"));
-sleep 0.25;
+$i3->command('bb')->recv;
test_resize;
# Test with 1-px-border
-$sock->write(i3test::format_ipc_command("bp"));
-sleep 0.25;
+$i3->command('bp')->recv;
test_resize;
# the workspace to be empty).
# TODO: skip it by default?
-use Test::More tests => 9;
+use Test::More tests => 7;
use Test::Deep;
use X11::XCB qw(:all);
use Data::Dumper;
use Digest::SHA1 qw(sha1_base64);
use lib "$FindBin::Bin/lib";
use i3test;
+use AnyEvent::I3;
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');
}
my $x = X11::XCB::Connection->new;
-my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock');
-isa_ok($sock, 'IO::Socket::UNIX');
+my $i3 = i3;
# Switch to the nineth workspace
-$sock->write(i3test::format_ipc_command("9"));
-
-sleep 0.25;
+$i3->command('9')->recv;
#####################################################################
# Create two windows and put them in stacking mode
my $bottom = i3test::open_standard_window($x);
sleep 0.25;
-$sock->write(i3test::format_ipc_command("s"));
-sleep 0.25;
+$i3->command('s')->recv;
#####################################################################
# Add the urgency hint, switch to a different workspace and back again
$top->add_hint('urgency');
sleep 1;
-$sock->write(i3test::format_ipc_command("1"));
-sleep 0.25;
-$sock->write(i3test::format_ipc_command("9"));
-sleep 0.25;
-$sock->write(i3test::format_ipc_command("1"));
-sleep 0.25;
+$i3->command('1')->recv;
+$i3->command('9')->recv;
+$i3->command('1')->recv;
my $std = i3test::open_standard_window($x);
sleep 0.25;
# the workspace to be empty).
# TODO: skip it by default?
-use Test::More tests => 5;
+use Test::More tests => 3;
use Test::Deep;
use X11::XCB qw(:all);
use Data::Dumper;
use Digest::SHA1 qw(sha1_base64);
use lib "$FindBin::Bin/lib";
use i3test;
+use AnyEvent::I3;
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');
}
my $x = X11::XCB::Connection->new;
-
-my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock');
-isa_ok($sock, 'IO::Socket::UNIX');
+my $i3 = i3;
# Switch to the nineth workspace
-$sock->write(i3test::format_ipc_command("9"));
-
-sleep 0.25;
+$i3->command('9')->recv;
#####################################################################
# Create a parent window
# Switch workspace to 10 and open a child window. It should be positioned
# on workspace 9.
#########################################################################
-$sock->write(i3test::format_ipc_command("10"));
-sleep 0.25;
+$i3->command('10')->recv;
my $child = $x->root->create_child(
class => WINDOW_CLASS_INPUT_OUTPUT,
isnt($x->input_focus, $child->id, "Child window focused");
# Switch back
-$sock->write(i3test::format_ipc_command("9"));
-sleep 0.25;
+$i3->command('9')->recv;
is($x->input_focus, $child->id, "Child window focused");
#!perl
# vim:ts=4:sw=4:expandtab
-use Test::More tests => 8;
+use Test::More tests => 3;
use Test::Exception;
-use Data::Dumper;
-use JSON::XS;
use List::MoreUtils qw(all);
use FindBin;
use lib "$FindBin::Bin/lib";
use i3test;
+use AnyEvent::I3;
-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');
-}
-
-my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock');
-isa_ok($sock, 'IO::Socket::UNIX');
+my $i3 = i3;
####################
# Request workspaces
####################
-# message type 1 is GET_WORKSPACES
-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';
+my $workspaces = $i3->get_workspaces->recv;
ok(@{$workspaces} > 0, "More than zero workspaces found");
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