Class: PresenceTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/vendor/xmpp4r/test/tc_presence.rb

Instance Method Summary collapse

Instance Method Details

#test_chainingObject



93
94
95
96
97
98
99
# File 'lib/vendor/xmpp4r/test/tc_presence.rb', line 93

def test_chaining
  x = Presence.new()
  x.set_show(:xa).set_status("Plundering the fridge.").set_priority(0)
  assert_equal(:xa, x.show)
  assert_equal("Plundering the fridge.", x.status)
  assert_equal(0, x.priority)
end

#test_compare_interestObject



141
142
143
144
145
146
147
148
# File 'lib/vendor/xmpp4r/test/tc_presence.rb', line 141

def test_compare_interest
  unav = Presence.new.set_type(:unavailable)
  assert_equal(0, unav.cmp_interest(unav))
  assert_equal(1, unav.cmp_interest(Presence.new))
  assert_equal(-1, Presence.new.cmp_interest(unav))
  assert_equal(1, Presence.new(:chat).cmp_interest(Presence.new))
  assert_equal(-1, Presence.new(:away).cmp_interest(Presence.new(:dnd)))
end

#test_compare_prioObject



132
133
134
135
136
137
138
139
# File 'lib/vendor/xmpp4r/test/tc_presence.rb', line 132

def test_compare_prio
  assert_equal(0, Presence.new(:chat, '', 5) <=> Presence.new(:chat, '', 5))
  assert_equal(-1, Presence.new(:chat, '', 4) <=> Presence.new(:chat, '', 5))
  assert_equal(1, Presence.new(:chat, '', 4) <=> Presence.new(:chat, '', 3))
  assert_equal(-1, Presence.new(:chat, '', nil) <=> Presence.new(:chat, '', 3))
  assert_equal(1, Presence.new(:chat, '', 10) <=> Presence.new(:chat, '', nil))
  assert_equal(0, Presence.new(:chat, '', nil) <=> Presence.new(:chat, '', nil))
end

#test_createObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vendor/xmpp4r/test/tc_presence.rb', line 13

def test_create
  x = Presence.new()
  assert_equal("presence", x.name)
  assert_equal("jabber:client", x.namespace)
  assert_equal(nil, x.to)
  assert_equal(nil, x.show)
  assert_equal(nil, x.status)
  assert_equal(nil, x.priority)

  x = Presence.new(:away, "I am away", 23)
  assert_equal("presence", x.name)
  assert_equal(:away, x.show)
  assert_equal("away", x.show.to_s)
  assert_equal("I am away", x.status)
  assert_equal(23, x.priority)
end

#test_errorObject



101
102
103
104
105
106
107
108
109
# File 'lib/vendor/xmpp4r/test/tc_presence.rb', line 101

def test_error
  x = Presence.new()
  e = REXML::Element.new('error')
  x.add(e)
  x2 = Presence.new.import(x)
  # test if, after an import, the error element is successfully changed
  # into an ErrorResponse object.
  assert_equal(ErrorResponse, x2.first_element('error').class)
end

#test_priorityObject



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/vendor/xmpp4r/test/tc_presence.rb', line 65

def test_priority
  x = Presence.new()
  assert_equal(nil, x.priority)
  x.priority = 5
  assert_equal(5, x.priority)
  x.each_element('priority') { |e| assert(e.class == REXML::Element, "<priority/> is not REXML::Element") }
  x.priority = "5"
  assert_equal(5, x.priority)
  x.priority = nil
  assert_equal(nil, x.priority)
  x.each_element('priority') { |e| assert(true, "<priority/> exists after 'priority=nil'") }
end

#test_sampleObject



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/vendor/xmpp4r/test/tc_presence.rb', line 111

def test_sample
  x = Presence.new
  require 'rexml/document'
  d = REXML::Document.new("<presence from='[email protected]/versionbot' to='[email protected]/edgarr' xmlns='jabber:client'>\n    <x from='[email protected]/versionbot' stamp='20050823T02:18:42' xmlns='jabber:x:delay'/><show>xa</show>\n    <status>I am the evil fingerprinting robot</status>\n  </presence>")
  x.import(d.root)
  num = 0
  x.each_element('show') { num += 1 }
  assert_equal(1, num)
  assert_equal(:xa, x.show)
  assert_equal('I am the evil fingerprinting robot', x.status)
end

#test_showObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/vendor/xmpp4r/test/tc_presence.rb', line 30

def test_show
  x = Presence.new()
  assert_equal(nil, x.show)
  assert_raise(RuntimeError) { x.show = "a" }
  assert_equal(nil, x.show)
  assert_raise(RuntimeError) { x.show = 'away' }
  assert_equal(nil, x.show)
  x.show = :away
  assert_equal(:away, x.show)
  x.each_element('show') { |e| assert(e.class == REXML::Element, "<show/> is not REXML::Element") }
  x.show = nil
  assert_equal(nil, x.show)
  x.each_element('show') { |e| assert(true, "<show/> exists after 'show=nil'") }
  x.show = nil
  assert_equal(nil, x.show)

  showelement = REXML::Element.new('show')
  showelement.text = 'chat'
  x.add(showelement)
  assert_equal(:chat, x.show)
end

#test_statusObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/vendor/xmpp4r/test/tc_presence.rb', line 52

def test_status
  x = Presence.new()
  assert_equal(nil, x.status)
  x.status = "b"
  assert_equal("b", x.status)
  x.each_element('status') { |e| assert(e.class == REXML::Element, "<status/> is not REXML::Element") }
  x.status = nil
  assert_equal(nil, x.status)
  x.each_element('status') { |e| assert(true, "<status/> exists after 'status=nil'") }
  x.status = nil
  assert_equal(nil, x.status)
end

#test_typeObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/vendor/xmpp4r/test/tc_presence.rb', line 78

def test_type
  x = Presence.new()
  assert_equal(nil, x.type)
  x.type = :delete
  assert_equal(nil, x.type)
  x.type = nil
  assert_equal(nil, x.type)
  x.type = nil
  assert_equal(nil, x.type)
  [:error, :probe, :subscribe, :subscribed, :unavailable, :unsubscribe, :unsubscribed, nil].each { |type|
    x.type = type
    assert_equal(type, x.type)
  }
end

#test_xpathbugObject



123
124
125
126
127
128
129
130
# File 'lib/vendor/xmpp4r/test/tc_presence.rb', line 123

def test_xpathbug
  require 'rexml/document'
  d = REXML::Document.new("<tag1 xmlns='ns1'><tag2 xmlns='ns2'/><tada>xa</tada></tag1>")
  x = d.root
  num = 0
  x.each_element('tada') {  num += 1 }
  assert_equal(1, num)
end