File: tc_streamSend.rb

package info (click to toggle)
ruby-xmpp4r 0.5.6-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,384 kB
  • sloc: ruby: 17,382; xml: 74; sh: 12; makefile: 4
file content (59 lines) | stat: -rwxr-xr-x 1,234 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/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