File: 63-coll-relations.t

package info (click to toggle)
libpoe-component-client-mpd-perl 1.121670-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 320 kB
  • sloc: perl: 2,070; makefile: 2
file content (119 lines) | stat: -rw-r--r-- 4,143 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!perl
#
# This file is part of POE-Component-Client-MPD
#
# This software is copyright (c) 2007 by Jerome Quelin.
#
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
#

use 5.010;
use strict;
use warnings;

use POE;
use POE::Component::Client::MPD;
use POE::Component::Client::MPD::Test;
use Test::More;

# are we able to test module?
eval 'use Test::Corpus::Audio::MPD';
plan skip_all => $@ if $@ =~ s/\n+Compilation failed.*//s;
plan tests => 38;

# launch fake mpd
POE::Component::Client::MPD->spawn;

# launch the tests
POE::Component::Client::MPD::Test->new( { tests => [
    # [ 'event', [ $arg1, $arg2, ... ], $sleep, \&check_results ]

    # albums_by_artist
    [ 'coll.albums_by_artist',         ['dir1-artist'], 0, \&check_albums_by_artist         ],

    # songs_by_artist
    [ 'coll.songs_by_artist',          ['dir1-artist'], 0, \&check_songs_by_artist          ],

    # songs_by_artist_partial
    [ 'coll.songs_by_artist_partial',       ['artist'], 0, \&check_songs_by_artist_partial  ],

    # songs_from_album
    [ 'coll.songs_from_album',           ['our album'], 0, \&check_songs_from_album         ],

    # songs_from_album_partial
    [ 'coll.songs_from_album_partial',       ['album'], 0, \&check_songs_from_album_partial ],

    # songs_with_title
    [ 'coll.songs_with_title',            ['ok-title'], 0, \&check_songs_with_title         ],

    # songs_with_title_partial
    [ 'coll.songs_with_title_partial',       ['title'], 0, \&check_songs_with_title_partial ],
] } );
POE::Kernel->run;
exit;

#--

sub check_success {
    my ($msg) = @_;
    is($msg->status, 1, "command '" . $msg->request . "' returned an ok status");
}

sub check_albums_by_artist {
    my ($msg, $items) = @_;
    check_success($msg);
    # mpd 0.14 returns empty strings too
    is(scalar @$items, 2, 'albums_by_artist() return the album');
    is($items->[1], 'our album', 'albums_by_artist() return plain strings');
}

sub check_songs_by_artist {
    my ($msg, $items) = @_;
    check_success($msg);
    is(scalar @$items, 3, 'songs_by_artist() return all the songs found' );
    isa_ok($_, 'Audio::MPD::Common::Item::Song', 'songs_by_artist() return') for @$items;
    is($items->[0]->artist, 'dir1-artist', 'songs_by_artist() return correct objects');
}

sub check_songs_by_artist_partial {
    my ($msg, $items) = @_;
    check_success($msg);
    is(scalar @$items, 3, 'songs_by_artist_partial() return all the songs found');
    isa_ok($_, 'Audio::MPD::Common::Item::Song', 'songs_by_artist_partial() return') for @$items;
    like($items->[0]->artist, qr/artist/, 'songs_by_artist_partial() return correct objects');
}


sub check_songs_from_album {
    my ($msg, $items) = @_;
    check_success($msg);
    is(scalar @$items, 3, 'songs_from_album() return all the songs found');
    isa_ok($_, 'Audio::MPD::Common::Item::Song', 'songs_from_album() return') for @$items;
    is($items->[0]->album, 'our album', 'songs_from_album() return correct objects' );
}

sub check_songs_from_album_partial {
    my ($msg, $items) = @_;
    check_success($msg);
    is(scalar @$items, 3, 'songs_from_album_partial() return all the songs found' );
    isa_ok($_, 'Audio::MPD::Common::Item::Song', 'songs_from_album_partial() return') for @$items;
    like($items->[0]->album, qr/album/, 'songs_from_album_partial() return correct objects');
}

sub check_songs_with_title {
    my ($msg, $items) = @_;
    check_success($msg);
    is(scalar @$items, 1, 'songs_with_title() return all the songs found');
    isa_ok($_, 'Audio::MPD::Common::Item::Song', 'songs_with_title() return') for @$items;
    is($items->[0]->title, 'ok-title', 'songs_with_title() return correct objects');
}

sub check_songs_with_title_partial {
    my ($msg, $items) = @_;
    check_success($msg);
    is(scalar @$items, 4, 'songs_with_title_partial() return all the songs found');
    isa_ok($_, 'Audio::MPD::Common::Item::Song', 'songs_with_title_partial() return') for @$items;
    like($items->[0]->title, qr/title/, 'songs_with_title_partial() return correct objects');
}