diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-08-03 16:19:40 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-08-03 16:19:40 +0000 |
commit | b53cf149ad8d7c46572e4567ca949b4f82ebb22c (patch) | |
tree | ee5032bcb38573dade8ba2c46acbcc0d5f3ddfe3 /spec/ruby/library/socket/option | |
parent | aeeaadaad08038217440c1e9e7c5ca126d7dc633 (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/option')
-rw-r--r-- | spec/ruby/library/socket/option/bool_spec.rb | 10 | ||||
-rw-r--r-- | spec/ruby/library/socket/option/initialize_spec.rb | 83 | ||||
-rw-r--r-- | spec/ruby/library/socket/option/inspect_spec.rb | 3 | ||||
-rw-r--r-- | spec/ruby/library/socket/option/int_spec.rb | 23 | ||||
-rw-r--r-- | spec/ruby/library/socket/option/linger_spec.rb | 16 | ||||
-rw-r--r-- | spec/ruby/library/socket/option/new_spec.rb | 2 |
6 files changed, 125 insertions, 12 deletions
diff --git a/spec/ruby/library/socket/option/bool_spec.rb b/spec/ruby/library/socket/option/bool_spec.rb index 31be00fee3..c4f8a277ba 100644 --- a/spec/ruby/library/socket/option/bool_spec.rb +++ b/spec/ruby/library/socket/option/bool_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../spec_helper' +require_relative '../spec_helper' require_relative '../fixtures/classes' describe "Socket::Option.bool" do @@ -18,8 +18,10 @@ describe "Socket::Option#bool" do Socket::Option.bool(:INET, :SOCKET, :KEEPALIVE, false).bool.should == false end - it "raises TypeError if option has not good size" do - so = Socket::Option.new(:UNSPEC, :SOCKET, :SO_LINGER, [0, 0].pack('i*')) - lambda { so.bool }.should raise_error(TypeError) + platform_is_not :windows do + it 'raises TypeError when called on a non boolean option' do + opt = Socket::Option.linger(1, 4) + lambda { opt.bool }.should raise_error(TypeError) + end end end diff --git a/spec/ruby/library/socket/option/initialize_spec.rb b/spec/ruby/library/socket/option/initialize_spec.rb new file mode 100644 index 0000000000..986cfa8ad4 --- /dev/null +++ b/spec/ruby/library/socket/option/initialize_spec.rb @@ -0,0 +1,83 @@ +require_relative '../spec_helper' + +describe 'Socket::Option#initialize' do + before do + @bool = [0].pack('i') + end + + describe 'using Fixnums' do + it 'returns a Socket::Option' do + opt = Socket::Option + .new(Socket::AF_INET, Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, @bool) + + opt.should be_an_instance_of(Socket::Option) + + opt.family.should == Socket::AF_INET + opt.level.should == Socket::SOL_SOCKET + opt.optname.should == Socket::SO_KEEPALIVE + opt.data.should == @bool + end + end + + describe 'using Symbols' do + it 'returns a Socket::Option' do + opt = Socket::Option.new(:INET, :SOCKET, :KEEPALIVE, @bool) + + opt.should be_an_instance_of(Socket::Option) + + opt.family.should == Socket::AF_INET + opt.level.should == Socket::SOL_SOCKET + opt.optname.should == Socket::SO_KEEPALIVE + opt.data.should == @bool + end + + it 'raises when using an invalid address family' do + lambda { + Socket::Option.new(:INET2, :SOCKET, :KEEPALIVE, @bool) + }.should raise_error(SocketError) + end + + it 'raises when using an invalid level' do + lambda { + Socket::Option.new(:INET, :CATS, :KEEPALIVE, @bool) + }.should raise_error(SocketError) + end + + it 'raises when using an invalid option name' do + lambda { + Socket::Option.new(:INET, :SOCKET, :CATS, @bool) + }.should raise_error(SocketError) + end + end + + describe 'using Strings' do + it 'returns a Socket::Option' do + opt = Socket::Option.new('INET', 'SOCKET', 'KEEPALIVE', @bool) + + opt.should be_an_instance_of(Socket::Option) + + opt.family.should == Socket::AF_INET + opt.level.should == Socket::SOL_SOCKET + opt.optname.should == Socket::SO_KEEPALIVE + opt.data.should == @bool + end + + it 'raises when using an invalid address family' do + lambda { + Socket::Option.new('INET2', 'SOCKET', 'KEEPALIVE', @bool) + }.should raise_error(SocketError) + end + + it 'raises when using an invalid level' do + lambda { + Socket::Option.new('INET', 'CATS', 'KEEPALIVE', @bool) + }.should raise_error(SocketError) + end + + it 'raises when using an invalid option name' do + lambda { + Socket::Option.new('INET', 'SOCKET', 'CATS', @bool) + }.should raise_error(SocketError) + end + end +end diff --git a/spec/ruby/library/socket/option/inspect_spec.rb b/spec/ruby/library/socket/option/inspect_spec.rb index 2a03421710..ebea940d2f 100644 --- a/spec/ruby/library/socket/option/inspect_spec.rb +++ b/spec/ruby/library/socket/option/inspect_spec.rb @@ -1,7 +1,6 @@ -require_relative '../../../spec_helper' +require_relative '../spec_helper' require_relative '../fixtures/classes' -require 'socket' describe 'Socket::Option#inspect' do it 'correctly returns SO_LINGER value' do diff --git a/spec/ruby/library/socket/option/int_spec.rb b/spec/ruby/library/socket/option/int_spec.rb index b270374f62..5c67ec26d8 100644 --- a/spec/ruby/library/socket/option/int_spec.rb +++ b/spec/ruby/library/socket/option/int_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../spec_helper' +require_relative '../spec_helper' require_relative '../fixtures/classes' describe "Socket::Option.int" do @@ -10,6 +10,17 @@ describe "Socket::Option.int" do so.optname.should == Socket::Constants::SO_KEEPALIVE so.data.should == [5].pack('i') end + + it 'returns a Socket::Option' do + opt = Socket::Option.int(:INET, :IP, :TTL, 4) + + opt.should be_an_instance_of(Socket::Option) + + opt.family.should == Socket::AF_INET + opt.level.should == Socket::IPPROTO_IP + opt.optname.should == Socket::IP_TTL + opt.data.should == [4].pack('i') + end end describe "Socket::Option#int" do @@ -19,10 +30,14 @@ describe "Socket::Option#int" do so = Socket::Option.int(:INET, :SOCKET, :KEEPALIVE, 32765) so.int.should == 32765 + + Socket::Option.int(:INET, :IP, :TTL, 4).int.should == 4 end - it "raises TypeError if option has not good size" do - so = Socket::Option.new(:UNSPEC, :SOCKET, :SO_LINGER, [0, 0].pack('i*')) - lambda { so.int }.should raise_error(TypeError) + platform_is_not :windows do + it 'raises TypeError when called on a non integer option' do + opt = Socket::Option.linger(1, 4) + lambda { opt.int }.should raise_error(TypeError) + end end end diff --git a/spec/ruby/library/socket/option/linger_spec.rb b/spec/ruby/library/socket/option/linger_spec.rb index 2090c8a0e8..94467ebf71 100644 --- a/spec/ruby/library/socket/option/linger_spec.rb +++ b/spec/ruby/library/socket/option/linger_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../spec_helper' +require_relative '../spec_helper' require_relative '../fixtures/classes' option_pack = 'i*' @@ -10,9 +10,11 @@ describe "Socket::Option.linger" do it "creates a new Socket::Option for SO_LINGER" do so = Socket::Option.linger(1, 10) so.should be_an_instance_of(Socket::Option) + so.family.should == Socket::Constants::AF_UNSPEC so.level.should == Socket::Constants::SOL_SOCKET so.optname.should == Socket::Constants::SO_LINGER + so.data.should == [1, 10].pack(option_pack) end @@ -53,10 +55,22 @@ describe "Socket::Option#linger" do lambda { so.linger }.should raise_error(TypeError) end + it 'raises TypeError when called on a non SOL_SOCKET/SO_LINGER option' do + opt = Socket::Option.int(:INET, :IP, :TTL, 4) + + lambda { opt.linger }.should raise_error(TypeError) + end + platform_is_not :windows do it "raises TypeError if option has not good size" do so = Socket::Option.int(:AF_UNSPEC, :SOL_SOCKET, :LINGER, 1) lambda { so.linger }.should raise_error(TypeError) end end + + it 'raises TypeError when called on a non linger option' do + opt = Socket::Option.new(:INET, :SOCKET, :LINGER, '') + + lambda { opt.linger }.should raise_error(TypeError) + end end diff --git a/spec/ruby/library/socket/option/new_spec.rb b/spec/ruby/library/socket/option/new_spec.rb index b2c76fb24d..f3b7b31c91 100644 --- a/spec/ruby/library/socket/option/new_spec.rb +++ b/spec/ruby/library/socket/option/new_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../spec_helper' +require_relative '../spec_helper' require_relative '../fixtures/classes' describe "Socket::Option.new" do |