[project @ 6332]
[audio-mpd-common.git] / t / 51-pl-add_rm.t
blob1d42010be401577e059548676b97baeaad384100
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 @songs = qw[
20     title.ogg dir1/title-artist-album.ogg
21     dir1/title-artist.ogg dir2/album.ogg
23 my ($nb);
24 our $nbtests = 5;
25 our @tests   = (
26     # [ 'event', [ $arg1, $arg2, ... ], $answer_back, \&check_results ]
28     # pl.delete / pl.deleteid
29     # should come first to be sure songid #0 is really here.
30     [ 'pl.clear',    [],      $DISCARD, undef         ],
31     [ 'pl.add',      \@songs, $DISCARD, undef         ],
32     [ 'status',      [],      $SEND,    \&get_nb      ],
33     [ 'pl.delete',   [1,2],   $DISCARD, undef         ],
34     [ 'status',      [],      $SEND,    \&check_del   ],
35     [ 'status',      [],      $SEND,    \&get_nb      ],
36     [ 'pl.deleteid', [0],     $DISCARD, undef         ],
37     [ 'status',      [],      $SEND,    \&check_delid ],
39     # pl.add
40     [ 'pl.clear', [],              $DISCARD, undef       ],
41     [ 'status',   [],              $SEND,    \&get_nb    ],
42     [ 'pl.add',   [ 'title.ogg' ], $DISCARD, undef       ],
43     [ 'pl.add',   \@songs,         $DISCARD, undef       ],
44     [ 'status',   [],              $SEND,    \&check_add ],
46     # pl.clear
47     [ 'pl.add',   \@songs, $DISCARD, undef         ],
48     [ 'pl.clear', [],      $DISCARD, undef         ],
49     [ 'status',   [],      $SEND,    \&check_clear ],
51     # pl.crop
52     [ 'pl.add',  \@songs, $DISCARD, undef        ],
53     [ 'play',    [1],     $DISCARD, undef        ], # to set song
54     [ 'stop',    [],      $DISCARD, undef        ],
55     [ 'pl.crop', [],      $SLEEP1,  undef        ],
56     [ 'status',   [],     $SEND,    \&check_crop ],
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 get_nb      { $nb = $_[0]->data->playlistlength }
67 sub check_add   { is( $_[0]->data->playlistlength, $nb+5, 'add() songs' ); }
68 sub check_del   { is( $_[0]->data->playlistlength, $nb-2, 'delete() songs' ); }
69 sub check_delid { is( $_[0]->data->playlistlength, $nb-1, 'deleteid() songs' ); }
70 sub check_clear { is( $_[0]->data->playlistlength, 0, 'clear() leaves 0 song' ); }
71 sub check_crop  { is( $_[0]->data->playlistlength, 1, 'crop() leaves only 1 song' ); }