summaryrefslogtreecommitdiff
path: root/spec/ruby/library/socket/unixsocket
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-03 16:19:40 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-03 16:19:40 +0000
commitb53cf149ad8d7c46572e4567ca949b4f82ebb22c (patch)
treeee5032bcb38573dade8ba2c46acbcc0d5f3ddfe3 /spec/ruby/library/socket/unixsocket
parentaeeaadaad08038217440c1e9e7c5ca126d7dc633 (diff)
Update to ruby/spec@9be7c7e
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/library/socket/unixsocket')
-rw-r--r--spec/ruby/library/socket/unixsocket/addr_spec.rb12
-rw-r--r--spec/ruby/library/socket/unixsocket/initialize_spec.rb38
-rw-r--r--spec/ruby/library/socket/unixsocket/inspect_spec.rb2
-rw-r--r--spec/ruby/library/socket/unixsocket/local_address_spec.rb45
-rw-r--r--spec/ruby/library/socket/unixsocket/new_spec.rb2
-rw-r--r--spec/ruby/library/socket/unixsocket/open_spec.rb3
-rw-r--r--spec/ruby/library/socket/unixsocket/pair_spec.rb2
-rw-r--r--spec/ruby/library/socket/unixsocket/partially_closable_spec.rb2
-rw-r--r--spec/ruby/library/socket/unixsocket/path_spec.rb2
-rw-r--r--spec/ruby/library/socket/unixsocket/peeraddr_spec.rb2
-rw-r--r--spec/ruby/library/socket/unixsocket/recv_io_spec.rb47
-rw-r--r--spec/ruby/library/socket/unixsocket/recvfrom_spec.rb54
-rw-r--r--spec/ruby/library/socket/unixsocket/remote_address_spec.rb45
-rw-r--r--spec/ruby/library/socket/unixsocket/send_io_spec.rb25
-rw-r--r--spec/ruby/library/socket/unixsocket/shared/new.rb2
-rw-r--r--spec/ruby/library/socket/unixsocket/socketpair_spec.rb40
16 files changed, 304 insertions, 19 deletions
diff --git a/spec/ruby/library/socket/unixsocket/addr_spec.rb b/spec/ruby/library/socket/unixsocket/addr_spec.rb
index 4fd3e30532..e8431bea16 100644
--- a/spec/ruby/library/socket/unixsocket/addr_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/addr_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../../../spec_helper'
+require_relative '../spec_helper'
require_relative '../fixtures/classes'
describe "UNIXSocket#addr" do
@@ -16,8 +16,13 @@ describe "UNIXSocket#addr" do
SocketSpecs.rm_socket @path
end
+ it "returns an array" do
+ @client.addr.should be_kind_of(Array)
+ end
+
it "returns the address family of this socket in an array" do
@client.addr[0].should == "AF_UNIX"
+ @server.addr[0].should == "AF_UNIX"
end
it "returns the path of the socket in an array if it's a server" do
@@ -27,10 +32,5 @@ describe "UNIXSocket#addr" do
it "returns an empty string for path if it's a client" do
@client.addr[1].should == ""
end
-
- it "returns an array" do
- @client.addr.should be_kind_of(Array)
- end
end
-
end
diff --git a/spec/ruby/library/socket/unixsocket/initialize_spec.rb b/spec/ruby/library/socket/unixsocket/initialize_spec.rb
new file mode 100644
index 0000000000..a6217d404f
--- /dev/null
+++ b/spec/ruby/library/socket/unixsocket/initialize_spec.rb
@@ -0,0 +1,38 @@
+require_relative '../spec_helper'
+require_relative '../fixtures/classes'
+
+with_feature :unix_socket do
+ describe 'UNIXSocket#initialize' do
+ describe 'using a non existing path' do
+ it 'raises Errno::ENOENT' do
+ lambda { UNIXSocket.new(SocketSpecs.socket_path) }.should raise_error(Errno::ENOENT)
+ end
+ end
+
+ describe 'using an existing socket path' do
+ before do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.new(@path)
+ @socket = UNIXSocket.new(@path)
+ end
+
+ after do
+ @socket.close
+ @server.close
+ rm_r(@path)
+ end
+
+ it 'returns a new UNIXSocket' do
+ @socket.should be_an_instance_of(UNIXSocket)
+ end
+
+ it 'sets the socket path to an empty String' do
+ @socket.path.should == ''
+ end
+
+ it 'sets the socket to binmode' do
+ @socket.binmode?.should be_true
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/unixsocket/inspect_spec.rb b/spec/ruby/library/socket/unixsocket/inspect_spec.rb
index 52b2f508c0..d2e3cabbd3 100644
--- a/spec/ruby/library/socket/unixsocket/inspect_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/inspect_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../../../spec_helper'
+require_relative '../spec_helper'
require_relative '../fixtures/classes'
describe "UNIXSocket#inspect" do
diff --git a/spec/ruby/library/socket/unixsocket/local_address_spec.rb b/spec/ruby/library/socket/unixsocket/local_address_spec.rb
new file mode 100644
index 0000000000..8c77519830
--- /dev/null
+++ b/spec/ruby/library/socket/unixsocket/local_address_spec.rb
@@ -0,0 +1,45 @@
+require_relative '../spec_helper'
+require_relative '../fixtures/classes'
+
+with_feature :unix_socket do
+ describe 'UNIXSocket#local_address' do
+ before do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.new(@path)
+ @client = UNIXSocket.new(@path)
+ end
+
+ after do
+ @client.close
+ @server.close
+
+ rm_r(@path)
+ end
+
+ it 'returns an Addrinfo' do
+ @client.local_address.should be_an_instance_of(Addrinfo)
+ end
+
+ describe 'the returned Addrinfo' do
+ it 'uses AF_UNIX as the address family' do
+ @client.local_address.afamily.should == Socket::AF_UNIX
+ end
+
+ it 'uses PF_UNIX as the protocol family' do
+ @client.local_address.pfamily.should == Socket::PF_UNIX
+ end
+
+ it 'uses SOCK_STREAM as the socket type' do
+ @client.local_address.socktype.should == Socket::SOCK_STREAM
+ end
+
+ it 'uses an empty socket path' do
+ @client.local_address.unix_path.should == ''
+ end
+
+ it 'uses 0 as the protocol' do
+ @client.local_address.protocol.should == 0
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/unixsocket/new_spec.rb b/spec/ruby/library/socket/unixsocket/new_spec.rb
index 8b87e9f8c2..05a6b3eda2 100644
--- a/spec/ruby/library/socket/unixsocket/new_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/new_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../../../spec_helper'
+require_relative '../spec_helper'
require_relative 'shared/new'
describe "UNIXSocket.new" do
diff --git a/spec/ruby/library/socket/unixsocket/open_spec.rb b/spec/ruby/library/socket/unixsocket/open_spec.rb
index d15487be94..6c4b7c5676 100644
--- a/spec/ruby/library/socket/unixsocket/open_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/open_spec.rb
@@ -1,4 +1,5 @@
-require_relative '../../../spec_helper'
+require_relative '../spec_helper'
+require_relative '../fixtures/classes'
require_relative 'shared/new'
describe "UNIXSocket.open" do
diff --git a/spec/ruby/library/socket/unixsocket/pair_spec.rb b/spec/ruby/library/socket/unixsocket/pair_spec.rb
index ba69776b53..845ff76ecc 100644
--- a/spec/ruby/library/socket/unixsocket/pair_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/pair_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../../../spec_helper'
+require_relative '../spec_helper'
require_relative '../fixtures/classes'
require_relative '../shared/partially_closable_sockets'
diff --git a/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb b/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb
index bbe1a8a5ba..78a64fe6be 100644
--- a/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../../../spec_helper'
+require_relative '../spec_helper'
require_relative '../fixtures/classes'
require_relative '../shared/partially_closable_sockets'
diff --git a/spec/ruby/library/socket/unixsocket/path_spec.rb b/spec/ruby/library/socket/unixsocket/path_spec.rb
index 9808e4132d..317ffc0975 100644
--- a/spec/ruby/library/socket/unixsocket/path_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/path_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../../../spec_helper'
+require_relative '../spec_helper'
require_relative '../fixtures/classes'
describe "UNIXSocket#path" do
diff --git a/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb b/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb
index bb22a38b8e..ec57b40970 100644
--- a/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../../../spec_helper'
+require_relative '../spec_helper'
require_relative '../fixtures/classes'
describe "UNIXSocket#peeraddr" do
diff --git a/spec/ruby/library/socket/unixsocket/recv_io_spec.rb b/spec/ruby/library/socket/unixsocket/recv_io_spec.rb
index 688f1b6436..533f02a0fa 100644
--- a/spec/ruby/library/socket/unixsocket/recv_io_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/recv_io_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../../../spec_helper'
+require_relative '../spec_helper'
require_relative '../fixtures/classes'
describe "UNIXSocket#recv_io" do
@@ -38,7 +38,50 @@ describe "UNIXSocket#recv_io" do
@socket = @server.accept
@io = @socket.recv_io(File)
- @io.should be_kind_of(File)
+ @io.should be_an_instance_of(File)
+ end
+ end
+end
+
+with_feature :unix_socket do
+ describe 'UNIXSocket#recv_io' do
+ before do
+ @file = File.open('/dev/null', 'w')
+ @client, @server = UNIXSocket.socketpair
+ end
+
+ after do
+ @client.close
+ @server.close
+ @io.close if @io
+ @file.close
+ end
+
+ describe 'without a custom class' do
+ it 'returns an IO' do
+ @client.send_io(@file)
+
+ @io = @server.recv_io
+ @io.should be_an_instance_of(IO)
+ end
+ end
+
+ describe 'with a custom class' do
+ it 'returns an instance of the custom class' do
+ @client.send_io(@file)
+
+ @io = @server.recv_io(File)
+ @io.should be_an_instance_of(File)
+ end
+ end
+
+ describe 'with a custom mode' do
+ it 'opens the IO using the given mode' do
+ @client.send_io(@file)
+
+ @io = @server.recv_io(File, File::WRONLY)
+ @io.should be_an_instance_of(File)
+ end
end
end
end
diff --git a/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb b/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb
index d142d84fdc..f24caaf686 100644
--- a/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb
@@ -1,8 +1,7 @@
-require_relative '../../../spec_helper'
+require_relative '../spec_helper'
require_relative '../fixtures/classes'
describe "UNIXSocket#recvfrom" do
-
platform_is_not :windows do
before :each do
@path = SocketSpecs.socket_path
@@ -43,5 +42,56 @@ describe "UNIXSocket#recvfrom" do
sock.close
end
end
+end
+
+
+with_feature :unix_socket do
+ describe 'UNIXSocket#recvfrom' do
+ describe 'using a socket pair' do
+ before do
+ @client, @server = UNIXSocket.socketpair
+ @client.write('hello')
+ end
+
+ after do
+ @client.close
+ @server.close
+ end
+
+ it 'returns an Array containing the data and address information' do
+ @server.recvfrom(5).should == ['hello', ['AF_UNIX', '']]
+ end
+ end
+
+ # These specs are taken from the rdoc examples on UNIXSocket#recvfrom.
+ describe 'using a UNIX socket constructed using UNIXSocket.for_fd' do
+ before do
+ @path1 = SocketSpecs.socket_path
+ @path2 = SocketSpecs.socket_path + '2'
+ rm_r(@path2)
+ @client_raw = Socket.new(:UNIX, :DGRAM)
+ @client_raw.bind(Socket.sockaddr_un(@path1))
+
+ @server_raw = Socket.new(:UNIX, :DGRAM)
+ @server_raw.bind(Socket.sockaddr_un(@path2))
+
+ @socket = UNIXSocket.for_fd(@server_raw.fileno)
+ end
+
+ after do
+ @client_raw.close
+ @server_raw.close # also closes @socket
+
+ rm_r @path1
+ rm_r @path2
+ end
+
+ it 'returns an Array containing the data and address information' do
+ @client_raw.send('hello', 0, Socket.sockaddr_un(@path2))
+
+ @socket.recvfrom(5).should == ['hello', ['AF_UNIX', @path1]]
+ end
+ end
+ end
end
diff --git a/spec/ruby/library/socket/unixsocket/remote_address_spec.rb b/spec/ruby/library/socket/unixsocket/remote_address_spec.rb
new file mode 100644
index 0000000000..0b416254d0
--- /dev/null
+++ b/spec/ruby/library/socket/unixsocket/remote_address_spec.rb
@@ -0,0 +1,45 @@
+require_relative '../spec_helper'
+require_relative '../fixtures/classes'
+
+with_feature :unix_socket do
+ describe 'UNIXSocket#remote_address' do
+ before do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.new(@path)
+ @client = UNIXSocket.new(@path)
+ end
+
+ after do
+ @client.close
+ @server.close
+
+ rm_r(@path)
+ end
+
+ it 'returns an Addrinfo' do
+ @client.remote_address.should be_an_instance_of(Addrinfo)
+ end
+
+ describe 'the returned Addrinfo' do
+ it 'uses AF_UNIX as the address family' do
+ @client.remote_address.afamily.should == Socket::AF_UNIX
+ end
+
+ it 'uses PF_UNIX as the protocol family' do
+ @client.remote_address.pfamily.should == Socket::PF_UNIX
+ end
+
+ it 'uses SOCK_STREAM as the socket type' do
+ @client.remote_address.socktype.should == Socket::SOCK_STREAM
+ end
+
+ it 'uses the correct socket path' do
+ @client.remote_address.unix_path.should == @path
+ end
+
+ it 'uses 0 as the protocol' do
+ @client.remote_address.protocol.should == 0
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/unixsocket/send_io_spec.rb b/spec/ruby/library/socket/unixsocket/send_io_spec.rb
index fbc99be38d..a2a7d26539 100644
--- a/spec/ruby/library/socket/unixsocket/send_io_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/send_io_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../../../spec_helper'
+require_relative '../spec_helper'
require_relative '../fixtures/classes'
describe "UNIXSocket#send_io" do
@@ -33,3 +33,26 @@ describe "UNIXSocket#send_io" do
end
end
end
+
+with_feature :unix_socket do
+ describe 'UNIXSocket#send_io' do
+ before do
+ @file = File.open('/dev/null', 'w')
+ @client, @server = UNIXSocket.socketpair
+ end
+
+ after do
+ @client.close
+ @server.close
+ @io.close if @io
+ @file.close
+ end
+
+ it 'sends an IO object' do
+ @client.send_io(@file)
+
+ @io = @server.recv_io
+ @io.should be_an_instance_of(IO)
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/unixsocket/shared/new.rb b/spec/ruby/library/socket/unixsocket/shared/new.rb
index afb57f95cf..76a4e1701e 100644
--- a/spec/ruby/library/socket/unixsocket/shared/new.rb
+++ b/spec/ruby/library/socket/unixsocket/shared/new.rb
@@ -1,4 +1,4 @@
-require_relative '../../../../spec_helper'
+require_relative '../../spec_helper'
require_relative '../../fixtures/classes'
describe :unixsocket_new, shared: true do
diff --git a/spec/ruby/library/socket/unixsocket/socketpair_spec.rb b/spec/ruby/library/socket/unixsocket/socketpair_spec.rb
new file mode 100644
index 0000000000..3e9646f76b
--- /dev/null
+++ b/spec/ruby/library/socket/unixsocket/socketpair_spec.rb
@@ -0,0 +1,40 @@
+require_relative '../spec_helper'
+
+with_feature :unix_socket do
+ describe 'UNIXSocket.socketpair' do
+ before do
+ @s1, @s2 = UNIXSocket.socketpair
+ end
+
+ after do
+ @s1.close
+ @s2.close
+ end
+
+ it 'returns two UNIXSockets' do
+ @s1.should be_an_instance_of(UNIXSocket)
+ @s2.should be_an_instance_of(UNIXSocket)
+ end
+
+ it 'connects the sockets to each other' do
+ @s1.write('hello')
+
+ @s2.recv(5).should == 'hello'
+ end
+
+ it 'sets the socket paths to empty Strings' do
+ @s1.path.should == ''
+ @s2.path.should == ''
+ end
+
+ it 'sets the socket addresses to empty Strings' do
+ @s1.addr.should == ['AF_UNIX', '']
+ @s2.addr.should == ['AF_UNIX', '']
+ end
+
+ it 'sets the socket peer addresses to empty Strings' do
+ @s1.peeraddr.should == ['AF_UNIX', '']
+ @s2.peeraddr.should == ['AF_UNIX', '']
+ end
+ end
+end