Class: StreamSendTest

Inherits:
Test::Unit::TestCase show all
Defined in:
lib/gems/xmpp4r-0.4/test/tc_streamSend.rb

Instance Method Summary collapse

Methods inherited from Test::Unit::TestCase

#assert_array_equal, expect, #run

Instance Method Details

#mysend(s) ⇒ Object



32
33
34
35
# File 'lib/gems/xmpp4r-0.4/test/tc_streamSend.rb', line 32

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

#setupObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gems/xmpp4r-0.4/test/tc_streamSend.rb', line 13

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

#teardownObject



26
27
28
29
30
# File 'lib/gems/xmpp4r-0.4/test/tc_streamSend.rb', line 26

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

#test_sendbasicObject

Tries to send a basic message



39
40
41
42
# File 'lib/gems/xmpp4r-0.4/test/tc_streamSend.rb', line 39

def test_sendbasic
  mysend(Message.new)
  assert_equal("<message/>\n", @server.gets)
end

#test_sendiqObject



54
55
56
57
# File 'lib/gems/xmpp4r-0.4/test/tc_streamSend.rb', line 54

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

#test_sendmessageObject



44
45
46
47
# File 'lib/gems/xmpp4r-0.4/test/tc_streamSend.rb', line 44

def test_sendmessage
  mysend(Message.new('[email protected]', 'coucou'))
  assert_equal("<message to='[email protected]'><body>coucou</body></message>\n", @server.gets)
end

#test_sendpresenceObject



49
50
51
52
# File 'lib/gems/xmpp4r-0.4/test/tc_streamSend.rb', line 49

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