libastag 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/BUGS +10 -0
- data/CHANGES +8 -1
- data/MIT-LICENSE +2 -1
- data/README +7 -3
- data/Rakefile +3 -2
- data/TODO +4 -7
- data/doc/classes/Helpers.html +16 -20
- data/doc/classes/Helpers/REXML.html +4 -4
- data/doc/classes/Helpers/REXML/Attributes.html +10 -10
- data/doc/classes/Libastag.html +5 -5
- data/doc/classes/Libastag/Rabbit.html +56 -56
- data/doc/classes/Libastag/RabitEar.html +4 -4
- data/doc/classes/Libastag/RabitLed.html +4 -4
- data/doc/classes/Request.html +33 -37
- data/doc/classes/Request/Action.html +34 -34
- data/doc/classes/Request/AudioStream.html +313 -0
- data/doc/classes/Request/Base.html +13 -10
- data/doc/classes/Request/Base/Event.html +58 -23
- data/doc/classes/Request/Base/EventCollection.html +35 -32
- data/doc/classes/Request/Choregraphy.html +500 -0
- data/doc/classes/Request/Choregraphy/BadChorDesc.html +135 -0
- data/doc/classes/Request/Choregraphy/Ears.html +130 -0
- data/doc/classes/Request/Choregraphy/Ears/Directions.html +141 -0
- data/doc/classes/Request/Choregraphy/Ears/Positions.html +146 -0
- data/doc/classes/Request/Choregraphy/Leds.html +130 -0
- data/doc/classes/Request/Choregraphy/Leds/Colors.html +171 -0
- data/doc/classes/Request/Choregraphy/Leds/Positions.html +161 -0
- data/doc/classes/Request/GET_EARS_POSITION.html +17 -14
- data/doc/classes/Request/IdMessage.html +234 -0
- data/doc/classes/Request/Query.html +80 -55
- data/doc/classes/Request/SetEarsPosition.html +58 -36
- data/doc/classes/Request/TtsMessage.html +74 -50
- data/doc/classes/Response.html +55 -124
- data/doc/classes/Response/AbuseSending.html +34 -34
- data/doc/classes/Response/Base.html +34 -34
- data/doc/classes/Response/Base/BadServerRsp.html +34 -34
- data/doc/classes/Response/Base/GoodServerRsp.html +34 -34
- data/doc/classes/Response/Base/ServerRsp.html +53 -53
- data/doc/classes/Response/Blacklist.html +34 -34
- data/doc/classes/Response/ChorNotSend.html +34 -34
- data/doc/classes/Response/ChorSend.html +34 -34
- data/doc/classes/Response/CommandSend.html +34 -34
- data/doc/classes/Response/EarPositionNotSend.html +34 -34
- data/doc/classes/Response/EarPositionSend.html +34 -34
- data/doc/classes/Response/EmptyServerRsp.html +34 -34
- data/doc/classes/Response/LangListUser.html +34 -34
- data/doc/classes/Response/LinkPreview.html +34 -34
- data/doc/classes/Response/ListFriend.html +34 -34
- data/doc/classes/Response/ListReceivedMsg.html +34 -34
- data/doc/classes/Response/MessageNotSend.html +34 -34
- data/doc/classes/Response/MessageSend.html +34 -34
- data/doc/classes/Response/NabCastNotSend.html +34 -34
- data/doc/classes/Response/NabCastSend.html +34 -34
- data/doc/classes/Response/NoCorrectParameters.html +34 -34
- data/doc/classes/Response/NoGoodTokenOrSerial.html +34 -34
- data/doc/classes/Response/NotV2Rabbit.html +34 -34
- data/doc/classes/Response/PositionEar.html +34 -34
- data/doc/classes/Response/ProtocolExcepion.html +35 -35
- data/doc/classes/Response/RabbitName.html +34 -34
- data/doc/classes/Response/RabbitSleep.html +34 -34
- data/doc/classes/Response/RabbitVersion.html +34 -34
- data/doc/classes/Response/Signature.html +34 -34
- data/doc/classes/Response/Timezone.html +34 -34
- data/doc/classes/Response/TtsNotSend.html +34 -34
- data/doc/classes/Response/TtsSend.html +34 -34
- data/doc/classes/Response/VoiceListTts.html +34 -34
- data/doc/classes/Response/WebRadioNotSend.html +34 -34
- data/doc/classes/Response/WebRadioSend.html +34 -34
- data/doc/created.rid +1 -1
- data/doc/dot/f_0.png +0 -0
- data/doc/dot/f_5.dot +13 -445
- data/doc/dot/f_5.png +0 -0
- data/doc/dot/f_6.dot +445 -11
- data/doc/dot/f_6.png +0 -0
- data/doc/dot/f_7.dot +30 -5
- data/doc/dot/f_7.png +0 -0
- data/doc/dot/f_8.dot +39 -0
- data/doc/dot/f_8.png +0 -0
- data/doc/files/{lib/violet/violetapi_rb.html → BUGS.html} +17 -9
- data/doc/files/CHANGES.html +15 -2
- data/doc/files/MIT-LICENSE.html +2 -2
- data/doc/files/README.html +13 -3
- data/doc/files/TODO.html +5 -8
- data/doc/files/lib/libastag_rb.html +12 -10
- data/doc/files/lib/violet/helpers_rb.html +5 -5
- data/doc/files/lib/violet/request_rb.html +16 -12
- data/doc/files/lib/violet/response_rb.html +36 -35
- data/doc/fr_class_index.html +10 -1
- data/doc/fr_file_index.html +1 -1
- data/doc/fr_method_index.html +25 -12
- data/examples/morse.rb +72 -0
- data/lib/libastag.rb +6 -2
- data/lib/violet/helpers.rb +4 -2
- data/lib/violet/request.rb +501 -47
- data/lib/violet/response.rb +5 -2
- data/test/fake_violet_srv.rb +1 -1
- data/test/test_helpers.rb +3 -5
- data/test/{test_send.rb → test_query_and_actions.rb} +27 -10
- data/test/test_request_base.rb +76 -0
- data/test/test_request_chor.rb +162 -0
- data/test/test_request_stuff.rb +171 -0
- data/test/test_response.rb +3 -4
- metadata +45 -20
- data/doc/classes/VioletAPI.html +0 -118
- data/doc/dot/f_4.dot +0 -57
- data/doc/dot/f_4.png +0 -0
- data/lib/violet/violetapi.rb +0 -14
- data/test/test_request.rb +0 -20
data/lib/violet/response.rb
CHANGED
|
@@ -48,13 +48,16 @@ if you want to access to the REXML::Document object of a ServerRsp you can eithe
|
|
|
48
48
|
|
|
49
49
|
=end
|
|
50
50
|
|
|
51
|
+
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) or $:.include?(File.expand_path(File.dirname(__FILE__)))
|
|
52
|
+
|
|
53
|
+
require 'helpers.rb'
|
|
54
|
+
|
|
51
55
|
module Response
|
|
52
|
-
require File.join(File.dirname(__FILE__), 'helpers.rb')
|
|
53
56
|
|
|
54
57
|
# ProtocolExcepion are raised if server return a unknown response.
|
|
55
58
|
#
|
|
56
59
|
# see http://api.nabaztag.com/docs/home.html#messages
|
|
57
|
-
class ProtocolExcepion <
|
|
60
|
+
class ProtocolExcepion < StandardError; end
|
|
58
61
|
|
|
59
62
|
|
|
60
63
|
# contains some basic stuff, abstract class etc. they're used internaly and you should not access this module.
|
data/test/fake_violet_srv.rb
CHANGED
data/test/test_helpers.rb
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/ruby
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
File.join( File.dirname(__FILE__), *args )
|
|
6
|
-
end
|
|
3
|
+
MY_PATH = File.join( File.dirname(__FILE__), '..', 'lib', 'violet' )
|
|
4
|
+
$:.unshift(MY_PATH) unless $:.include?(MY_PATH)
|
|
7
5
|
|
|
8
6
|
|
|
9
|
-
require
|
|
7
|
+
require 'helpers.rb'
|
|
10
8
|
|
|
11
9
|
require 'rexml/document'
|
|
12
10
|
require 'test/unit'
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/ruby
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
File.join( File.dirname(__FILE__), *args )
|
|
6
|
-
end
|
|
3
|
+
MY_PATH = File.join( File.dirname(__FILE__), '..', 'lib', 'violet' )
|
|
4
|
+
$:.unshift(MY_PATH) unless $:.include?(MY_PATH)
|
|
7
5
|
|
|
8
6
|
|
|
9
|
-
require
|
|
10
|
-
require
|
|
11
|
-
require
|
|
7
|
+
require File.join( File.dirname(__FILE__), 'fake_violet_srv.rb' )
|
|
8
|
+
require 'request.rb'
|
|
9
|
+
require 'response.rb'
|
|
12
10
|
|
|
13
11
|
require 'test/unit'
|
|
14
12
|
require 'open-uri'
|
|
@@ -20,12 +18,12 @@ require 'open-uri'
|
|
|
20
18
|
#
|
|
21
19
|
|
|
22
20
|
t = Thread.new do
|
|
23
|
-
FakeVioletSrv.start
|
|
21
|
+
FakeVioletSrv.start 3_000, File.join( File.dirname(__FILE__), 'testsend_log.tmp' )
|
|
24
22
|
end
|
|
25
23
|
sleep 1 # wait for server start.
|
|
26
24
|
|
|
27
25
|
|
|
28
|
-
class
|
|
26
|
+
class QueryAndActionTest < Test::Unit::TestCase
|
|
29
27
|
require 'rexml/document'
|
|
30
28
|
|
|
31
29
|
GOOD_SERIAL = '1234567890AB'
|
|
@@ -33,7 +31,7 @@ class ActionTest < Test::Unit::TestCase
|
|
|
33
31
|
BAD_SERIAL = '1X34U67890AB'
|
|
34
32
|
BAD_TOKEN = '123456789A'
|
|
35
33
|
|
|
36
|
-
LOCAL_URI = 'http://localhost:3000/api.jsp
|
|
34
|
+
LOCAL_URI = 'http://localhost:3000/api.jsp'
|
|
37
35
|
|
|
38
36
|
# Hacky ! yes !
|
|
39
37
|
Request::API_URL = LOCAL_URI
|
|
@@ -46,6 +44,25 @@ class ActionTest < Test::Unit::TestCase
|
|
|
46
44
|
end
|
|
47
45
|
|
|
48
46
|
|
|
47
|
+
def test_query_new
|
|
48
|
+
assert_nothing_raised { Request::Query.new :token => GOOD_TOKEN, :serial => GOOD_SERIAL, :event => Request::GET_SIGNATURE }
|
|
49
|
+
assert_raise(ArgumentError) { Request::Query.new :serial => GOOD_SERIAL, :event => Request::GET_SIGNATURE }
|
|
50
|
+
assert_raise(ArgumentError) { Request::Query.new :token => GOOD_TOKEN, :event => Request::GET_SIGNATURE }
|
|
51
|
+
assert_raise(ArgumentError) { Request::Query.new :token => GOOD_TOKEN, :serial => GOOD_SERIAL }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_query_to_url
|
|
56
|
+
[ Request::GET_RABBIT_NAME,
|
|
57
|
+
Request::GET_FRIENDS_LIST,
|
|
58
|
+
Request::GET_EARS_POSITION
|
|
59
|
+
].each do |e|
|
|
60
|
+
q = Request::Query.new :event => e, :serial => GOOD_SERIAL, :token => GOOD_TOKEN
|
|
61
|
+
assert_equal "#{Request::API_URL}?sn=#{GOOD_SERIAL}&token=#{GOOD_TOKEN}&#{e.to_url}", q.to_url
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
|
|
49
66
|
def test_xml_response
|
|
50
67
|
rsp = Request::Query.new(:event => Request::GET_RABBIT_NAME, :serial => GOOD_SERIAL, :token => GOOD_TOKEN).send!(:xml)
|
|
51
68
|
assert_nothing_raised { REXML::Document.new(rsp) }
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
MY_PATH = File.join( File.dirname(__FILE__), '..', 'lib', 'violet' )
|
|
5
|
+
$:.unshift(MY_PATH) unless $:.include?(MY_PATH)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
require 'request.rb'
|
|
9
|
+
require 'response.rb'
|
|
10
|
+
|
|
11
|
+
require 'test/unit'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class RequestBaseTest < Test::Unit::TestCase
|
|
17
|
+
include Request
|
|
18
|
+
|
|
19
|
+
class EventTestFake < Base::Event
|
|
20
|
+
# nothin'
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class EventTestSimple < Base::Event
|
|
24
|
+
def initialize str
|
|
25
|
+
@val = str
|
|
26
|
+
end
|
|
27
|
+
def to_url
|
|
28
|
+
@val.to_s
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# make sure that Event is an abstract class and that all class that
|
|
33
|
+
# inherit of Event has to redefine initialize and to_url.
|
|
34
|
+
def test_class_Event
|
|
35
|
+
assert_raise(NotImplementedError) { Base::Event.new }
|
|
36
|
+
assert_raise(NotImplementedError) { EventTestFake.new }
|
|
37
|
+
|
|
38
|
+
EventTestFake.class_eval do
|
|
39
|
+
def initialize
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
assert_nothing_raised { EventTestFake.new }
|
|
43
|
+
assert_raise(NotImplementedError) { EventTestFake.new.to_url }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_EventCollection_new_and_add
|
|
48
|
+
assert_raise(ArgumentError) { Base::EventCollection.new(1,2) }
|
|
49
|
+
|
|
50
|
+
class << (s = String.new)
|
|
51
|
+
def to_url
|
|
52
|
+
self
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
assert_nothing_raised { Base::EventCollection.new(s,s) }
|
|
56
|
+
assert_nothing_raised { Base::EventCollection.new(EventTestSimple.new(1),EventTestSimple.new(2)) }
|
|
57
|
+
|
|
58
|
+
gou = EventTestSimple.new 'gou'
|
|
59
|
+
foo = EventTestSimple.new 'foo'
|
|
60
|
+
assert_equal Base::EventCollection.new(gou,foo).to_url, (gou+foo).to_url
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_EventCollection_to_url
|
|
66
|
+
one = EventTestSimple.new 1
|
|
67
|
+
two = EventTestSimple.new 2
|
|
68
|
+
three = EventTestSimple.new 3
|
|
69
|
+
all = nil
|
|
70
|
+
|
|
71
|
+
assert_nothing_raised { all = one + two + three }
|
|
72
|
+
|
|
73
|
+
expected_uri = [ one.to_url, two.to_url, three.to_url ]
|
|
74
|
+
assert_equal expected_uri, all.to_url
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
MY_PATH = File.join( File.dirname(__FILE__), '..', 'lib', 'violet' )
|
|
5
|
+
$:.unshift(MY_PATH) unless $:.include?(MY_PATH)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
require 'request.rb'
|
|
9
|
+
require 'response.rb'
|
|
10
|
+
|
|
11
|
+
require 'test/unit'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ChorTrinity < Struct.new :code, :strcode, :result
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class ChoregraphyTest < Test::Unit::TestCase
|
|
20
|
+
include Request
|
|
21
|
+
|
|
22
|
+
SIMPLES_CHORS = [
|
|
23
|
+
ChorTrinity.new(Proc.new { set top led red },
|
|
24
|
+
'set top led red',
|
|
25
|
+
'chor=10,0,led,4,255,0,0'),
|
|
26
|
+
ChorTrinity.new(Proc.new { move right ear forward of degrees 10 },
|
|
27
|
+
'move right ear forward of degrees 10',
|
|
28
|
+
'chor=10,0,motor,0,10,0,0')
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
ALL_CHORS = SIMPLES_CHORS
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_creating_simple_choregraphy
|
|
35
|
+
SIMPLES_CHORS.each do |chor|
|
|
36
|
+
assert_equal [chor.result], Choregraphy.new(&chor.code).to_url
|
|
37
|
+
assert_equal [chor.result, 'chortitle=foo'], Choregraphy.new({:name => :foo},&chor.code).to_url
|
|
38
|
+
end
|
|
39
|
+
# <bugfix:001>
|
|
40
|
+
c = Choregraphy.new { set left right off }
|
|
41
|
+
assert_equal 'chor=10,0,led,1,0,0,0,0,led,3,0,0,0', c.to_url.first
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_protected_and_private_methods
|
|
46
|
+
c = Choregraphy.new
|
|
47
|
+
%w[chor __choreval__ at time right left both all top bottom middle led leds ear ears to rgb red green blue cyan magenta yellow white off forward backward of degrees].each do |sym|
|
|
48
|
+
assert_raise(NoMethodError) { eval "c.#{sym}" }
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_creating_with_strings
|
|
54
|
+
ALL_CHORS.each do |chor|
|
|
55
|
+
assert_equal Choregraphy.new(&chor.code), Choregraphy.new(:code => chor.strcode)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_creating_with_multiple_args
|
|
61
|
+
chors = ALL_CHORS.collect { |c| c.strcode }
|
|
62
|
+
assert_equal Choregraphy.new(:code => chors), Choregraphy.new(:code => chors.join("\n"))
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def test_at_time_syntax
|
|
67
|
+
ary = Array.new
|
|
68
|
+
ary << Choregraphy.new do
|
|
69
|
+
at time 0
|
|
70
|
+
set right led to green
|
|
71
|
+
at time 1
|
|
72
|
+
set left led to red
|
|
73
|
+
end
|
|
74
|
+
ary << Choregraphy.new do
|
|
75
|
+
at time 0 do set right led to green end
|
|
76
|
+
at time 1 do set left led to red end
|
|
77
|
+
end
|
|
78
|
+
ary << Choregraphy.new do
|
|
79
|
+
set right led to green at time 0
|
|
80
|
+
set left led to red at time 1
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
element = ary.pop
|
|
84
|
+
ary.each { |e| assert_equal element, e }
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def test_move_syntax
|
|
89
|
+
ary = Array.new
|
|
90
|
+
ary << Choregraphy.new { move both ears forward degrees 130 }
|
|
91
|
+
ary << Choregraphy.new { move both forward degrees 130 }
|
|
92
|
+
ary << Choregraphy.new { move both forward of degrees 130 }
|
|
93
|
+
ary << Choregraphy.new { move both ears forward of degrees 130 }
|
|
94
|
+
ary << Choregraphy.new { move left ear forward of degrees 130
|
|
95
|
+
move right ear forward of degrees 130 }
|
|
96
|
+
|
|
97
|
+
element = ary.pop
|
|
98
|
+
ary.each { |e| assert_equal element, e }
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def test_set_syntax
|
|
103
|
+
ary = Array.new
|
|
104
|
+
ary << Choregraphy.new { set left led green
|
|
105
|
+
set right led green }
|
|
106
|
+
ary << Choregraphy.new { set left right led to green }
|
|
107
|
+
ary << Choregraphy.new { set right left rgb(0,255,0) }
|
|
108
|
+
ary << Choregraphy.new { set right left to 0,255,0 }
|
|
109
|
+
|
|
110
|
+
element = ary.pop
|
|
111
|
+
ary.each { |e| assert_equal element, e }
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def test_operators
|
|
116
|
+
one = Choregraphy.new { move left ear forward of degrees 42 }
|
|
117
|
+
two = Choregraphy.new { move right ear forward of degrees 42 }
|
|
118
|
+
onetwo = Choregraphy.new { move both ears forward of degrees 42 }
|
|
119
|
+
|
|
120
|
+
assert_equal one | two, one + two
|
|
121
|
+
assert_equal one & two, Choregraphy.new
|
|
122
|
+
assert_equal one - two, one
|
|
123
|
+
assert_equal two - one, two
|
|
124
|
+
assert_equal onetwo, one + two
|
|
125
|
+
assert_equal onetwo & two, two
|
|
126
|
+
assert_equal onetwo & one, one
|
|
127
|
+
assert_equal onetwo - two, one
|
|
128
|
+
assert_equal onetwo - one, two
|
|
129
|
+
assert_equal onetwo | two, onetwo
|
|
130
|
+
assert_equal onetwo | one, onetwo
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def test_low_level_EarCommandStruct
|
|
135
|
+
expected = Choregraphy.new { at time 0 do move left ear forward of degrees 120 end }
|
|
136
|
+
|
|
137
|
+
e = Choregraphy::EarCommandStruct.new
|
|
138
|
+
e.element = Choregraphy::Ears::Positions::LEFT
|
|
139
|
+
e.direction = Choregraphy::Ears::Directions::FORWARD
|
|
140
|
+
e.angle = 120
|
|
141
|
+
e.time = 0 * 10
|
|
142
|
+
|
|
143
|
+
c = Choregraphy.new
|
|
144
|
+
c.move(e)
|
|
145
|
+
assert_equal expected, c
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def test_low_level_LedCommandStruct
|
|
150
|
+
expected = Choregraphy.new { at time 2 do set right top red end }
|
|
151
|
+
|
|
152
|
+
l = Choregraphy::LedCommandStruct.new
|
|
153
|
+
l.elements = [ Choregraphy::Leds::Positions::RIGHT,
|
|
154
|
+
Choregraphy::Leds::Positions::TOP ]
|
|
155
|
+
l.color = Choregraphy::Leds::Colors::RED
|
|
156
|
+
l.time = 2 * 10
|
|
157
|
+
|
|
158
|
+
c = Choregraphy.new
|
|
159
|
+
c.set(l)
|
|
160
|
+
assert_equal expected, c
|
|
161
|
+
end
|
|
162
|
+
end
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
MY_PATH = File.join( File.dirname(__FILE__), '..', 'lib', 'violet' )
|
|
5
|
+
$:.unshift(MY_PATH) unless $:.include?(MY_PATH)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
require 'request.rb'
|
|
9
|
+
require 'response.rb'
|
|
10
|
+
|
|
11
|
+
require 'test/unit'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class RequestStuffTest < Test::Unit::TestCase
|
|
17
|
+
include Request
|
|
18
|
+
|
|
19
|
+
def test_SetEarsPosition_new
|
|
20
|
+
assert_equal 0, SetEarsPosition::MIN_POS
|
|
21
|
+
assert_equal 16, SetEarsPosition::MAX_POS
|
|
22
|
+
|
|
23
|
+
min, max = SetEarsPosition::MIN_POS, SetEarsPosition::MAX_POS
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
[:posleft, :posright].each do |sym|
|
|
27
|
+
assert_raise(ArgumentError) { SetEarsPosition.new }
|
|
28
|
+
assert_raise(ArgumentError) { SetEarsPosition.new sym => (min-1) }
|
|
29
|
+
assert_raise(ArgumentError) { SetEarsPosition.new sym => (max+1) }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
assert_nothing_raised do
|
|
33
|
+
SetEarsPosition.new :posleft => min
|
|
34
|
+
SetEarsPosition.new :posright => max
|
|
35
|
+
SetEarsPosition.new :posright => min, :posleft => max
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_SetEarsPosition
|
|
41
|
+
e = SetEarsPosition.new :posleft => 12, :posright => 1.1
|
|
42
|
+
assert_equal ['posleft=12','posright=1'], e.to_url
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_TtsMessage_new
|
|
47
|
+
assert_equal 1, TtsMessage::MIN_PITCH
|
|
48
|
+
assert_equal 32000, TtsMessage::MAX_PITCH
|
|
49
|
+
assert_equal 1, TtsMessage::MIN_PITCH
|
|
50
|
+
assert_equal 32000, TtsMessage::MAX_PITCH
|
|
51
|
+
|
|
52
|
+
assert_raise(ArgumentError) { TtsMessage.new }
|
|
53
|
+
assert_raise(ArgumentError) { TtsMessage.new :tts => '', :speed => (TtsMessage::MAX_SPEED) +1 }
|
|
54
|
+
assert_raise(ArgumentError) { TtsMessage.new :tts => '', :speed => (TtsMessage::MIN_SPEED) -1 }
|
|
55
|
+
assert_raise(ArgumentError) { TtsMessage.new :tts => '', :pitch => (TtsMessage::MAX_PITCH) +1 }
|
|
56
|
+
assert_raise(ArgumentError) { TtsMessage.new :tts => '', :pitch => (TtsMessage::MIN_PITCH) -1 }
|
|
57
|
+
|
|
58
|
+
assert_nothing_raised do
|
|
59
|
+
TtsMessage.new :tts => 'foo'
|
|
60
|
+
TtsMessage.new :tts => 'foo', :pitch => TtsMessage::MIN_PITCH
|
|
61
|
+
TtsMessage.new :tts => 'foo', :pitch => TtsMessage::MAX_PITCH
|
|
62
|
+
TtsMessage.new :tts => 'foo', :speed => TtsMessage::MIN_PITCH
|
|
63
|
+
TtsMessage.new :tts => 'foo', :speed => TtsMessage::MAX_PITCH
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_TtsMessage
|
|
69
|
+
e = nil
|
|
70
|
+
tts = 'Hello world'
|
|
71
|
+
assert_nothing_raised { e = TtsMessage.new :tts => tts }
|
|
72
|
+
assert_equal ["tts=#{URI.escape(tts)}"], e.to_url
|
|
73
|
+
|
|
74
|
+
pitch = 12
|
|
75
|
+
speed = 11.1
|
|
76
|
+
assert_nothing_raised do
|
|
77
|
+
e = TtsMessage.new :tts => tts,
|
|
78
|
+
:speed => speed,
|
|
79
|
+
:pitch => pitch
|
|
80
|
+
end
|
|
81
|
+
assert_equal ["pitch=#{pitch}","speed=#{speed.to_i}","tts=#{URI.escape(tts)}"], e.to_url
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_TtsMessage_with_nabcast
|
|
86
|
+
title = 'this is a test'
|
|
87
|
+
msg = 'wow ! a message !'
|
|
88
|
+
t = nil
|
|
89
|
+
|
|
90
|
+
assert_nothing_raised do
|
|
91
|
+
TtsMessage.new :tts => msg, :nabcast => 12
|
|
92
|
+
TtsMessage.new :tts => msg, :nabcast => 12, :nabcasttitle => title
|
|
93
|
+
t = TtsMessage.new :tts => msg, :nabcast => 12, :nabcasttitle => title, :pitch => 42, :speed => 120
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
expected = ['nabcast=12',"nabcasttitle=#{URI.escape(title)}",'pitch=42','speed=120',"tts=#{URI.escape(msg)}"]
|
|
97
|
+
assert_equal expected, t.to_url
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def test_IdMessage_new
|
|
102
|
+
assert_equal 1, IdMessage::MIN_IDMESSAGE
|
|
103
|
+
|
|
104
|
+
assert_raise(ArgumentError) { IdMessage.new }
|
|
105
|
+
assert_raise(ArgumentError) { IdMessage.new :idmessage => (IdMessage::MIN_IDMESSAGE)-1 }
|
|
106
|
+
assert_nothing_raised { IdMessage.new :idmessage => IdMessage::MIN_IDMESSAGE }
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def test_IdMessage_with_nabcast
|
|
111
|
+
id = 1337
|
|
112
|
+
nabcast = 118218
|
|
113
|
+
title = "it's gonna rain"
|
|
114
|
+
|
|
115
|
+
assert_equal ['idmessage=1337'], IdMessage.new(:idmessage => id).to_url
|
|
116
|
+
|
|
117
|
+
i = IdMessage.new :idmessage => id, :nabcast => nabcast, :nabcasttitle => title
|
|
118
|
+
assert_equal [ 'idmessage=1337', "nabcast=#{nabcast}", "nabcasttitle=#{URI.escape(title)}"].sort, i.to_url.sort
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def test_AudioStream_new
|
|
123
|
+
assert_raise(ArgumentError) { AudioStream.new }
|
|
124
|
+
assert_raise(ArgumentError) { AudioStream.new('') }
|
|
125
|
+
assert_raise(ArgumentError) { AudioStream.new([]) }
|
|
126
|
+
assert_raise(ArgumentError) { AudioStream.new(Hash.new) }
|
|
127
|
+
assert_raise(ArgumentError) { AudioStream.new(:foo => "bar") }
|
|
128
|
+
|
|
129
|
+
assert_nothing_raised { AudioStream.new 'foo' }
|
|
130
|
+
assert_nothing_raised { AudioStream.new %w[foo] }
|
|
131
|
+
assert_nothing_raised { AudioStream.new :url_list => 'foo' }
|
|
132
|
+
assert_nothing_raised { AudioStream.new :url_list => %w[foo] }
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def test_AudioStream_to_url
|
|
137
|
+
assert_equal 'urlList=one', AudioStream.new('one').to_url
|
|
138
|
+
assert_equal 'urlList=two', AudioStream.new('two').to_url
|
|
139
|
+
assert_equal 'urlList=two|one', AudioStream.new(%w[two one]).to_url
|
|
140
|
+
assert_equal 'urlList=one|two', AudioStream.new(%w[one two]).to_url
|
|
141
|
+
assert_equal 'urlList=one|two|three', AudioStream.new(%w[one two], 'three').to_url
|
|
142
|
+
assert_equal 'urlList=one|two|three', AudioStream.new(%w[one], 'two', ['three']).to_url
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def test_AudioStream_equals
|
|
147
|
+
one = AudioStream.new('one')
|
|
148
|
+
assert_equal one, AudioStream.new('one')
|
|
149
|
+
assert_equal one, AudioStream.new(%w[one])
|
|
150
|
+
assert_equal one, AudioStream.new(:url_list => %w[one])
|
|
151
|
+
assert_equal one, AudioStream.new(:url_list => 'one')
|
|
152
|
+
assert_not_equal one, AudioStream.new('two')
|
|
153
|
+
|
|
154
|
+
onetwo = AudioStream.new('one', 'two')
|
|
155
|
+
assert_equal onetwo, AudioStream.new('one', 'two')
|
|
156
|
+
assert_equal onetwo, AudioStream.new(['one', 'two'])
|
|
157
|
+
assert_equal onetwo, AudioStream.new('one', %w[two])
|
|
158
|
+
assert_equal onetwo, AudioStream.new(:url_list => ['one', 'two'])
|
|
159
|
+
assert_not_equal onetwo, AudioStream.new('two' 'one')
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def test_AudioStream_add
|
|
164
|
+
one = AudioStream.new('one')
|
|
165
|
+
two = AudioStream.new('two')
|
|
166
|
+
|
|
167
|
+
assert_equal one + two, AudioStream.new('one', 'two')
|
|
168
|
+
assert_equal two + one, AudioStream.new('two', 'one')
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|