Sha256: 2bafae002c425652b49bac6de0f3ca2bb4152d4ca24c573da8bc9f0428a8a4ba

Contents?: true

Size: 1.96 KB

Versions: 24

Compression:

Stored size: 1.96 KB

Contents

#!/usr/bin/ruby

$:.unshift '../lib'

require 'tempfile'
require 'test/unit'
require 'socket'
require 'xmpp4r/component'
require 'xmpp4r/bytestreams'
require 'xmpp4r/semaphore'
require 'xmpp4r'
include Jabber

class StreamComponentTest < Test::Unit::TestCase
  @@SOCKET_PORT = 65224
  STREAM = 'stream:stream xmlns:stream="http://etherx.jabber.org/streams"'

  def setup
    servlisten = TCPServer.new(@@SOCKET_PORT)
    serverwait = Semaphore.new
    Thread.new do
      Thread.current.abort_on_exception = true
      serversock = servlisten.accept
      servlisten.close
      serversock.sync = true
      @server = Stream.new
      @server.add_xml_callback do |xml|
        if xml.prefix == 'stream' and xml.name == 'stream'
          @server.send("<#{STREAM} xmlns='jabber:component:accept'>")
          true
        else
          false
        end
      end
      @server.start(serversock)

      serverwait.run
    end

    @stream = Component.new('test')
    @stream.connect('localhost', @@SOCKET_PORT)

    serverwait.wait
  end

  def teardown
    @stream.close
    @server.close
  end

  def test_process
    stanzas = 0
    message_lock = Semaphore.new
    iq_lock = Semaphore.new
    presence_lock = Semaphore.new

    @stream.add_message_callback { |msg|
      assert_kind_of(Message, msg)
      stanzas += 1
      message_lock.run
    }
    @stream.add_iq_callback { |iq|
      assert_kind_of(Iq, iq)
      stanzas += 1
      iq_lock.run
    }
    @stream.add_presence_callback { |pres|
      assert_kind_of(Presence, pres)
      stanzas += 1
      presence_lock.run
    }

    @server.send('<message/>')
    @server.send('<iq/>')
    @server.send('<presence/>')

    message_lock.wait
    iq_lock.wait
    presence_lock.wait

    assert_equal(3, stanzas)
  end

  def test_outgoing
    received_wait = Semaphore.new

    @server.add_message_callback { |msg|
      assert_kind_of(Message, msg)
      received_wait.run
    }

    @stream.send(Message.new)
    received_wait.wait
  end
end

Version data entries

24 entries across 24 versions & 11 rubygems

Version Path
brontes3d-xmpp4r-0.4 test/tc_streamComponent.rb
bryanl-xmpp4r-0.3.2 test/tc_streamComponent.rb
edavey-xmpp4r-0.4.1 test/tc_streamComponent.rb
edavey-xmpp4r-0.4.2 test/tc_streamComponent.rb
edavey-xmpp4r-0.4 test/tc_streamComponent.rb
heipei-xmpp4r-0.3.2 test/tc_streamComponent.rb
ln-xmpp4r-0.5 test/tc_streamComponent.rb
mojodna-xmpp4r-0.4.0.2 test/tc_streamComponent.rb
mojodna-xmpp4r-0.4.0.3 test/tc_streamComponent.rb
seanohalpin-xmpp4r-0.4.1 test/tc_streamComponent.rb
cerberus-0.8.0 lib/vendor/xmpp4r/test/tc_streamComponent.rb
cerberus-0.7.9 lib/vendor/xmpp4r/test/tc_streamComponent.rb
edavis10-cerberus-0.7.8 lib/vendor/xmpp4r/test/tc_streamComponent.rb
cerberus-0.7.8 lib/vendor/xmpp4r/test/tc_streamComponent.rb
cerberus-0.7.7 lib/vendor/xmpp4r/test/tc_streamComponent.rb
cerberus-0.7.6 lib/vendor/xmpp4r/test/tc_streamComponent.rb
cerberus-0.7.2 lib/vendor/xmpp4r/test/tc_streamComponent.rb
cerberus-0.7.5 lib/vendor/xmpp4r/test/tc_streamComponent.rb
cerberus-0.7 lib/vendor/xmpp4r/test/tc_streamComponent.rb
xmpp4r-0.5 test/tc_streamComponent.rb