Class: XMPPStanzaTest

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

Defined Under Namespace

Classes: MyStanza, MyXMPPStanza

Instance Method Summary collapse

Instance Method Details

#test_clone_and_dupObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/vendor/xmpp4r/test/tc_xmppstanza.rb', line 111

def test_clone_and_dup
  x = MyXMPPStanza.new
  x.attributes['xyz'] = '123'
  x.text = 'abc'

  assert_equal(x.attributes['xyz'], '123')
  assert_equal(x.text, 'abc')

  x2 = x.clone
  assert_kind_of(MyXMPPStanza, x2)
  assert_equal('123', x2.attributes['xyz'])
  assert_nil(x2.text)

  x3 = x.dup
  assert_kind_of(MyXMPPStanza, x3)
  assert_equal('123', x3.attributes['xyz'])
  assert_equal('abc', x3.text)
end

#test_errorObject



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

def test_error
  x = MyXMPPStanza.new
  assert_equal(nil, x.error)
  x.typed_add(REXML::Element.new('error'))
  assert_equal('<error/>', x.error.to_s)
  assert_equal(ErrorResponse, x.error.class)
end

#test_fromObject



27
28
29
30
31
32
33
34
# File 'lib/vendor/xmpp4r/test/tc_xmppstanza.rb', line 27

def test_from
  x = MyXMPPStanza.new
  assert_equal(nil, x.from)
  assert_equal(x, x.set_from("blop"))
  assert_equal("blop", x.from.to_s)
  x.from = "tada"
  assert_equal("tada", x.from.to_s)
end

#test_idObject



45
46
47
48
49
50
51
52
# File 'lib/vendor/xmpp4r/test/tc_xmppstanza.rb', line 45

def test_id
  x = MyXMPPStanza.new
  assert_equal(nil, x.id)
  assert_equal(x, x.set_id("blop"))
  assert_equal("blop", x.id)
  x.id = "tada"
  assert_equal("tada", x.id)
end

#test_importObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/vendor/xmpp4r/test/tc_xmppstanza.rb', line 63

def test_import
  x = MyXMPPStanza.new
  x.id = "heya"
  q = x.add_element("query")
  q.add_namespace("about:blank")
  q.add_element("b").text = "I am b"
  q.add_text("I am text")
  q.add_element("a").add_attribute("href", "http://home.gna.org/xmpp4r/")
  x.add_text("yow")
  x.add_element("query")

  assert_raise(RuntimeError) { iq = Iq.import(x) }
  x.name = 'iq'
  iq = Iq.import(x)

  assert_equal(x.id, iq.id)
  assert_equal(q.to_s, iq.query.to_s)
  assert_equal(x.to_s, iq.to_s)
  assert_equal(q.namespace, iq.queryns)
end

#test_import2Object



84
85
86
87
88
89
90
91
92
# File 'lib/vendor/xmpp4r/test/tc_xmppstanza.rb', line 84

def test_import2
  feature = FeatureNegotiation::IqFeature.new
  xdata = feature.add(Dataforms::XData.new(:form))
  field = xdata.add(Dataforms::XDataField.new('stream-method', :list_single))

  feature2 = FeatureNegotiation::IqFeature.new.import(feature)
  assert_equal(field.var, feature2.x.fields.first.var)
  assert_equal(field.type, feature2.x.fields.first.type)
end

#test_import_xml_entitiesObject



94
95
96
97
98
99
100
101
# File 'lib/vendor/xmpp4r/test/tc_xmppstanza.rb', line 94

def test_import_xml_entities
  e = REXML::Element.new('e')
  e.text = '&'
  assert_equal('<e>&amp;</e>', e.to_s)

  e2 = REXML::Element.new('e').import(e)
  assert_equal('<e>&amp;</e>', e2.to_s)
end

#test_raiseObject



130
131
132
133
134
# File 'lib/vendor/xmpp4r/test/tc_xmppstanza.rb', line 130

def test_raise
  assert_raises(NoNameXmlnsRegistered) {
    XMPPStanza.name_xmlns_for_class(MyStanza)
  }
end

#test_toObject



36
37
38
39
40
41
42
43
# File 'lib/vendor/xmpp4r/test/tc_xmppstanza.rb', line 36

def test_to
  x = MyXMPPStanza.new
  assert_equal(nil, x.to)
  assert_equal(x, x.set_to("blop"))
  assert_equal("blop", x.to.to_s)
  x.to = "tada"
  assert_equal("tada", x.to.to_s)
end

#test_typeObject



54
55
56
57
58
59
60
61
# File 'lib/vendor/xmpp4r/test/tc_xmppstanza.rb', line 54

def test_type
  x = MyXMPPStanza.new
  assert_equal(nil, x.type)
  assert_equal(x, x.set_type("blop"))
  assert_equal("blop", x.type)
  x.type = "tada"
  assert_equal("tada", x.type)
end