ruby-mpd 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3405 @@
1
+ #
2
+ # Unit tests for librmpd test server
3
+ #
4
+ # This tests the MPDTestServer class
5
+
6
+ require '../lib/librmpd'
7
+ require '../lib/mpdserver'
8
+ require 'test/unit'
9
+ require 'socket'
10
+
11
+ class MPDServerTester < Test::Unit::TestCase
12
+
13
+ def setup
14
+ begin
15
+ @port = 93932
16
+ @mpd = MPDTestServer.new @port
17
+ @mpd.start
18
+ @sock = TCPSocket.new 'localhost', @port
19
+ rescue Errno::EADDRINUSE
20
+ @port = 94942
21
+ @mpd = MPDTestServer.new @port
22
+ @mpd.start
23
+ @sock = TCPSocket.new 'localhost', @port
24
+ end
25
+ end
26
+
27
+ def teardown
28
+ @mpd.stop
29
+ end
30
+
31
+ def get_response
32
+ msg = ''
33
+ reading = true
34
+ error = nil
35
+ while reading
36
+ line = @sock.gets
37
+ case line
38
+ when "OK\n"
39
+ reading = false;
40
+ when /^ACK/
41
+ error = line
42
+ reading = false;
43
+ else
44
+ msg += line
45
+ end
46
+ end
47
+
48
+ if error.nil?
49
+ return msg
50
+ else
51
+ raise error.gsub( /^ACK \[(\d+)\@(\d+)\] \{(.+)\} (.+)$/, 'MPD Error #\1: \3: \4')
52
+ end
53
+ end
54
+
55
+ def build_hash( reply )
56
+ lines = reply.split "\n"
57
+
58
+ hash = {}
59
+ lines.each do |l|
60
+ key = l.gsub(/^([^:]*): .*/, '\1')
61
+ hash[key.downcase] = l.gsub( key + ': ', '' )
62
+ end
63
+
64
+ return hash
65
+ end
66
+
67
+ def build_songs( reply )
68
+ lines = reply.split "\n"
69
+
70
+ song = nil
71
+ songs = []
72
+ lines.each do |l|
73
+ if l =~ /^file: /
74
+ songs << song unless song == nil
75
+ song = {}
76
+ song['file'] = l.gsub(/^file: /, '')
77
+ else
78
+ key = l.gsub( /^([^:]*): .*/, '\1' )
79
+ song[key] = l.gsub( key + ': ', '' )
80
+ end
81
+ end
82
+
83
+ songs << song
84
+
85
+ return songs
86
+ end
87
+
88
+ def extract_song( lines )
89
+ song = {}
90
+ lines.each do |l|
91
+ key = l.gsub /^([^:]*): .*/, '\1'
92
+ song[key] = l.gsub key + ': ', ''
93
+ end
94
+
95
+ return song
96
+ end
97
+
98
+ def test_connect
99
+ assert_equal "OK MPD 0.11.5\n", @sock.gets
100
+ end
101
+
102
+ def test_add
103
+ @sock.gets
104
+
105
+ # Add w/o args (Adds All Songs)
106
+ @sock.puts 'add'
107
+ assert_equal "OK\n", @sock.gets
108
+
109
+ @sock.puts 'playlist'
110
+ reply = get_response
111
+ songs = reply.split "\n"
112
+ assert_equal 46, songs.length
113
+
114
+ @sock.puts 'clear'
115
+ assert_equal "OK\n", @sock.gets
116
+
117
+ # Add a dir
118
+ @sock.puts 'add Shpongle'
119
+ assert_equal "OK\n", @sock.gets
120
+
121
+ @sock.puts 'playlist'
122
+ reply = get_response
123
+ songs = reply.split "\n"
124
+ assert_equal 27, songs.length
125
+
126
+ @sock.puts 'clear'
127
+ assert_equal "OK\n", @sock.gets
128
+
129
+ @sock.puts 'add Shpongle/Are_You_Shpongled'
130
+ assert_equal "OK\n", @sock.gets
131
+
132
+ @sock.puts 'playlist'
133
+ reply = get_response
134
+ songs = reply.split "\n"
135
+ assert_equal 7, songs.length
136
+
137
+ @sock.puts 'clear'
138
+ assert_equal "OK\n", @sock.gets
139
+
140
+ # Add a song
141
+ @sock.puts 'add Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg'
142
+ assert_equal "OK\n", @sock.gets
143
+
144
+ @sock.puts 'playlist'
145
+ reply = get_response
146
+ songs = reply.split "\n"
147
+ assert_equal 1, songs.length
148
+ assert_equal '0:Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg', songs[0]
149
+
150
+ # Add a non existant item
151
+ @sock.puts 'add ABOMINATION'
152
+ assert_equal "ACK [50@0] {add} directory or file not found\n", @sock.gets
153
+ end
154
+
155
+ def test_clear
156
+ @sock.gets
157
+
158
+ @sock.puts 'add'
159
+ assert_equal "OK\n", @sock.gets
160
+
161
+ @sock.puts 'playlist'
162
+ reply = get_response
163
+ songs = reply.split "\n"
164
+ assert_equal 46, songs.length
165
+
166
+ @sock.puts 'clear'
167
+ assert_equal "OK\n", @sock.gets
168
+
169
+ @sock.puts 'playlist'
170
+ assert_equal "OK\n", @sock.gets
171
+
172
+ # Test improper args
173
+ @sock.puts 'clear blah'
174
+ assert_equal "ACK [2@0] {clear} wrong number of arguments for \"clear\"\n", @sock.gets
175
+ end
176
+
177
+ def test_clearerror
178
+ @sock.gets
179
+
180
+ @sock.puts 'clearerror 1'
181
+ assert_equal "ACK [2@0] {clearerror} wrong number of arguments for \"clearerror\"\n", @sock.gets
182
+
183
+ @sock.puts 'clearerror'
184
+ assert_equal "OK\n", @sock.gets
185
+ end
186
+
187
+ def test_close
188
+ @sock.gets
189
+
190
+ # Test improper args
191
+ @sock.puts 'close blah'
192
+ assert_raises(Errno::EPIPE) { @sock.puts 'data' }
193
+
194
+ @sock = TCPSocket.new 'localhost', @port
195
+ @sock.puts 'close'
196
+ assert_raises(Errno::EPIPE) { @sock.puts 'data' }
197
+
198
+ end
199
+
200
+ def test_crossfade
201
+ @sock.gets
202
+
203
+ # Test no args
204
+ @sock.puts 'crossfade'
205
+ assert_equal "ACK [2@0] {crossfade} wrong number of arguments for \"crossfade\"\n", @sock.gets
206
+
207
+ # Test not a number arg
208
+ @sock.puts 'crossfade a'
209
+ assert_equal "ACK [2@0] {crossfade} \"a\" is not a integer >= 0\n", @sock.gets
210
+
211
+ # Test arg < 0
212
+ @sock.puts 'crossfade -1'
213
+ assert_equal "ACK [2@0] {crossfade} \"-1\" is not a integer >= 0\n", @sock.gets
214
+
215
+ # Test correct arg
216
+ @sock.puts 'crossfade 10'
217
+ assert_equal "OK\n", @sock.gets
218
+
219
+ @sock.puts 'status'
220
+ hash = build_hash(get_response)
221
+ assert_equal '10', hash['xfade']
222
+
223
+ @sock.puts 'crossfade 49'
224
+ assert_equal "OK\n", @sock.gets
225
+
226
+ @sock.puts 'status'
227
+ hash = build_hash(get_response)
228
+ assert_equal '49', hash['xfade']
229
+ end
230
+
231
+ def test_currentsong
232
+ @sock.gets
233
+
234
+ # Test args > 0
235
+ @sock.puts 'currentsong 1'
236
+ assert_equal "ACK [2@0] {currentsong} wrong number of arguments for \"currentsong\"\n", @sock.gets
237
+
238
+ @sock.puts 'currentsong'
239
+ assert_equal "OK\n", @sock.gets
240
+
241
+ @sock.puts 'load Astral_Projection_-_Dancing_Galaxy'
242
+ assert_equal "OK\n", @sock.gets
243
+
244
+ @sock.puts 'currentsong'
245
+ assert_equal "OK\n", @sock.gets
246
+
247
+ @sock.puts 'play'
248
+ assert_equal "OK\n", @sock.gets
249
+
250
+ sleep 2
251
+
252
+ @sock.puts 'currentsong'
253
+ songs = build_songs get_response
254
+ assert_equal 1, songs.size
255
+ assert_equal '7', songs[0]['Id']
256
+ assert_equal 'Astral_Projection/Dancing_Galaxy/1.Dancing_Galaxy.ogg', songs[0]['file']
257
+
258
+ @sock.puts 'pause'
259
+ assert_equal "OK\n", @sock.gets
260
+
261
+ sleep 2
262
+
263
+ @sock.puts 'currentsong'
264
+ songs = build_songs get_response
265
+ assert_equal 1, songs.size
266
+ assert_equal '7', songs[0]['Id']
267
+ assert_equal 'Astral_Projection/Dancing_Galaxy/1.Dancing_Galaxy.ogg', songs[0]['file']
268
+
269
+ @sock.puts 'stop'
270
+ assert_equal "OK\n", @sock.gets
271
+
272
+ sleep 2
273
+
274
+ @sock.puts 'currentsong'
275
+ songs = build_songs get_response
276
+ assert_equal 1, songs.size
277
+ assert_equal '7', songs[0]['Id']
278
+ assert_equal 'Astral_Projection/Dancing_Galaxy/1.Dancing_Galaxy.ogg', songs[0]['file']
279
+
280
+ @sock.puts 'clear'
281
+ assert_equal "OK\n", @sock.gets
282
+
283
+ @sock.puts 'currentsong'
284
+ assert_equal "OK\n", @sock.gets
285
+ end
286
+
287
+ def test_delete
288
+ @sock.gets
289
+
290
+ @sock.puts 'add Shpongle/Are_You_Shpongled'
291
+ assert_equal "OK\n", @sock.gets
292
+
293
+ @sock.puts 'playlist'
294
+ reply = get_response
295
+ songs = reply.split "\n"
296
+ assert_equal 7, songs.length
297
+ assert_equal '0:Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg', songs[0]
298
+ assert_equal '1:Shpongle/Are_You_Shpongled/2.Monster_Hit.ogg', songs[1]
299
+
300
+ # Test correct arg
301
+ @sock.puts 'delete 0'
302
+ assert_equal "OK\n", @sock.gets
303
+
304
+ @sock.puts 'playlist'
305
+ reply = get_response
306
+ songs = reply.split "\n"
307
+ assert_equal 6, songs.length
308
+ assert_equal '0:Shpongle/Are_You_Shpongled/2.Monster_Hit.ogg', songs[0]
309
+ assert_equal '3:Shpongle/Are_You_Shpongled/5.Behind_Closed_Eyelids.ogg', songs[3]
310
+ assert_equal '4:Shpongle/Are_You_Shpongled/6.Divine_Moments_of_Truth.ogg', songs[4]
311
+
312
+ @sock.puts 'delete 3'
313
+ assert_equal "OK\n", @sock.gets
314
+
315
+ @sock.puts 'playlist'
316
+ reply = get_response
317
+ songs = reply.split "\n"
318
+ assert_equal 5, songs.length
319
+ assert_equal '0:Shpongle/Are_You_Shpongled/2.Monster_Hit.ogg', songs[0]
320
+ assert_equal '2:Shpongle/Are_You_Shpongled/4.Shpongle_Spores.ogg', songs[2]
321
+ assert_equal '3:Shpongle/Are_You_Shpongled/6.Divine_Moments_of_Truth.ogg', songs[3]
322
+ assert_equal '4:Shpongle/Are_You_Shpongled/7...._and_the_Day_Turned_to_Night.ogg', songs[4]
323
+
324
+ # Test arg == length
325
+ @sock.puts 'delete 5'
326
+ assert_equal "ACK [50@0] {delete} song doesn't exist: \"5\"\n", @sock.gets
327
+
328
+ # Test arg > length
329
+ @sock.puts 'delete 900'
330
+ assert_equal "ACK [50@0] {delete} song doesn't exist: \"900\"\n", @sock.gets
331
+
332
+ # Test arg < 0
333
+ @sock.puts 'delete -1'
334
+ assert_equal "ACK [50@0] {delete} song doesn't exist: \"-1\"\n", @sock.gets
335
+
336
+ # Test no args
337
+ @sock.puts 'delete'
338
+ assert_equal "ACK [2@0] {delete} wrong number of arguments for \"delete\"\n", @sock.gets
339
+ end
340
+
341
+ def test_deleteid
342
+ @sock.gets
343
+
344
+ @sock.puts 'add Shpongle/Are_You_Shpongled'
345
+ assert_equal "OK\n", @sock.gets
346
+
347
+ @sock.puts 'playlist'
348
+ reply = get_response
349
+ songs = reply.split "\n"
350
+ assert_equal 7, songs.length
351
+ assert_equal '0:Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg', songs[0]
352
+ assert_equal '1:Shpongle/Are_You_Shpongled/2.Monster_Hit.ogg', songs[1]
353
+
354
+ # Test correct arg
355
+ @sock.puts 'deleteid 0'
356
+ assert_equal "OK\n", @sock.gets
357
+
358
+ @sock.puts 'playlist'
359
+ reply = get_response
360
+ songs = reply.split "\n"
361
+ assert_equal 6, songs.length
362
+ assert_equal '0:Shpongle/Are_You_Shpongled/2.Monster_Hit.ogg', songs[0]
363
+ assert_equal '1:Shpongle/Are_You_Shpongled/3.Vapour_Rumours.ogg', songs[1]
364
+ assert_equal '2:Shpongle/Are_You_Shpongled/4.Shpongle_Spores.ogg', songs[2]
365
+
366
+ @sock.puts 'deleteid 3'
367
+ assert_equal "OK\n", @sock.gets
368
+
369
+ @sock.puts 'playlist'
370
+ reply = get_response
371
+ songs = reply.split "\n"
372
+ assert_equal 5, songs.length
373
+ assert_equal '0:Shpongle/Are_You_Shpongled/2.Monster_Hit.ogg', songs[0]
374
+ assert_equal '1:Shpongle/Are_You_Shpongled/3.Vapour_Rumours.ogg', songs[1]
375
+ assert_equal '2:Shpongle/Are_You_Shpongled/5.Behind_Closed_Eyelids.ogg', songs[2]
376
+
377
+ # Test arg no present but valid
378
+ @sock.puts 'deleteid 8'
379
+ assert_equal "ACK [50@0] {deleteid} song id doesn't exist: \"8\"\n", @sock.gets
380
+
381
+ # Test arg > length
382
+ @sock.puts 'deleteid 900'
383
+ assert_equal "ACK [50@0] {deleteid} song id doesn't exist: \"900\"\n", @sock.gets
384
+
385
+ # Test arg < 0
386
+ @sock.puts 'deleteid -1'
387
+ assert_equal "ACK [50@0] {deleteid} song id doesn't exist: \"-1\"\n", @sock.gets
388
+
389
+ # Test no args
390
+ @sock.puts 'deleteid'
391
+ assert_equal "ACK [2@0] {deleteid} wrong number of arguments for \"deleteid\"\n", @sock.gets
392
+ end
393
+
394
+ def test_find
395
+ @sock.gets
396
+
397
+ # Test no args
398
+ @sock.puts 'find'
399
+ assert_equal "ACK [2@0] {find} wrong number of arguments for \"find\"\n", @sock.gets
400
+
401
+ # Test one arg
402
+ @sock.puts 'find album'
403
+ assert_equal "ACK [2@0] {find} wrong number of arguments for \"find\"\n", @sock.gets
404
+
405
+ # Test incorrect args
406
+ @sock.puts 'find wrong test'
407
+ assert_equal "ACK [2@0] {find} incorrect arguments\n", @sock.gets
408
+
409
+ # Test album search
410
+ @sock.puts 'find album "Are You Shpongled?"'
411
+ songs = build_songs(get_response)
412
+ assert_equal 7, songs.length
413
+ assert_equal 'Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg', songs[0]['file']
414
+ assert_equal 'Shpongle/Are_You_Shpongled/2.Monster_Hit.ogg', songs[1]['file']
415
+ assert_equal 'Shpongle/Are_You_Shpongled/3.Vapour_Rumours.ogg', songs[2]['file']
416
+ assert_equal 'Shpongle/Are_You_Shpongled/4.Shpongle_Spores.ogg', songs[3]['file']
417
+ assert_equal 'Shpongle/Are_You_Shpongled/5.Behind_Closed_Eyelids.ogg', songs[4]['file']
418
+ assert_equal 'Shpongle/Are_You_Shpongled/6.Divine_Moments_of_Truth.ogg', songs[5]['file']
419
+ assert_equal 'Shpongle/Are_You_Shpongled/7...._and_the_Day_Turned_to_Night.ogg', songs[6]['file']
420
+
421
+ songs.each_with_index do |s,i|
422
+ assert_equal 'Shpongle', s['Artist']
423
+ assert_equal 'Are You Shpongled?', s['Album']
424
+ assert_equal (i+1).to_s, s['Track']
425
+ assert_not_nil s['Time']
426
+ end
427
+
428
+ # Test artist search
429
+ @sock.puts 'find artist "Carbon Based Lifeforms"'
430
+ songs = build_songs(get_response)
431
+ assert_equal 11, songs.length
432
+ assert_equal 'Carbon_Based_Lifeforms/Hydroponic_Garden/01.Central_Plains.ogg', songs[0]['file']
433
+ assert_equal 'Carbon_Based_Lifeforms/Hydroponic_Garden/02.Tensor.ogg', songs[1]['file']
434
+ assert_equal 'Carbon_Based_Lifeforms/Hydroponic_Garden/03.MOS_6581_(Album_Version).ogg', songs[2]['file']
435
+ assert_equal 'Carbon_Based_Lifeforms/Hydroponic_Garden/04.Silent_Running.ogg', songs[3]['file']
436
+ assert_equal 'Carbon_Based_Lifeforms/Hydroponic_Garden/05.Neurotransmitter.ogg', songs[4]['file']
437
+ assert_equal 'Carbon_Based_Lifeforms/Hydroponic_Garden/06.Hydroponic_Garden.ogg', songs[5]['file']
438
+ assert_equal 'Carbon_Based_Lifeforms/Hydroponic_Garden/07.Exosphere.ogg', songs[6]['file']
439
+ assert_equal 'Carbon_Based_Lifeforms/Hydroponic_Garden/08.Comsat.ogg', songs[7]['file']
440
+ assert_equal 'Carbon_Based_Lifeforms/Hydroponic_Garden/09.Epicentre_(First_Movement).ogg', songs[8]['file']
441
+ assert_equal 'Carbon_Based_Lifeforms/Hydroponic_Garden/10.Artificial_Island.ogg', songs[9]['file']
442
+ assert_equal 'Carbon_Based_Lifeforms/Hydroponic_Garden/11.Refraction_1.33.ogg', songs[10]['file']
443
+
444
+ songs.each_with_index do |s,i|
445
+ assert_equal 'Carbon Based Lifeforms', s['Artist']
446
+ assert_equal 'Hydroponic Garden', s['Album']
447
+ assert_equal (i+1).to_s, s['Track']
448
+ assert_not_nil s['Time']
449
+ end
450
+
451
+ # Test title search
452
+ @sock.puts 'find title "Ambient Galaxy (Disco Valley Mix)"'
453
+ songs = build_songs(get_response)
454
+ assert_equal 1, songs.length
455
+ assert_equal 'Astral_Projection/Dancing_Galaxy/8.Ambient_Galaxy_(Disco_Valley_Mix).ogg', songs[0]['file']
456
+ assert_equal 'Astral Projection', songs[0]['Artist']
457
+ assert_equal 'Dancing Galaxy', songs[0]['Album']
458
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', songs[0]['Title']
459
+ assert_equal '8', songs[0]['Track']
460
+ assert_equal '825', songs[0]['Time']
461
+
462
+ end
463
+
464
+ def test_kill
465
+ @sock.gets
466
+
467
+ @sock.puts 'kill'
468
+ assert_raises(Errno::EPIPE) { @sock.puts 'data' }
469
+ end
470
+
471
+ def test_list
472
+ @sock.gets
473
+
474
+ # Test no args
475
+ @sock.puts 'list'
476
+ assert_equal "ACK [2@0] {list} wrong number of arguments for \"list\"\n", @sock.gets
477
+
478
+ # Test wrong args
479
+ @sock.puts 'list bad'
480
+ assert_equal "ACK [2@0] {list} \"bad\" is not known\n", @sock.gets
481
+
482
+ # Test wrong args
483
+ @sock.puts 'list bad blah'
484
+ assert_equal "ACK [2@0] {list} \"bad\" is not known\n", @sock.gets
485
+
486
+ # Test wrong args
487
+ @sock.puts 'list artist blah'
488
+ assert_equal "ACK [2@0] {list} should be \"Album\" for 3 arguments\n", @sock.gets
489
+
490
+ # Test album
491
+ @sock.puts 'list album'
492
+ reply = get_response
493
+ albums = reply.split "\n"
494
+ assert_equal 4, albums.length
495
+ assert_equal 'Album: Are You Shpongled?', albums[0]
496
+ assert_equal 'Album: Dancing Galaxy', albums[1]
497
+ assert_equal 'Album: Hydroponic Garden', albums[2]
498
+ assert_equal 'Album: Nothing Lasts... But Nothing Is Lost', albums[3]
499
+
500
+ # Test album + artist
501
+ @sock.puts 'list album Shpongle'
502
+ reply = get_response
503
+ albums = reply.split "\n"
504
+ assert_equal 2, albums.length
505
+ assert_equal 'Album: Are You Shpongled?', albums[0]
506
+ assert_equal 'Album: Nothing Lasts... But Nothing Is Lost', albums[1]
507
+
508
+ # Test album + non artist
509
+ @sock.puts 'list album zero'
510
+ assert_equal "OK\n", @sock.gets
511
+
512
+ # Test artist
513
+ @sock.puts 'list artist'
514
+ reply = get_response
515
+ artists = reply.split "\n"
516
+ assert_equal 3, artists.length
517
+ assert_equal 'Artist: Astral Projection', artists[0]
518
+ assert_equal 'Artist: Carbon Based Lifeforms', artists[1]
519
+ assert_equal 'Artist: Shpongle', artists[2]
520
+
521
+ # Test title
522
+ @sock.puts 'list title'
523
+ reply = get_response
524
+ titles = reply.split "\n"
525
+ assert_equal 46, titles.length
526
+ assert_equal 'Title: ... and the Day Turned to Night', titles[0]
527
+ assert_equal 'Title: ...But Nothing Is Lost', titles[1]
528
+ assert_equal 'Title: When Shall I Be Free', titles[45]
529
+
530
+ end
531
+
532
+ def test_listall
533
+ @sock.gets
534
+
535
+ # Test too many args
536
+ @sock.puts 'listall blah blah'
537
+ assert_equal "ACK [2@0] {listall} wrong number of arguments for \"listall\"\n", @sock.gets
538
+
539
+ # Test no args
540
+ @sock.puts 'listall'
541
+ reply = get_response
542
+ lines = reply.split "\n"
543
+ assert_equal 53, lines.length
544
+ assert_equal 'directory: Astral_Projection', lines[0]
545
+ assert_equal 'directory: Astral_Projection/Dancing_Galaxy', lines[1]
546
+ assert_equal 'file: Astral_Projection/Dancing_Galaxy/1.Dancing_Galaxy.ogg', lines[2]
547
+ for i in 3...10
548
+ assert lines[i] =~ /^file: Astral_Projection\/Dancing_Galaxy\//
549
+ end
550
+
551
+ assert_equal 'directory: Carbon_Based_Lifeforms', lines[10]
552
+ assert_equal 'directory: Carbon_Based_Lifeforms/Hydroponic_Garden', lines[11]
553
+ assert_equal 'file: Carbon_Based_Lifeforms/Hydroponic_Garden/01.Central_Plains.ogg', lines[12]
554
+ for i in 13...23
555
+ assert lines[i] =~ /^file: Carbon_Based_Lifeforms\/Hydroponic_Garden\//
556
+ end
557
+
558
+ assert_equal 'directory: Shpongle', lines[23]
559
+ assert_equal 'directory: Shpongle/Are_You_Shpongled', lines[24]
560
+ assert_equal 'file: Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg', lines[25]
561
+ for i in 26...32
562
+ assert lines[i] =~ /^file: Shpongle\/Are_You_Shpongled\//
563
+ end
564
+
565
+ assert_equal 'directory: Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost', lines[32]
566
+ assert_equal 'file: Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/01.Botanical_Dimensions.ogg', lines[33]
567
+ for i in 34...53
568
+ assert lines[i] =~ /^file: Shpongle\/Nothing_Lasts..._But_Nothing_Is_Lost\//
569
+ end
570
+
571
+ # Test one arg
572
+ @sock.puts 'listall Carbon_Based_Lifeforms'
573
+ reply = get_response
574
+ lines = reply.split "\n"
575
+ assert_equal 13, lines.length
576
+ assert_equal 'directory: Carbon_Based_Lifeforms', lines[0]
577
+ assert_equal 'directory: Carbon_Based_Lifeforms/Hydroponic_Garden', lines[1]
578
+ assert_equal 'file: Carbon_Based_Lifeforms/Hydroponic_Garden/01.Central_Plains.ogg', lines[2]
579
+ for i in 2...13
580
+ assert lines[i] =~ /^file: Carbon_Based_Lifeforms\/Hydroponic_Garden\//
581
+ end
582
+
583
+ @sock.puts 'listall Shpongle/Are_You_Shpongled'
584
+ reply = get_response
585
+ lines = reply.split "\n"
586
+ assert_equal 8, lines.length
587
+ assert_equal 'directory: Shpongle/Are_You_Shpongled', lines[0]
588
+ assert_equal 'file: Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg', lines[1]
589
+ for i in 2...8
590
+ assert lines[i] =~ /^file: Shpongle\/Are_You_Shpongled\//
591
+ end
592
+
593
+ @sock.puts 'listall nothere'
594
+ assert_equal "ACK [50@0] {listall} directory or file not found\n", @sock.gets
595
+
596
+ @sock.puts 'listall Shpongle/nothere'
597
+ assert_equal "ACK [50@0] {listall} directory or file not found\n", @sock.gets
598
+
599
+ end
600
+
601
+ def test_listallinfo
602
+ @sock.gets
603
+
604
+ # Test too many args
605
+ @sock.puts 'listallinfo blah blah'
606
+ assert_equal "ACK [2@0] {listallinfo} wrong number of arguments for \"listallinfo\"\n", @sock.gets
607
+
608
+ # Test no args
609
+ @sock.puts 'listallinfo'
610
+ reply = get_response
611
+ lines = reply.split "\n"
612
+ assert_equal 329, lines.length
613
+ assert_equal 'directory: Astral_Projection', lines[0]
614
+ assert_equal 'directory: Astral_Projection/Dancing_Galaxy', lines[1]
615
+ assert_equal 'file: Astral_Projection/Dancing_Galaxy/1.Dancing_Galaxy.ogg', lines[2]
616
+ song = extract_song lines[3..8]
617
+ assert_equal 'Astral Projection', song['Artist']
618
+ assert_equal 'Dancing Galaxy', song['Album']
619
+ assert_equal 'Dancing Galaxy', song['Title']
620
+ assert_equal '558', song['Time']
621
+ assert_equal '1', song['Track']
622
+ assert_equal '7', song['Id']
623
+
624
+ song_num = 1
625
+ while song_num < 8
626
+ index = (song_num * 7) + 2
627
+ song = extract_song lines[index..(index+6)]
628
+ assert_equal 'Astral Projection', song['Artist']
629
+ assert_equal 'Dancing Galaxy', song['Album']
630
+ assert_equal (song_num+1).to_s, song['Track']
631
+ assert_equal (song_num+7).to_s, song['Id']
632
+ assert_not_nil song['Time']
633
+ assert_not_nil song['Title']
634
+ assert_not_nil song['file']
635
+ song_num += 1
636
+ end
637
+
638
+ assert_equal 'directory: Carbon_Based_Lifeforms', lines[58]
639
+ assert_equal 'directory: Carbon_Based_Lifeforms/Hydroponic_Garden', lines[59]
640
+ assert_equal 'file: Carbon_Based_Lifeforms/Hydroponic_Garden/01.Central_Plains.ogg', lines[60]
641
+
642
+ song = extract_song lines[61..66]
643
+ assert_equal 'Carbon Based Lifeforms', song['Artist']
644
+ assert_equal 'Hydroponic Garden', song['Album']
645
+ assert_equal 'Central Plains', song['Title']
646
+ assert_equal '1', song['Track']
647
+ assert_equal '15', song['Id']
648
+
649
+ song_num = 1
650
+ while song_num < 11
651
+ index = (song_num * 7) + 60
652
+ song = extract_song lines[index..(index+6)]
653
+ assert_equal 'Carbon Based Lifeforms', song['Artist']
654
+ assert_equal 'Hydroponic Garden', song['Album']
655
+ assert_equal (song_num+1).to_s, song['Track']
656
+ assert_equal (song_num+15).to_s, song['Id']
657
+ assert_not_nil song['Time']
658
+ assert_not_nil song['Title']
659
+ assert_not_nil song['file']
660
+ song_num += 1
661
+ end
662
+
663
+ assert_equal 'directory: Shpongle', lines[137]
664
+ assert_equal 'directory: Shpongle/Are_You_Shpongled', lines[138]
665
+ assert_equal 'file: Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg', lines[139]
666
+
667
+ song = extract_song lines[140..145]
668
+ assert_equal 'Shpongle', song['Artist']
669
+ assert_equal 'Are You Shpongled?', song['Album']
670
+ assert_equal 'Shpongle Falls', song['Title']
671
+ assert_equal '1', song['Track']
672
+ assert_equal '0', song['Id']
673
+
674
+ song_num = 1
675
+ while song_num < 7
676
+ index = (song_num * 7) + 139
677
+ song = extract_song lines[index..(index+6)]
678
+ assert_equal 'Shpongle', song['Artist']
679
+ assert_equal 'Are You Shpongled?', song['Album']
680
+ assert_equal (song_num+1).to_s, song['Track']
681
+ assert_equal (song_num).to_s, song['Id']
682
+ assert_not_nil song['Time']
683
+ assert_not_nil song['Title']
684
+ assert_not_nil song['file']
685
+ song_num += 1
686
+ end
687
+
688
+ assert_equal 'directory: Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost', lines[188]
689
+ assert_equal 'file: Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/01.Botanical_Dimensions.ogg', lines[189]
690
+
691
+ song = extract_song lines[190..195]
692
+ assert_equal 'Shpongle', song['Artist']
693
+ assert_equal 'Nothing Lasts... But Nothing Is Lost', song['Album']
694
+ assert_equal 'Botanical Dimensions', song['Title']
695
+ assert_equal '1', song['Track']
696
+ assert_equal '26', song['Id']
697
+
698
+ song_num = 1
699
+ while song_num < 20
700
+ index = (song_num * 7) + 189
701
+ song = extract_song lines[index..(index+6)]
702
+ assert_equal 'Shpongle', song['Artist']
703
+ assert_equal 'Nothing Lasts... But Nothing Is Lost', song['Album']
704
+ assert_equal (song_num+1).to_s, song['Track']
705
+ assert_equal (song_num+26).to_s, song['Id']
706
+ assert_not_nil song['Time']
707
+ assert_not_nil song['Title']
708
+ assert_not_nil song['file']
709
+ song_num += 1
710
+ end
711
+
712
+ # Test one arg that doesn't exist
713
+ @sock.puts 'listallinfo noentry'
714
+ assert_equal "ACK [50@0] {listallinfo} directory or file not found\n", @sock.gets
715
+
716
+ # Test one arg that exists
717
+ @sock.puts 'listallinfo Carbon_Based_Lifeforms'
718
+ reply = get_response
719
+ lines = reply.split "\n"
720
+ assert_equal 'directory: Carbon_Based_Lifeforms', lines[0]
721
+ assert_equal 'directory: Carbon_Based_Lifeforms/Hydroponic_Garden', lines[1]
722
+ lines.shift
723
+ lines.shift
724
+ reply = lines.join "\n"
725
+ songs = build_songs reply
726
+
727
+ songs.each_with_index do |s,i|
728
+ assert_equal 'Carbon Based Lifeforms', s['Artist']
729
+ assert_equal 'Hydroponic Garden', s['Album']
730
+ assert_equal (i+1).to_s, s['Track']
731
+ assert_equal (i+15).to_s, s['Id']
732
+ assert_not_nil s['Time']
733
+ assert_nil s['directory']
734
+ end
735
+ end
736
+
737
+ def test_load
738
+ @sock.gets
739
+
740
+ # Test no args
741
+ @sock.puts 'load'
742
+ assert_equal "ACK [2@0] {load} wrong number of arguments for \"load\"\n", @sock.gets
743
+
744
+ # Test args > 1
745
+ @sock.puts 'load blah blah'
746
+ assert_equal "ACK [2@0] {load} wrong number of arguments for \"load\"\n", @sock.gets
747
+
748
+ @sock.puts 'clear'
749
+ assert_equal "OK\n", @sock.gets
750
+
751
+ # Test arg doesn't exist
752
+ @sock.puts 'load nopls'
753
+ assert_equal "ACK [50@0] {load} playlist \"nopls\" not found\n", @sock.gets
754
+
755
+ @sock.puts 'status'
756
+ status = build_hash get_response
757
+ assert_equal '0', status['playlistlength']
758
+
759
+ # Test arg that exists but contains m3u
760
+ @sock.puts 'load Astral_Projection_-_Dancing_Galaxy.m3u'
761
+ assert_equal "ACK [50@0] {load} playlist \"Astral_Projection_-_Dancing_Galaxy.m3u\" not found\n", @sock.gets
762
+
763
+ @sock.puts 'status'
764
+ status = build_hash get_response
765
+ assert_equal '0', status['playlistlength']
766
+
767
+ # Test correct arg
768
+ @sock.puts 'load Astral_Projection_-_Dancing_Galaxy'
769
+ assert_equal "OK\n", @sock.gets
770
+
771
+ @sock.puts 'status'
772
+ status = build_hash get_response
773
+ assert_equal '8', status['playlistlength']
774
+
775
+ @sock.puts 'playlist'
776
+ reply = get_response
777
+ lines = reply.split "\n"
778
+ assert_equal 8, lines.length
779
+ assert_equal '0:Astral_Projection/Dancing_Galaxy/1.Dancing_Galaxy.ogg', lines[0]
780
+ assert_equal '1:Astral_Projection/Dancing_Galaxy/2.Soundform.ogg', lines[1]
781
+ assert_equal '2:Astral_Projection/Dancing_Galaxy/3.Flying_Into_A_Star.ogg', lines[2]
782
+ assert_equal '3:Astral_Projection/Dancing_Galaxy/4.No_One_Ever_Dreams.ogg', lines[3]
783
+ assert_equal '4:Astral_Projection/Dancing_Galaxy/5.Cosmic_Ascension_(ft._DJ_Jorg).ogg', lines[4]
784
+ assert_equal '5:Astral_Projection/Dancing_Galaxy/6.Life_On_Mars.ogg', lines[5]
785
+ assert_equal '6:Astral_Projection/Dancing_Galaxy/7.Liquid_Sun.ogg', lines[6]
786
+ assert_equal '7:Astral_Projection/Dancing_Galaxy/8.Ambient_Galaxy_(Disco_Valley_Mix).ogg', lines[7]
787
+ end
788
+
789
+ def test_lsinfo
790
+ @sock.gets
791
+
792
+ # Test args > 1
793
+ @sock.puts 'lsinfo 1 2'
794
+ assert_equal "ACK [2@0] {lsinfo} wrong number of arguments for \"lsinfo\"\n", @sock.gets
795
+
796
+ # Test arg not exist
797
+ @sock.puts 'lsinfo abomination'
798
+ assert_equal "ACK [50@0] {lsinfo} directory not found\n", @sock.gets
799
+
800
+ @sock.puts 'lsinfo Shpongle/a'
801
+ assert_equal "ACK [50@0] {lsinfo} directory not found\n", @sock.gets
802
+
803
+ # Test no args
804
+ @sock.puts 'lsinfo'
805
+ reply = get_response
806
+ lines = reply.split "\n"
807
+ assert_equal 5, lines.length
808
+ assert_equal 'directory: Astral_Projection', lines[0]
809
+ assert_equal 'directory: Carbon_Based_Lifeforms', lines[1]
810
+ assert_equal 'directory: Shpongle', lines[2]
811
+ assert_equal 'playlist: Shpongle_-_Are_You_Shpongled', lines[3]
812
+ assert_equal 'playlist: Astral_Projection_-_Dancing_Galaxy', lines[4]
813
+
814
+ # Test arg
815
+ @sock.puts 'lsinfo Shpongle'
816
+ reply = get_response
817
+ lines = reply.split "\n"
818
+ assert_equal 2, lines.length
819
+ assert_equal 'directory: Shpongle/Are_You_Shpongled', lines[0]
820
+ assert_equal 'directory: Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost', lines[1]
821
+
822
+ @sock.puts 'lsinfo Astral_Projection/Dancing_Galaxy'
823
+ songs = build_songs get_response
824
+ assert_equal 8, songs.length
825
+ songs.each_with_index do |s,i|
826
+ assert s['file'] =~ /^Astral_Projection\/Dancing_Galaxy\//
827
+ assert_equal 'Astral Projection', s['Artist']
828
+ assert_equal 'Dancing Galaxy', s['Album']
829
+ assert_not_nil s['Title']
830
+ assert_not_nil s['Time']
831
+ assert_equal (i+1).to_s, s['Track']
832
+ assert_equal (i+7).to_s, s['Id']
833
+ end
834
+ end
835
+
836
+ def test_move
837
+ @sock.gets
838
+
839
+ # Test args == 0
840
+ @sock.puts 'move'
841
+ assert_equal "ACK [2@0] {move} wrong number of arguments for \"move\"\n", @sock.gets
842
+
843
+ # Test args > 2
844
+ @sock.puts 'move 1 2 3'
845
+ assert_equal "ACK [2@0] {move} wrong number of arguments for \"move\"\n", @sock.gets
846
+
847
+ # Test args not integers
848
+ @sock.puts 'move a b'
849
+ assert_equal "ACK [2@0] {move} \"a\" is not a integer\n", @sock.gets
850
+
851
+ @sock.puts 'move 1 b'
852
+ assert_equal "ACK [2@0] {move} \"b\" is not a integer\n", @sock.gets
853
+
854
+ # Test arg doesn't exist
855
+ @sock.puts 'move 1 2'
856
+ assert_equal "ACK [50@0] {move} song doesn't exist: \"1\"\n", @sock.gets
857
+
858
+ @sock.puts 'load Shpongle_-_Are_You_Shpongled'
859
+ assert_equal "OK\n", @sock.gets
860
+
861
+ @sock.puts 'move 1 99'
862
+ assert_equal "ACK [50@0] {move} song doesn't exist: \"99\"\n", @sock.gets
863
+
864
+ @sock.puts 'playlist'
865
+ reply = get_response
866
+ lines = reply.split "\n"
867
+ assert_equal 7, lines.size
868
+ lines.each_with_index do |l,i|
869
+ assert /^#{i}:Shpongle\/Are_You_Shpongled\/#{i+1}/ =~ l
870
+ end
871
+
872
+ @sock.puts 'move 1 7'
873
+ assert_equal "ACK [50@0] {move} song doesn't exist: \"7\"\n", @sock.gets
874
+
875
+ @sock.puts 'move 2 -3'
876
+ assert_equal "ACK [50@0] {move} song doesn't exist: \"-3\"\n", @sock.gets
877
+
878
+ @sock.puts 'playlist'
879
+ reply = get_response
880
+ lines = reply.split "\n"
881
+ assert_equal 7, lines.size
882
+ lines.each_with_index do |l,i|
883
+ assert /^#{i}:Shpongle\/Are_You_Shpongled\/#{i+1}/ =~ l
884
+ end
885
+
886
+ # Test correct usage
887
+ @sock.puts 'move 0 0'
888
+ assert_equal "OK\n", @sock.gets
889
+
890
+ @sock.puts 'playlist'
891
+ reply = get_response
892
+ lines = reply.split "\n"
893
+ assert_equal 7, lines.size
894
+ lines.each_with_index do |l,i|
895
+ assert /^#{i}:Shpongle\/Are_You_Shpongled\/#{i+1}/ =~ l
896
+ end
897
+
898
+ @sock.puts 'move 0 1'
899
+ assert_equal "OK\n", @sock.gets
900
+
901
+ @sock.puts 'playlist'
902
+ reply = get_response
903
+ lines = reply.split "\n"
904
+ assert_equal 7, lines.size
905
+ assert_equal '0:Shpongle/Are_You_Shpongled/2.Monster_Hit.ogg', lines[0]
906
+ assert_equal '1:Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg', lines[1]
907
+ assert_equal '2:Shpongle/Are_You_Shpongled/3.Vapour_Rumours.ogg', lines[2]
908
+
909
+ @sock.puts 'clear'
910
+ assert_equal "OK\n", @sock.gets
911
+
912
+ @sock.puts 'load Shpongle_-_Are_You_Shpongled'
913
+ assert_equal "OK\n", @sock.gets
914
+
915
+ @sock.puts 'move 0 6'
916
+ assert_equal "OK\n", @sock.gets
917
+
918
+ @sock.puts 'playlist'
919
+ reply = get_response
920
+ lines = reply.split "\n"
921
+ assert_equal 7, lines.size
922
+ assert_equal '0:Shpongle/Are_You_Shpongled/2.Monster_Hit.ogg', lines[0]
923
+ assert_equal '5:Shpongle/Are_You_Shpongled/7...._and_the_Day_Turned_to_Night.ogg', lines[5]
924
+ assert_equal '6:Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg', lines[6]
925
+
926
+ @sock.puts 'clear'
927
+ assert_equal "OK\n", @sock.gets
928
+
929
+ @sock.puts 'load Shpongle_-_Are_You_Shpongled'
930
+ assert_equal "OK\n", @sock.gets
931
+
932
+ @sock.puts 'move 5 2'
933
+ assert_equal "OK\n", @sock.gets
934
+
935
+ @sock.puts 'playlist'
936
+ reply = get_response
937
+ lines = reply.split "\n"
938
+ assert_equal 7, lines.size
939
+ assert_equal '1:Shpongle/Are_You_Shpongled/2.Monster_Hit.ogg', lines[1]
940
+ assert_equal '2:Shpongle/Are_You_Shpongled/6.Divine_Moments_of_Truth.ogg', lines[2]
941
+ assert_equal '3:Shpongle/Are_You_Shpongled/3.Vapour_Rumours.ogg', lines[3]
942
+ assert_equal '4:Shpongle/Are_You_Shpongled/4.Shpongle_Spores.ogg', lines[4]
943
+ assert_equal '5:Shpongle/Are_You_Shpongled/5.Behind_Closed_Eyelids.ogg', lines[5]
944
+ assert_equal '6:Shpongle/Are_You_Shpongled/7...._and_the_Day_Turned_to_Night.ogg', lines[6]
945
+ end
946
+
947
+ def test_moveid
948
+ @sock.gets
949
+
950
+ # Test args = 0
951
+ @sock.puts 'moveid'
952
+ assert_equal "ACK [2@0] {moveid} wrong number of arguments for \"moveid\"\n", @sock.gets
953
+
954
+ # Test args > 2
955
+ @sock.puts 'moveid 1 2 3'
956
+ assert_equal "ACK [2@0] {moveid} wrong number of arguments for \"moveid\"\n", @sock.gets
957
+
958
+ # Test args not ints
959
+ @sock.puts 'moveid a 2'
960
+ assert_equal "ACK [2@0] {moveid} \"a\" is not a integer\n", @sock.gets
961
+
962
+ @sock.puts 'moveid 1 b'
963
+ assert_equal "ACK [2@0] {moveid} \"b\" is not a integer\n", @sock.gets
964
+
965
+ # Load some songs
966
+ @sock.puts 'load Astral_Projection_-_Dancing_Galaxy'
967
+ assert_equal "OK\n", @sock.gets
968
+
969
+ # Test id doesn't exist
970
+ @sock.puts 'moveid 9999 2'
971
+ assert_equal "ACK [50@0] {moveid} song id doesn't exist: \"9999\"\n", @sock.gets
972
+
973
+ # Test 'to' doesn't exist
974
+ @sock.puts 'moveid 8 8'
975
+ assert_equal "ACK [50@0] {moveid} song doesn't exist: \"8\"\n", @sock.gets
976
+
977
+ @sock.puts 'moveid 8 5'
978
+ assert_equal "OK\n", @sock.gets
979
+
980
+ @sock.puts 'playlist'
981
+ reply = get_response
982
+ lines = reply.split "\n"
983
+ assert_equal 8, lines.size
984
+ assert_equal '0:Astral_Projection/Dancing_Galaxy/1.Dancing_Galaxy.ogg', lines[0]
985
+ assert_equal '1:Astral_Projection/Dancing_Galaxy/3.Flying_Into_A_Star.ogg', lines[1]
986
+ assert_equal '4:Astral_Projection/Dancing_Galaxy/6.Life_On_Mars.ogg', lines[4]
987
+ assert_equal '5:Astral_Projection/Dancing_Galaxy/2.Soundform.ogg', lines[5]
988
+ assert_equal '6:Astral_Projection/Dancing_Galaxy/7.Liquid_Sun.ogg', lines[6]
989
+
990
+ @sock.puts 'moveid 12 1'
991
+ assert_equal "OK\n", @sock.gets
992
+
993
+ @sock.puts 'playlist'
994
+ reply = get_response
995
+ lines = reply.split "\n"
996
+ assert_equal 8, lines.size
997
+ assert_equal '0:Astral_Projection/Dancing_Galaxy/1.Dancing_Galaxy.ogg', lines[0]
998
+ assert_equal '1:Astral_Projection/Dancing_Galaxy/6.Life_On_Mars.ogg', lines[1]
999
+ assert_equal '2:Astral_Projection/Dancing_Galaxy/3.Flying_Into_A_Star.ogg', lines[2]
1000
+ assert_equal '3:Astral_Projection/Dancing_Galaxy/4.No_One_Ever_Dreams.ogg', lines[3]
1001
+ assert_equal '4:Astral_Projection/Dancing_Galaxy/5.Cosmic_Ascension_(ft._DJ_Jorg).ogg', lines[4]
1002
+ assert_equal '5:Astral_Projection/Dancing_Galaxy/2.Soundform.ogg', lines[5]
1003
+ assert_equal '6:Astral_Projection/Dancing_Galaxy/7.Liquid_Sun.ogg', lines[6]
1004
+ assert_equal '7:Astral_Projection/Dancing_Galaxy/8.Ambient_Galaxy_(Disco_Valley_Mix).ogg', lines[7]
1005
+ end
1006
+
1007
+ def test_next
1008
+ @sock.gets
1009
+
1010
+ # Test with too many args
1011
+ @sock.puts 'next 1'
1012
+ assert_equal "ACK [2@0] {next} wrong number of arguments for \"next\"\n", @sock.gets
1013
+
1014
+ @sock.puts 'load Astral_Projection_-_Dancing_Galaxy'
1015
+ assert_equal "OK\n", @sock.gets
1016
+
1017
+ # Shouldn't do anything
1018
+ @sock.puts 'next'
1019
+ assert_equal "OK\n", @sock.gets
1020
+
1021
+ @sock.puts 'next'
1022
+ assert_equal "OK\n", @sock.gets
1023
+
1024
+ @sock.puts 'play'
1025
+ assert_equal "OK\n", @sock.gets
1026
+
1027
+ sleep 2
1028
+
1029
+ @sock.puts 'status'
1030
+ status = build_hash get_response
1031
+ assert_equal 12, status.size
1032
+ assert_equal '0', status['song']
1033
+ assert_equal '7', status['songid']
1034
+ assert_equal 'play', status['state']
1035
+
1036
+ @sock.puts 'next'
1037
+ assert_equal "OK\n", @sock.gets
1038
+
1039
+ sleep 2
1040
+
1041
+ @sock.puts 'status'
1042
+ status = build_hash get_response
1043
+ assert_equal 12, status.size
1044
+ assert_equal '1', status['song']
1045
+ assert_equal '8', status['songid']
1046
+ assert_equal 'play', status['state']
1047
+
1048
+ @sock.puts 'pause'
1049
+ assert_equal "OK\n", @sock.gets
1050
+
1051
+ sleep 2
1052
+
1053
+ @sock.puts 'next'
1054
+ assert_equal "OK\n", @sock.gets
1055
+
1056
+ sleep 2
1057
+
1058
+ @sock.puts 'status'
1059
+ status = build_hash get_response
1060
+ assert_equal 12, status.size
1061
+ assert_equal '2', status['song']
1062
+ assert_equal '9', status['songid']
1063
+ assert_equal 'play', status['state']
1064
+
1065
+ @sock.puts 'stop'
1066
+ assert_equal "OK\n", @sock.gets
1067
+
1068
+ sleep 2
1069
+
1070
+ @sock.puts 'next'
1071
+ assert_equal "OK\n", @sock.gets
1072
+
1073
+ sleep 2
1074
+
1075
+ @sock.puts 'status'
1076
+ status = build_hash get_response
1077
+ assert_equal 9, status.size
1078
+ assert_equal '2', status['song']
1079
+ assert_equal '9', status['songid']
1080
+ assert_equal 'stop', status['state']
1081
+
1082
+ @sock.puts 'play'
1083
+ assert_equal "OK\n", @sock.gets
1084
+
1085
+ sleep 2
1086
+
1087
+ @sock.puts 'status'
1088
+ status = build_hash get_response
1089
+ assert_equal 12, status.size
1090
+ assert_equal '2', status['song']
1091
+ assert_equal '9', status['songid']
1092
+ assert_equal 'play', status['state']
1093
+
1094
+ @sock.puts 'play 7'
1095
+ assert_equal "OK\n", @sock.gets
1096
+
1097
+ sleep 2
1098
+
1099
+ @sock.puts 'next'
1100
+ assert_equal "OK\n", @sock.gets
1101
+
1102
+ sleep 2
1103
+
1104
+ @sock.puts 'status'
1105
+ status = build_hash get_response
1106
+ assert_equal 7, status.size
1107
+ assert_equal 'stop', status['state']
1108
+ end
1109
+
1110
+ def test_pause
1111
+ @sock.gets
1112
+
1113
+ @sock.puts 'load Astral_Projection_-_Dancing_Galaxy'
1114
+ assert_equal "OK\n", @sock.gets
1115
+
1116
+ @sock.puts 'play'
1117
+ assert_equal "OK\n", @sock.gets
1118
+
1119
+ sleep 2
1120
+
1121
+ @sock.puts 'status'
1122
+ status = build_hash get_response
1123
+ assert_equal 12, status.size
1124
+ assert_equal 'play', status['state']
1125
+ assert_equal '0', status['song']
1126
+ assert_equal '7', status['songid']
1127
+
1128
+ # Test too many args
1129
+ @sock.puts 'pause 1 2'
1130
+ assert_equal "ACK [2@0] {pause} wrong number of arguments for \"pause\"\n", @sock.gets
1131
+
1132
+ # Test arg NaN
1133
+ @sock.puts 'pause a'
1134
+ assert_equal "ACK [2@0] {pause} \"a\" is not 0 or 1\n", @sock.gets
1135
+
1136
+ # Test int args
1137
+ @sock.puts 'pause 1'
1138
+ assert_equal "OK\n", @sock.gets
1139
+
1140
+ sleep 2
1141
+
1142
+ @sock.puts 'status'
1143
+ status = build_hash get_response
1144
+ assert_equal 12, status.size
1145
+ assert_equal 'pause', status['state']
1146
+ assert_equal '0', status['song']
1147
+ assert_equal '7', status['songid']
1148
+ assert_not_nil status['time']
1149
+ time = status['time']
1150
+
1151
+ sleep 5
1152
+
1153
+ @sock.puts 'status'
1154
+ status = build_hash get_response
1155
+ assert_equal time, status['time']
1156
+
1157
+ @sock.puts 'pause 0'
1158
+ assert_equal "OK\n", @sock.gets
1159
+
1160
+ sleep 2
1161
+
1162
+ @sock.puts 'status'
1163
+ status = build_hash get_response
1164
+ assert_equal 12, status.size
1165
+ assert_equal 'play', status['state']
1166
+ assert_equal '0', status['song']
1167
+ assert_equal '7', status['songid']
1168
+ assert_not_nil status['time']
1169
+ assert_not_equal time, status['time']
1170
+
1171
+ # Test no args
1172
+ @sock.puts 'pause'
1173
+ assert_equal "OK\n", @sock.gets
1174
+
1175
+ sleep 2
1176
+
1177
+ @sock.puts 'status'
1178
+ status = build_hash get_response
1179
+ assert_equal 12, status.size
1180
+ assert_equal 'pause', status['state']
1181
+ assert_equal '0', status['song']
1182
+ assert_equal '7', status['songid']
1183
+ assert_not_nil status['time']
1184
+ time = status['time']
1185
+
1186
+ @sock.puts 'pause'
1187
+ assert_equal "OK\n", @sock.gets
1188
+
1189
+ sleep 2
1190
+
1191
+ @sock.puts 'status'
1192
+ status = build_hash get_response
1193
+ assert_equal 12, status.size
1194
+ assert_equal 'play', status['state']
1195
+ assert_equal '0', status['song']
1196
+ assert_equal '7', status['songid']
1197
+ assert_not_nil status['time']
1198
+ assert_not_equal time, status['time']
1199
+
1200
+ @sock.puts 'stop'
1201
+ assert_equal "OK\n", @sock.gets
1202
+
1203
+ sleep 2
1204
+
1205
+ @sock.puts 'status'
1206
+ status = build_hash get_response
1207
+ assert_equal 9, status.size
1208
+ assert_equal 'stop', status['state']
1209
+
1210
+ @sock.puts 'pause 1'
1211
+ assert_equal "OK\n", @sock.gets
1212
+
1213
+ sleep 2
1214
+
1215
+ @sock.puts 'status'
1216
+ status = build_hash get_response
1217
+ assert_equal 9, status.size
1218
+ assert_equal 'stop', status['state']
1219
+
1220
+ @sock.puts 'pause 0'
1221
+ assert_equal "OK\n", @sock.gets
1222
+
1223
+ sleep 2
1224
+
1225
+ @sock.puts 'status'
1226
+ status = build_hash get_response
1227
+ assert_equal 9, status.size
1228
+ assert_equal 'stop', status['state']
1229
+
1230
+ @sock.puts 'pause'
1231
+ assert_equal "OK\n", @sock.gets
1232
+
1233
+ sleep 2
1234
+
1235
+ @sock.puts 'status'
1236
+ status = build_hash get_response
1237
+ assert_equal 9, status.size
1238
+ assert_equal 'stop', status['state']
1239
+ end
1240
+
1241
+ def test_password
1242
+ @sock.gets
1243
+
1244
+ @sock.puts 'password'
1245
+ assert_equal "ACK [2@0] {password} wrong number of arguments for \"password\"\n", @sock.gets
1246
+
1247
+ @sock.puts 'password test'
1248
+ assert_equal "OK\n", @sock.gets
1249
+
1250
+ @sock.puts 'password wrong'
1251
+ assert_equal "ACK [3@0] {password} incorrect password\n", @sock.gets
1252
+ end
1253
+
1254
+ def test_ping
1255
+ @sock.gets
1256
+
1257
+ # Test ping w/ args
1258
+ @sock.puts 'ping blah'
1259
+ assert_equal "ACK [2@0] {ping} wrong number of arguments for \"ping\"\n", @sock.gets
1260
+
1261
+ # Test ping
1262
+ @sock.puts 'ping'
1263
+ assert_equal "OK\n", @sock.gets
1264
+ end
1265
+
1266
+ def test_play
1267
+ @sock.gets
1268
+
1269
+ # Test play w/ args > 1
1270
+ @sock.puts 'play 1 2'
1271
+ assert_equal "ACK [2@0] {play} wrong number of arguments for \"play\"\n", @sock.gets
1272
+
1273
+ # Test play w/ arg != integer
1274
+ @sock.puts 'play a'
1275
+ assert_equal "ACK [2@0] {play} need a positive integer\n", @sock.gets
1276
+
1277
+ @sock.puts 'load Astral_Projection_-_Dancing_Galaxy'
1278
+ assert_equal "OK\n", @sock.gets
1279
+
1280
+ # Test play w/o args
1281
+ @sock.puts 'play'
1282
+ assert_equal "OK\n", @sock.gets
1283
+
1284
+ # Wait for the thing to start playing
1285
+ sleep 2
1286
+
1287
+ @sock.puts 'status'
1288
+ status = build_hash get_response
1289
+ assert_equal 12, status.length
1290
+ assert_equal '0', status['song']
1291
+ assert_equal '7', status['songid']
1292
+ assert_equal 'play', status['state']
1293
+ assert_not_nil status['time']
1294
+ assert_not_equal '0', status['time']
1295
+ assert_equal '44100:16:2', status['audio']
1296
+ assert_equal '192', status['bitrate']
1297
+
1298
+ @sock.puts 'stop'
1299
+ assert_equal "OK\n", @sock.gets
1300
+
1301
+ # Test play w/ args
1302
+ @sock.puts 'play 2'
1303
+ assert_equal "OK\n", @sock.gets
1304
+
1305
+ sleep 2
1306
+
1307
+ @sock.puts 'status'
1308
+ status = build_hash get_response
1309
+ assert_equal 12, status.length
1310
+ assert_equal '2', status['song']
1311
+ assert_equal '9', status['songid']
1312
+ assert_equal 'play', status['state']
1313
+ assert_not_nil status['time']
1314
+ assert_not_equal '0', status['time']
1315
+ assert_equal '44100:16:2', status['audio']
1316
+ assert_equal '192', status['bitrate']
1317
+
1318
+ sleep 10
1319
+
1320
+ # Check that play doesn't start over if issued during playback
1321
+ @sock.puts 'play'
1322
+ assert_equal "OK\n", @sock.gets
1323
+
1324
+ @sock.puts 'status'
1325
+ status = build_hash get_response
1326
+ assert_equal 12, status.length
1327
+ assert_not_nil status['time']
1328
+ assert status['time'].to_i > 10
1329
+ assert_equal '2', status['song']
1330
+ assert_equal '9', status['songid']
1331
+ assert_equal '44100:16:2', status['audio']
1332
+ assert_equal '192', status['bitrate']
1333
+
1334
+ # Test play w/ arg > length
1335
+ @sock.puts 'play 99'
1336
+ assert_equal "ACK [50@0] {play} song doesn't exist: \"99\"\n", @sock.gets
1337
+ end
1338
+
1339
+ def test_playid
1340
+ @sock.gets
1341
+
1342
+ # Test playid w/ args > 1
1343
+ @sock.puts 'playid 1 2'
1344
+ assert_equal "ACK [2@0] {playid} wrong number of arguments for \"playid\"\n", @sock.gets
1345
+
1346
+ # Test playid w/ arg != integer
1347
+ @sock.puts 'playid a'
1348
+ assert_equal "ACK [2@0] {playid} need a positive integer\n", @sock.gets
1349
+
1350
+ @sock.puts 'load Astral_Projection_-_Dancing_Galaxy'
1351
+ assert_equal "OK\n", @sock.gets
1352
+
1353
+ # Test playid w/o args
1354
+ @sock.puts 'playid'
1355
+ assert_equal "OK\n", @sock.gets
1356
+
1357
+ # Wait for the thing to start playing
1358
+ sleep 2
1359
+
1360
+ @sock.puts 'status'
1361
+ status = build_hash get_response
1362
+ assert_equal 12, status.length
1363
+ assert_equal '0', status['song']
1364
+ assert_equal '7', status['songid']
1365
+ assert_equal 'play', status['state']
1366
+ assert_not_nil status['time']
1367
+ assert_not_equal '0', status['time']
1368
+ assert_equal '44100:16:2', status['audio']
1369
+ assert_equal '192', status['bitrate']
1370
+
1371
+ @sock.puts 'stop'
1372
+ assert_equal "OK\n", @sock.gets
1373
+
1374
+ # Test playid w/ args
1375
+ @sock.puts 'playid 12'
1376
+ assert_equal "OK\n", @sock.gets
1377
+
1378
+ sleep 2
1379
+
1380
+ @sock.puts 'status'
1381
+ status = build_hash get_response
1382
+ assert_equal 12, status.length
1383
+ assert_equal '5', status['song']
1384
+ assert_equal '12', status['songid']
1385
+ assert_equal 'play', status['state']
1386
+ assert_not_nil status['time']
1387
+ assert_not_equal '0', status['time']
1388
+ assert_equal '44100:16:2', status['audio']
1389
+ assert_equal '192', status['bitrate']
1390
+
1391
+ sleep 10
1392
+
1393
+ # Check that play doesn't start over if issued during playback
1394
+ @sock.puts 'playid'
1395
+ assert_equal "OK\n", @sock.gets
1396
+
1397
+ @sock.puts 'status'
1398
+ status = build_hash get_response
1399
+ assert_equal 12, status.length
1400
+ assert_not_nil status['time']
1401
+ assert status['time'].to_i > 10
1402
+ assert_equal '5', status['song']
1403
+ assert_equal '12', status['songid']
1404
+ assert_equal '44100:16:2', status['audio']
1405
+ assert_equal '192', status['bitrate']
1406
+
1407
+ # Test playid w/ arg > length
1408
+ @sock.puts 'playid 99'
1409
+ assert_equal "ACK [50@0] {playid} song id doesn't exist: \"99\"\n", @sock.gets
1410
+ end
1411
+
1412
+ def test_playlist
1413
+ @sock.gets
1414
+
1415
+ # Test with args
1416
+ @sock.puts 'playlist blah'
1417
+ assert_equal "ACK [2@0] {playlist} wrong number of arguments for \"playlist\"\n", @sock.gets
1418
+
1419
+ # Test w/o args
1420
+ @sock.puts 'clear'
1421
+ assert_equal "OK\n", @sock.gets
1422
+
1423
+ @sock.puts 'load Shpongle_-_Are_You_Shpongled'
1424
+ assert_equal "OK\n", @sock.gets
1425
+
1426
+ @sock.puts 'playlist'
1427
+ reply = get_response
1428
+ lines = reply.split "\n"
1429
+ assert_equal 7, lines.length
1430
+ assert_equal '0:Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg', lines[0]
1431
+ assert_equal '1:Shpongle/Are_You_Shpongled/2.Monster_Hit.ogg', lines[1]
1432
+ assert_equal '2:Shpongle/Are_You_Shpongled/3.Vapour_Rumours.ogg', lines[2]
1433
+ assert_equal '3:Shpongle/Are_You_Shpongled/4.Shpongle_Spores.ogg', lines[3]
1434
+ assert_equal '4:Shpongle/Are_You_Shpongled/5.Behind_Closed_Eyelids.ogg', lines[4]
1435
+ assert_equal '5:Shpongle/Are_You_Shpongled/6.Divine_Moments_of_Truth.ogg', lines[5]
1436
+ assert_equal '6:Shpongle/Are_You_Shpongled/7...._and_the_Day_Turned_to_Night.ogg', lines[6]
1437
+ end
1438
+
1439
+ def test_playlistinfo
1440
+ @sock.gets
1441
+
1442
+ # Test with too many args
1443
+ @sock.puts 'playlistinfo blah blah'
1444
+ assert_equal "ACK [2@0] {playlistinfo} wrong number of arguments for \"playlistinfo\"\n", @sock.gets
1445
+
1446
+ # Test with no args
1447
+ @sock.puts 'clear'
1448
+ assert_equal "OK\n", @sock.gets
1449
+
1450
+ @sock.puts 'load Astral_Projection_-_Dancing_Galaxy'
1451
+ assert_equal "OK\n", @sock.gets
1452
+
1453
+ @sock.puts 'playlistinfo'
1454
+ songs = build_songs get_response
1455
+ assert_equal 8, songs.length
1456
+
1457
+ songs.each_with_index do |s,i|
1458
+ assert s['file'] =~ /^Astral_Projection\/Dancing_Galaxy\//
1459
+ assert_equal 'Astral Projection', s['Artist']
1460
+ assert_equal 'Dancing Galaxy', s['Album']
1461
+ assert_not_nil s['Title']
1462
+ assert_not_nil s['Time']
1463
+ assert_equal (i+1).to_s, s['Track']
1464
+ assert_equal (i+7).to_s, s['Id']
1465
+ assert_equal (i).to_s, s['Pos']
1466
+ end
1467
+
1468
+ # Test with arg > pls length
1469
+ @sock.puts 'playlistinfo 900'
1470
+ assert_equal "ACK [50@0] {playlistinfo} song doesn't exist: \"900\"\n", @sock.gets
1471
+
1472
+ # Test with arg < 0
1473
+ @sock.puts 'playlistinfo -10'
1474
+ songs = build_songs get_response
1475
+ assert_equal 8, songs.length
1476
+
1477
+ songs.each_with_index do |s,i|
1478
+ assert s['file'] =~ /^Astral_Projection\/Dancing_Galaxy\//
1479
+ assert_equal 'Astral Projection', s['Artist']
1480
+ assert_equal 'Dancing Galaxy', s['Album']
1481
+ assert_not_nil s['Title']
1482
+ assert_not_nil s['Time']
1483
+ assert_equal (i+1).to_s, s['Track']
1484
+ assert_equal (i+7).to_s, s['Id']
1485
+ assert_equal (i).to_s, s['Pos']
1486
+ end
1487
+
1488
+ #Test with valid arg
1489
+ @sock.puts 'playlistinfo 3'
1490
+ songs = build_songs get_response
1491
+ assert_equal 1, songs.length
1492
+ assert_equal 'Astral_Projection/Dancing_Galaxy/4.No_One_Ever_Dreams.ogg', songs[0]['file']
1493
+ assert_equal 'Astral Projection', songs[0]['Artist']
1494
+ assert_equal 'Dancing Galaxy', songs[0]['Album']
1495
+ assert_equal 'No One Ever Dreams', songs[0]['Title']
1496
+ assert_equal '505', songs[0]['Time']
1497
+ assert_equal '4', songs[0]['Track']
1498
+ assert_equal '10', songs[0]['Id']
1499
+ assert_equal '3', songs[0]['Pos']
1500
+ end
1501
+
1502
+ def test_playlistid
1503
+ @sock.gets
1504
+
1505
+ # Test with too many args
1506
+ @sock.puts 'playlistid blah blah'
1507
+ assert_equal "ACK [2@0] {playlistid} wrong number of arguments for \"playlistid\"\n", @sock.gets
1508
+
1509
+ # Test with no args
1510
+ @sock.puts 'clear'
1511
+ assert_equal "OK\n", @sock.gets
1512
+
1513
+ @sock.puts 'load Astral_Projection_-_Dancing_Galaxy'
1514
+ assert_equal "OK\n", @sock.gets
1515
+
1516
+ @sock.puts 'playlistid'
1517
+ songs = build_songs get_response
1518
+ assert_equal 8, songs.length
1519
+
1520
+ songs.each_with_index do |s,i|
1521
+ assert s['file'] =~ /^Astral_Projection\/Dancing_Galaxy\//
1522
+ assert_equal 'Astral Projection', s['Artist']
1523
+ assert_equal 'Dancing Galaxy', s['Album']
1524
+ assert_not_nil s['Title']
1525
+ assert_not_nil s['Time']
1526
+ assert_equal (i+1).to_s, s['Track']
1527
+ assert_equal (i+7).to_s, s['Id']
1528
+ assert_equal (i).to_s, s['Pos']
1529
+ end
1530
+
1531
+ # Test with arg doesn't exist
1532
+ @sock.puts 'playlistid 900'
1533
+ assert_equal "ACK [50@0] {playlistid} song id doesn't exist: \"900\"\n", @sock.gets
1534
+
1535
+ # Test with arg < 0
1536
+ @sock.puts 'playlistid -10'
1537
+ songs = build_songs get_response
1538
+ assert_equal 8, songs.length
1539
+
1540
+ songs.each_with_index do |s,i|
1541
+ assert s['file'] =~ /^Astral_Projection\/Dancing_Galaxy\//
1542
+ assert_equal 'Astral Projection', s['Artist']
1543
+ assert_equal 'Dancing Galaxy', s['Album']
1544
+ assert_not_nil s['Title']
1545
+ assert_not_nil s['Time']
1546
+ assert_equal (i+1).to_s, s['Track']
1547
+ assert_equal (i+7).to_s, s['Id']
1548
+ assert_equal (i).to_s, s['Pos']
1549
+ end
1550
+
1551
+ #Test with valid arg
1552
+ @sock.puts 'playlistid 10'
1553
+ songs = build_songs get_response
1554
+ assert_equal 1, songs.length
1555
+ assert_equal 'Astral_Projection/Dancing_Galaxy/4.No_One_Ever_Dreams.ogg', songs[0]['file']
1556
+ assert_equal 'Astral Projection', songs[0]['Artist']
1557
+ assert_equal 'Dancing Galaxy', songs[0]['Album']
1558
+ assert_equal 'No One Ever Dreams', songs[0]['Title']
1559
+ assert_equal '505', songs[0]['Time']
1560
+ assert_equal '4', songs[0]['Track']
1561
+ assert_equal '10', songs[0]['Id']
1562
+ assert_equal '3', songs[0]['Pos']
1563
+ end
1564
+
1565
+ def test_plchanges
1566
+ @sock.gets
1567
+
1568
+ # Test args = 0
1569
+ @sock.puts 'plchanges'
1570
+ assert_equal "ACK [2@0] {plchanges} wrong number of arguments for \"plchanges\"\n", @sock.gets
1571
+
1572
+ # Test args > 1
1573
+ @sock.puts 'plchanges 1 2'
1574
+ assert_equal "ACK [2@0] {plchanges} wrong number of arguments for \"plchanges\"\n", @sock.gets
1575
+
1576
+ # Test arg not integer
1577
+ @sock.puts 'plchanges a'
1578
+ assert_equal "ACK [2@0] {plchanges} need a positive integer\n", @sock.gets
1579
+
1580
+ # Add some stuff to manipulate
1581
+ @sock.puts 'add Shpongle/Are_You_Shpongled'
1582
+ assert_equal "OK\n", @sock.gets
1583
+
1584
+ @sock.puts 'status'
1585
+ status = build_hash get_response
1586
+ assert_equal '8', status['playlist']
1587
+ assert_equal '7', status['playlistlength']
1588
+
1589
+ @sock.puts 'plchanges 7'
1590
+ songs = build_songs get_response
1591
+ assert_equal 1, songs.size
1592
+ assert_equal '... and the Day Turned to Night', songs[0]['Title']
1593
+ assert_equal '6', songs[0]['Pos']
1594
+
1595
+ @sock.puts 'plchanges 6'
1596
+ songs = build_songs get_response
1597
+ assert_equal 2, songs.size
1598
+ assert_equal 'Divine Moments of Truth', songs[0]['Title']
1599
+ assert_equal '5', songs[0]['Pos']
1600
+ assert_equal '... and the Day Turned to Night', songs[1]['Title']
1601
+ assert_equal '6', songs[1]['Pos']
1602
+
1603
+ @sock.puts 'delete 3'
1604
+ assert_equal "OK\n", @sock.gets
1605
+
1606
+ @sock.puts 'status'
1607
+ status = build_hash get_response
1608
+ assert_equal '9', status['playlist']
1609
+ assert_equal '6', status['playlistlength']
1610
+
1611
+ @sock.puts 'plchanges 8'
1612
+ songs = build_songs get_response
1613
+ assert_equal 3, songs.size
1614
+ assert_equal 'Behind Closed Eyelids', songs[0]['Title']
1615
+ assert_equal '3', songs[0]['Pos']
1616
+ assert_equal 'Divine Moments of Truth', songs[1]['Title']
1617
+ assert_equal '4', songs[1]['Pos']
1618
+ assert_equal '... and the Day Turned to Night', songs[2]['Title']
1619
+ assert_equal '5', songs[2]['Pos']
1620
+
1621
+ @sock.puts 'plchanges 5'
1622
+ songs = build_songs get_response
1623
+ assert_equal 3, songs.size
1624
+ assert_equal 'Behind Closed Eyelids', songs[0]['Title']
1625
+ assert_equal '3', songs[0]['Pos']
1626
+ assert_equal 'Divine Moments of Truth', songs[1]['Title']
1627
+ assert_equal '4', songs[1]['Pos']
1628
+ assert_equal '... and the Day Turned to Night', songs[2]['Title']
1629
+ assert_equal '5', songs[2]['Pos']
1630
+
1631
+ @sock.puts 'deleteid 1'
1632
+ assert_equal "OK\n", @sock.gets
1633
+
1634
+ @sock.puts 'status'
1635
+ status = build_hash get_response
1636
+ assert_equal '10', status['playlist']
1637
+ assert_equal '5', status['playlistlength']
1638
+
1639
+ @sock.puts 'plchanges 9'
1640
+ songs = build_songs get_response
1641
+ assert_equal 4, songs.size
1642
+ assert_equal 'Vapour Rumours', songs[0]['Title']
1643
+ assert_equal '1', songs[0]['Pos']
1644
+ assert_equal 'Behind Closed Eyelids', songs[1]['Title']
1645
+ assert_equal '2', songs[1]['Pos']
1646
+ assert_equal 'Divine Moments of Truth', songs[2]['Title']
1647
+ assert_equal '3', songs[2]['Pos']
1648
+ assert_equal '... and the Day Turned to Night', songs[3]['Title']
1649
+ assert_equal '4', songs[3]['Pos']
1650
+
1651
+ @sock.puts 'plchanges 8'
1652
+ songs = build_songs get_response
1653
+ assert_equal 4, songs.size
1654
+ assert_equal 'Vapour Rumours', songs[0]['Title']
1655
+ assert_equal '1', songs[0]['Pos']
1656
+ assert_equal 'Behind Closed Eyelids', songs[1]['Title']
1657
+ assert_equal '2', songs[1]['Pos']
1658
+ assert_equal 'Divine Moments of Truth', songs[2]['Title']
1659
+ assert_equal '3', songs[2]['Pos']
1660
+ assert_equal '... and the Day Turned to Night', songs[3]['Title']
1661
+ assert_equal '4', songs[3]['Pos']
1662
+
1663
+ @sock.puts 'move 1 3'
1664
+ assert_equal "OK\n", @sock.gets
1665
+
1666
+ @sock.puts 'status'
1667
+ status = build_hash get_response
1668
+ assert_equal '11', status['playlist']
1669
+ assert_equal '5', status['playlistlength']
1670
+
1671
+ @sock.puts 'plchanges 10'
1672
+ songs = build_songs get_response
1673
+ assert_equal 3, songs.size
1674
+ assert_equal 'Behind Closed Eyelids', songs[0]['Title']
1675
+ assert_equal '1', songs[0]['Pos']
1676
+ assert_equal 'Divine Moments of Truth', songs[1]['Title']
1677
+ assert_equal '2', songs[1]['Pos']
1678
+ assert_equal 'Vapour Rumours', songs[2]['Title']
1679
+ assert_equal '3', songs[2]['Pos']
1680
+
1681
+ @sock.puts 'move 4 2'
1682
+ assert_equal "OK\n", @sock.gets
1683
+
1684
+ @sock.puts 'status'
1685
+ status = build_hash get_response
1686
+ assert_equal '12', status['playlist']
1687
+ assert_equal '5', status['playlistlength']
1688
+
1689
+ @sock.puts 'plchanges 11'
1690
+ songs = build_songs get_response
1691
+ assert_equal 3, songs.size
1692
+ assert_equal '... and the Day Turned to Night', songs[0]['Title']
1693
+ assert_equal '2', songs[0]['Pos']
1694
+ assert_equal 'Divine Moments of Truth', songs[1]['Title']
1695
+ assert_equal '3', songs[1]['Pos']
1696
+ assert_equal 'Vapour Rumours', songs[2]['Title']
1697
+ assert_equal '4', songs[2]['Pos']
1698
+
1699
+ @sock.puts 'move 3 3'
1700
+ assert_equal "OK\n", @sock.gets
1701
+
1702
+ @sock.puts 'status'
1703
+ status = build_hash get_response
1704
+ assert_equal '13', status['playlist']
1705
+ assert_equal '5', status['playlistlength']
1706
+
1707
+ @sock.puts 'plchanges 12'
1708
+ songs = build_songs get_response
1709
+ assert_equal 1, songs.size
1710
+ assert_equal 'Divine Moments of Truth', songs[0]['Title']
1711
+ assert_equal '3', songs[0]['Pos']
1712
+
1713
+ # load test
1714
+ @sock.puts 'clear'
1715
+ assert_equal "OK\n", @sock.gets
1716
+
1717
+ @sock.puts 'load Astral_Projection_-_Dancing_Galaxy'
1718
+ assert_equal "OK\n", @sock.gets
1719
+
1720
+ @sock.puts 'status'
1721
+ status = build_hash get_response
1722
+ assert_equal '22', status['playlist']
1723
+ assert_equal '8', status['playlistlength']
1724
+
1725
+ @sock.puts 'plchanges 21'
1726
+ songs = build_songs get_response
1727
+ assert_equal 1, songs.size
1728
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', songs[0]['Title']
1729
+ assert_equal '7', songs[0]['Pos']
1730
+
1731
+ @sock.puts 'plchanges 18'
1732
+ songs = build_songs get_response
1733
+ assert_equal 4, songs.size
1734
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', songs[0]['Title']
1735
+ assert_equal '4', songs[0]['Pos']
1736
+ assert_equal 'Life On Mars', songs[1]['Title']
1737
+ assert_equal '5', songs[1]['Pos']
1738
+ assert_equal 'Liquid Sun', songs[2]['Title']
1739
+ assert_equal '6', songs[2]['Pos']
1740
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', songs[3]['Title']
1741
+ assert_equal '7', songs[3]['Pos']
1742
+
1743
+ # moveid test
1744
+ @sock.puts 'moveid 8 5'
1745
+ assert_equal "OK\n", @sock.gets
1746
+
1747
+ @sock.puts 'status'
1748
+ status = build_hash get_response
1749
+ assert_equal '23', status['playlist']
1750
+ assert_equal '8', status['playlistlength']
1751
+
1752
+ @sock.puts 'plchanges 22'
1753
+ songs = build_songs get_response
1754
+ assert_equal 5, songs.size
1755
+ assert_equal 'Flying Into A Star', songs[0]['Title']
1756
+ assert_equal '1', songs[0]['Pos']
1757
+ assert_equal 'No One Ever Dreams', songs[1]['Title']
1758
+ assert_equal '2', songs[1]['Pos']
1759
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', songs[2]['Title']
1760
+ assert_equal '3', songs[2]['Pos']
1761
+ assert_equal 'Life On Mars', songs[3]['Title']
1762
+ assert_equal '4', songs[3]['Pos']
1763
+ assert_equal 'Soundform', songs[4]['Title']
1764
+ assert_equal '5', songs[4]['Pos']
1765
+
1766
+ @sock.puts 'moveid 12 1'
1767
+ assert_equal "OK\n", @sock.gets
1768
+
1769
+ @sock.puts 'status'
1770
+ status = build_hash get_response
1771
+ assert_equal '24', status['playlist']
1772
+ assert_equal '8', status['playlistlength']
1773
+
1774
+ @sock.puts 'plchanges 23'
1775
+ songs = build_songs get_response
1776
+ assert_equal 4, songs.size
1777
+ assert_equal 'Life On Mars', songs[0]['Title']
1778
+ assert_equal '1', songs[0]['Pos']
1779
+ assert_equal 'Flying Into A Star', songs[1]['Title']
1780
+ assert_equal '2', songs[1]['Pos']
1781
+ assert_equal 'No One Ever Dreams', songs[2]['Title']
1782
+ assert_equal '3', songs[2]['Pos']
1783
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', songs[3]['Title']
1784
+ assert_equal '4', songs[3]['Pos']
1785
+
1786
+ @sock.puts 'plchanges 22'
1787
+ songs = build_songs get_response
1788
+ assert_equal 5, songs.size
1789
+ assert_equal 'Life On Mars', songs[0]['Title']
1790
+ assert_equal '1', songs[0]['Pos']
1791
+ assert_equal 'Flying Into A Star', songs[1]['Title']
1792
+ assert_equal '2', songs[1]['Pos']
1793
+ assert_equal 'No One Ever Dreams', songs[2]['Title']
1794
+ assert_equal '3', songs[2]['Pos']
1795
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', songs[3]['Title']
1796
+ assert_equal '4', songs[3]['Pos']
1797
+ assert_equal 'Soundform', songs[4]['Title']
1798
+ assert_equal '5', songs[4]['Pos']
1799
+
1800
+ @sock.puts 'swap 2 5'
1801
+ assert_equal "OK\n", @sock.gets
1802
+
1803
+ @sock.puts 'status'
1804
+ status = build_hash get_response
1805
+ assert_equal '25', status['playlist']
1806
+ assert_equal '8', status['playlistlength']
1807
+
1808
+ @sock.puts 'plchanges 24'
1809
+ songs = build_songs get_response
1810
+ assert_equal 2, songs.size
1811
+ assert_equal 'Soundform', songs[0]['Title']
1812
+ assert_equal '2', songs[0]['Pos']
1813
+ assert_equal 'Flying Into A Star', songs[1]['Title']
1814
+ assert_equal '5', songs[1]['Pos']
1815
+
1816
+ @sock.puts 'swap 7 3'
1817
+ assert_equal "OK\n", @sock.gets
1818
+
1819
+ @sock.puts 'status'
1820
+ status = build_hash get_response
1821
+ assert_equal '26', status['playlist']
1822
+ assert_equal '8', status['playlistlength']
1823
+
1824
+ @sock.puts 'plchanges 25'
1825
+ songs = build_songs get_response
1826
+ assert_equal 2, songs.size
1827
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', songs[0]['Title']
1828
+ assert_equal '3', songs[0]['Pos']
1829
+ assert_equal 'No One Ever Dreams', songs[1]['Title']
1830
+ assert_equal '7', songs[1]['Pos']
1831
+
1832
+ @sock.puts 'plchanges 24'
1833
+ songs = build_songs get_response
1834
+ assert_equal 4, songs.size
1835
+ assert_equal 'Soundform', songs[0]['Title']
1836
+ assert_equal '2', songs[0]['Pos']
1837
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', songs[1]['Title']
1838
+ assert_equal '3', songs[1]['Pos']
1839
+ assert_equal 'Flying Into A Star', songs[2]['Title']
1840
+ assert_equal '5', songs[2]['Pos']
1841
+ assert_equal 'No One Ever Dreams', songs[3]['Title']
1842
+ assert_equal '7', songs[3]['Pos']
1843
+
1844
+ @sock.puts 'swapid 7 13'
1845
+ assert_equal "OK\n", @sock.gets
1846
+
1847
+ @sock.puts 'status'
1848
+ status = build_hash get_response
1849
+ assert_equal '27', status['playlist']
1850
+ assert_equal '8', status['playlistlength']
1851
+
1852
+ @sock.puts 'plchanges 26'
1853
+ songs = build_songs get_response
1854
+ assert_equal 2, songs.size
1855
+ assert_equal 'Liquid Sun', songs[0]['Title']
1856
+ assert_equal '0', songs[0]['Pos']
1857
+ assert_equal 'Dancing Galaxy', songs[1]['Title']
1858
+ assert_equal '6', songs[1]['Pos']
1859
+
1860
+ @sock.puts 'swapid 11 12'
1861
+ assert_equal "OK\n", @sock.gets
1862
+
1863
+ @sock.puts 'status'
1864
+ status = build_hash get_response
1865
+ assert_equal '28', status['playlist']
1866
+ assert_equal '8', status['playlistlength']
1867
+
1868
+ @sock.puts 'plchanges 27'
1869
+ songs = build_songs get_response
1870
+ assert_equal 2, songs.size
1871
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', songs[0]['Title']
1872
+ assert_equal '1', songs[0]['Pos']
1873
+ assert_equal 'Life On Mars', songs[1]['Title']
1874
+ assert_equal '4', songs[1]['Pos']
1875
+
1876
+ @sock.puts 'plchanges 26'
1877
+ songs = build_songs get_response
1878
+ assert_equal 4, songs.size
1879
+ assert_equal 'Liquid Sun', songs[0]['Title']
1880
+ assert_equal '0', songs[0]['Pos']
1881
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', songs[1]['Title']
1882
+ assert_equal '1', songs[1]['Pos']
1883
+ assert_equal 'Life On Mars', songs[2]['Title']
1884
+ assert_equal '4', songs[2]['Pos']
1885
+ assert_equal 'Dancing Galaxy', songs[3]['Title']
1886
+ assert_equal '6', songs[3]['Pos']
1887
+
1888
+ @sock.puts 'shuffle'
1889
+ assert_equal "OK\n", @sock.gets
1890
+
1891
+ @sock.puts 'status'
1892
+ status = build_hash get_response
1893
+ assert_equal '29', status['playlist']
1894
+ assert_equal '8', status['playlistlength']
1895
+
1896
+ @sock.puts 'plchanges 28'
1897
+ songs = build_songs get_response
1898
+ assert_equal 8, songs.size
1899
+ assert_equal 'No One Ever Dreams', songs[0]['Title']
1900
+ assert_equal '0', songs[0]['Pos']
1901
+ assert_equal 'Dancing Galaxy', songs[1]['Title']
1902
+ assert_equal '1', songs[1]['Pos']
1903
+ assert_equal 'Flying Into A Star', songs[2]['Title']
1904
+ assert_equal '2', songs[2]['Pos']
1905
+ assert_equal 'Life On Mars', songs[3]['Title']
1906
+ assert_equal '3', songs[3]['Pos']
1907
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', songs[4]['Title']
1908
+ assert_equal '4', songs[4]['Pos']
1909
+ assert_equal 'Soundform', songs[5]['Title']
1910
+ assert_equal '5', songs[5]['Pos']
1911
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', songs[6]['Title']
1912
+ assert_equal '6', songs[6]['Pos']
1913
+ assert_equal 'Liquid Sun', songs[7]['Title']
1914
+ assert_equal '7', songs[7]['Pos']
1915
+
1916
+ @sock.puts 'add Shpongle/Are_You_Shpongled/6.Divine_Moments_of_Truth.ogg'
1917
+ assert_equal "OK\n", @sock.gets
1918
+
1919
+ @sock.puts 'status'
1920
+ status = build_hash get_response
1921
+ assert_equal '30', status['playlist']
1922
+ assert_equal '9', status['playlistlength']
1923
+
1924
+ @sock.puts 'plchanges 29'
1925
+ songs = build_songs get_response
1926
+ assert_equal 1, songs.size
1927
+ assert_equal 'Divine Moments of Truth', songs[0]['Title']
1928
+ assert_equal '8', songs[0]['Pos']
1929
+ end
1930
+
1931
+ def test_plchangesposid
1932
+ @sock.gets
1933
+
1934
+ # Test args = 0
1935
+ @sock.puts 'plchangesposid'
1936
+ assert_equal "ACK [2@0] {plchangesposid} wrong number of arguments for \"plchangesposid\"\n", @sock.gets
1937
+
1938
+ # Test args > 1
1939
+ @sock.puts 'plchangesposid 1 2'
1940
+ assert_equal "ACK [2@0] {plchangesposid} wrong number of arguments for \"plchangesposid\"\n", @sock.gets
1941
+
1942
+ # Test arg not integer
1943
+ @sock.puts 'plchangesposid a'
1944
+ assert_equal "ACK [2@0] {plchangesposid} need a positive integer\n", @sock.gets
1945
+
1946
+ # Add some stuff to manipulate
1947
+ @sock.puts 'add Shpongle/Are_You_Shpongled'
1948
+ assert_equal "OK\n", @sock.gets
1949
+
1950
+ @sock.puts 'status'
1951
+ status = build_hash get_response
1952
+ assert_equal '8', status['playlist']
1953
+ assert_equal '7', status['playlistlength']
1954
+
1955
+ @sock.puts 'plchangesposid 7'
1956
+ reply = get_response
1957
+ songs = reply.split "\n"
1958
+ assert_equal 2, songs.size
1959
+ assert_equal 'cpos: 6', songs[0]
1960
+ assert_equal 'Id: 6', songs[1]
1961
+
1962
+ @sock.puts 'plchangesposid 6'
1963
+ reply = get_response
1964
+ songs = reply.split "\n"
1965
+ assert_equal 4, songs.size
1966
+ assert_equal 'cpos: 5', songs[0]
1967
+ assert_equal 'Id: 5', songs[1]
1968
+ assert_equal 'cpos: 6', songs[2]
1969
+ assert_equal 'Id: 6', songs[3]
1970
+
1971
+ @sock.puts 'delete 3'
1972
+ assert_equal "OK\n", @sock.gets
1973
+
1974
+ @sock.puts 'status'
1975
+ status = build_hash get_response
1976
+ assert_equal '9', status['playlist']
1977
+ assert_equal '6', status['playlistlength']
1978
+
1979
+ @sock.puts 'plchangesposid 8'
1980
+ reply = get_response
1981
+ songs = reply.split "\n"
1982
+ assert_equal 6, songs.size
1983
+ assert_equal 'cpos: 3', songs[0]
1984
+ assert_equal 'Id: 4', songs[1]
1985
+ assert_equal 'cpos: 4', songs[2]
1986
+ assert_equal 'Id: 5', songs[3]
1987
+ assert_equal 'cpos: 5', songs[4]
1988
+ assert_equal 'Id: 6', songs[5]
1989
+
1990
+ @sock.puts 'plchangesposid 5'
1991
+ reply = get_response
1992
+ songs = reply.split "\n"
1993
+ assert_equal 6, songs.size
1994
+ assert_equal 'cpos: 3', songs[0]
1995
+ assert_equal 'Id: 4', songs[1]
1996
+ assert_equal 'cpos: 4', songs[2]
1997
+ assert_equal 'Id: 5', songs[3]
1998
+ assert_equal 'cpos: 5', songs[4]
1999
+ assert_equal 'Id: 6', songs[5]
2000
+
2001
+ @sock.puts 'deleteid 1'
2002
+ assert_equal "OK\n", @sock.gets
2003
+
2004
+ @sock.puts 'status'
2005
+ status = build_hash get_response
2006
+ assert_equal '10', status['playlist']
2007
+ assert_equal '5', status['playlistlength']
2008
+
2009
+ @sock.puts 'plchangesposid 9'
2010
+ reply = get_response
2011
+ songs = reply.split "\n"
2012
+ assert_equal 8, songs.size
2013
+ assert_equal 'cpos: 1', songs[0]
2014
+ assert_equal 'Id: 2', songs[1]
2015
+ assert_equal 'cpos: 2', songs[2]
2016
+ assert_equal 'Id: 4', songs[3]
2017
+ assert_equal 'cpos: 3', songs[4]
2018
+ assert_equal 'Id: 5', songs[5]
2019
+ assert_equal 'cpos: 4', songs[6]
2020
+ assert_equal 'Id: 6', songs[7]
2021
+
2022
+ @sock.puts 'plchangesposid 8'
2023
+ reply = get_response
2024
+ songs = reply.split "\n"
2025
+ assert_equal 8, songs.size
2026
+ assert_equal 'cpos: 1', songs[0]
2027
+ assert_equal 'Id: 2', songs[1]
2028
+ assert_equal 'cpos: 2', songs[2]
2029
+ assert_equal 'Id: 4', songs[3]
2030
+ assert_equal 'cpos: 3', songs[4]
2031
+ assert_equal 'Id: 5', songs[5]
2032
+ assert_equal 'cpos: 4', songs[6]
2033
+ assert_equal 'Id: 6', songs[7]
2034
+
2035
+ @sock.puts 'move 1 3'
2036
+ assert_equal "OK\n", @sock.gets
2037
+
2038
+ @sock.puts 'status'
2039
+ status = build_hash get_response
2040
+ assert_equal '11', status['playlist']
2041
+ assert_equal '5', status['playlistlength']
2042
+
2043
+ @sock.puts 'plchangesposid 10'
2044
+ reply = get_response
2045
+ songs = reply.split "\n"
2046
+ assert_equal 6, songs.size
2047
+ assert_equal 'cpos: 1', songs[0]
2048
+ assert_equal 'Id: 4', songs[1]
2049
+ assert_equal 'cpos: 2', songs[2]
2050
+ assert_equal 'Id: 5', songs[3]
2051
+ assert_equal 'cpos: 3', songs[4]
2052
+ assert_equal 'Id: 2', songs[5]
2053
+
2054
+ @sock.puts 'move 4 2'
2055
+ assert_equal "OK\n", @sock.gets
2056
+
2057
+ @sock.puts 'status'
2058
+ status = build_hash get_response
2059
+ assert_equal '12', status['playlist']
2060
+ assert_equal '5', status['playlistlength']
2061
+
2062
+ @sock.puts 'plchangesposid 11'
2063
+ reply = get_response
2064
+ songs = reply.split "\n"
2065
+ assert_equal 6, songs.size
2066
+ assert_equal 'cpos: 2', songs[0]
2067
+ assert_equal 'Id: 6', songs[1]
2068
+ assert_equal 'cpos: 3', songs[2]
2069
+ assert_equal 'Id: 5', songs[3]
2070
+ assert_equal 'cpos: 4', songs[4]
2071
+ assert_equal 'Id: 2', songs[5]
2072
+
2073
+ @sock.puts 'move 3 3'
2074
+ assert_equal "OK\n", @sock.gets
2075
+
2076
+ @sock.puts 'status'
2077
+ status = build_hash get_response
2078
+ assert_equal '13', status['playlist']
2079
+ assert_equal '5', status['playlistlength']
2080
+
2081
+ @sock.puts 'plchangesposid 12'
2082
+ reply = get_response
2083
+ songs = reply.split "\n"
2084
+ assert_equal 2, songs.size
2085
+ assert_equal 'cpos: 3', songs[0]
2086
+ assert_equal 'Id: 5', songs[1]
2087
+
2088
+ # load test
2089
+ @sock.puts 'clear'
2090
+ assert_equal "OK\n", @sock.gets
2091
+
2092
+ @sock.puts 'load Astral_Projection_-_Dancing_Galaxy'
2093
+ assert_equal "OK\n", @sock.gets
2094
+
2095
+ @sock.puts 'status'
2096
+ status = build_hash get_response
2097
+ assert_equal '22', status['playlist']
2098
+ assert_equal '8', status['playlistlength']
2099
+
2100
+ @sock.puts 'plchangesposid 21'
2101
+ reply = get_response
2102
+ songs = reply.split "\n"
2103
+ assert_equal 2, songs.size
2104
+ assert_equal 'cpos: 7', songs[0]
2105
+ assert_equal 'Id: 14', songs[1]
2106
+
2107
+ @sock.puts 'plchangesposid 18'
2108
+ reply = get_response
2109
+ songs = reply.split "\n"
2110
+ assert_equal 8, songs.size
2111
+ assert_equal 'cpos: 4', songs[0]
2112
+ assert_equal 'Id: 11', songs[1]
2113
+ assert_equal 'cpos: 5', songs[2]
2114
+ assert_equal 'Id: 12', songs[3]
2115
+ assert_equal 'cpos: 6', songs[4]
2116
+ assert_equal 'Id: 13', songs[5]
2117
+ assert_equal 'cpos: 7', songs[6]
2118
+ assert_equal 'Id: 14', songs[7]
2119
+
2120
+ # moveid test
2121
+ @sock.puts 'moveid 8 5'
2122
+ assert_equal "OK\n", @sock.gets
2123
+
2124
+ @sock.puts 'status'
2125
+ status = build_hash get_response
2126
+ assert_equal '23', status['playlist']
2127
+ assert_equal '8', status['playlistlength']
2128
+
2129
+ @sock.puts 'plchangesposid 22'
2130
+ reply = get_response
2131
+ songs = reply.split "\n"
2132
+ assert_equal 10, songs.size
2133
+ assert_equal 'cpos: 1', songs[0]
2134
+ assert_equal 'Id: 9', songs[1]
2135
+ assert_equal 'cpos: 2', songs[2]
2136
+ assert_equal 'Id: 10', songs[3]
2137
+ assert_equal 'cpos: 3', songs[4]
2138
+ assert_equal 'Id: 11', songs[5]
2139
+ assert_equal 'cpos: 4', songs[6]
2140
+ assert_equal 'Id: 12', songs[7]
2141
+ assert_equal 'cpos: 5', songs[8]
2142
+ assert_equal 'Id: 8', songs[9]
2143
+
2144
+ @sock.puts 'moveid 12 1'
2145
+ assert_equal "OK\n", @sock.gets
2146
+
2147
+ @sock.puts 'status'
2148
+ status = build_hash get_response
2149
+ assert_equal '24', status['playlist']
2150
+ assert_equal '8', status['playlistlength']
2151
+
2152
+ @sock.puts 'plchangesposid 23'
2153
+ reply = get_response
2154
+ songs = reply.split "\n"
2155
+ assert_equal 8, songs.size
2156
+ assert_equal 'cpos: 1', songs[0]
2157
+ assert_equal 'Id: 12', songs[1]
2158
+ assert_equal 'cpos: 2', songs[2]
2159
+ assert_equal 'Id: 9', songs[3]
2160
+ assert_equal 'cpos: 3', songs[4]
2161
+ assert_equal 'Id: 10', songs[5]
2162
+ assert_equal 'cpos: 4', songs[6]
2163
+ assert_equal 'Id: 11', songs[7]
2164
+
2165
+ @sock.puts 'plchangesposid 22'
2166
+ reply = get_response
2167
+ songs = reply.split "\n"
2168
+ assert_equal 10, songs.size
2169
+ assert_equal 'cpos: 1', songs[0]
2170
+ assert_equal 'Id: 12', songs[1]
2171
+ assert_equal 'cpos: 2', songs[2]
2172
+ assert_equal 'Id: 9', songs[3]
2173
+ assert_equal 'cpos: 3', songs[4]
2174
+ assert_equal 'Id: 10', songs[5]
2175
+ assert_equal 'cpos: 4', songs[6]
2176
+ assert_equal 'Id: 11', songs[7]
2177
+ assert_equal 'cpos: 5', songs[8]
2178
+ assert_equal 'Id: 8', songs[9]
2179
+
2180
+ @sock.puts 'swap 2 5'
2181
+ assert_equal "OK\n", @sock.gets
2182
+
2183
+ @sock.puts 'status'
2184
+ status = build_hash get_response
2185
+ assert_equal '25', status['playlist']
2186
+ assert_equal '8', status['playlistlength']
2187
+
2188
+ @sock.puts 'plchangesposid 24'
2189
+ reply = get_response
2190
+ songs = reply.split "\n"
2191
+ assert_equal 4, songs.size
2192
+ assert_equal 'cpos: 2', songs[0]
2193
+ assert_equal 'Id: 8', songs[1]
2194
+ assert_equal 'cpos: 5', songs[2]
2195
+ assert_equal 'Id: 9', songs[3]
2196
+
2197
+ @sock.puts 'swap 7 3'
2198
+ assert_equal "OK\n", @sock.gets
2199
+
2200
+ @sock.puts 'status'
2201
+ status = build_hash get_response
2202
+ assert_equal '26', status['playlist']
2203
+ assert_equal '8', status['playlistlength']
2204
+
2205
+ @sock.puts 'plchangesposid 25'
2206
+ reply = get_response
2207
+ songs = reply.split "\n"
2208
+ assert_equal 4, songs.size
2209
+ assert_equal 'cpos: 3', songs[0]
2210
+ assert_equal 'Id: 14', songs[1]
2211
+ assert_equal 'cpos: 7', songs[2]
2212
+ assert_equal 'Id: 10', songs[3]
2213
+
2214
+ @sock.puts 'plchangesposid 24'
2215
+ reply = get_response
2216
+ songs = reply.split "\n"
2217
+ assert_equal 8, songs.size
2218
+ assert_equal 'cpos: 2', songs[0]
2219
+ assert_equal 'Id: 8', songs[1]
2220
+ assert_equal 'cpos: 3', songs[2]
2221
+ assert_equal 'Id: 14', songs[3]
2222
+ assert_equal 'cpos: 5', songs[4]
2223
+ assert_equal 'Id: 9', songs[5]
2224
+ assert_equal 'cpos: 7', songs[6]
2225
+ assert_equal 'Id: 10', songs[7]
2226
+
2227
+ @sock.puts 'swapid 7 13'
2228
+ assert_equal "OK\n", @sock.gets
2229
+
2230
+ @sock.puts 'status'
2231
+ status = build_hash get_response
2232
+ assert_equal '27', status['playlist']
2233
+ assert_equal '8', status['playlistlength']
2234
+
2235
+ @sock.puts 'plchangesposid 26'
2236
+ reply = get_response
2237
+ songs = reply.split "\n"
2238
+ assert_equal 4, songs.size
2239
+ assert_equal 'cpos: 0', songs[0]
2240
+ assert_equal 'Id: 13', songs[1]
2241
+ assert_equal 'cpos: 6', songs[2]
2242
+ assert_equal 'Id: 7', songs[3]
2243
+
2244
+ @sock.puts 'swapid 11 12'
2245
+ assert_equal "OK\n", @sock.gets
2246
+
2247
+ @sock.puts 'status'
2248
+ status = build_hash get_response
2249
+ assert_equal '28', status['playlist']
2250
+ assert_equal '8', status['playlistlength']
2251
+
2252
+ @sock.puts 'plchangesposid 27'
2253
+ reply = get_response
2254
+ songs = reply.split "\n"
2255
+ assert_equal 4, songs.size
2256
+ assert_equal 'cpos: 1', songs[0]
2257
+ assert_equal 'Id: 11', songs[1]
2258
+ assert_equal 'cpos: 4', songs[2]
2259
+ assert_equal 'Id: 12', songs[3]
2260
+
2261
+ @sock.puts 'plchangesposid 26'
2262
+ reply = get_response
2263
+ songs = reply.split "\n"
2264
+ assert_equal 8, songs.size
2265
+ assert_equal 'cpos: 0', songs[0]
2266
+ assert_equal 'Id: 13', songs[1]
2267
+ assert_equal 'cpos: 1', songs[2]
2268
+ assert_equal 'Id: 11', songs[3]
2269
+ assert_equal 'cpos: 4', songs[4]
2270
+ assert_equal 'Id: 12', songs[5]
2271
+ assert_equal 'cpos: 6', songs[6]
2272
+ assert_equal 'Id: 7', songs[7]
2273
+
2274
+ @sock.puts 'shuffle'
2275
+ assert_equal "OK\n", @sock.gets
2276
+
2277
+ @sock.puts 'status'
2278
+ status = build_hash get_response
2279
+ assert_equal '29', status['playlist']
2280
+ assert_equal '8', status['playlistlength']
2281
+
2282
+ @sock.puts 'plchangesposid 28'
2283
+ reply = get_response
2284
+ songs = reply.split "\n"
2285
+ assert_equal 16, songs.size
2286
+ assert_equal 'cpos: 0', songs[0]
2287
+ assert_equal 'Id: 10', songs[1]
2288
+ assert_equal 'cpos: 1', songs[2]
2289
+ assert_equal 'Id: 7', songs[3]
2290
+ assert_equal 'cpos: 2', songs[4]
2291
+ assert_equal 'Id: 9', songs[5]
2292
+ assert_equal 'cpos: 3', songs[6]
2293
+ assert_equal 'Id: 12', songs[7]
2294
+ assert_equal 'cpos: 4', songs[8]
2295
+ assert_equal 'Id: 14', songs[9]
2296
+ assert_equal 'cpos: 5', songs[10]
2297
+ assert_equal 'Id: 8', songs[11]
2298
+ assert_equal 'cpos: 6', songs[12]
2299
+ assert_equal 'Id: 11', songs[13]
2300
+ assert_equal 'cpos: 7', songs[14]
2301
+ assert_equal 'Id: 13', songs[15]
2302
+
2303
+ @sock.puts 'add Shpongle/Are_You_Shpongled/6.Divine_Moments_of_Truth.ogg'
2304
+ assert_equal "OK\n", @sock.gets
2305
+
2306
+ @sock.puts 'status'
2307
+ status = build_hash get_response
2308
+ assert_equal '30', status['playlist']
2309
+ assert_equal '9', status['playlistlength']
2310
+
2311
+ @sock.puts 'plchangesposid 29'
2312
+ reply = get_response
2313
+ songs = reply.split "\n"
2314
+ assert_equal 2, songs.size
2315
+ assert_equal 'cpos: 8', songs[0]
2316
+ assert_equal 'Id: 5', songs[1]
2317
+ end
2318
+
2319
+ def test_previous
2320
+ @sock.gets
2321
+
2322
+ # Test with too many args
2323
+ @sock.puts 'previous 1'
2324
+ assert_equal "ACK [2@0] {previous} wrong number of arguments for \"previous\"\n", @sock.gets
2325
+
2326
+ @sock.puts 'load Astral_Projection_-_Dancing_Galaxy'
2327
+ assert_equal "OK\n", @sock.gets
2328
+
2329
+ # Shouldn't do anything
2330
+ @sock.puts 'previous'
2331
+ assert_equal "OK\n", @sock.gets
2332
+
2333
+ @sock.puts 'previous'
2334
+ assert_equal "OK\n", @sock.gets
2335
+
2336
+ @sock.puts 'status'
2337
+ status = build_hash get_response
2338
+ assert_equal 7, status.size
2339
+ assert_equal 'stop', status['state']
2340
+
2341
+ @sock.puts 'play 7'
2342
+ assert_equal "OK\n", @sock.gets
2343
+
2344
+ sleep 2
2345
+
2346
+ @sock.puts 'previous'
2347
+ assert_equal "OK\n", @sock.gets
2348
+
2349
+ sleep 2
2350
+
2351
+ @sock.puts 'status'
2352
+ status = build_hash get_response
2353
+ assert_equal 12, status.size
2354
+ assert_equal '6', status['song']
2355
+ assert_equal '13', status['songid']
2356
+ assert_equal 'play', status['state']
2357
+
2358
+ @sock.puts 'previous'
2359
+ assert_equal "OK\n", @sock.gets
2360
+
2361
+ @sock.puts 'previous'
2362
+ assert_equal "OK\n", @sock.gets
2363
+
2364
+ @sock.puts 'previous'
2365
+ assert_equal "OK\n", @sock.gets
2366
+
2367
+ @sock.puts 'previous'
2368
+ assert_equal "OK\n", @sock.gets
2369
+
2370
+ @sock.puts 'previous'
2371
+ assert_equal "OK\n", @sock.gets
2372
+
2373
+ @sock.puts 'previous'
2374
+ assert_equal "OK\n", @sock.gets
2375
+
2376
+ sleep 2
2377
+
2378
+ @sock.puts 'status'
2379
+ status = build_hash get_response
2380
+ assert_equal 12, status.size
2381
+ assert_equal '0', status['song']
2382
+ assert_equal '7', status['songid']
2383
+ assert_equal 'play', status['state']
2384
+
2385
+ @sock.puts 'previous'
2386
+ assert_equal "OK\n", @sock.gets
2387
+
2388
+ sleep 2
2389
+
2390
+ @sock.puts 'status'
2391
+ status = build_hash get_response
2392
+ assert_equal 12, status.size
2393
+ assert_equal '0', status['song']
2394
+ assert_equal '7', status['songid']
2395
+ assert_equal 'play', status['state']
2396
+
2397
+ @sock.puts 'stop'
2398
+ assert_equal "OK\n", @sock.gets
2399
+
2400
+ @sock.puts 'play 4'
2401
+ assert_equal "OK\n", @sock.gets
2402
+
2403
+ sleep 2
2404
+
2405
+ @sock.puts 'pause'
2406
+ assert_equal "OK\n", @sock.gets
2407
+
2408
+ sleep 2
2409
+
2410
+ @sock.puts 'previous'
2411
+ assert_equal "OK\n", @sock.gets
2412
+
2413
+ sleep 2
2414
+
2415
+ @sock.puts 'status'
2416
+ status = build_hash get_response
2417
+ assert_equal 12, status.size
2418
+ assert_equal '3', status['song']
2419
+ assert_equal '10', status['songid']
2420
+ assert_equal 'play', status['state']
2421
+
2422
+ @sock.puts 'stop'
2423
+ assert_equal "OK\n", @sock.gets
2424
+
2425
+ sleep 2
2426
+
2427
+ @sock.puts 'play 6'
2428
+ assert_equal "OK\n", @sock.gets
2429
+
2430
+ sleep 2
2431
+
2432
+ @sock.puts 'stop'
2433
+ assert_equal "OK\n", @sock.gets
2434
+
2435
+ @sock.puts 'previous'
2436
+ assert_equal "OK\n", @sock.gets
2437
+
2438
+ @sock.puts 'previous'
2439
+ assert_equal "OK\n", @sock.gets
2440
+
2441
+ @sock.puts 'status'
2442
+ status = build_hash get_response
2443
+ assert_equal 9, status.size
2444
+ assert_equal 'stop', status['state']
2445
+ assert_equal '6', status['song']
2446
+ assert_equal '13', status['songid']
2447
+ end
2448
+
2449
+ def test_random
2450
+ @sock.gets
2451
+ # Test no args
2452
+ @sock.puts 'random'
2453
+ assert_equal "ACK [2@0] {random} wrong number of arguments for \"random\"\n", @sock.gets
2454
+
2455
+ # Test too many args
2456
+ @sock.puts 'random blah blah'
2457
+ assert_equal "ACK [2@0] {random} wrong number of arguments for \"random\"\n", @sock.gets
2458
+
2459
+ # Test arg != integer
2460
+ @sock.puts 'random b'
2461
+ assert_equal "ACK [2@0] {random} need an integer\n", @sock.gets
2462
+
2463
+ # Test arg != (0||1)
2464
+ @sock.puts 'random 3'
2465
+ assert_equal "ACK [2@0] {random} \"3\" is not 0 or 1\n", @sock.gets
2466
+
2467
+ # Test arg < 0
2468
+ @sock.puts 'random -1'
2469
+ assert_equal "ACK [2@0] {random} \"-1\" is not 0 or 1\n", @sock.gets
2470
+
2471
+ # Test disable
2472
+ @sock.puts 'random 0'
2473
+ assert_equal "OK\n", @sock.gets
2474
+
2475
+ @sock.puts 'status'
2476
+ status = build_hash get_response
2477
+ assert_equal '0', status['random']
2478
+
2479
+ # Test Enable
2480
+ @sock.puts 'random 1'
2481
+ assert_equal "OK\n", @sock.gets
2482
+
2483
+ @sock.puts 'status'
2484
+ status = build_hash get_response
2485
+ assert_equal '1', status['random']
2486
+
2487
+ @sock.puts 'random 0'
2488
+ assert_equal "OK\n", @sock.gets
2489
+
2490
+ @sock.puts 'status'
2491
+ status = build_hash get_response
2492
+ assert_equal '0', status['random']
2493
+ end
2494
+
2495
+ def test_repeat
2496
+ @sock.gets
2497
+ # Test no args
2498
+ @sock.puts 'repeat'
2499
+ assert_equal "ACK [2@0] {repeat} wrong number of arguments for \"repeat\"\n", @sock.gets
2500
+
2501
+ # Test too many args
2502
+ @sock.puts 'repeat blah blah'
2503
+ assert_equal "ACK [2@0] {repeat} wrong number of arguments for \"repeat\"\n", @sock.gets
2504
+
2505
+ # Test arg != integer
2506
+ @sock.puts 'repeat b'
2507
+ assert_equal "ACK [2@0] {repeat} need an integer\n", @sock.gets
2508
+
2509
+ # Test arg != (0||1)
2510
+ @sock.puts 'repeat 3'
2511
+ assert_equal "ACK [2@0] {repeat} \"3\" is not 0 or 1\n", @sock.gets
2512
+
2513
+ # Test arg < 0
2514
+ @sock.puts 'repeat -1'
2515
+ assert_equal "ACK [2@0] {repeat} \"-1\" is not 0 or 1\n", @sock.gets
2516
+
2517
+ # Test disable
2518
+ @sock.puts 'repeat 0'
2519
+ assert_equal "OK\n", @sock.gets
2520
+
2521
+ @sock.puts 'status'
2522
+ status = build_hash get_response
2523
+ assert_equal '0', status['repeat']
2524
+
2525
+ # Test enable
2526
+ @sock.puts 'repeat 1'
2527
+ assert_equal "OK\n", @sock.gets
2528
+
2529
+ @sock.puts 'status'
2530
+ status = build_hash get_response
2531
+ assert_equal '1', status['repeat']
2532
+
2533
+ @sock.puts 'repeat 0'
2534
+ assert_equal "OK\n", @sock.gets
2535
+
2536
+ @sock.puts 'status'
2537
+ status = build_hash get_response
2538
+ assert_equal '0', status['repeat']
2539
+ end
2540
+
2541
+ def test_rm
2542
+ @sock.gets
2543
+
2544
+ # Test no args
2545
+ @sock.puts 'rm'
2546
+ assert_equal "ACK [2@0] {rm} wrong number of arguments for \"rm\"\n", @sock.gets
2547
+
2548
+ # Test args > 1
2549
+ @sock.puts 'rm 1 2'
2550
+ assert_equal "ACK [2@0] {rm} wrong number of arguments for \"rm\"\n", @sock.gets
2551
+
2552
+ # Test arg not exist
2553
+ @sock.puts 'rm abomination'
2554
+ assert_equal "ACK [50@0] {rm} playlist \"abomination\" not found\n", @sock.gets
2555
+
2556
+ # Test arg exists
2557
+ @sock.puts 'rm Shpongle_-_Are_You_Shpongled'
2558
+ assert_equal "OK\n", @sock.gets
2559
+
2560
+ # Ensure the pls was removed
2561
+ @sock.puts 'lsinfo'
2562
+ reply = get_response
2563
+ lines = reply.split "\n"
2564
+ found = false
2565
+ lines.each do |l|
2566
+ if l == 'playlist: Shpongle_-_Are_You_Shpongled'
2567
+ found = true
2568
+ break
2569
+ end
2570
+ end
2571
+
2572
+ assert !found, 'The playlist was not removed'
2573
+ end
2574
+
2575
+ def test_save
2576
+ @sock.gets
2577
+
2578
+ # Test no args
2579
+ @sock.puts 'save'
2580
+ assert_equal "ACK [2@0] {save} wrong number of arguments for \"save\"\n", @sock.gets
2581
+
2582
+ # Test args > 1
2583
+ @sock.puts 'save 1 2'
2584
+ assert_equal "ACK [2@0] {save} wrong number of arguments for \"save\"\n", @sock.gets
2585
+
2586
+ @sock.puts 'load Shpongle_-_Are_You_Shpongled'
2587
+ assert_equal "OK\n", @sock.gets
2588
+
2589
+ @sock.puts 'load Astral_Projection_-_Dancing_Galaxy'
2590
+ assert_equal "OK\n", @sock.gets
2591
+
2592
+ # Test correct args
2593
+ @sock.puts 'save Save_Test'
2594
+ assert_equal "OK\n", @sock.gets
2595
+
2596
+ @sock.puts 'lsinfo'
2597
+ reply = get_response
2598
+ lines = reply.split "\n"
2599
+ assert_equal 6, lines.length
2600
+ assert_equal 'directory: Astral_Projection', lines[0]
2601
+ assert_equal 'directory: Carbon_Based_Lifeforms', lines[1]
2602
+ assert_equal 'directory: Shpongle', lines[2]
2603
+ assert_equal 'playlist: Shpongle_-_Are_You_Shpongled', lines[3]
2604
+ assert_equal 'playlist: Astral_Projection_-_Dancing_Galaxy', lines[4]
2605
+ assert_equal 'playlist: Save_Test', lines[5]
2606
+
2607
+ @sock.puts 'clear'
2608
+ assert_equal "OK\n", @sock.gets
2609
+
2610
+ @sock.puts 'playlist'
2611
+ assert_equal "OK\n", @sock.gets
2612
+
2613
+ @sock.puts 'load Save_Test'
2614
+ assert_equal "OK\n", @sock.gets
2615
+
2616
+ @sock.puts 'playlist'
2617
+ reply = get_response
2618
+ lines = reply.split "\n"
2619
+ assert_equal 15, lines.length
2620
+ assert_equal '0:Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg', lines[0]
2621
+ assert_equal '3:Shpongle/Are_You_Shpongled/4.Shpongle_Spores.ogg', lines[3]
2622
+ assert_equal '6:Shpongle/Are_You_Shpongled/7...._and_the_Day_Turned_to_Night.ogg', lines[6]
2623
+ assert_equal '7:Astral_Projection/Dancing_Galaxy/1.Dancing_Galaxy.ogg', lines[7]
2624
+ assert_equal '11:Astral_Projection/Dancing_Galaxy/5.Cosmic_Ascension_(ft._DJ_Jorg).ogg', lines[11]
2625
+ assert_equal '14:Astral_Projection/Dancing_Galaxy/8.Ambient_Galaxy_(Disco_Valley_Mix).ogg', lines[14]
2626
+ end
2627
+
2628
+ def test_search
2629
+ @sock.gets
2630
+
2631
+ @sock.puts 'search'
2632
+ assert_equal "ACK [2@0] {search} wrong number of arguments for \"search\"\n", @sock.gets
2633
+
2634
+ @sock.puts 'search 1 2 3'
2635
+ assert_equal "ACK [2@0] {search} wrong number of arguments for \"search\"\n", @sock.gets
2636
+
2637
+ @sock.puts 'search wrong Shpongle'
2638
+ assert_equal "ACK [2@0] {search} incorrect arguments\n", @sock.gets
2639
+
2640
+ @sock.puts 'search artist "arbon based life"'
2641
+ songs = build_songs get_response
2642
+ assert_equal 11, songs.size
2643
+ songs.each_with_index do |song,i|
2644
+ assert_equal i+1, song['Track'].to_i
2645
+ assert_equal i+15, song['Id'].to_i
2646
+ assert_equal 'Carbon Based Lifeforms', song['Artist']
2647
+ assert_equal 'Hydroponic Garden', song['Album']
2648
+ assert song['file'] =~ /^Carbon_Based_Lifeforms\/Hydroponic_Garden\//
2649
+ end
2650
+
2651
+ @sock.puts 'search album hydroponic'
2652
+ songs = build_songs get_response
2653
+ assert_equal 11, songs.size
2654
+ songs.each_with_index do |song,i|
2655
+ assert_equal i+1, song['Track'].to_i
2656
+ assert_equal i+15, song['Id'].to_i
2657
+ assert_equal 'Carbon Based Lifeforms', song['Artist']
2658
+ assert_equal 'Hydroponic Garden', song['Album']
2659
+ assert song['file'] =~ /^Carbon_Based_Lifeforms\/Hydroponic_Garden\//
2660
+ end
2661
+
2662
+ @sock.puts 'search filename hydropo'
2663
+ songs = build_songs get_response
2664
+ assert_equal 11, songs.size
2665
+ songs.each_with_index do |song,i|
2666
+ assert_equal i+1, song['Track'].to_i
2667
+ assert_equal i+15, song['Id'].to_i
2668
+ assert_equal 'Carbon Based Lifeforms', song['Artist']
2669
+ assert_equal 'Hydroponic Garden', song['Album']
2670
+ assert song['file'] =~ /^Carbon_Based_Lifeforms\/Hydroponic_Garden\//
2671
+ end
2672
+
2673
+ @sock.puts 'search title "silent running"'
2674
+ songs = build_songs get_response
2675
+ assert_equal 1, songs.size
2676
+ assert_equal '4', songs[0]['Track']
2677
+ assert_equal '18', songs[0]['Id']
2678
+ assert_equal 'Carbon_Based_Lifeforms/Hydroponic_Garden/04.Silent_Running.ogg', songs[0]['file']
2679
+ assert_equal 'Silent Running', songs[0]['Title']
2680
+ assert_equal 'Hydroponic Garden', songs[0]['Album']
2681
+ assert_equal 'Carbon Based Lifeforms', songs[0]['Artist']
2682
+
2683
+ @sock.puts 'search title "no title"'
2684
+ assert_equal "OK\n", @sock.gets
2685
+
2686
+ @sock.puts 'search artist "no artist"'
2687
+ assert_equal "OK\n", @sock.gets
2688
+
2689
+ @sock.puts 'search album "no album"'
2690
+ assert_equal "OK\n", @sock.gets
2691
+
2692
+ @sock.puts 'search filename "no file"'
2693
+ assert_equal "OK\n", @sock.gets
2694
+ end
2695
+
2696
+ def test_seek
2697
+ @sock.gets
2698
+
2699
+ @sock.puts 'seek'
2700
+ assert_equal "ACK [2@0] {seek} wrong number of arguments for \"seek\"\n", @sock.gets
2701
+
2702
+ @sock.puts 'seek 1 2 3'
2703
+ assert_equal "ACK [2@0] {seek} wrong number of arguments for \"seek\"\n", @sock.gets
2704
+
2705
+ @sock.puts 'seek a 2'
2706
+ assert_equal "ACK [2@0] {seek} \"a\" is not a integer\n", @sock.gets
2707
+
2708
+ @sock.puts 'seek 1 a'
2709
+ assert_equal "ACK [2@0] {seek} \"a\" is not a integer\n", @sock.gets
2710
+
2711
+ @sock.puts 'load Astral_Projection_-_Dancing_Galaxy'
2712
+ assert_equal "OK\n", @sock.gets
2713
+
2714
+ @sock.puts 'seek 99 10'
2715
+ assert_equal "ACK [50@0] {seek} song doesn't exist: \"99\"\n", @sock.gets
2716
+
2717
+ @sock.puts 'seek -1 10'
2718
+ assert_equal "ACK [50@0] {seek} song doesn't exist: \"-1\"\n", @sock.gets
2719
+
2720
+ @sock.puts 'seek 0 40'
2721
+ assert_equal "OK\n", @sock.gets
2722
+
2723
+ sleep 4
2724
+
2725
+ @sock.puts 'status'
2726
+ status = build_hash get_response
2727
+ assert_equal 12, status.size
2728
+ assert_equal 'play', status['state']
2729
+ assert_equal '0', status['song']
2730
+ assert_equal '7', status['songid']
2731
+ assert_not_nil status['time']
2732
+ assert 40 < status['time'].to_i
2733
+ assert 55 > status['time'].to_i
2734
+
2735
+ @sock.puts 'pause 1'
2736
+ assert_equal "OK\n", @sock.gets
2737
+
2738
+ sleep 2
2739
+
2740
+ @sock.puts 'seek 4 100'
2741
+ assert_equal "OK\n", @sock.gets
2742
+
2743
+ sleep 2
2744
+
2745
+ @sock.puts 'status'
2746
+ status = build_hash get_response
2747
+ assert_equal 12, status.size
2748
+ assert_equal 'pause', status['state']
2749
+ assert_equal '4', status['song']
2750
+ assert_equal '11', status['songid']
2751
+ assert_equal 100, status['time'].to_i
2752
+
2753
+ @sock.puts 'pause 0'
2754
+ assert_equal "OK\n", @sock.gets
2755
+
2756
+ sleep 2
2757
+
2758
+ @sock.puts 'seek 6 200'
2759
+ assert_equal "OK\n", @sock.gets
2760
+
2761
+ sleep 4
2762
+
2763
+ @sock.puts 'status'
2764
+ status = build_hash get_response
2765
+ assert_equal 12, status.size
2766
+ assert_equal 'play', status['state']
2767
+ assert_equal '6', status['song']
2768
+ assert_equal '13', status['songid']
2769
+ assert 200 < status['time'].to_i
2770
+ assert 215 > status['time'].to_i
2771
+
2772
+ @sock.puts 'seek 2 10000'
2773
+ assert_equal "OK\n", @sock.gets
2774
+
2775
+ sleep 2
2776
+
2777
+ @sock.puts 'status'
2778
+ status = build_hash get_response
2779
+ assert_equal 12, status.size
2780
+ assert_equal 'play', status['state']
2781
+ assert_equal '3', status['song']
2782
+ assert_equal '10', status['songid']
2783
+ assert 10 > status['time'].to_i
2784
+
2785
+ @sock.puts 'seek 7 10000'
2786
+ assert_equal "OK\n", @sock.gets
2787
+
2788
+ sleep 2
2789
+
2790
+ @sock.puts 'status'
2791
+ status = build_hash get_response
2792
+ assert_equal 7, status.size
2793
+ assert_equal 'stop', status['state']
2794
+
2795
+ @sock.puts 'seek 2 -100'
2796
+ assert_equal "OK\n", @sock.gets
2797
+
2798
+ sleep 2
2799
+
2800
+ @sock.puts 'status'
2801
+ status = build_hash get_response
2802
+ assert_equal 12, status.size
2803
+ assert_equal 'play', status['state']
2804
+ assert_equal '2', status['song']
2805
+ assert_equal '9', status['songid']
2806
+ assert 5 > status['time'].to_i
2807
+ end
2808
+
2809
+ def test_seekid
2810
+ @sock.gets
2811
+
2812
+ @sock.puts 'seekid'
2813
+ assert_equal "ACK [2@0] {seekid} wrong number of arguments for \"seekid\"\n", @sock.gets
2814
+
2815
+ @sock.puts 'seekid 1 2 3'
2816
+ assert_equal "ACK [2@0] {seekid} wrong number of arguments for \"seekid\"\n", @sock.gets
2817
+
2818
+ @sock.puts 'seekid a 2'
2819
+ assert_equal "ACK [2@0] {seekid} \"a\" is not a integer\n", @sock.gets
2820
+
2821
+ @sock.puts 'seekid 1 a'
2822
+ assert_equal "ACK [2@0] {seekid} \"a\" is not a integer\n", @sock.gets
2823
+
2824
+ @sock.puts 'load Astral_Projection_-_Dancing_Galaxy'
2825
+ assert_equal "OK\n", @sock.gets
2826
+
2827
+ @sock.puts 'seekid 99 10'
2828
+ assert_equal "ACK [50@0] {seekid} song id doesn't exist: \"99\"\n", @sock.gets
2829
+
2830
+ @sock.puts 'seekid -1 10'
2831
+ assert_equal "ACK [50@0] {seekid} song id doesn't exist: \"-1\"\n", @sock.gets
2832
+
2833
+ @sock.puts 'seekid 7 40'
2834
+ assert_equal "OK\n", @sock.gets
2835
+
2836
+ sleep 4
2837
+
2838
+ @sock.puts 'status'
2839
+ status = build_hash get_response
2840
+ assert_equal 12, status.size
2841
+ assert_equal 'play', status['state']
2842
+ assert_equal '0', status['song']
2843
+ assert_equal '7', status['songid']
2844
+ assert_not_nil status['time']
2845
+ assert 40 < status['time'].to_i
2846
+ assert 55 > status['time'].to_i
2847
+
2848
+ @sock.puts 'pause 1'
2849
+ assert_equal "OK\n", @sock.gets
2850
+
2851
+ sleep 2
2852
+
2853
+ @sock.puts 'seekid 11 100'
2854
+ assert_equal "OK\n", @sock.gets
2855
+
2856
+ sleep 2
2857
+
2858
+ @sock.puts 'status'
2859
+ status = build_hash get_response
2860
+ assert_equal 12, status.size
2861
+ assert_equal 'pause', status['state']
2862
+ assert_equal '4', status['song']
2863
+ assert_equal '11', status['songid']
2864
+ assert_equal 100, status['time'].to_i
2865
+
2866
+ @sock.puts 'pause 0'
2867
+ assert_equal "OK\n", @sock.gets
2868
+
2869
+ sleep 2
2870
+
2871
+ @sock.puts 'seekid 13 200'
2872
+ assert_equal "OK\n", @sock.gets
2873
+
2874
+ sleep 4
2875
+
2876
+ @sock.puts 'status'
2877
+ status = build_hash get_response
2878
+ assert_equal 12, status.size
2879
+ assert_equal 'play', status['state']
2880
+ assert_equal '6', status['song']
2881
+ assert_equal '13', status['songid']
2882
+ assert 200 < status['time'].to_i
2883
+ assert 215 > status['time'].to_i
2884
+
2885
+ @sock.puts 'seekid 9 10000'
2886
+ assert_equal "OK\n", @sock.gets
2887
+
2888
+ sleep 2
2889
+
2890
+ @sock.puts 'status'
2891
+ status = build_hash get_response
2892
+ assert_equal 12, status.size
2893
+ assert_equal 'play', status['state']
2894
+ assert_equal '3', status['song']
2895
+ assert_equal '10', status['songid']
2896
+ assert 10 > status['time'].to_i
2897
+
2898
+ @sock.puts 'seekid 14 10000'
2899
+ assert_equal "OK\n", @sock.gets
2900
+
2901
+ sleep 2
2902
+
2903
+ @sock.puts 'status'
2904
+ status = build_hash get_response
2905
+ assert_equal 7, status.size
2906
+ assert_equal 'stop', status['state']
2907
+
2908
+ @sock.puts 'seekid 9 -100'
2909
+ assert_equal "OK\n", @sock.gets
2910
+
2911
+ sleep 2
2912
+
2913
+ @sock.puts 'status'
2914
+ status = build_hash get_response
2915
+ assert_equal 12, status.size
2916
+ assert_equal 'play', status['state']
2917
+ assert_equal '2', status['song']
2918
+ assert_equal '9', status['songid']
2919
+ assert 5 > status['time'].to_i
2920
+ end
2921
+
2922
+ def test_setvol
2923
+ @sock.gets
2924
+
2925
+ # Test no args
2926
+ @sock.puts 'setvol'
2927
+ assert_equal "ACK [2@0] {setvol} wrong number of arguments for \"setvol\"\n", @sock.gets
2928
+
2929
+ # Test too many args
2930
+ @sock.puts 'setvol 1 2'
2931
+ assert_equal "ACK [2@0] {setvol} wrong number of arguments for \"setvol\"\n", @sock.gets
2932
+
2933
+ # Test arg not an int
2934
+ @sock.puts 'setvol a'
2935
+ assert_equal "ACK [2@0] {setvol} need an integer\n", @sock.gets
2936
+
2937
+ # Test correct arg
2938
+ @sock.puts 'setvol 0'
2939
+ assert_equal "OK\n", @sock.gets
2940
+
2941
+ @sock.puts 'status'
2942
+ status = build_hash get_response
2943
+ assert_equal '0', status['volume']
2944
+
2945
+ @sock.puts 'setvol 20'
2946
+ assert_equal "OK\n", @sock.gets
2947
+
2948
+ @sock.puts 'status'
2949
+ status = build_hash get_response
2950
+ assert_equal '20', status['volume']
2951
+
2952
+ @sock.puts 'setvol -30'
2953
+ assert_equal "OK\n", @sock.gets
2954
+
2955
+ @sock.puts 'status'
2956
+ status = build_hash get_response
2957
+ assert_equal '-30', status['volume']
2958
+ end
2959
+
2960
+ def test_shuffle
2961
+ @sock.gets
2962
+
2963
+ @sock.puts 'load Shpongle_-_Are_You_Shpongled'
2964
+ assert_equal "OK\n", @sock.gets
2965
+
2966
+ # Test args > 0
2967
+ @sock.puts 'shuffle 1'
2968
+ assert_equal "ACK [2@0] {shuffle} wrong number of arguments for \"shuffle\"\n", @sock.gets
2969
+
2970
+ @sock.puts 'playlist'
2971
+ reply = get_response
2972
+ lines = reply.split "\n"
2973
+ assert_equal 7, lines.size
2974
+ assert_equal "0:Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg", lines[0]
2975
+ assert_equal "1:Shpongle/Are_You_Shpongled/2.Monster_Hit.ogg", lines[1]
2976
+
2977
+ @sock.puts 'shuffle 1 2'
2978
+ assert_equal "ACK [2@0] {shuffle} wrong number of arguments for \"shuffle\"\n", @sock.gets
2979
+
2980
+ @sock.puts 'playlist'
2981
+ reply = get_response
2982
+ lines = reply.split "\n"
2983
+ assert_equal 7, lines.size
2984
+ assert_equal "0:Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg", lines[0]
2985
+ assert_equal "1:Shpongle/Are_You_Shpongled/2.Monster_Hit.ogg", lines[1]
2986
+
2987
+ # Test correct usage
2988
+ @sock.puts 'shuffle'
2989
+ assert_equal "OK\n", @sock.gets
2990
+
2991
+ @sock.puts 'playlist'
2992
+ reply = get_response
2993
+ lines = reply.split "\n"
2994
+ assert_equal 7, lines.size
2995
+ assert_equal "0:Shpongle/Are_You_Shpongled/7...._and_the_Day_Turned_to_Night.ogg", lines[0]
2996
+ assert_equal "1:Shpongle/Are_You_Shpongled/6.Divine_Moments_of_Truth.ogg", lines[1]
2997
+ end
2998
+
2999
+ def test_stats
3000
+ @sock.gets
3001
+
3002
+ # Test args > 0
3003
+ @sock.puts 'stats 1'
3004
+ assert_equal "ACK [2@0] {stats} wrong number of arguments for \"stats\"\n", @sock.gets
3005
+
3006
+ @sock.puts 'stats 1 2'
3007
+ assert_equal "ACK [2@0] {stats} wrong number of arguments for \"stats\"\n", @sock.gets
3008
+
3009
+ # Test correct usage
3010
+ @sock.puts 'stats'
3011
+ stats = build_hash get_response
3012
+ assert_equal 7, stats.size
3013
+ assert_equal '3', stats['artists']
3014
+ assert_equal '4', stats['albums']
3015
+ assert_equal '46', stats['songs']
3016
+ assert_equal '500', stats['uptime']
3017
+ assert_equal '18091', stats['db_playtime']
3018
+ assert_equal '1159418502', stats['db_update']
3019
+ assert_equal '10', stats['playtime']
3020
+ end
3021
+
3022
+ def test_status
3023
+ @sock.gets
3024
+
3025
+ # Test args > 0
3026
+ @sock.puts 'status 1'
3027
+ assert_equal "ACK [2@0] {status} wrong number of arguments for \"status\"\n", @sock.gets
3028
+
3029
+ @sock.puts 'status 1 2'
3030
+ assert_equal "ACK [2@0] {status} wrong number of arguments for \"status\"\n", @sock.gets
3031
+
3032
+ # Test correct usage
3033
+ @sock.puts 'status'
3034
+ status = build_hash get_response
3035
+ assert_equal 7, status.size
3036
+ assert_equal '0', status['volume']
3037
+ assert_equal '0', status['repeat']
3038
+ assert_equal '1', status['playlist']
3039
+ assert_equal '0', status['playlistlength']
3040
+ assert_equal 'stop', status['state']
3041
+
3042
+ @sock.puts 'load Astral_Projection_-_Dancing_Galaxy'
3043
+ assert_equal "OK\n", @sock.gets
3044
+
3045
+ @sock.puts 'setvol 50'
3046
+ assert_equal "OK\n", @sock.gets
3047
+
3048
+ @sock.puts 'status'
3049
+ status = build_hash get_response
3050
+ assert_equal 7, status.size
3051
+ assert_equal '50', status['volume']
3052
+
3053
+ @sock.puts 'repeat 1'
3054
+ assert_equal "OK\n", @sock.gets
3055
+
3056
+ @sock.puts 'status'
3057
+ status = build_hash get_response
3058
+ assert_equal 7, status.size
3059
+ assert_equal '50', status['volume']
3060
+ assert_equal '1', status['repeat']
3061
+
3062
+ @sock.puts 'play'
3063
+ assert_equal "OK\n", @sock.gets
3064
+
3065
+ sleep 2
3066
+
3067
+ @sock.puts 'status'
3068
+ status = build_hash get_response
3069
+ assert_equal 12, status.size
3070
+ assert_equal 'play', status['state']
3071
+ assert_equal '0', status['song']
3072
+ assert_equal '7', status['songid']
3073
+ assert_not_nil status['time']
3074
+ assert_equal '192', status['bitrate']
3075
+ assert_equal '44100:16:2', status['audio']
3076
+
3077
+ @sock.puts 'pause 1'
3078
+ assert_equal "OK\n", @sock.gets
3079
+
3080
+ sleep 2
3081
+
3082
+ @sock.puts 'status'
3083
+ status = build_hash get_response
3084
+ assert_equal 12, status.size
3085
+ assert_equal 'pause', status['state']
3086
+ assert_equal '0', status['song']
3087
+ assert_equal '7', status['songid']
3088
+ assert_not_nil status['time']
3089
+ assert_equal '192', status['bitrate']
3090
+ assert_equal '44100:16:2', status['audio']
3091
+ time = status['time']
3092
+
3093
+ sleep 5
3094
+
3095
+ @sock.puts 'status'
3096
+ status = build_hash get_response
3097
+ assert_equal 12, status.size
3098
+ assert_equal time, status['time']
3099
+ assert_equal '0', status['song']
3100
+ assert_equal '7', status['songid']
3101
+
3102
+ @sock.puts 'pause 0'
3103
+ assert_equal "OK\n", @sock.gets
3104
+
3105
+ sleep 2
3106
+
3107
+ @sock.puts 'status'
3108
+ status = build_hash get_response
3109
+ assert_equal 12, status.size
3110
+ assert_equal 'play', status['state']
3111
+
3112
+ @sock.puts 'stop'
3113
+ assert_equal "OK\n", @sock.gets
3114
+
3115
+ sleep 2
3116
+
3117
+ @sock.puts 'status'
3118
+ status = build_hash get_response
3119
+ assert_equal 9, status.size
3120
+ assert_equal 'stop', status['state']
3121
+ assert_equal '0', status['song']
3122
+ assert_equal '7', status['songid']
3123
+ assert_nil status['time']
3124
+ assert_nil status['bitrate']
3125
+ assert_nil status['audio']
3126
+ end
3127
+
3128
+ def test_stop
3129
+ @sock.gets
3130
+
3131
+ @sock.puts 'load Astral_Projection_-_Dancing_Galaxy'
3132
+ assert_equal "OK\n", @sock.gets
3133
+
3134
+ @sock.puts 'play'
3135
+ assert_equal "OK\n", @sock.gets
3136
+
3137
+ sleep 2
3138
+
3139
+ @sock.puts 'status'
3140
+ status = build_hash get_response
3141
+ assert_equal 12, status.size
3142
+ assert_equal 'play', status['state']
3143
+ assert_equal '0', status['song']
3144
+ assert_equal '7', status['songid']
3145
+ assert_not_nil status['time']
3146
+ assert_equal '192', status['bitrate']
3147
+ assert_equal '44100:16:2', status['audio']
3148
+
3149
+ # Test too many args
3150
+ @sock.puts 'stop 1'
3151
+ assert_equal "ACK [2@0] {stop} wrong number of arguments for \"stop\"\n", @sock.gets
3152
+
3153
+ sleep 2
3154
+
3155
+ @sock.puts 'status'
3156
+ status = build_hash get_response
3157
+ assert_equal 12, status.size
3158
+ assert_equal 'play', status['state']
3159
+ assert_equal '0', status['song']
3160
+ assert_equal '7', status['songid']
3161
+
3162
+ @sock.puts 'stop'
3163
+ assert_equal "OK\n", @sock.gets
3164
+
3165
+ sleep 2
3166
+
3167
+ @sock.puts 'status'
3168
+ status = build_hash get_response
3169
+ assert_equal 9, status.size
3170
+ assert_equal 'stop', status['state']
3171
+ assert_equal '0', status['song']
3172
+ assert_equal '7', status['songid']
3173
+ end
3174
+
3175
+ def test_swap
3176
+ @sock.gets
3177
+
3178
+ # Test args = 0
3179
+ @sock.puts 'swap'
3180
+ assert_equal "ACK [2@0] {swap} wrong number of arguments for \"swap\"\n", @sock.gets
3181
+
3182
+ # Test args > 2
3183
+ @sock.puts 'swap 1 2 3'
3184
+ assert_equal "ACK [2@0] {swap} wrong number of arguments for \"swap\"\n", @sock.gets
3185
+
3186
+ # Test args not int
3187
+ @sock.puts 'swap a 3'
3188
+ assert_equal "ACK [2@0] {swap} \"a\" is not a integer\n", @sock.gets
3189
+
3190
+ @sock.puts 'swap 1 b'
3191
+ assert_equal "ACK [2@0] {swap} \"b\" is not a integer\n", @sock.gets
3192
+
3193
+ @sock.puts 'load Astral_Projection_-_Dancing_Galaxy'
3194
+ assert_equal "OK\n", @sock.gets
3195
+
3196
+ # Test args out of bounds
3197
+ @sock.puts 'swap 99 5'
3198
+ assert_equal "ACK [50@0] {swap} song doesn't exist: \"99\"\n", @sock.gets
3199
+
3200
+ @sock.puts 'swap 1 99'
3201
+ assert_equal "ACK [50@0] {swap} song doesn't exist: \"99\"\n", @sock.gets
3202
+
3203
+ @sock.puts 'swap -1 4'
3204
+ assert_equal "ACK [50@0] {swap} song doesn't exist: \"-1\"\n", @sock.gets
3205
+
3206
+ @sock.puts 'swap 1 -4'
3207
+ assert_equal "ACK [50@0] {swap} song doesn't exist: \"-4\"\n", @sock.gets
3208
+
3209
+ @sock.puts 'swap 1 5'
3210
+ assert_equal "OK\n", @sock.gets
3211
+
3212
+ @sock.puts 'playlist'
3213
+ reply = get_response
3214
+ lines = reply.split "\n"
3215
+ assert_equal 8, lines.size
3216
+ assert_equal '0:Astral_Projection/Dancing_Galaxy/1.Dancing_Galaxy.ogg', lines[0]
3217
+ assert_equal '1:Astral_Projection/Dancing_Galaxy/6.Life_On_Mars.ogg', lines[1]
3218
+ assert_equal '2:Astral_Projection/Dancing_Galaxy/3.Flying_Into_A_Star.ogg', lines[2]
3219
+ assert_equal '3:Astral_Projection/Dancing_Galaxy/4.No_One_Ever_Dreams.ogg', lines[3]
3220
+ assert_equal '4:Astral_Projection/Dancing_Galaxy/5.Cosmic_Ascension_(ft._DJ_Jorg).ogg', lines[4]
3221
+ assert_equal '5:Astral_Projection/Dancing_Galaxy/2.Soundform.ogg', lines[5]
3222
+ assert_equal '6:Astral_Projection/Dancing_Galaxy/7.Liquid_Sun.ogg', lines[6]
3223
+ assert_equal '7:Astral_Projection/Dancing_Galaxy/8.Ambient_Galaxy_(Disco_Valley_Mix).ogg', lines[7]
3224
+
3225
+ @sock.puts 'swap 7 3'
3226
+ assert_equal "OK\n", @sock.gets
3227
+
3228
+ @sock.puts 'playlist'
3229
+ reply = get_response
3230
+ lines = reply.split "\n"
3231
+ assert_equal 8, lines.size
3232
+ assert_equal '0:Astral_Projection/Dancing_Galaxy/1.Dancing_Galaxy.ogg', lines[0]
3233
+ assert_equal '1:Astral_Projection/Dancing_Galaxy/6.Life_On_Mars.ogg', lines[1]
3234
+ assert_equal '2:Astral_Projection/Dancing_Galaxy/3.Flying_Into_A_Star.ogg', lines[2]
3235
+ assert_equal '3:Astral_Projection/Dancing_Galaxy/8.Ambient_Galaxy_(Disco_Valley_Mix).ogg', lines[3]
3236
+ assert_equal '4:Astral_Projection/Dancing_Galaxy/5.Cosmic_Ascension_(ft._DJ_Jorg).ogg', lines[4]
3237
+ assert_equal '5:Astral_Projection/Dancing_Galaxy/2.Soundform.ogg', lines[5]
3238
+ assert_equal '6:Astral_Projection/Dancing_Galaxy/7.Liquid_Sun.ogg', lines[6]
3239
+ assert_equal '7:Astral_Projection/Dancing_Galaxy/4.No_One_Ever_Dreams.ogg', lines[7]
3240
+
3241
+ @sock.puts 'swap 0 2'
3242
+ assert_equal "OK\n", @sock.gets
3243
+
3244
+ @sock.puts 'playlist'
3245
+ reply = get_response
3246
+ lines = reply.split "\n"
3247
+ assert_equal 8, lines.size
3248
+ assert_equal '0:Astral_Projection/Dancing_Galaxy/3.Flying_Into_A_Star.ogg', lines[0]
3249
+ assert_equal '1:Astral_Projection/Dancing_Galaxy/6.Life_On_Mars.ogg', lines[1]
3250
+ assert_equal '2:Astral_Projection/Dancing_Galaxy/1.Dancing_Galaxy.ogg', lines[2]
3251
+ assert_equal '3:Astral_Projection/Dancing_Galaxy/8.Ambient_Galaxy_(Disco_Valley_Mix).ogg', lines[3]
3252
+ end
3253
+
3254
+ def test_swapid
3255
+ @sock.gets
3256
+
3257
+ # Test args = 0
3258
+ @sock.puts 'swapid'
3259
+ assert_equal "ACK [2@0] {swapid} wrong number of arguments for \"swapid\"\n", @sock.gets
3260
+
3261
+ # Test args > 2
3262
+ @sock.puts 'swapid 1 2 3'
3263
+ assert_equal "ACK [2@0] {swapid} wrong number of arguments for \"swapid\"\n", @sock.gets
3264
+
3265
+ # Test args not int
3266
+ @sock.puts 'swapid a 3'
3267
+ assert_equal "ACK [2@0] {swapid} \"a\" is not a integer\n", @sock.gets
3268
+
3269
+ @sock.puts 'swapid 1 b'
3270
+ assert_equal "ACK [2@0] {swapid} \"b\" is not a integer\n", @sock.gets
3271
+
3272
+ @sock.puts 'load Astral_Projection_-_Dancing_Galaxy'
3273
+ assert_equal "OK\n", @sock.gets
3274
+
3275
+ # Test args out of bounds
3276
+ @sock.puts 'swapid 9999 7'
3277
+ assert_equal "ACK [50@0] {swapid} song id doesn't exist: \"9999\"\n", @sock.gets
3278
+
3279
+ @sock.puts 'swapid 7 9999'
3280
+ assert_equal "ACK [50@0] {swapid} song id doesn't exist: \"9999\"\n", @sock.gets
3281
+
3282
+ @sock.puts 'swapid -1 7'
3283
+ assert_equal "ACK [50@0] {swapid} song id doesn't exist: \"-1\"\n", @sock.gets
3284
+
3285
+ @sock.puts 'swapid 7 -4'
3286
+ assert_equal "ACK [50@0] {swapid} song id doesn't exist: \"-4\"\n", @sock.gets
3287
+
3288
+ @sock.puts 'swapid 8 12'
3289
+ assert_equal "OK\n", @sock.gets
3290
+
3291
+ @sock.puts 'playlist'
3292
+ reply = get_response
3293
+ lines = reply.split "\n"
3294
+ assert_equal 8, lines.size
3295
+ assert_equal '0:Astral_Projection/Dancing_Galaxy/1.Dancing_Galaxy.ogg', lines[0]
3296
+ assert_equal '1:Astral_Projection/Dancing_Galaxy/6.Life_On_Mars.ogg', lines[1]
3297
+ assert_equal '2:Astral_Projection/Dancing_Galaxy/3.Flying_Into_A_Star.ogg', lines[2]
3298
+ assert_equal '3:Astral_Projection/Dancing_Galaxy/4.No_One_Ever_Dreams.ogg', lines[3]
3299
+ assert_equal '4:Astral_Projection/Dancing_Galaxy/5.Cosmic_Ascension_(ft._DJ_Jorg).ogg', lines[4]
3300
+ assert_equal '5:Astral_Projection/Dancing_Galaxy/2.Soundform.ogg', lines[5]
3301
+ assert_equal '6:Astral_Projection/Dancing_Galaxy/7.Liquid_Sun.ogg', lines[6]
3302
+ assert_equal '7:Astral_Projection/Dancing_Galaxy/8.Ambient_Galaxy_(Disco_Valley_Mix).ogg', lines[7]
3303
+
3304
+ @sock.puts 'swapid 14 10'
3305
+ assert_equal "OK\n", @sock.gets
3306
+
3307
+ @sock.puts 'playlist'
3308
+ reply = get_response
3309
+ lines = reply.split "\n"
3310
+ assert_equal 8, lines.size
3311
+ assert_equal '0:Astral_Projection/Dancing_Galaxy/1.Dancing_Galaxy.ogg', lines[0]
3312
+ assert_equal '1:Astral_Projection/Dancing_Galaxy/6.Life_On_Mars.ogg', lines[1]
3313
+ assert_equal '2:Astral_Projection/Dancing_Galaxy/3.Flying_Into_A_Star.ogg', lines[2]
3314
+ assert_equal '3:Astral_Projection/Dancing_Galaxy/8.Ambient_Galaxy_(Disco_Valley_Mix).ogg', lines[3]
3315
+ assert_equal '4:Astral_Projection/Dancing_Galaxy/5.Cosmic_Ascension_(ft._DJ_Jorg).ogg', lines[4]
3316
+ assert_equal '5:Astral_Projection/Dancing_Galaxy/2.Soundform.ogg', lines[5]
3317
+ assert_equal '6:Astral_Projection/Dancing_Galaxy/7.Liquid_Sun.ogg', lines[6]
3318
+ assert_equal '7:Astral_Projection/Dancing_Galaxy/4.No_One_Ever_Dreams.ogg', lines[7]
3319
+
3320
+ @sock.puts 'swapid 7 9'
3321
+ assert_equal "OK\n", @sock.gets
3322
+
3323
+ @sock.puts 'playlist'
3324
+ reply = get_response
3325
+ lines = reply.split "\n"
3326
+ assert_equal 8, lines.size
3327
+ assert_equal '0:Astral_Projection/Dancing_Galaxy/3.Flying_Into_A_Star.ogg', lines[0]
3328
+ assert_equal '1:Astral_Projection/Dancing_Galaxy/6.Life_On_Mars.ogg', lines[1]
3329
+ assert_equal '2:Astral_Projection/Dancing_Galaxy/1.Dancing_Galaxy.ogg', lines[2]
3330
+ assert_equal '3:Astral_Projection/Dancing_Galaxy/8.Ambient_Galaxy_(Disco_Valley_Mix).ogg', lines[3]
3331
+ end
3332
+
3333
+ def test_update
3334
+ @sock.gets
3335
+
3336
+ @sock.puts 'update 1 2'
3337
+ assert_equal "ACK [2@0] {update} wrong number of arguments for \"update\"\n", @sock.gets
3338
+
3339
+ @sock.puts 'update a'
3340
+ assert_equal "updating_db: 1\n", @sock.gets
3341
+ assert_equal "OK\n", @sock.gets
3342
+
3343
+ @sock.puts 'status'
3344
+ status = build_hash get_response
3345
+ assert_equal 8, status.size
3346
+ assert_equal '1', status['updating_db']
3347
+
3348
+ @sock.puts 'status'
3349
+ status = build_hash get_response
3350
+ assert_equal 7, status.size
3351
+ assert_nil status['updating_db']
3352
+
3353
+ @sock.puts 'update'
3354
+ assert_equal "updating_db: 1\n", @sock.gets
3355
+ assert_equal "OK\n", @sock.gets
3356
+
3357
+ @sock.puts 'status'
3358
+ status = build_hash get_response
3359
+ assert_equal 8, status.size
3360
+ assert_equal '1', status['updating_db']
3361
+
3362
+ @sock.puts 'status'
3363
+ status = build_hash get_response
3364
+ assert_equal 7, status.size
3365
+ assert_nil status['updating_db']
3366
+ end
3367
+
3368
+ def test_volume
3369
+ @sock.gets
3370
+
3371
+ @sock.puts 'volume'
3372
+ assert_equal "ACK [2@0] {volume} wrong number of arguments for \"volume\"\n", @sock.gets
3373
+
3374
+ @sock.puts 'volume 1 2'
3375
+ assert_equal "ACK [2@0] {volume} wrong number of arguments for \"volume\"\n", @sock.gets
3376
+
3377
+ @sock.puts 'volume 30'
3378
+ assert_equal "OK\n", @sock.gets
3379
+
3380
+ @sock.puts 'status'
3381
+ status = build_hash get_response
3382
+ assert_equal '30', status['volume']
3383
+
3384
+ @sock.puts 'volume 10'
3385
+ assert_equal "OK\n", @sock.gets
3386
+
3387
+ @sock.puts 'status'
3388
+ status = build_hash get_response
3389
+ assert_equal '40', status['volume']
3390
+
3391
+ @sock.puts 'volume -15'
3392
+ assert_equal "OK\n", @sock.gets
3393
+
3394
+ @sock.puts 'status'
3395
+ status = build_hash get_response
3396
+ assert_equal '25', status['volume']
3397
+
3398
+ @sock.puts 'volume 0'
3399
+ assert_equal "OK\n", @sock.gets
3400
+
3401
+ @sock.puts 'status'
3402
+ status = build_hash get_response
3403
+ assert_equal '25', status['volume']
3404
+ end
3405
+ end