Class: PresenceTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- PresenceTest
- Defined in:
- lib/gems/xmpp4r-0.4/test/tc_presence.rb
Instance Method Summary collapse
- #test_chaining ⇒ Object
- #test_compare_interest ⇒ Object
- #test_compare_prio ⇒ Object
- #test_create ⇒ Object
- #test_error ⇒ Object
- #test_priority ⇒ Object
- #test_sample ⇒ Object
- #test_show ⇒ Object
- #test_status ⇒ Object
- #test_type ⇒ Object
- #test_xpathbug ⇒ Object
Methods inherited from Test::Unit::TestCase
#assert_array_equal, expect, #run
Instance Method Details
#test_chaining ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/gems/xmpp4r-0.4/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_interest ⇒ Object
141 142 143 144 145 146 147 148 |
# File 'lib/gems/xmpp4r-0.4/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_prio ⇒ Object
132 133 134 135 136 137 138 139 |
# File 'lib/gems/xmpp4r-0.4/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_create ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gems/xmpp4r-0.4/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_error ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/gems/xmpp4r-0.4/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_priority ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/gems/xmpp4r-0.4/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_sample ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/gems/xmpp4r-0.4/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_show ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/gems/xmpp4r-0.4/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_status ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/gems/xmpp4r-0.4/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_type ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/gems/xmpp4r-0.4/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_xpathbug ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'lib/gems/xmpp4r-0.4/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 |