Sha256: aab61f15b10262559941b31a91f9fb4da85bb692d4db452f6bd494a71c9cab8f

Contents?: true

Size: 1.67 KB

Versions: 4

Compression:

Stored size: 1.67 KB

Contents

require 'minitest/autorun'
require 'dnssd'
require 'socket'

class TestDNSSD < MiniTest::Unit::TestCase

  def setup
    @abort = Thread.abort_on_exception
    Thread.abort_on_exception = true

    @port = Socket.getservbyname 'blackjack'
  end

  def teardown
    Thread.abort_on_exception = @abort
  end

  def test_class_announce_tcp_server
    t = Thread.current
    DNSSD.browse '_blackjack._tcp' do |reply|
      next unless 'blackjack tcp server' == reply.name
      t[:reply] = reply
      break
    end

    s = TCPServer.new 'localhost', @port

    DNSSD.announce s, 'blackjack tcp server'

    sleep 1

    assert_equal 'blackjack tcp server', t[:reply].name
  ensure
    s.close
  end

  def test_class_announce_tcp_server_service
    t = Thread.current

    resolver = DNSSD.resolve 'blackjack resolve', '_blackjack._tcp',
                             'local.' do |reply|
      t[:reply] = reply
      break
    end

    s = TCPServer.new 'localhost', @port + 1

    DNSSD.announce s, 'blackjack resolve', 'blackjack'

    sleep 1

    assert_equal 'blackjack resolve', t[:reply].name
    assert_equal @port + 1, t[:reply].port
  ensure
    s.close
  end

  def test_class_getservbyport
    assert_equal 'blackjack', DNSSD.getservbyport(1025),
                 "Your /etc/services is out of date, sorry!"
  end

  def test_class_interface_index
    index = DNSSD.interface_index 'lo0'
    index = DNSSD.interface_index 'lo' if index.zero?
    refute_equal 0, index, 'what? no lo0? no lo?'
  end

  def test_class_interface_name
    index = DNSSD.interface_index 'lo0'
    index = DNSSD.interface_index 'lo' if index.zero?

    assert_match %r%^lo0?$%, DNSSD.interface_name(index)
  end

end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
dnssd-1.3.2 test/test_dnssd.rb
rackjour-0.1.8 vendor/gems/gems/dnssd-1.3.1/test/test_dnssd.rb
dnssd-1.3.1 test/test_dnssd.rb
dnssd-1.3 test/test_dnssd.rb