aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/library/socket/constants/constants_spec.rb
blob: 710af128283fd7353e345c822a0eca3359b278ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
require_relative '../spec_helper'
require_relative '../fixtures/classes'

describe "Socket::Constants" do
  it "defines socket types" do
    consts = ["SOCK_DGRAM", "SOCK_RAW", "SOCK_RDM", "SOCK_SEQPACKET", "SOCK_STREAM"]
    consts.each do |c|
      Socket::Constants.should have_constant(c)
    end
  end

  it "defines protocol families" do
    consts = ["PF_INET6", "PF_INET", "PF_UNIX", "PF_UNSPEC"]
    consts.each do |c|
      Socket::Constants.should have_constant(c)
    end
  end

  platform_is_not :aix do
    it "defines PF_IPX protocol" do
      Socket::Constants.should have_constant("PF_IPX")
    end
  end

  it "defines address families" do
    consts = ["AF_INET6", "AF_INET", "AF_UNIX", "AF_UNSPEC"]
    consts.each do |c|
      Socket::Constants.should have_constant(c)
    end
  end

  platform_is_not :aix do
    it "defines AF_IPX address" do
      Socket::Constants.should have_constant("AF_IPX")
    end
  end

  it "defines send/receive options" do
    consts = ["MSG_DONTROUTE", "MSG_OOB", "MSG_PEEK"]
    consts.each do |c|
      Socket::Constants.should have_constant(c)
    end
  end

  it "defines socket level options" do
    consts = ["SOL_SOCKET"]
    consts.each do |c|
      Socket::Constants.should have_constant(c)
    end
  end

  it "defines socket options" do
    consts = ["SO_BROADCAST", "SO_DEBUG", "SO_DONTROUTE", "SO_ERROR", "SO_KEEPALIVE", "SO_LINGER",
              "SO_OOBINLINE", "SO_RCVBUF", "SO_REUSEADDR", "SO_SNDBUF", "SO_TYPE"]
    consts.each do |c|
      Socket::Constants.should have_constant(c)
    end
  end

  it "defines multicast options" do
    consts = ["IP_ADD_MEMBERSHIP",
              "IP_MULTICAST_LOOP", "IP_MULTICAST_TTL"]
    platform_is_not :windows do
      consts += ["IP_DEFAULT_MULTICAST_LOOP", "IP_DEFAULT_MULTICAST_TTL"]
    end
    consts.each do |c|
      Socket::Constants.should have_constant(c)
    end
  end

  platform_is_not :solaris, :windows, :aix do
    it "defines multicast options" do
      consts = ["IP_MAX_MEMBERSHIPS"]
      consts.each do |c|
        Socket::Constants.should have_constant(c)
      end
    end
  end

  it "defines TCP options" do
    consts = ["TCP_NODELAY"]
    platform_is_not :windows do
      consts << "TCP_MAXSEG"
    end
    consts.each do |c|
      Socket::Constants.should have_constant(c)
    end
  end

  platform_is_not :windows do
    it 'defines SCM options' do
      Socket::Constants.should have_constant('SCM_RIGHTS')
    end

    it 'defines error options' do
      consts = ["EAI_ADDRFAMILY", "EAI_NODATA"]

      # FreeBSD (11.1, at least) obsoletes EAI_ADDRFAMILY and EAI_NODATA
      platform_is :freebsd do
        consts = %w(EAI_MEMORY)
      end

      consts.each do |c|
        Socket::Constants.should have_constant(c)
      end
    end
  end
end