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.
data/tests/libtests.rb ADDED
@@ -0,0 +1,1146 @@
1
+ #
2
+ # Unit tests for librmpd
3
+ #
4
+ # This uses the included mpdserver.rb test server
5
+
6
+ require 'rubygems'
7
+ require 'librmpd'
8
+ require 'mpdserver'
9
+ require 'test/unit'
10
+
11
+ class MPDTester < Test::Unit::TestCase
12
+
13
+ def setup
14
+ begin
15
+ @port = 9393
16
+ @server = MPDTestServer.new @port
17
+ @server.start
18
+ rescue Errno::EADDRINUSE
19
+ @port = 9494
20
+ @server = MPDTestServer.new @port
21
+ @server.start
22
+ end
23
+ @mpd = MPD.new 'localhost', @port
24
+ end
25
+
26
+ def teardown
27
+ @mpd.disconnect
28
+ @server.stop
29
+ end
30
+
31
+ def test_connect
32
+ ret = @mpd.connect
33
+ assert_match /OK MPD [0-9.]*\n/, ret
34
+ end
35
+
36
+ def test_connected?
37
+ # test a good connection
38
+ @mpd.connect
39
+ assert @mpd.connected?
40
+
41
+ # Test a disconnect
42
+ @server.stop
43
+ assert !@mpd.connected?
44
+
45
+ # test a bad connection
46
+ bad = MPD.new 'no-connection', 6600
47
+ assert !bad.connected?
48
+ end
49
+
50
+ def test_disconnect
51
+ # test a good connection
52
+ @mpd.connect
53
+ assert @mpd.connected?
54
+ @mpd.disconnect
55
+ assert !@mpd.connected?
56
+ @mpd.disconnect
57
+ assert !@mpd.connected?
58
+
59
+ # test a bad connection
60
+ bad = MPD.new 'no-connection'
61
+ bad.disconnect
62
+ assert !bad.connected?
63
+ end
64
+
65
+ def test_add
66
+ @mpd.connect
67
+ assert @mpd.connected?
68
+
69
+ assert @mpd.add('Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg')
70
+
71
+ pls = @mpd.playlist
72
+ assert_equal 1, pls.size
73
+ assert_equal 'Shpongle', pls[0].artist
74
+ assert_equal 'Are You Shpongled?', pls[0].album
75
+ assert_equal 'Shpongle Falls', pls[0].title
76
+
77
+ assert_raise(RuntimeError) {@mpd.add('Does/Not/Exist')}
78
+
79
+ @mpd.disconnect
80
+ assert_raise(RuntimeError) {@mpd.add('Shpongle')}
81
+ end
82
+
83
+ def test_clear
84
+ @mpd.connect
85
+ assert @mpd.connected?
86
+
87
+ assert @mpd.add('Shpongle')
88
+
89
+ pls = @mpd.playlist
90
+ assert_equal 27, pls.size
91
+
92
+ assert @mpd.clear
93
+
94
+ pls = @mpd.playlist
95
+ assert_equal 0, pls.size
96
+
97
+ @mpd.disconnect
98
+ assert_raise(RuntimeError) {@mpd.clear}
99
+ end
100
+
101
+ def test_clearerror
102
+ @mpd.connect
103
+ assert @mpd.connected?
104
+
105
+ assert @mpd.clearerror
106
+
107
+ @mpd.disconnect
108
+ assert_raise(RuntimeError) {@mpd.clearerror}
109
+ end
110
+
111
+ def test_crossfade
112
+ @mpd.connect
113
+
114
+ @mpd.crossfade = 40
115
+
116
+ assert_equal 40, @mpd.crossfade
117
+ assert_equal '40', @mpd.status['xfade']
118
+
119
+ @mpd.disconnect
120
+ assert_raise(RuntimeError) {@mpd.crossfade = 20}
121
+ assert_raise(RuntimeError) {@mpd.crossfade}
122
+ end
123
+
124
+ def test_current_song
125
+ @mpd.connect
126
+
127
+ s = @mpd.current_song
128
+ assert_nil s
129
+
130
+ assert @mpd.add('Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg')
131
+
132
+ assert @mpd.play
133
+
134
+ sleep 2
135
+
136
+ assert @mpd.playing?
137
+
138
+ s = @mpd.current_song
139
+
140
+ assert_equal 'Shpongle', s.artist
141
+ assert_equal 'Are You Shpongled?', s.album
142
+ assert_equal 'Shpongle Falls', s.title
143
+ assert_equal '1', s.track
144
+
145
+ @mpd.stop
146
+
147
+ sleep 2
148
+
149
+ assert !@mpd.playing?
150
+
151
+ s = @mpd.current_song
152
+
153
+ assert_equal 'Shpongle', s.artist
154
+ assert_equal 'Are You Shpongled?', s.album
155
+ assert_equal 'Shpongle Falls', s.title
156
+ assert_equal '1', s.track
157
+
158
+ @mpd.disconnect
159
+ assert_raise(RuntimeError) {@mpd.current_song}
160
+ end
161
+
162
+ def test_delete
163
+ @mpd.connect
164
+
165
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
166
+
167
+ assert @mpd.delete(3)
168
+
169
+ pls = @mpd.playlist
170
+ assert_equal 7, pls.size
171
+ pls.each do |song|
172
+ assert_not_equal 'No On Ever Dreams', song.title
173
+ end
174
+
175
+ assert_raise(RuntimeError) {@mpd.delete(999)}
176
+
177
+ @mpd.disconnect
178
+ assert_raise(RuntimeError) {@mpd.delete(3)}
179
+ end
180
+
181
+ def test_deleteid
182
+ @mpd.connect
183
+
184
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
185
+
186
+ assert @mpd.deleteid(10)
187
+
188
+ pls = @mpd.playlist
189
+ assert_equal 7, pls.size
190
+ pls.each do |song|
191
+ assert_not_equal 'No One Ever Dreams', song.title
192
+ end
193
+
194
+ assert_raise(RuntimeError) {@mpd.deleteid(999)}
195
+
196
+ @mpd.disconnect
197
+ assert_raise(RuntimeError) {@mpd.deleteid(11)}
198
+ end
199
+
200
+ def test_find
201
+ @mpd.connect
202
+
203
+ a = @mpd.find 'album', 'Are You Shpongled?'
204
+ assert_equal 7, a.size
205
+ assert_equal 'Shpongle Falls', a[0].title
206
+ assert_equal 'Monster Hit', a[1].title
207
+ assert_equal 'Vapour Rumours', a[2].title
208
+ assert_equal 'Shpongle Spores', a[3].title
209
+ assert_equal 'Behind Closed Eyelids', a[4].title
210
+ assert_equal 'Divine Moments of Truth', a[5].title
211
+ assert_equal '... and the Day Turned to Night', a[6].title
212
+
213
+ b = @mpd.find 'artist', 'Carbon Based Lifeforms'
214
+ assert_equal 11, b.size
215
+ assert_equal 'Central Plains', b[0].title
216
+ assert_equal 'Tensor', b[1].title
217
+ assert_equal 'MOS 6581 (Album Version)', b[2].title
218
+ assert_equal 'Silent Running', b[3].title
219
+ assert_equal 'Neurotransmitter', b[4].title
220
+ assert_equal 'Hydroponic Garden', b[5].title
221
+ assert_equal 'Exosphere', b[6].title
222
+ assert_equal 'Comsat', b[7].title
223
+ assert_equal 'Epicentre (First Movement)', b[8].title
224
+ assert_equal 'Artificial Island', b[9].title
225
+ assert_equal 'Refraction 1.33', b[10].title
226
+
227
+ c = @mpd.find 'title', 'Silent Running'
228
+ assert_equal 1, c.size
229
+ assert_equal 'Silent Running', c[0].title
230
+
231
+ d = @mpd.find 'artist', 'no artist'
232
+ assert_equal 0, d.size
233
+
234
+ assert_raise(RuntimeError) {@mpd.find('error', 'no-such')}
235
+
236
+ @mpd.disconnect
237
+ assert_raise(RuntimeError) {@mpd.find('album', 'Are You Shpongled')}
238
+ end
239
+
240
+ def test_kill
241
+ @mpd.connect
242
+
243
+ assert @mpd.kill
244
+
245
+ assert !@mpd.connected?
246
+
247
+ assert_raise(RuntimeError) {@mpd.kill}
248
+ end
249
+
250
+ def test_albums
251
+ @mpd.connect
252
+
253
+ albums = @mpd.albums
254
+
255
+ assert_equal 4, albums.size
256
+ assert_equal 'Are You Shpongled?', albums[0]
257
+ assert_equal 'Dancing Galaxy', albums[1]
258
+ assert_equal 'Hydroponic Garden', albums[2]
259
+ assert_equal 'Nothing Lasts... But Nothing Is Lost', albums[3]
260
+
261
+ sh = @mpd.albums 'Shpongle'
262
+
263
+ assert_equal 2, sh.size
264
+ assert_equal 'Are You Shpongled?', sh[0]
265
+ assert_equal 'Nothing Lasts... But Nothing Is Lost', sh[1]
266
+
267
+ @mpd.disconnect
268
+ assert_raise(RuntimeError) {@mpd.albums}
269
+ end
270
+
271
+ def test_artists
272
+ @mpd.connect
273
+
274
+ artists = @mpd.artists
275
+
276
+ assert_equal 3, artists.size
277
+ assert_equal 'Astral Projection', artists[0]
278
+ assert_equal 'Carbon Based Lifeforms', artists[1]
279
+ assert_equal 'Shpongle', artists[2]
280
+
281
+ @mpd.disconnect
282
+ assert_raise(RuntimeError) {@mpd.artists}
283
+ end
284
+
285
+ def test_list
286
+ @mpd.connect
287
+
288
+ albums = @mpd.list 'album'
289
+
290
+ assert_equal 4, albums.size
291
+ assert_equal 'Are You Shpongled?', albums[0]
292
+ assert_equal 'Dancing Galaxy', albums[1]
293
+ assert_equal 'Hydroponic Garden', albums[2]
294
+ assert_equal 'Nothing Lasts... But Nothing Is Lost', albums[3]
295
+
296
+ artists = @mpd.list 'artist'
297
+
298
+ assert_equal 3, artists.size
299
+ assert_equal 'Astral Projection', artists[0]
300
+ assert_equal 'Carbon Based Lifeforms', artists[1]
301
+ assert_equal 'Shpongle', artists[2]
302
+
303
+ arg = @mpd.list 'album', 'Shpongle'
304
+
305
+ assert_equal 2, arg.size
306
+ assert_equal 'Are You Shpongled?', arg[0]
307
+ assert_equal 'Nothing Lasts... But Nothing Is Lost', arg[1]
308
+
309
+ assert_raise(RuntimeError) {@mpd.list('fail')}
310
+ assert_raise(RuntimeError) {@mpd.list('fail', 'Shpongle')}
311
+
312
+ @mpd.disconnect
313
+ assert_raise(RuntimeError) {@mpd.artists}
314
+ end
315
+
316
+ def test_directories
317
+ @mpd.connect
318
+
319
+ dirs = @mpd.directories
320
+
321
+ assert_equal 7, dirs.size
322
+ assert_equal 'Astral_Projection', dirs[0]
323
+ assert_equal 'Astral_Projection/Dancing_Galaxy', dirs[1]
324
+ assert_equal 'Carbon_Based_Lifeforms', dirs[2]
325
+ assert_equal 'Carbon_Based_Lifeforms/Hydroponic_Garden', dirs[3]
326
+ assert_equal 'Shpongle', dirs[4]
327
+ assert_equal 'Shpongle/Are_You_Shpongled', dirs[5]
328
+ assert_equal 'Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost', dirs[6]
329
+
330
+ shpongle = @mpd.directories 'Shpongle'
331
+
332
+ assert_equal 3, shpongle.size
333
+ assert_equal 'Shpongle', shpongle[0]
334
+ assert_equal 'Shpongle/Are_You_Shpongled', shpongle[1]
335
+ assert_equal 'Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost', shpongle[2]
336
+
337
+ assert_raise(RuntimeError) {@mpd.directories('no-dirs')}
338
+
339
+ @mpd.disconnect
340
+ assert_raise(RuntimeError) {@mpd.directories}
341
+ end
342
+
343
+ def test_files
344
+ @mpd.connect
345
+
346
+ files = @mpd.files
347
+
348
+ assert_equal 46, files.size
349
+
350
+ assert_equal 'Astral_Projection/Dancing_Galaxy/1.Dancing_Galaxy.ogg', files[0]
351
+ assert_equal 'Astral_Projection/Dancing_Galaxy/8.Ambient_Galaxy_(Disco_Valley_Mix).ogg', files[7]
352
+ assert_equal 'Carbon_Based_Lifeforms/Hydroponic_Garden/01.Central_Plains.ogg', files[8]
353
+ assert_equal 'Carbon_Based_Lifeforms/Hydroponic_Garden/11.Refraction_1.33.ogg', files[18]
354
+ assert_equal 'Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg', files[19]
355
+ assert_equal 'Shpongle/Are_You_Shpongled/7...._and_the_Day_Turned_to_Night.ogg', files[25]
356
+ assert_equal 'Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/01.Botanical_Dimensions.ogg', files[26]
357
+ assert_equal 'Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/20.Falling_Awake.ogg', files[45]
358
+
359
+ sh = @mpd.files 'Shpongle'
360
+
361
+ assert_equal 27, sh.size
362
+
363
+ assert_equal 'Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg', sh[0]
364
+ assert_equal 'Shpongle/Are_You_Shpongled/7...._and_the_Day_Turned_to_Night.ogg', sh[6]
365
+ assert_equal 'Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/01.Botanical_Dimensions.ogg', sh[7]
366
+ assert_equal 'Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/20.Falling_Awake.ogg', sh[26]
367
+
368
+ assert_raise(RuntimeError) {@mpd.files('no-files')}
369
+
370
+ @mpd.disconnect
371
+ assert_raise(RuntimeError) {@mpd.files}
372
+ end
373
+
374
+ def test_playlists
375
+ @mpd.connect
376
+
377
+ pls = @mpd.playlists
378
+
379
+ assert_equal 2, pls.size
380
+
381
+ assert_equal 'Shpongle_-_Are_You_Shpongled', pls[0]
382
+ assert_equal 'Astral_Projection_-_Dancing_Galaxy', pls[1]
383
+
384
+ @mpd.disconnect
385
+ assert_raise(RuntimeError) {@mpd.playlists}
386
+ end
387
+
388
+ def test_songs
389
+ @mpd.connect
390
+
391
+ songs = @mpd.songs
392
+
393
+ assert_equal 46, songs.size
394
+
395
+ assert_equal 'Dancing Galaxy', songs[0].title
396
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', songs[7].title
397
+ assert_equal 'Central Plains', songs[8].title
398
+ assert_equal 'Refraction 1.33', songs[18].title
399
+ assert_equal 'Shpongle Falls', songs[19].title
400
+ assert_equal '... and the Day Turned to Night', songs[25].title
401
+ assert_equal 'Botanical Dimensions', songs[26].title
402
+ assert_equal 'Falling Awake', songs[45].title
403
+
404
+ sh = @mpd.songs 'Shpongle'
405
+
406
+ assert_equal 27, sh.size
407
+
408
+ sh.each do |s|
409
+ assert_equal 'Shpongle', s.artist
410
+ end
411
+
412
+ assert_equal 'Shpongle Falls', sh[0].title
413
+ assert_equal '... and the Day Turned to Night', sh[6].title
414
+ assert_equal 'Botanical Dimensions', sh[7].title
415
+ assert_equal 'Falling Awake', sh[26].title
416
+
417
+ assert_raise(RuntimeError) {@mpd.songs('no-songs')}
418
+
419
+ @mpd.disconnect
420
+ assert_raise(RuntimeError) {@mpd.songs}
421
+ end
422
+
423
+ def test_songs_by_artist
424
+ @mpd.connect
425
+
426
+ songs = @mpd.songs_by_artist 'Shpongle'
427
+
428
+ assert_equal 27, songs.size
429
+
430
+ songs.each do |s|
431
+ assert_equal 'Shpongle', s.artist
432
+ end
433
+
434
+ assert_equal 'Shpongle Falls', songs[0].title
435
+ assert_equal '... and the Day Turned to Night', songs[6].title
436
+ assert_equal 'Botanical Dimensions', songs[7].title
437
+ assert_equal 'Falling Awake', songs[26].title
438
+
439
+ songs = @mpd.songs_by_artist 'no-songs'
440
+ assert_equal 0, songs.size
441
+
442
+ @mpd.disconnect
443
+ assert_raise(RuntimeError) {@mpd.songs_by_artist('Shpongle')}
444
+ end
445
+
446
+ def test_load
447
+ @mpd.connect
448
+
449
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
450
+
451
+ pls = @mpd.playlist
452
+
453
+ assert_equal 8, pls.size
454
+
455
+ pls.each do |song|
456
+ assert_equal 'Astral Projection', song.artist
457
+ assert_equal 'Dancing Galaxy', song.album
458
+ end
459
+
460
+ assert_equal 'Dancing Galaxy', pls[0].title
461
+ assert_equal 'Soundform', pls[1].title
462
+ assert_equal 'Flying Into A Star', pls[2].title
463
+ assert_equal 'No One Ever Dreams', pls[3].title
464
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[4].title
465
+ assert_equal 'Life On Mars', pls[5].title
466
+ assert_equal 'Liquid Sun', pls[6].title
467
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[7].title
468
+
469
+ assert_raise(RuntimeError) {@mpd.load('No-PLS')}
470
+
471
+ @mpd.disconnect
472
+ assert_raise(RuntimeError) {@mpd.load('Astral_Projection_-_Dancing_Galaxy')}
473
+ end
474
+
475
+ def test_move
476
+ @mpd.connect
477
+
478
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
479
+
480
+ assert @mpd.move( 3, 1 )
481
+
482
+ pls = @mpd.playlist
483
+
484
+ assert_equal 'Dancing Galaxy', pls[0].title
485
+ assert_equal 'No One Ever Dreams', pls[1].title
486
+ assert_equal 'Soundform', pls[2].title
487
+ assert_equal 'Flying Into A Star', pls[3].title
488
+
489
+ assert @mpd.move( 2, 7 )
490
+
491
+ pls = @mpd.playlist
492
+
493
+ assert_equal 'No One Ever Dreams', pls[1].title
494
+ assert_equal 'Flying Into A Star', pls[2].title
495
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[3].title
496
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[6].title
497
+ assert_equal 'Soundform', pls[7].title
498
+
499
+ assert_raise(RuntimeError) {@mpd.move(999,1)}
500
+
501
+ @mpd.disconnect
502
+ assert_raise(RuntimeError) {@mpd.move(3,1)}
503
+ end
504
+
505
+ def test_moveid
506
+ @mpd.connect
507
+
508
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
509
+
510
+ assert @mpd.moveid( 10, 1 )
511
+
512
+ pls = @mpd.playlist
513
+
514
+ assert_equal 'Dancing Galaxy', pls[0].title
515
+ assert_equal 'No One Ever Dreams', pls[1].title
516
+ assert_equal 'Soundform', pls[2].title
517
+ assert_equal 'Flying Into A Star', pls[3].title
518
+
519
+ assert @mpd.moveid( 8, 7 )
520
+
521
+ pls = @mpd.playlist
522
+
523
+ assert_equal 'No One Ever Dreams', pls[1].title
524
+ assert_equal 'Flying Into A Star', pls[2].title
525
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[3].title
526
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[6].title
527
+ assert_equal 'Soundform', pls[7].title
528
+
529
+ assert_raise(RuntimeError) {@mpd.moveid(999,1)}
530
+
531
+ @mpd.disconnect
532
+ assert_raise(RuntimeError) {@mpd.moveid(10,1)}
533
+
534
+ end
535
+
536
+ def test_next
537
+ @mpd.connect
538
+
539
+ @mpd.load 'Astral_Projection_-_Dancing_Galaxy'
540
+
541
+ @mpd.play 3
542
+
543
+ pos = @mpd.status['song'].to_i
544
+
545
+ assert @mpd.next
546
+
547
+ assert_equal pos + 1, @mpd.status['song'].to_i
548
+
549
+ @mpd.disconnect
550
+ assert_raise(RuntimeError) {@mpd.next}
551
+ end
552
+
553
+ def test_pause
554
+ @mpd.connect
555
+ assert @mpd.connected?
556
+
557
+ @mpd.load 'Astral_Projection_-_Dancing_Galaxy'
558
+
559
+ assert @mpd.play
560
+ assert @mpd.playing?
561
+
562
+ @mpd.pause = true
563
+ assert @mpd.paused?
564
+
565
+ @mpd.pause = false
566
+ assert !@mpd.paused?
567
+
568
+ assert @mpd.stop
569
+ assert @mpd.stopped?
570
+
571
+ @mpd.pause = true
572
+ assert @mpd.stopped?
573
+
574
+ assert !@mpd.paused?
575
+
576
+ @mpd.disconnect
577
+ assert_raise(RuntimeError) {@mpd.pause = true}
578
+ assert_raise(RuntimeError) {@mpd.paused?}
579
+ end
580
+
581
+ def test_password
582
+ @mpd.connect
583
+
584
+ assert_raise(RuntimeError) {@mpd.password('wrong')}
585
+
586
+ assert @mpd.password('test')
587
+
588
+ @mpd.disconnect
589
+ assert_raise(RuntimeError) {@mpd.password('test')}
590
+ end
591
+
592
+ def test_ping
593
+ @mpd.connect
594
+
595
+ assert @mpd.ping
596
+
597
+ @mpd.disconnect
598
+ assert_raise(RuntimeError) {@mpd.ping}
599
+ end
600
+
601
+ def test_play
602
+ @mpd.connect
603
+ assert @mpd.connected?
604
+
605
+ @mpd.load 'Astral_Projection_-_Dancing_Galaxy'
606
+
607
+ assert @mpd.play
608
+
609
+ sleep 2
610
+
611
+ assert @mpd.playing?
612
+
613
+ song = @mpd.current_song
614
+
615
+ assert_equal 'Dancing Galaxy', song.title
616
+
617
+ assert @mpd.play(2)
618
+
619
+ sleep 2
620
+
621
+ assert @mpd.playing?
622
+
623
+ song = @mpd.current_song
624
+
625
+ assert_equal 'Flying Into A Star', song.title
626
+
627
+ @mpd.disconnect
628
+ assert_raise(RuntimeError) {@mpd.play}
629
+ assert_raise(RuntimeError) {@mpd.playing?}
630
+ end
631
+
632
+ def test_playid
633
+ @mpd.connect
634
+ assert @mpd.connected?
635
+
636
+ @mpd.load 'Astral_Projection_-_Dancing_Galaxy'
637
+
638
+ assert @mpd.playid
639
+
640
+ sleep 2
641
+
642
+ assert @mpd.playing?
643
+
644
+ song = @mpd.current_song
645
+
646
+ assert_equal 'Dancing Galaxy', song.title
647
+
648
+ assert @mpd.playid(9)
649
+
650
+ sleep 2
651
+
652
+ assert @mpd.playing?
653
+
654
+ song = @mpd.current_song
655
+
656
+ assert_equal 'Flying Into A Star', song.title
657
+
658
+ @mpd.disconnect
659
+ assert_raise(RuntimeError) {@mpd.playid}
660
+ assert_raise(RuntimeError) {@mpd.playing?}
661
+
662
+ end
663
+
664
+ def test_playlist_version
665
+ @mpd.connect
666
+
667
+ ver = @mpd.playlist_version
668
+
669
+ assert_equal 1, ver
670
+
671
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
672
+
673
+ ver = @mpd.playlist_version
674
+
675
+ assert_equal 9, ver
676
+
677
+ @mpd.disconnect
678
+ assert_raise(RuntimeError) {@mpd.playlist_version}
679
+ end
680
+
681
+ def test_playlist
682
+ @mpd.connect
683
+
684
+ pls = @mpd.playlist
685
+
686
+ assert_equal 0, pls.size
687
+
688
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
689
+
690
+ pls = @mpd.playlist
691
+
692
+ assert_equal 8, pls.size
693
+
694
+ assert_equal 'Dancing Galaxy', pls[0].title
695
+ assert_equal 'Soundform', pls[1].title
696
+ assert_equal 'Flying Into A Star', pls[2].title
697
+ assert_equal 'No One Ever Dreams', pls[3].title
698
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[4].title
699
+ assert_equal 'Life On Mars', pls[5].title
700
+ assert_equal 'Liquid Sun', pls[6].title
701
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[7].title
702
+
703
+ @mpd.disconnect
704
+ assert_raise(RuntimeError) {@mpd.playlist}
705
+ end
706
+
707
+ def test_song_at_pos
708
+ @mpd.connect
709
+
710
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
711
+
712
+ assert_equal 'Dancing Galaxy', @mpd.song_at_pos(0).title
713
+ assert_equal 'Soundform', @mpd.song_at_pos(1).title
714
+ assert_equal 'Flying Into A Star', @mpd.song_at_pos(2).title
715
+ assert_equal 'No One Ever Dreams', @mpd.song_at_pos(3).title
716
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', @mpd.song_at_pos(4).title
717
+ assert_equal 'Life On Mars', @mpd.song_at_pos(5).title
718
+ assert_equal 'Liquid Sun', @mpd.song_at_pos(6).title
719
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', @mpd.song_at_pos(7).title
720
+
721
+ assert_raise(RuntimeError) {@mpd.song_at_pos(999)}
722
+
723
+ @mpd.disconnect
724
+ assert_raise(RuntimeError) {@mpd.song_at_pos(0)}
725
+ end
726
+
727
+ def test_song_with_id
728
+ @mpd.connect
729
+
730
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
731
+
732
+ assert_equal 'Dancing Galaxy', @mpd.song_with_id(7).title
733
+ assert_equal 'Soundform', @mpd.song_with_id(8).title
734
+ assert_equal 'Flying Into A Star', @mpd.song_with_id(9).title
735
+ assert_equal 'No One Ever Dreams', @mpd.song_with_id(10).title
736
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', @mpd.song_with_id(11).title
737
+ assert_equal 'Life On Mars', @mpd.song_with_id(12).title
738
+ assert_equal 'Liquid Sun', @mpd.song_with_id(13).title
739
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', @mpd.song_with_id(14).title
740
+
741
+ assert_raise(RuntimeError) {@mpd.song_with_id(999)}
742
+
743
+ @mpd.disconnect
744
+ assert_raise(RuntimeError) {@mpd.song_with_id(10)}
745
+ end
746
+
747
+ def test_playlist_changes
748
+ @mpd.connect
749
+
750
+ assert @mpd.add('Astral_Projection')
751
+
752
+ changes = @mpd.playlist_changes 8
753
+
754
+ assert_equal 1, changes.size
755
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', changes[0].title
756
+
757
+ changes = @mpd.playlist_changes 1
758
+
759
+ assert_equal 8, changes.size
760
+ assert_equal 'Dancing Galaxy', changes[0].title
761
+ assert_equal 'Soundform', changes[1].title
762
+ assert_equal 'Flying Into A Star', changes[2].title
763
+ assert_equal 'No One Ever Dreams', changes[3].title
764
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', changes[4].title
765
+ assert_equal 'Life On Mars', changes[5].title
766
+ assert_equal 'Liquid Sun', changes[6].title
767
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', changes[7].title
768
+
769
+ changes = @mpd.playlist_changes 999
770
+
771
+ assert_equal 8, changes.size
772
+
773
+ @mpd.disconnect
774
+ assert_raise(RuntimeError) {@mpd.playlist_changes(9)}
775
+ end
776
+
777
+ def test_previous
778
+ @mpd.connect
779
+
780
+ @mpd.load 'Astral_Projection_-_Dancing_Galaxy'
781
+
782
+ @mpd.play 3
783
+
784
+ sleep 2
785
+
786
+ assert @mpd.playing?
787
+
788
+ pos = @mpd.status['song'].to_i
789
+
790
+ assert @mpd.previous
791
+
792
+ assert_equal pos - 1, @mpd.status['song'].to_i
793
+
794
+ @mpd.disconnect
795
+ assert_raise(RuntimeError) {@mpd.previous}
796
+ end
797
+
798
+ def test_random
799
+ @mpd.connect
800
+
801
+ @mpd.random = true
802
+ assert @mpd.random?
803
+
804
+ @mpd.random = false
805
+ assert !@mpd.random?
806
+
807
+ @mpd.disconnect
808
+ assert_raise(RuntimeError) {@mpd.random = false}
809
+ assert_raise(RuntimeError) {@mpd.random?}
810
+ end
811
+
812
+ def test_repeat
813
+ @mpd.connect
814
+
815
+ @mpd.repeat = true
816
+ assert @mpd.repeat?
817
+
818
+ @mpd.repeat = false
819
+ assert !@mpd.repeat?
820
+
821
+ @mpd.disconnect
822
+ assert_raise(RuntimeError) {@mpd.repeat = false}
823
+ assert_raise(RuntimeError) {@mpd.repeat?}
824
+ end
825
+
826
+ def test_rm
827
+ @mpd.connect
828
+
829
+ assert @mpd.rm('Astral_Projection_-_Dancing_Galaxy')
830
+
831
+ pls = @mpd.playlists
832
+
833
+ assert 1, pls.size
834
+
835
+ assert_equal 'Shpongle_-_Are_You_Shpongled', pls[0]
836
+
837
+ assert_raise(RuntimeError) {@mpd.rm('Not-Exist')}
838
+
839
+ @mpd.disconnect
840
+ assert_raise(RuntimeError) {@mpd.rm('Astral_Projection_-_Dancing_Galaxy')}
841
+ end
842
+
843
+ def test_save
844
+ @mpd.connect
845
+
846
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
847
+ assert @mpd.load('Shpongle_-_Are_You_Shpongled')
848
+
849
+ assert @mpd.save('UnitTests')
850
+
851
+ assert @mpd.clear
852
+
853
+ assert @mpd.load('UnitTests')
854
+
855
+ pls = @mpd.playlist
856
+
857
+ assert_equal 15, pls.size
858
+
859
+ assert_equal 'Dancing Galaxy', pls[0].title
860
+ assert_equal 'Soundform', pls[1].title
861
+ assert_equal 'Flying Into A Star', pls[2].title
862
+ assert_equal 'No One Ever Dreams', pls[3].title
863
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[4].title
864
+ assert_equal 'Life On Mars', pls[5].title
865
+ assert_equal 'Liquid Sun', pls[6].title
866
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[7].title
867
+ assert_equal 'Shpongle Falls', pls[8].title
868
+ assert_equal 'Monster Hit', pls[9].title
869
+ assert_equal 'Vapour Rumours', pls[10].title
870
+ assert_equal 'Shpongle Spores', pls[11].title
871
+ assert_equal 'Behind Closed Eyelids', pls[12].title
872
+ assert_equal 'Divine Moments of Truth', pls[13].title
873
+ assert_equal '... and the Day Turned to Night', pls[14].title
874
+
875
+ @mpd.disconnect
876
+ assert_raise(RuntimeError) {@mpd.save('test')}
877
+ end
878
+
879
+ def test_search
880
+ @mpd.connect
881
+
882
+ a = @mpd.search 'album', 'ydroponic gar'
883
+
884
+ assert_equal 11, a.size
885
+ a.each do |song|
886
+ assert_equal 'Carbon Based Lifeforms', song.artist
887
+ assert_equal 'Hydroponic Garden', song.album
888
+ end
889
+
890
+ b = @mpd.search 'artist', 'hpon'
891
+
892
+ assert_equal 27, b.size
893
+ b.each do |song|
894
+ assert_equal 'Shpongle', song.artist
895
+ end
896
+
897
+ c = @mpd.search 'title', 'falls'
898
+ assert_equal 1, c.size
899
+ assert_equal 'Shpongle', c[0].artist
900
+ assert_equal 'Shpongle Falls', c[0].title
901
+ assert_equal 'Are You Shpongled?', c[0].album
902
+
903
+ d = @mpd.search 'filename', 'disco_valley'
904
+ assert_equal 1, d.size
905
+ assert_equal 'Astral Projection', d[0].artist
906
+ assert_equal 'Dancing Galaxy', d[0].album
907
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', d[0].title
908
+
909
+ z = @mpd.search 'title', 'no-title'
910
+ assert_equal 0, z.size
911
+
912
+ assert_raise(RuntimeError) {@mpd.search('error', 'nosuch')}
913
+
914
+ @mpd.disconnect
915
+ assert_raise(RuntimeError) {@mpd.search('artist','searching')}
916
+ end
917
+
918
+ def test_seek
919
+ @mpd.connect
920
+
921
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
922
+
923
+ assert @mpd.play
924
+
925
+ sleep 2
926
+
927
+ assert @mpd.pause = true
928
+
929
+ sleep 2
930
+
931
+ assert @mpd.seek(2, 200)
932
+
933
+ sleep 2
934
+
935
+ song = @mpd.current_song
936
+
937
+ assert_equal 'Flying Into A Star', song.title
938
+
939
+ status = @mpd.status
940
+
941
+ assert_equal '200:585', status['time']
942
+
943
+ @mpd.disconnect
944
+ assert_raise(RuntimeError) {@mpd.seek(1, 100)}
945
+ end
946
+
947
+ def test_seekid
948
+ @mpd.connect
949
+
950
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
951
+
952
+ assert @mpd.play
953
+
954
+ sleep 2
955
+
956
+ assert @mpd.pause = true
957
+
958
+ sleep 2
959
+
960
+ assert @mpd.seekid(9, 200)
961
+
962
+ sleep 2
963
+
964
+ song = @mpd.current_song
965
+
966
+ assert_equal 'Flying Into A Star', song.title
967
+
968
+ status = @mpd.status
969
+
970
+ assert_equal '200:585', status['time']
971
+
972
+ @mpd.disconnect
973
+ assert_raise(RuntimeError) {@mpd.seekid(1, 100)}
974
+ end
975
+
976
+ def test_volume
977
+ @mpd.connect
978
+
979
+ vol = @mpd.volume
980
+
981
+ @mpd.volume = 30
982
+ assert_equal 30, @mpd.volume
983
+
984
+ @mpd.volume = vol
985
+ assert_equal vol, @mpd.volume
986
+
987
+ @mpd.disconnect
988
+ assert_raise(RuntimeError) {@mpd.volume = 10}
989
+ assert_raise(RuntimeError) {@mpd.volume}
990
+ end
991
+
992
+ def test_shuffle
993
+ @mpd.connect
994
+
995
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
996
+
997
+ assert @mpd.shuffle
998
+
999
+ pls = @mpd.playlist
1000
+
1001
+ assert_equal 8, pls.size
1002
+ assert_not_equal 'Dancing Galaxy', pls[0].title
1003
+
1004
+ @mpd.disconnect
1005
+ assert_raise(RuntimeError) {@mpd.shuffle}
1006
+ end
1007
+
1008
+ def test_stats
1009
+ @mpd.connect
1010
+
1011
+ stats = @mpd.stats
1012
+
1013
+ assert_equal '3', stats['artists']
1014
+ assert_equal '4', stats['albums']
1015
+ assert_equal '46', stats['songs']
1016
+ assert_equal '500', stats['uptime']
1017
+
1018
+ @mpd.disconnect
1019
+ assert_raise(RuntimeError) {@mpd.stats}
1020
+ end
1021
+
1022
+ def test_status
1023
+ @mpd.connect
1024
+
1025
+ status = @mpd.status
1026
+
1027
+ assert_equal 'stop', status['state']
1028
+ assert_equal '0', status['repeat']
1029
+ assert_equal '0', status['random']
1030
+
1031
+ @mpd.disconnect
1032
+ assert_raise(RuntimeError) {@mpd.status}
1033
+ end
1034
+
1035
+ def test_stop
1036
+ @mpd.connect
1037
+ assert @mpd.connected?
1038
+
1039
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
1040
+
1041
+ assert @mpd.play
1042
+ assert @mpd.playing?
1043
+
1044
+ assert @mpd.stop
1045
+ assert @mpd.stopped?
1046
+
1047
+ assert !@mpd.playing?
1048
+
1049
+ @mpd.disconnect
1050
+ assert_raise(RuntimeError) {@mpd.stop}
1051
+ assert_raise(RuntimeError) {@mpd.stopped?}
1052
+ end
1053
+
1054
+ def test_swap
1055
+ @mpd.connect
1056
+
1057
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
1058
+
1059
+ assert @mpd.swap(2,5)
1060
+
1061
+ pls = @mpd.playlist
1062
+
1063
+ assert_equal 'Dancing Galaxy', pls[0].title
1064
+ assert_equal 'Soundform', pls[1].title
1065
+ assert_equal 'Flying Into A Star', pls[5].title
1066
+ assert_equal 'No One Ever Dreams', pls[3].title
1067
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[4].title
1068
+ assert_equal 'Life On Mars', pls[2].title
1069
+ assert_equal 'Liquid Sun', pls[6].title
1070
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[7].title
1071
+
1072
+ assert @mpd.swap(7,1)
1073
+
1074
+ pls = @mpd.playlist
1075
+
1076
+ assert_equal 'Dancing Galaxy', pls[0].title
1077
+ assert_equal 'Soundform', pls[7].title
1078
+ assert_equal 'Flying Into A Star', pls[5].title
1079
+ assert_equal 'No One Ever Dreams', pls[3].title
1080
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[4].title
1081
+ assert_equal 'Life On Mars', pls[2].title
1082
+ assert_equal 'Liquid Sun', pls[6].title
1083
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[1].title
1084
+
1085
+ assert_raise(RuntimeError) {@mpd.swap(999,1)}
1086
+
1087
+ @mpd.disconnect
1088
+ assert_raise(RuntimeError) {@mpd.swap(2, 5)}
1089
+ end
1090
+
1091
+ def test_swapid
1092
+ @mpd.connect
1093
+
1094
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
1095
+
1096
+ assert @mpd.swapid(9,12)
1097
+
1098
+ pls = @mpd.playlist
1099
+
1100
+ assert_equal 'Dancing Galaxy', pls[0].title
1101
+ assert_equal 'Soundform', pls[1].title
1102
+ assert_equal 'Flying Into A Star', pls[5].title
1103
+ assert_equal 'No One Ever Dreams', pls[3].title
1104
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[4].title
1105
+ assert_equal 'Life On Mars', pls[2].title
1106
+ assert_equal 'Liquid Sun', pls[6].title
1107
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[7].title
1108
+
1109
+ assert @mpd.swapid(14,8)
1110
+
1111
+ pls = @mpd.playlist
1112
+
1113
+ assert_equal 'Dancing Galaxy', pls[0].title
1114
+ assert_equal 'Soundform', pls[7].title
1115
+ assert_equal 'Flying Into A Star', pls[5].title
1116
+ assert_equal 'No One Ever Dreams', pls[3].title
1117
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[4].title
1118
+ assert_equal 'Life On Mars', pls[2].title
1119
+ assert_equal 'Liquid Sun', pls[6].title
1120
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[1].title
1121
+
1122
+ assert_raise(RuntimeError) {@mpd.swapid(999,8)}
1123
+
1124
+ @mpd.disconnect
1125
+ assert_raise(RuntimeError) {@mpd.swapid(9, 12)}
1126
+ end
1127
+
1128
+ def test_update
1129
+ @mpd.connect
1130
+
1131
+ ret = @mpd.update
1132
+
1133
+ assert_equal 1, ret
1134
+
1135
+ status = @mpd.status
1136
+
1137
+ assert_equal '1', status['updating_db']
1138
+
1139
+ status = @mpd.status
1140
+
1141
+ assert_nil status['updating_db']
1142
+
1143
+ @mpd.disconnect
1144
+ assert_raise(RuntimeError) {@mpd.update}
1145
+ end
1146
+ end