1#!/usr/bin/perl -w 2 3use strict; 4use Test::More tests => 43; 5use File::Spec::Functions qw(:ALL); 6 7BEGIN { use_ok('Audio::FLAC::Header') }; 8 9######################### 10 11{ 12 # Always test pure perl 13 my @constructors = ('_new_PP'); 14 15 # Only test XS if built 16 SKIP: { 17 eval { Audio::FLAC::Header->_new_XS(catdir('data', 'test.flac')) }; 18 skip "Not built with XS", 21 if $@; 19 20 push @constructors, '_new_XS'; 21 } 22 23 24 # Be sure to test both code paths. 25 for my $constructor (@constructors) { 26 27 my $flac = Audio::FLAC::Header->$constructor(catdir('data', 'test.flac')); 28 29 ok($flac, "constructor: $constructor"); 30 31 my $info = $flac->info(); 32 33 ok($info, "info block"); 34 35 ok($flac->info('SAMPLERATE') == 44100, "sample rate"); 36 ok($flac->info('MD5CHECKSUM') eq '592fb7897a3589c6acf957fd3f8dc854', "md5"); 37 ok($flac->info('TOTALSAMPLES') == 153200460, "total samples"); 38 ok($flac->info('BITSPERSAMPLE') == 16, "bits per sample $constructor"); 39 ok($flac->info('NUMCHANNELS') == 2, "channels $constructor"); 40 ok($flac->info('MINIMUMBLOCKSIZE') == 4608, "minimum block size $constructor"); 41 ok($flac->info('MAXIMUMBLOCKSIZE') == 4608, "maximum block size $constructor"); 42 ok($flac->info('MINIMUMFRAMESIZE') == 14, "minimum frame size $constructor"); 43 ok($flac->info('MAXIMUMFRAMESIZE') == 18002, "maximum frame size $constructor"); 44 45 my $tags = $flac->tags(); 46 47 ok($tags, "tags read"); 48 49 is($flac->tags('AUTHOR'), 'Praga Khan', "AUTHOR ok"); 50 51 # XXX - should have accessors 52 ok($flac->{'trackLengthFrames'} =~ /70.00\d+/); 53 ok($flac->{'trackLengthMinutes'} == 57); 54 ok($flac->{'bitRate'} =~ /1.236\d+/); 55 ok($flac->{'trackTotalLengthSeconds'} =~ /3473.93\d+/); 56 57 my $cue = $flac->cuesheet(); 58 59 ok $cue; 60 61 ok(scalar @{$cue} == 37); 62 63 ok($cue->[35] =~ /REM FLAC__lead-in 88200/); 64 ok($cue->[36] =~ /REM FLAC__lead-out 170 153200460/); 65 } 66} 67 68__END__ 69