Class: MessageTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- MessageTest
- Defined in:
- lib/vendor/xmpp4r/test/tc_message.rb
Instance Method Summary collapse
- #test_answer ⇒ Object
- #test_body ⇒ Object
- #test_create ⇒ Object
- #test_error ⇒ Object
- #test_import ⇒ Object
- #test_subject ⇒ Object
- #test_thread ⇒ Object
- #test_type ⇒ Object
Instance Method Details
#test_answer ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/vendor/xmpp4r/test/tc_message.rb', line 98 def test_answer orig = Message.new orig.from = 'a@b' orig.to = 'b@a' orig.id = '123' orig.type = :chat orig.add(REXML::Element.new('x')) answer = orig.answer assert_equal(JID.new('b@a'), answer.from) assert_equal(JID.new('a@b'), answer.to) assert_equal('123', answer.id) assert_equal(:chat, answer.type) answer.each_element { |e| assert_equal('x', e.name) assert_kind_of(X, e) } end |
#test_body ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/vendor/xmpp4r/test/tc_message.rb', line 50 def test_body x = Message.new() assert_equal(nil, x.body) assert_equal(x, x.set_body("trezrze ezfrezr ezr zer ezr ezrezrez ezr z")) assert_equal("trezrze ezfrezr ezr zer ezr ezrezrez ezr z", x.body) x.body = "2" assert_equal("2", x.body) end |
#test_create ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/vendor/xmpp4r/test/tc_message.rb', line 13 def test_create x = Message.new() assert_equal("message", x.name) assert_equal("jabber:client", x.namespace) assert_equal(nil, x.to) assert_equal(nil, x.body) x = Message.new("[email protected]", "coucou") assert_equal("message", x.name) assert_equal("[email protected]", x.to.to_s) assert_equal("coucou", x.body) end |
#test_error ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/vendor/xmpp4r/test/tc_message.rb', line 87 def test_error x = Message.new() assert_equal(nil, x.error) e = REXML::Element.new('error') x.add(e) # test if, after an import, the error element is successfully changed # into an ErrorResponse object. x2 = Message.new.import(x) assert_equal(ErrorResponse, x2.first_element('error').class) end |
#test_import ⇒ Object
26 27 28 29 30 31 |
# File 'lib/vendor/xmpp4r/test/tc_message.rb', line 26 def test_import x = Message.new assert_kind_of(REXML::Element, x.typed_add(REXML::Element.new('thread'))) assert_kind_of(X, x.typed_add(REXML::Element.new('x'))) assert_kind_of(X, x.x) end |
#test_subject ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/vendor/xmpp4r/test/tc_message.rb', line 59 def test_subject x = Message.new assert_equal(nil, x.subject) subject = REXML::Element.new('subject') subject.text = 'A' x.add(subject) assert_equal('A', x.subject) x.subject = 'Test message' assert_equal('Test message', x.subject) x.each_element('subject') { |s| assert_equal('Test message', s.text) } assert_equal(x, x.set_subject('Breaking news')) assert_equal('Breaking news', x.subject) end |
#test_thread ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/vendor/xmpp4r/test/tc_message.rb', line 73 def test_thread x = Message.new assert_equal(nil, x.thread) thread = REXML::Element.new('thread') thread.text = '123' x.add(thread) assert_equal('123', x.thread) x.thread = '321' assert_equal('321', x.thread) x.each_element('thread') { |s| assert_equal('321', s.text) } assert_equal(x, x.set_thread('abc')) assert_equal('abc', x.thread) end |
#test_type ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vendor/xmpp4r/test/tc_message.rb', line 33 def test_type x = Message.new assert_equal(nil, x.type) x.type = :chat assert_equal(:chat, x.type) assert_equal(x, x.set_type(:error)) assert_equal(:error, x.type) x.type = :groupchat assert_equal(:groupchat, x.type) x.type = :headline assert_equal(:headline, x.type) x.type = :normal assert_equal(:normal, x.type) x.type = :invalid assert_equal(nil, x.type) end |