File: tc_helper_send.rb

package info (click to toggle)
ruby-xmpp4r 0.5.6-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,384 kB
  • sloc: ruby: 17,382; xml: 74; sh: 12; makefile: 4
file content (74 lines) | stat: -rwxr-xr-x 2,175 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/ruby

$:.unshift File::dirname(__FILE__) + '/../../lib'

require 'test/unit'
require File::dirname(__FILE__) + '/../lib/clienttester'

require 'xmpp4r'
require 'xmpp4r/tune/helper/helper'
require 'xmpp4r/tune/tune'
include Jabber

#Jabber::debug=true

class UserTune::HelperTest < Test::Unit::TestCase
  include ClientTester

  ##
  # Test sending 'now playing' notifications
  #
  # See http://www.xmpp.org/extensions/xep-0118.html#protocol-transport,
  # example 1
  def test_send_now_playing
    artist = 'Mike Flowers Pops'
    title = 'Light My Fire'
    tune_to_send = UserTune::Tune.new(artist, title)

    h = UserTune::Helper.new(@client, nil)
    assert_kind_of(UserTune::Helper, h)

    state { |now_playing|
      assert_kind_of(Jabber::Iq, now_playing)
      assert_equal :set, now_playing.type

      assert_kind_of(Jabber::PubSub::IqPubSub,now_playing.first_element('pubsub'))
      assert_equal(Jabber::UserTune::NS_USERTUNE,now_playing.first_element('pubsub').first_element('publish').node)

      tune=now_playing.first_element('pubsub').first_element('publish').first_element('item').first_element('tune')
      assert_kind_of Jabber::UserTune::Tune,tune
      assert_equal true, tune.playing?
      assert_equal artist,tune.artist
      assert_equal title,tune.title
      assert_equal nil,tune.length
      assert_equal nil,tune.track
      assert_equal nil,tune.source
      assert_equal nil,tune.uri

      send("<iq type='result' id='#{now_playing.id}'/>")
    }
    h.now_playing(tune_to_send)
    wait_state
  end

  def test_send_stop_playing
    h = UserTune::Helper.new(@client, nil)

    state { |now_playing|
      tune = now_playing.first_element('pubsub').first_element('publish').first_element('item').first_element('tune')

      assert_kind_of Jabber::UserTune::Tune, tune
      assert_equal false, tune.playing?
      assert_equal nil, tune.artist
      assert_equal nil, tune.title
      assert_equal nil,tune.length
      assert_equal nil,tune.track
      assert_equal nil,tune.source
      assert_equal nil,tune.uri

      send("<iq type='result' id='#{now_playing.id}'/>")
    }
    h.stop_playing
    wait_state
  end
end