Class: Version::IqQueryVersionTest

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

Instance Method Summary collapse

Instance Method Details

#test_createObject



20
21
22
23
24
25
26
# File 'lib/vendor/xmpp4r/test/version/tc_iqqueryversion.rb', line 20

def test_create
  x = Version::IqQueryVersion.new('my test', 'XP')
  assert_equal('jabber:iq:version', x.namespace)
  assert_equal('my test', x.iname)
  assert_equal('XP', x.version)
  assert_equal(nil, x.os)
end

#test_create_emptyObject



12
13
14
15
16
17
18
# File 'lib/vendor/xmpp4r/test/version/tc_iqqueryversion.rb', line 12

def test_create_empty
  x = Version::IqQueryVersion.new
  assert_equal('jabber:iq:version', x.namespace)
  assert_nil(x.iname)
  assert_nil(x.version)
  assert_nil(x.os)
end

#test_create_with_osObject



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

def test_create_with_os
  x = Version::IqQueryVersion.new('superbot', '1.0-final', 'FreeBSD 5.4-RELEASE-p4')
  assert_equal('jabber:iq:version', x.namespace)
  assert_equal('superbot', x.iname)
  assert_equal('1.0-final', x.version)
  assert_equal('FreeBSD 5.4-RELEASE-p4', x.os)
end

#test_import1Object



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

def test_import1
  iq = Iq.new
  q = REXML::Element.new('query')
  q.add_namespace('jabber:iq:version')
  iq.add(q)
  iq2 = Iq.new.import(iq)
  assert_equal(Version::IqQueryVersion, iq2.query.class)
end

#test_import2Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/vendor/xmpp4r/test/version/tc_iqqueryversion.rb', line 45

def test_import2
  iq = Iq.new
  q = REXML::Element.new('query')
  q.add_namespace('jabber:iq:version')
  q.add_element('name').text = 'AstroBot'
  q.add_element('version').text = 'XP'
  q.add_element('os').text = 'FreeDOS'
  iq.add(q)
  iq = Iq.new.import(iq)
  assert_equal(Version::IqQueryVersion, iq.query.class)
  assert_equal('AstroBot', iq.query.iname)
  assert_equal('XP', iq.query.version)
  assert_equal('FreeDOS', iq.query.os)
end

#test_replaceObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/vendor/xmpp4r/test/version/tc_iqqueryversion.rb', line 60

def test_replace
  x = Version::IqQueryVersion.new('name', 'version', 'os')

  num = 0
  x.each_element('name') { |e| num += 1 }
  assert_equal(1, num)
  num = 0
  x.each_element('version') { |e| num += 1 }
  assert_equal(1, num)
  num = 0
  x.each_element('os') { |e| num += 1 }
  assert_equal(1, num)

  x.set_iname('N').set_version('V').set_os('O')

  num = 0
  x.each_element('name') { |e| num += 1 }
  assert_equal(1, num)
  num = 0
  x.each_element('version') { |e| num += 1 }
  assert_equal(1, num)
  num = 0
  x.each_element('os') { |e| num += 1 }
  assert_equal(1, num)

  x.set_iname(nil).set_version(nil).set_os(nil)

  num = 0
  x.each_element('name') { |e| num += 1 }
  assert_equal(1, num)
  num = 0
  x.each_element('version') { |e| num += 1 }
  assert_equal(1, num)
  num = 0
  x.each_element('os') { |e| num += 1 }
  assert_equal(0, num)
end