Class: IqTest

Inherits:
Test::Unit::TestCase show all
Defined in:
lib/gems/xmpp4r-0.4/test/tc_iq.rb

Instance Method Summary collapse

Methods inherited from Test::Unit::TestCase

#assert_array_equal, expect, #run

Instance Method Details

#test_browsegetObject



51
52
53
54
# File 'lib/gems/xmpp4r-0.4/test/tc_iq.rb', line 51

def test_browseget
  x = Iq.new_browseget
  assert_equal_xml("<iq type='get' xmlns='jabber:client'><query xmlns='jabber:iq:browse'/></iq>", x)
end

#test_createObject



15
16
17
18
19
20
# File 'lib/gems/xmpp4r-0.4/test/tc_iq.rb', line 15

def test_create
  x = Iq.new()
  assert_equal("iq", x.name)
  assert_equal("jabber:client", x.namespace)
  assert_equal_xml("<iq xmlns='jabber:client'/>", x)
end

#test_errorObject



95
96
97
98
99
100
101
102
103
# File 'lib/gems/xmpp4r-0.4/test/tc_iq.rb', line 95

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

#test_iqauthObject



22
23
24
25
# File 'lib/gems/xmpp4r-0.4/test/tc_iq.rb', line 22

def test_iqauth
  x = Iq.new_authset(JID.new('node@domain/resource'), 'password')
  assert_equal_xml("<iq type='set' xmlns='jabber:client'><query xmlns='jabber:iq:auth'><username>node</username><password>password</password><resource>resource</resource></query></iq>", x)
end

#test_iqauth_digestObject



27
28
29
30
# File 'lib/gems/xmpp4r-0.4/test/tc_iq.rb', line 27

def test_iqauth_digest
  x = Iq.new_authset_digest(JID.new('node@domain/resource'), '', 'password')
  assert_equal_xml("<iq type='set' xmlns='jabber:client'><query xmlns='jabber:iq:auth'><username>node</username><digest>#{Digest::SHA1.hexdigest('password')}</digest><resource>resource</resource></query></iq>", x)
end

#test_new_queryObject



105
106
107
108
109
110
111
112
# File 'lib/gems/xmpp4r-0.4/test/tc_iq.rb', line 105

def test_new_query
  x = Iq.new_query(:get, JID.new('a@b/c'))
  assert_equal(:get, x.type)
  assert_equal(nil, x.from)
  assert_equal(JID.new('a@b/c'), x.to)
  assert_kind_of(IqQuery, x.query)
  assert_equal('jabber:client', x.queryns)
end

#test_queryObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/gems/xmpp4r-0.4/test/tc_iq.rb', line 71

def test_query
  x = Iq.new(:set)
  assert_equal(nil, x.queryns)
  query = REXML::Element.new('query')
  x.add(query)
  assert_equal('jabber:client', x.queryns)
  query.add_namespace('jabber:iq:auth')
  assert_equal(query.to_s, x.query.to_s)
  assert_equal('jabber:iq:auth', x.queryns)

  query2 = REXML::Element.new('query')
  x.query = query2
  assert_equal('jabber:client', x.queryns)
  query2.add_namespace('jabber:iq:register')
  assert_equal('jabber:iq:register', x.queryns)
end

#test_registerObject



32
33
34
35
36
37
38
39
# File 'lib/gems/xmpp4r-0.4/test/tc_iq.rb', line 32

def test_register
  x1 = Iq.new_register
  assert_equal_xml("<iq type='set' xmlns='jabber:client'><query xmlns='jabber:iq:register'/></iq>", x1)
  x2 = Iq.new_register('node')
  assert_equal_xml("<iq type='set' xmlns='jabber:client'><query xmlns='jabber:iq:register'><username>node</username></query></iq>", x2)
  x3 = Iq.new_register('node', 'password')
  assert_equal_xml("<iq type='set' xmlns='jabber:client'><query xmlns='jabber:iq:register'><username>node</username><password>password</password></query></iq>", x3)
end

#test_rostergetObject



41
42
43
44
# File 'lib/gems/xmpp4r-0.4/test/tc_iq.rb', line 41

def test_rosterget
  x = Iq.new_rosterget
  assert_equal_xml("<iq type='get' xmlns='jabber:client'><query xmlns='jabber:iq:roster'/></iq>", x)
end

#test_rostersetObject



46
47
48
49
# File 'lib/gems/xmpp4r-0.4/test/tc_iq.rb', line 46

def test_rosterset
  x = Iq.new_rosterset
  assert_equal_xml("<iq type='set' xmlns='jabber:client'><query xmlns='jabber:iq:roster'/></iq>", x)
end

#test_typesObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/gems/xmpp4r-0.4/test/tc_iq.rb', line 56

def test_types
  iq = Iq.new
  assert_equal(nil, iq.type)
  iq.type = :get
  assert_equal(:get, iq.type)
  iq.type = :set
  assert_equal(:set, iq.type)
  iq.type = :result
  assert_equal(:result, iq.type)
  iq.type = :error
  assert_equal(:error, iq.type)
  iq.type = :invalid
  assert_equal(nil, iq.type)
end

#test_vcardObject



88
89
90
91
92
93
# File 'lib/gems/xmpp4r-0.4/test/tc_iq.rb', line 88

def test_vcard
  x = Iq.new
  assert_equal(nil, x.vcard)
  x.add(vcard = REXML::Element.new('vCard'))
  assert_equal(vcard, x.vcard)
end