librmpd 0.1.0

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