libastag 0.0.1
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/CHANGES +7 -0
- data/MIT-LICENSE +19 -0
- data/README +65 -0
- data/Rakefile +276 -0
- data/TODO +7 -0
- data/doc/classes/Helpers/REXML/Attributes.html +179 -0
- data/doc/classes/Helpers/REXML.html +115 -0
- data/doc/classes/Helpers.html +181 -0
- data/doc/classes/Libastag/Rabbit.html +462 -0
- data/doc/classes/Libastag/RabitEar.html +120 -0
- data/doc/classes/Libastag/RabitLed.html +120 -0
- data/doc/classes/Libastag.html +141 -0
- data/doc/classes/Request/Action.html +213 -0
- data/doc/classes/Request/Base/Event.html +226 -0
- data/doc/classes/Request/Base/EventCollection.html +246 -0
- data/doc/classes/Request/Base.html +134 -0
- data/doc/classes/Request/GET_EARS_POSITION.html +151 -0
- data/doc/classes/Request/Query.html +244 -0
- data/doc/classes/Request/SetEarsPosition.html +213 -0
- data/doc/classes/Request/TtsMessage.html +235 -0
- data/doc/classes/Request.html +414 -0
- data/doc/classes/Response/AbuseSending.html +165 -0
- data/doc/classes/Response/Base/BadServerRsp.html +163 -0
- data/doc/classes/Response/Base/GoodServerRsp.html +161 -0
- data/doc/classes/Response/Base/ServerRsp.html +347 -0
- data/doc/classes/Response/Base.html +162 -0
- data/doc/classes/Response/Blacklist.html +165 -0
- data/doc/classes/Response/ChorNotSend.html +166 -0
- data/doc/classes/Response/ChorSend.html +165 -0
- data/doc/classes/Response/CommandSend.html +168 -0
- data/doc/classes/Response/EarPositionNotSend.html +165 -0
- data/doc/classes/Response/EarPositionSend.html +165 -0
- data/doc/classes/Response/EmptyServerRsp.html +161 -0
- data/doc/classes/Response/LangListUser.html +166 -0
- data/doc/classes/Response/LinkPreview.html +165 -0
- data/doc/classes/Response/ListFriend.html +165 -0
- data/doc/classes/Response/ListReceivedMsg.html +165 -0
- data/doc/classes/Response/MessageNotSend.html +165 -0
- data/doc/classes/Response/MessageSend.html +165 -0
- data/doc/classes/Response/NabCastNotSend.html +169 -0
- data/doc/classes/Response/NabCastSend.html +165 -0
- data/doc/classes/Response/NoCorrectParameters.html +165 -0
- data/doc/classes/Response/NoGoodTokenOrSerial.html +165 -0
- data/doc/classes/Response/NotV2Rabbit.html +165 -0
- data/doc/classes/Response/PositionEar.html +166 -0
- data/doc/classes/Response/ProtocolExcepion.html +164 -0
- data/doc/classes/Response/RabbitName.html +164 -0
- data/doc/classes/Response/RabbitSleep.html +164 -0
- data/doc/classes/Response/RabbitVersion.html +164 -0
- data/doc/classes/Response/Signature.html +164 -0
- data/doc/classes/Response/Timezone.html +164 -0
- data/doc/classes/Response/TtsNotSend.html +168 -0
- data/doc/classes/Response/TtsSend.html +165 -0
- data/doc/classes/Response/VoiceListTts.html +165 -0
- data/doc/classes/Response/WebRadioNotSend.html +165 -0
- data/doc/classes/Response/WebRadioSend.html +165 -0
- data/doc/classes/Response.html +337 -0
- data/doc/classes/VioletAPI.html +118 -0
- data/doc/created.rid +1 -0
- data/doc/dot/f_0.dot +14 -0
- data/doc/dot/f_0.png +0 -0
- data/doc/dot/f_4.dot +57 -0
- data/doc/dot/f_4.png +0 -0
- data/doc/dot/f_5.dot +489 -0
- data/doc/dot/f_5.png +0 -0
- data/doc/dot/f_6.dot +55 -0
- data/doc/dot/f_6.png +0 -0
- data/doc/dot/f_7.dot +30 -0
- data/doc/dot/f_7.png +0 -0
- data/doc/dot/f_8.dot +142 -0
- data/doc/dot/f_8.png +0 -0
- data/doc/files/CHANGES.html +126 -0
- data/doc/files/MIT-LICENSE.html +134 -0
- data/doc/files/README.html +192 -0
- data/doc/files/TODO.html +126 -0
- data/doc/files/lib/libastag_rb.html +116 -0
- data/doc/files/lib/violet/helpers_rb.html +123 -0
- data/doc/files/lib/violet/request_rb.html +133 -0
- data/doc/files/lib/violet/response_rb.html +220 -0
- data/doc/files/lib/violet/violetapi_rb.html +114 -0
- data/doc/fr_class_index.html +79 -0
- data/doc/fr_file_index.html +35 -0
- data/doc/fr_method_index.html +56 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/lib/libastag.rb +116 -0
- data/lib/violet/helpers.rb +48 -0
- data/lib/violet/request.rb +301 -0
- data/lib/violet/response.rb +412 -0
- data/lib/violet/violetapi.rb +14 -0
- data/test/fake_violet_srv.rb +94 -0
- data/test/test_helpers.rb +31 -0
- data/test/test_request.rb +20 -0
- data/test/test_response.rb +295 -0
- data/test/test_send.rb +137 -0
- metadata +264 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def from_this_file_path *args
|
|
5
|
+
File.join( File.dirname(__FILE__), *args )
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
require from_this_file_path('..', 'lib', 'violet', 'response.rb')
|
|
10
|
+
|
|
11
|
+
require 'test/unit'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ResponseTest < Test::Unit::TestCase
|
|
16
|
+
|
|
17
|
+
def test_bad_protocol
|
|
18
|
+
assert_raise(Response::ProtocolExcepion) { Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><comment>a comment without messages</comment></rsp>' }
|
|
19
|
+
assert_raise(Response::ProtocolExcepion) { Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><friend name="toto"/><friend name="tata"/></rsp>' }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_invalid_xml
|
|
24
|
+
assert_raise(REXML::ParseException) { Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><open></rsp>' }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_simple_case
|
|
29
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><rabbitSleep>YES</rabbitSleep></rsp>'
|
|
30
|
+
assert_kind_of Response::Base::ServerRsp, rsp
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_get_all
|
|
35
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><rabbitSleep>YES</rabbitSleep></rsp>'
|
|
36
|
+
assert_equal 'YES', rsp.get_all(:rabbitSleep) { |e| e.text }.first
|
|
37
|
+
|
|
38
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><message>LINKPREVIEW</message><comment>a comment</comment></rsp>'
|
|
39
|
+
assert_equal 'LINKPREVIEW', rsp.get_all(:message) { |e| e.text }.first
|
|
40
|
+
assert_equal 'a comment', rsp.get_all(:comment) { |e| e.text }.first
|
|
41
|
+
|
|
42
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><listfriend nb="2"/><friend name="toto"/><friend name="tata"/></rsp>'
|
|
43
|
+
assert_equal({:nb => '2'}, rsp.get_all(:listfriend) { |e| e.attributes.to_hash }.first)
|
|
44
|
+
assert_equal [{:name => 'toto'},{:name => 'tata'}], rsp.get_all(:friend) { |e| e.attributes.to_hash }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_undefined_element
|
|
49
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><rabbitSleep>YES</rabbitSleep></rsp>'
|
|
50
|
+
assert_raise(NameError) { rsp.comment }
|
|
51
|
+
assert_raise(NameError) { rsp.message }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_has_and_has_many
|
|
56
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><message>LINKPREVIEW</message><comment>a comment</comment></rsp>'
|
|
57
|
+
assert rsp.has_message?
|
|
58
|
+
assert !rsp.has_messages?
|
|
59
|
+
assert !rsp.has_many_messages?
|
|
60
|
+
assert rsp.has_comment?
|
|
61
|
+
assert !rsp.has_comments?
|
|
62
|
+
assert !rsp.has_many_comments?
|
|
63
|
+
|
|
64
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><listfriend nb="2"/><friend name="toto"/><friend name="tata"/></rsp>'
|
|
65
|
+
assert rsp.has_listfriend?
|
|
66
|
+
assert !rsp.has_listfriends?
|
|
67
|
+
assert !rsp.has_many_listfriends?
|
|
68
|
+
assert rsp.has_friend?
|
|
69
|
+
assert !rsp.has_friends?
|
|
70
|
+
assert rsp.has_many_friends?
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_accessors_message_and_comment
|
|
75
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><message>NABCASTNOTSEND</message><comment>Your idmessage is private</comment></rsp>'
|
|
76
|
+
assert_equal 'NABCASTNOTSEND', rsp.message
|
|
77
|
+
assert_equal 'Your idmessage is private', rsp.comment
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_accessors_with_hash
|
|
82
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><listfriend nb="3"/><friend name="toto"/><friend name="tata"/><friend name="titi"/></rsp>'
|
|
83
|
+
assert_equal({:nb => '3'}, rsp.listfriend)
|
|
84
|
+
assert_equal({:name => 'toto'}, rsp.friend)
|
|
85
|
+
assert_equal [{:name => 'toto'}, {:name => 'tata'}, {:name => 'titi'}], rsp.friends
|
|
86
|
+
assert_equal rsp.listfriend[:nb], rsp.friends.size.to_s
|
|
87
|
+
|
|
88
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><listreceivedmsg nb="1"/><msg from="toto" title="my message" date="today 11:59" url="broad/001/948.mp3"/></rsp>'
|
|
89
|
+
assert_equal rsp.listreceivedmsg, {:nb => '1'}
|
|
90
|
+
assert_equal({:from => 'toto', :title => 'my message', :date => 'today 11:59', :url => 'broad/001/948.mp3'}, rsp.msg)
|
|
91
|
+
assert_equal rsp.listreceivedmsg[:nb].to_i, rsp.msgs.size
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def test_good
|
|
95
|
+
rsp = Response::Base::GoodServerRsp.new(String.new)
|
|
96
|
+
assert rsp.good?
|
|
97
|
+
assert !rsp.bad?
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def test_bad
|
|
102
|
+
rsp = Response::Base::BadServerRsp.new(String.new)
|
|
103
|
+
assert rsp.bad?
|
|
104
|
+
assert !rsp.good?
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def test_EmptyServerRsp
|
|
109
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp></rsp>'
|
|
110
|
+
rsp2 = Response.parse %{<?xml version="1.0" encoding="UTF-8"?><rsp> \n \n </rsp>}
|
|
111
|
+
|
|
112
|
+
assert_instance_of Response::EmptyServerRsp, rsp
|
|
113
|
+
assert_instance_of Response::EmptyServerRsp, rsp2
|
|
114
|
+
assert !rsp.good?
|
|
115
|
+
assert !rsp.bad?
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def test_LinkPreview
|
|
120
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><message>LINKPREVIEW</message><comment>a comment</comment></rsp>'
|
|
121
|
+
assert_instance_of Response::LinkPreview, rsp
|
|
122
|
+
assert_kind_of Response::Base::GoodServerRsp, rsp
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def test_ListFriend
|
|
126
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><listfriend nb="3"/><friend name="toto"/><friend name="tata"/><friend name="titi"/></rsp>'
|
|
127
|
+
assert_instance_of Response::ListFriend, rsp
|
|
128
|
+
assert_kind_of Response::Base::GoodServerRsp, rsp
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def test_ListReceivedMsg
|
|
132
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><listreceivedmsg nb="1"/><msg from="toto" title="my message" date="today 11:59" url="broad/001/948.mp3"/></rsp>'
|
|
133
|
+
assert_instance_of Response::ListReceivedMsg, rsp
|
|
134
|
+
assert_kind_of Response::Base::GoodServerRsp, rsp
|
|
135
|
+
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def test_Timezone
|
|
139
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><timezone>(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London</timezone></rsp>'
|
|
140
|
+
assert_instance_of Response::Timezone, rsp
|
|
141
|
+
assert_kind_of Response::Base::GoodServerRsp, rsp
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def test_Signature
|
|
145
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><signature>my pretty signature !</signature></rsp> '
|
|
146
|
+
assert_instance_of Response::Signature, rsp
|
|
147
|
+
assert_kind_of Response::Base::GoodServerRsp, rsp
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def test_Blacklist
|
|
151
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><blacklist nb="3"/><pseudo name="bill"/><pseudo name="steve"/><pseudo name="paul"/></rsp>'
|
|
152
|
+
assert_instance_of Response::Blacklist, rsp
|
|
153
|
+
assert_kind_of Response::Base::GoodServerRsp, rsp
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def test_RabbitSleep
|
|
157
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><rabbitSleep>YES</rabbitSleep></rsp>'
|
|
158
|
+
assert_instance_of Response::RabbitSleep, rsp
|
|
159
|
+
assert_kind_of Response::Base::GoodServerRsp, rsp
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def test_RabbitVersion
|
|
163
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><rabbitVersion>V2</rabbitVersion></rsp>'
|
|
164
|
+
assert_instance_of Response::RabbitVersion, rsp
|
|
165
|
+
assert_kind_of Response::Base::GoodServerRsp, rsp
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def test_VoiceListTTS
|
|
169
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><voiceListTTS nb="2"/><voice lang="fr" command="claire22k"/><voice lang="de" command="helga22k"/></rsp>'
|
|
170
|
+
assert_instance_of Response::VoiceListTts, rsp
|
|
171
|
+
assert_kind_of Response::Base::GoodServerRsp, rsp
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def test_RabbitName
|
|
175
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><rabbitName>Theo</rabbitName></rsp>'
|
|
176
|
+
assert_instance_of Response::RabbitName, rsp
|
|
177
|
+
assert_kind_of Response::Base::GoodServerRsp, rsp
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def test_LangListUser
|
|
181
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><langListUser nb="4"/><myLang lang="fr"/><myLang lang="us"/><myLang lang="uk"/><myLang lang="de"/></rsp>'
|
|
182
|
+
assert_instance_of Response::LangListUser, rsp
|
|
183
|
+
assert_kind_of Response::Base::GoodServerRsp, rsp
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def test_CommandSend
|
|
187
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><message>COMMANDSEND</message><comment>You rabbit will change status</comment></rsp>'
|
|
188
|
+
assert_instance_of Response::CommandSend, rsp
|
|
189
|
+
assert_kind_of Response::Base::GoodServerRsp, rsp
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def test_AbuseSending
|
|
193
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><message>ABUSESENDING</message><comment>Too much message sending,try later</comment></rsp>'
|
|
194
|
+
assert_instance_of Response::AbuseSending, rsp
|
|
195
|
+
assert_kind_of Response::Base::BadServerRsp, rsp
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def test_NoGoodTokenOrSerial
|
|
199
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><message>NOGOODTOKENORSERIAL</message><comment>Your token or serial number are not correct !</comment></rsp>'
|
|
200
|
+
assert_instance_of Response::NoGoodTokenOrSerial, rsp
|
|
201
|
+
assert_kind_of Response::Base::BadServerRsp, rsp
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def test_MessageNotSend
|
|
205
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><message>MESSAGENOTSEND</message><comment>Your idmessage is not correct or is private</comment></rsp>'
|
|
206
|
+
assert_instance_of Response::MessageNotSend, rsp
|
|
207
|
+
assert_kind_of Response::Base::BadServerRsp, rsp
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
def test_NabCastNotSend
|
|
211
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><message>NABCASTNOTSEND</message><comment>Your idmessage is private</comment></rsp>'
|
|
212
|
+
assert_instance_of Response::NabCastNotSend, rsp
|
|
213
|
+
assert_kind_of Response::Base::BadServerRsp, rsp
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def test_NabCastSend
|
|
217
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><message>NABCASTSEND</message><comment>Your nabcast has been sent</comment></rsp>'
|
|
218
|
+
assert_instance_of Response::NabCastSend, rsp
|
|
219
|
+
assert_kind_of Response::Base::GoodServerRsp, rsp
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def test_MessageSend
|
|
223
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><message>MESSAGESEND</message><comment>Your message has been sent</comment></rsp>'
|
|
224
|
+
assert_instance_of Response::MessageSend, rsp
|
|
225
|
+
assert_kind_of Response::Base::GoodServerRsp, rsp
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def test_TtsNotSend
|
|
229
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><message>TTSNOTSEND</message><comment>Your text could not be sent</comment></rsp>'
|
|
230
|
+
assert_instance_of Response::TtsNotSend, rsp
|
|
231
|
+
assert_kind_of Response::Base::BadServerRsp, rsp
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def test_TtsSend
|
|
235
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><message>TTSSEND</message><comment>Your text has been sent</comment></rsp>'
|
|
236
|
+
assert_instance_of Response::TtsSend, rsp
|
|
237
|
+
assert_kind_of Response::Base::GoodServerRsp, rsp
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
def test_ChorSend
|
|
241
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><message>CHORSEND</message><comment>Your chor has been sent</comment></rsp>'
|
|
242
|
+
assert_instance_of Response::ChorSend, rsp
|
|
243
|
+
assert_kind_of Response::Base::GoodServerRsp, rsp
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
def test_ChorNotSend
|
|
247
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><message>CHORNOTSEND</message><comment>Your chor could not be sent (bad chor)</comment></rsp>'
|
|
248
|
+
assert_instance_of Response::ChorNotSend, rsp
|
|
249
|
+
assert_kind_of Response::Base::BadServerRsp, rsp
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
def test_EarPositionSend
|
|
253
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><message>EARPOSITIONSEND</message><comment>Your ears command has been sent</comment></rsp>'
|
|
254
|
+
assert_instance_of Response::EarPositionSend, rsp
|
|
255
|
+
assert_kind_of Response::Base::GoodServerRsp, rsp
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
def test_EarPositionNotSend
|
|
259
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><message>EARPOSITIONNOTSEND</message><comment>Your ears command could not be sent</comment></rsp>'
|
|
260
|
+
assert_instance_of Response::EarPositionNotSend, rsp
|
|
261
|
+
assert_kind_of Response::Base::BadServerRsp, rsp
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
def test_PositionEar
|
|
265
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><message>POSITIONEAR</message><leftposition>8</leftposition><rightposition>10</rightposition></rsp>'
|
|
266
|
+
assert_instance_of Response::PositionEar, rsp
|
|
267
|
+
assert_kind_of Response::Base::GoodServerRsp, rsp
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
def test_WebRadioSend
|
|
271
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><message>WEBRADIOSEND</message><comment>Your webradio has been sent</comment></rsp>'
|
|
272
|
+
assert_instance_of Response::WebRadioSend, rsp
|
|
273
|
+
assert_kind_of Response::Base::GoodServerRsp, rsp
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
def test_WebRadioNotSend
|
|
277
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><message>WEBRADIONOTSEND</message><comment>Your webradio could not be sent</comment></rsp>'
|
|
278
|
+
assert_instance_of Response::WebRadioNotSend, rsp
|
|
279
|
+
assert_kind_of Response::Base::BadServerRsp, rsp
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
def test_NoCorrectParameters
|
|
283
|
+
rsp = Response.parse ' <?xml version="1.0" encoding="UTF-8"?><rsp><message>NOCORRECTPARAMETERS</message><comment>Please check urlList parameter !</comment></rsp>'
|
|
284
|
+
assert_instance_of Response::NoCorrectParameters, rsp
|
|
285
|
+
assert_kind_of Response::Base::BadServerRsp, rsp
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
def test_NotV2Rabbit
|
|
289
|
+
rsp = Response.parse '<?xml version="1.0" encoding="UTF-8"?><rsp><message>NOTV2RABBIT</message><comment>V2 rabbit can use this action</comment></rsp>'
|
|
290
|
+
assert_instance_of Response::NotV2Rabbit, rsp
|
|
291
|
+
assert_kind_of Response::Base::BadServerRsp, rsp
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
end
|
|
295
|
+
|
data/test/test_send.rb
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def from_this_file_path *args
|
|
5
|
+
File.join( File.dirname(__FILE__), *args )
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
require from_this_file_path('fake_violet_srv.rb')
|
|
10
|
+
require from_this_file_path('..', 'lib', 'violet', 'request.rb')
|
|
11
|
+
require from_this_file_path('..', 'lib', 'violet', 'response.rb')
|
|
12
|
+
|
|
13
|
+
require 'test/unit'
|
|
14
|
+
require 'open-uri'
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
#
|
|
19
|
+
# Start a fake server for tests
|
|
20
|
+
#
|
|
21
|
+
|
|
22
|
+
t = Thread.new do
|
|
23
|
+
FakeVioletSrv.start 3000, from_this_file_path('testsend_log.tmp')
|
|
24
|
+
end
|
|
25
|
+
sleep 1 # wait for server start.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class ActionTest < Test::Unit::TestCase
|
|
29
|
+
require 'rexml/document'
|
|
30
|
+
|
|
31
|
+
GOOD_SERIAL = '1234567890AB'
|
|
32
|
+
GOOD_TOKEN = '1234567890'
|
|
33
|
+
BAD_SERIAL = '1X34U67890AB'
|
|
34
|
+
BAD_TOKEN = '123456789A'
|
|
35
|
+
|
|
36
|
+
LOCAL_URI = 'http://localhost:3000/api.jsp?'
|
|
37
|
+
|
|
38
|
+
# Hacky ! yes !
|
|
39
|
+
Request::API_URL = LOCAL_URI
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_fake_server_is_up
|
|
43
|
+
assert_nothing_raised do
|
|
44
|
+
open(LOCAL_URI) { }
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_xml_response
|
|
50
|
+
rsp = Request::Query.new(:event => Request::GET_RABBIT_NAME, :serial => GOOD_SERIAL, :token => GOOD_TOKEN).send!(:xml)
|
|
51
|
+
assert_nothing_raised { REXML::Document.new(rsp) }
|
|
52
|
+
assert_match %r{<rsp>.*</rsp>}im, rsp
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_wrong_serial
|
|
57
|
+
rsp = Request::Query.new(:event => Request::GET_RABBIT_NAME, :serial => BAD_SERIAL, :token => GOOD_TOKEN).send!
|
|
58
|
+
assert_instance_of Response::NoGoodTokenOrSerial, rsp
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def test_wrong_token
|
|
63
|
+
rsp = Request::Query.new(:event => Request::GET_RABBIT_NAME, :serial => GOOD_SERIAL, :token => BAD_TOKEN).send!
|
|
64
|
+
assert_instance_of Response::NoGoodTokenOrSerial, rsp
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_GET_LINKPREVIEW
|
|
69
|
+
rsp = Request::Query.new(:event => Request::GET_LINKPREVIEW, :serial => GOOD_SERIAL, :token => GOOD_TOKEN).send!
|
|
70
|
+
assert_instance_of Response::LinkPreview, rsp
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_GET_FRIENDS_LIST
|
|
74
|
+
rsp = Request::Query.new(:event => Request::GET_FRIENDS_LIST, :serial => GOOD_SERIAL, :token => GOOD_TOKEN).send!
|
|
75
|
+
assert_instance_of Response::ListFriend, rsp
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def test_GET_INBOX_LIST
|
|
79
|
+
rsp = Request::Query.new(:event => Request::GET_INBOX_LIST, :serial => GOOD_SERIAL, :token => GOOD_TOKEN).send!
|
|
80
|
+
assert_instance_of Response::ListReceivedMsg, rsp
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def test_GET_TIMEZONE
|
|
84
|
+
rsp = Request::Query.new(:event => Request::GET_TIMEZONE, :serial => GOOD_SERIAL, :token => GOOD_TOKEN).send!
|
|
85
|
+
assert_instance_of Response::Timezone, rsp
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def test_GET_SIGNATURE
|
|
89
|
+
rsp = Request::Query.new(:event => Request::GET_SIGNATURE, :serial => GOOD_SERIAL, :token => GOOD_TOKEN).send!
|
|
90
|
+
assert_instance_of Response::Signature, rsp
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def test_GET_BLACKLISTED
|
|
94
|
+
rsp = Request::Query.new(:event => Request::GET_BLACKLISTED, :serial => GOOD_SERIAL, :token => GOOD_TOKEN).send!
|
|
95
|
+
assert_instance_of Response::Blacklist, rsp
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def test_GET_RABBIT_STATUS
|
|
99
|
+
rsp = Request::Query.new(:event => Request::GET_RABBIT_STATUS, :serial => GOOD_SERIAL, :token => GOOD_TOKEN).send!
|
|
100
|
+
assert_instance_of Response::RabbitSleep, rsp
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def test_GET_LANG_VOICE
|
|
104
|
+
rsp = Request::Query.new(:event => Request::GET_LANG_VOICE, :serial => GOOD_SERIAL, :token => GOOD_TOKEN).send!
|
|
105
|
+
assert_instance_of Response::VoiceListTts, rsp
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def test_GET_RABBIT_NAME
|
|
109
|
+
rsp = Request::Query.new(:event => Request::GET_RABBIT_NAME, :serial => GOOD_SERIAL, :token => GOOD_TOKEN).send!
|
|
110
|
+
assert_instance_of Response::RabbitName, rsp
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def test_GET_SELECTED_LANG
|
|
114
|
+
rsp = Request::Query.new(:event => Request::GET_SELECTED_LANG, :serial => GOOD_SERIAL, :token => GOOD_TOKEN).send!
|
|
115
|
+
assert_instance_of Response::LangListUser, rsp
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def test_GET_MESSAGE_PREVIEW
|
|
119
|
+
rsp = Request::Query.new(:event => Request::GET_MESSAGE_PREVIEW, :serial => GOOD_SERIAL, :token => GOOD_TOKEN).send!
|
|
120
|
+
assert_instance_of Response::LinkPreview, rsp
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def test_GET_EARS_POSITION
|
|
124
|
+
rsp = Request::Query.new(:event => Request::GET_EARS_POSITION, :serial => GOOD_SERIAL, :token => GOOD_TOKEN).send!
|
|
125
|
+
assert_instance_of Response::PositionEar, rsp
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def test_SET_RABBIT_ASLEEP
|
|
129
|
+
rsp = Request::Query.new(:event => Request::SET_RABBIT_ASLEEP, :serial => GOOD_SERIAL, :token => GOOD_TOKEN).send!
|
|
130
|
+
assert_instance_of Response::CommandSend, rsp
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def test_SET_RABBIT_AWAKE
|
|
134
|
+
rsp = Request::Query.new(:event => Request::SET_RABBIT_AWAKE, :serial => GOOD_SERIAL, :token => GOOD_TOKEN).send!
|
|
135
|
+
assert_instance_of Response::CommandSend, rsp
|
|
136
|
+
end
|
|
137
|
+
end
|