[project @ 6332]
[audio-mpd-common.git] / t / 52-pl-change.t
blobd68ba6a3271340333f2fe0c7d7bc22140803b38b
1 #!perl
3 # This file is part of POE::Component::Client::MPD.
4 # Copyright (c) 2007 Jerome Quelin, all rights reserved.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the same terms as Perl itself.
11 use strict;
12 use warnings;
14 use POE qw[ Component::Client::MPD::Message ];
15 use Readonly;
16 use Test::More;
19 my $plvers;
20 our $nbtests = 5;
21 my @songs = qw[
22     title.ogg
23     dir1/title-artist-album.ogg
24     dir1/title-artist.ogg
25     dir2/album.ogg
27 our @tests   = (
28     # [ 'event', [ $arg1, $arg2, ... ], $answer_back, \&check_results ]
30     # pl.swapid
31     # test should come first to know the song id
32     [ 'pl.clear',    [],       $DISCARD, undef          ],
33     [ 'pl.add',      \@songs,  $DISCARD, undef          ],
34     [ 'pl.swapid',   [0,2],    $DISCARD, undef          ],
35     [ 'pl.as_items', [],       $SEND,    \&check_2ndpos ],
36     [ 'pl.swapid',   [0,2],    $DISCARD, undef          ],
38     # pl.moveid
39     # test should come second to know the song id
40     [ 'pl.moveid',   [0,2],    $DISCARD, undef          ],
41     [ 'pl.as_items', [],       $SEND,    \&check_2ndpos ],
42     [ 'pl.moveid',   [0,0],    $DISCARD, undef          ],
44     # pl.swap
45     [ 'pl.swap',     [0,2],    $DISCARD, undef          ],
46     [ 'pl.as_items', [],       $SEND,    \&check_2ndpos ],
47     [ 'pl.swap',     [0,2],    $DISCARD, undef          ],
49     # pl.move
50     [ 'pl.move',     [0,2],    $DISCARD, undef          ],
51     [ 'pl.as_items', [],       $SEND,    \&check_2ndpos ],
53     # pl.shuffle
54     [ 'status',      [],       $SEND,    sub { $plvers=$_[0]->data->playlist; } ],
55     [ 'pl.shuffle',  [],       $DISCARD, undef                                  ],
56     [ 'status',      [],       $SEND,    \&check_shuffle                        ],
61 # are we able to test module?
62 eval 'use POE::Component::Client::MPD::Test';
63 plan skip_all => $@ if $@ =~ s/\n+BEGIN failed--compilation aborted.*//s;
64 exit;
66 sub check_shuffle {
67     is( $_[0]->data->playlist, $plvers+1, 'shuffle() changes playlist version' );
70 sub check_2ndpos {
71     my @items = @{ $_[0]->data };
72     is( $items[2]->title, 'ok-title', 'swap[id()] / swap[id()] changes songs' );