Class: SimpleMUCClientTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
ClientTester
Defined in:
lib/vendor/xmpp4r/test/muc/tc_muc_simplemucclient.rb

Instance Method Summary collapse

Instance Method Details

#test_complexObject



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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/vendor/xmpp4r/test/muc/tc_muc_simplemucclient.rb', line 23

def test_complex
  m = MUC::SimpleMUCClient.new(@client)

  block_args = []
  wait = Semaphore.new
  block = lambda { |*a| block_args = a; wait.run }
  m.on_room_message(&block)
  m.on_message(&block)
  m.on_private_message(&block)
  m.on_subject(&block)
  m.on_join(&block)
  m.on_leave(&block)
  m.on_self_leave(&block)

  state { |pres|
    assert_kind_of(Presence, pres)
    assert_equal(JID.new('[email protected]/pda'), pres.from)
    assert_equal(JID.new('[email protected]/thirdwitch'), pres.to)
    send("<presence from='[email protected]/firstwitch' to='[email protected]/pda'>" +
        "<x xmlns='http://jabber.org/protocol/muc#user'><item affiliation='owner' role='moderator'/></x>" +
        "</presence>" +
        "<presence from='[email protected]/secondwitch' to='[email protected]/pda'>" +
        "<x xmlns='http://jabber.org/protocol/muc#user'><item affiliation='admin' role='moderator'/></x>" +
        "</presence>" +
        "<presence from='[email protected]/thirdwitch' to='[email protected]/pda'>" +
        "<x xmlns='http://jabber.org/protocol/muc#user'><item affiliation='member' role='participant'/></x>" +
        "</presence>")
  }
  m.my_jid = '[email protected]/pda'
  assert_equal(m, m.join('[email protected]/thirdwitch'))
  wait_state
  assert(m.active?)
  assert_equal(3, m.roster.size)

  state { |msg|
    assert_kind_of(Message, msg)
    assert_equal(:groupchat, msg.type)
    assert_equal(JID.new('[email protected]/pda'), msg.from)
    assert_equal(JID.new('[email protected]'), msg.to)
    assert_equal('TestCasing room', msg.subject)
    assert_nil(msg.body)
    send(msg.set_from('[email protected]/thirdwitch').set_to('[email protected]/pda'))
  }
  assert_nil(m.subject)
  wait.wait
  m.subject = 'TestCasing room'
  wait_state
  wait.wait

  # FIXME : **Intermittently** failing (especially during RCOV run) at this line with:
  #   1) Failure:
  #   test_complex(SimpleMUCClientTest) [./test/muc/tc_muc_simplemucclient.rb:71]:
  #   <[nil, "thirdwitch", "TestCasing room"]> expected but was
  #   <[nil, "secondwitch"]>.
  #
  #assert_equal([nil, 'thirdwitch', 'TestCasing room'], block_args)

  # FIXME : **Intermittently** failing (especially during RCOV run) at this line with:
  #   1) Failure:
  # test_complex(SimpleMUCClientTest) [./test/muc/tc_muc_simplemucclient.rb:80]:
  # <"TestCasing room"> expected but was
  # <nil>.
  #
  #assert_equal('TestCasing room', m.subject)

end

#test_kickObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/vendor/xmpp4r/test/muc/tc_muc_simplemucclient.rb', line 90

def test_kick
  m = MUC::SimpleMUCClient.new(@client)

  state { |presence|
    send("<presence from='test@test/test'/>")
  }
  m.join('test@test/test')
  wait_state

  state { |iq|
    assert_kind_of(Iq, iq)
    assert_equal('http://jabber.org/protocol/muc#admin', iq.queryns)
    assert_kind_of(MUC::IqQueryMUCAdmin, iq.query)
    assert_equal(1, iq.query.items.size)
    assert_equal('pistol', iq.query.items[0].nick)
    assert_equal(:none, iq.query.items[0].role)
    assert_equal('Avaunt, you cullion!', iq.query.items[0].reason)
    a = iq.answer(false)
    a.type = :result
    send(a)
  }
  m.kick('pistol', 'Avaunt, you cullion!')
  wait_state
end

#test_new1Object



15
16
17
18
19
20
21
# File 'lib/vendor/xmpp4r/test/muc/tc_muc_simplemucclient.rb', line 15

def test_new1
  m = MUC::SimpleMUCClient.new(@client)
  assert_equal(nil, m.jid)
  assert_equal(nil, m.my_jid)
  assert_equal({}, m.roster)
  assert(!m.active?)
end