Class: UserTune::HelperTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
ClientTester
Defined in:
lib/gems/xmpp4r-0.4/test/tune/tc_helper_send.rb,
lib/gems/xmpp4r-0.4/test/tune/tc_helper_recv.rb

Overview

Jabber::debug=true

Instance Method Summary collapse

Instance Method Details

#deliver_usertuneObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/gems/xmpp4r-0.4/test/tune/tc_helper_recv.rb', line 51

def deliver_usertune
  "<message
  from='[email protected]'
  to='[email protected]'>
  <event xmlns='http://jabber.org/protocol/pubsub#event'>
  <items node='http://jabber.org/protocol/tune'>
    <item id='bffe6584-0f9c-11dc-84ba-001143d5d5db'>
      <tune xmlns='http://jabber.org/protocol/tune'>
        <artist>Yes</artist>
        <length>686</length>
        <source>Yessongs</source>
        <title>Heart of the Sunrise</title>
        <track>3</track>
        <uri>http://www.yesworld.com/lyrics/Fragile.html#9</uri>
      </tune>
    </item>
  </items>
  </event>
  </message>"
end

#psi_usertuneObject

an example from the Wild



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/gems/xmpp4r-0.4/test/tune/tc_helper_recv.rb', line 73

def psi_usertune
  "<message from='[email protected]' to='[email protected]/trackbot' xmlns='jabber:client'><event xmlns='http://jabber.org/protocol/pubsub#event'><items node='http://jabber.org/protocol/tune'><item id='current'>

  <tune xmlns='http://jabber.org/protocol/tune'>





  <artist>Wes Montgomery</artist><title>Jingles</title><source>Bags Meets Wes</source><track>8</track><length>410</length></tune></item></items></event></message>"
end

#test_recv_now_playingObject

Test receiving ‘now playing’ notifications

See www.xmpp.org/extensions/xep-0118.html#protocol-transport, example 1



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
# File 'lib/gems/xmpp4r-0.4/test/tune/tc_helper_recv.rb', line 23

def test_recv_now_playing
  state { |presence|
    send(deliver_usertune)
  }

  query_waiter = Semaphore.new

  h = UserTune::Helper.new(@client, '[email protected]')
  h.add_usertune_callback do |tune|
    assert_kind_of Jabber::UserTune::Tune, tune
    assert_equal true, tune.playing?
    assert_equal 'Yes', tune.artist
    assert_equal 686, tune.length
    assert_equal 'Yessongs', tune.source
    assert_equal 'Heart of the Sunrise', tune.title
    assert_equal '3', tune.track
    assert_equal 'http://www.yesworld.com/lyrics/Fragile.html#9',tune.uri
  end
  @client.add_message_callback do |m|
    query_waiter.run
  end
  @client.send Jabber::Presence.new
  wait_state

  query_waiter.wait
end

#test_send_now_playingObject

Test sending ‘now playing’ notifications

See www.xmpp.org/extensions/xep-0118.html#protocol-transport, example 1



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
# File 'lib/gems/xmpp4r-0.4/test/tune/tc_helper_send.rb', line 23

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

#test_send_stop_playingObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/gems/xmpp4r-0.4/test/tune/tc_helper_send.rb', line 54

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