Sha256: 16bdb311c310585bba3212bd50f32cc5e84d3a46fc6e4fc05712f194d69ceb4d

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

#!/usr/bin/env ruby

$:.unshift '../lib'

require 'test/unit'
require 'socket'
require 'tempfile'
require 'io/wait'
require 'xmpp4r'
include Jabber

class StreamSendTest < Test::Unit::TestCase
  def setup
    @tmpfile = Tempfile.new("StreamSendTest")
    @tmpfilepath = @tmpfile.path()
    @tmpfile.unlink
    @servlisten = UNIXServer.new(@tmpfilepath)
    thServer = Thread.new { @server = @servlisten.accept }
    @iostream = UNIXSocket.new(@tmpfilepath)
    @stream = Stream.new
    @stream.start(@iostream)

    thServer.join
  end

  def teardown
    @stream.close
    @server.close
    @servlisten.close
  end

  def mysend(s)
    @stream.send(s)
    @stream.send("\n") #needed for easy test writing
  end

  ##
  # Tries to send a basic message
  def test_sendbasic
    mysend(Message.new)
    assert_equal("<message/>\n", @server.gets)
  end

  def test_sendmessage
    mysend(Message.new('lucas@linux.ensimag.fr', 'coucou'))
    assert_equal("<message to='lucas@linux.ensimag.fr'><body>coucou</body></message>\n", @server.gets)
  end

  def test_sendpresence
    mysend(Presence.new)
    assert_equal("<presence/>\n", @server.gets)
  end

  def test_sendiq
    mysend(Iq.new)
    assert_equal("<iq/>\n", @server.gets)
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gmcmillan-xmpp4r-0.6.2 test/tc_streamSend.rb
gmcmillan-xmpp4r-0.6.1 test/tc_streamSend.rb
gmcmillan-xmpp4r-0.6 test/tc_streamSend.rb
gmcmillan-xmpp4r-0.5 test/tc_streamSend.rb