PageRenderTime 51ms CodeModel.GetById 29ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 0ms

/t/core_cd.t

http://github.com/PerlGameDev/SDL
Perl | 124 lines | 109 code | 14 blank | 1 comment | 10 complexity | 66e8255a2ef985700dbd8d15db3ccb86 MD5 | raw file
  1#!/usr/bin/perl -w
  2use strict;
  3use warnings;
  4use SDL;
  5
  6BEGIN {
  7	use Test::More;
  8	use lib 't/lib';
  9	use SDL::TestTool;
 10	use Config;
 11
 12	plan( skip_all => 'GNU Hurd <= 0.3 not supported' )
 13		if $^O eq 'gnu' && $Config{osvers} <= 0.3;
 14
 15	plan( skip_all => 'Failed to init cdrom' )
 16		unless SDL::TestTool->init(SDL_INIT_CDROM);
 17}
 18
 19use SDL::CD;
 20use SDL::CDROM;
 21use SDL::CDTrack;
 22
 23is( CD_ERROR,       -1, 'CD_ERROR should be imported' );
 24is( CD_ERROR(),     -1, 'CD_ERROR() should also be available' );
 25is( CD_PAUSED,      3,  'CD_PAUSED should be imported' );
 26is( CD_PAUSED(),    3,  'CD_PAUSED() should also be available' );
 27is( CD_PLAYING,     2,  'CD_PLAYING should be imported' );
 28is( CD_PLAYING(),   2,  'CD_PLAYING() should also be available' );
 29is( CD_STOPPED,     1,  'CD_STOPPED should be imported' );
 30is( CD_STOPPED(),   1,  'CD_STOPPED() should also be available' );
 31is( CD_TRAYEMPTY,   0,  'CD_TRAYEMPTY should be imported' );
 32is( CD_TRAYEMPTY(), 0,  'CD_TRAYEMPTY() should also be available' );
 33
 34is( SDL_AUDIO_TRACK,   0, 'SDL_AUDIO_TRACK should be imported' );
 35is( SDL_AUDIO_TRACK(), 0, 'SDL_AUDIO_TRACK() should also be available' );
 36is( SDL_DATA_TRACK,    4, 'SDL_DATA_TRACK should be imported' );
 37is( SDL_DATA_TRACK(),  4, 'SDL_DATA_TRACK() should also be available' );
 38
 39my $num_drives = SDL::CDROM::num_drives();
 40ok( $num_drives >= 0, "[SDL::CDROM::num_drives] is $num_drives" );
 41
 42SKIP:
 43{
 44	skip( "no drives available or SDL_RELEASE_TESTING not set", 17 )
 45		if $num_drives <= 0 || !$ENV{SDL_RELEASE_TESTING};
 46	for ( 0 .. $num_drives - 1 ) {
 47		my $name = SDL::CDROM::name($_);
 48		ok( $name, "[SDL::CDROM::name] for drive $_ is $name" );
 49	}
 50	my $cd = SDL::CD->new(0);
 51	isa_ok( $cd, 'SDL::CD', "[SDL::CD->new]" );
 52	my $status = $cd->status();
 53	my %states = (
 54		-1 => 'CD_ERROR',
 55		0  => 'CD_TRAYEMPTY',
 56		1  => 'CD_STOPPED',
 57		2  => 'CD_PLAYING',
 58		3  => 'CD_PAUSED'
 59	);
 60	my %types = (
 61		0 => 'SDL_AUDIO_TRACK',
 62		1 => 'SDL_DATA_TRACK'
 63	);
 64	ok( defined $states{$status},
 65		"[SDL::CD->status] is " . ( defined $states{$status} ? $states{$status} : 'undefined' )
 66	);
 67	SKIP:
 68	{
 69		skip( "CD should be in CD_STOPPED state", 14 )
 70			unless $status == CD_STOPPED;
 71		my $track = $cd->track(3);
 72		isa_ok( $track, 'SDL::CDTrack', "[SDL::CD->track]" );
 73		my $id = $cd->id();
 74		ok( $id >= 0, "[SDL::CD->id] is $id" );
 75		my $num_tracks = $cd->num_tracks();
 76		ok( $num_tracks >= 0, "[SDL::CD->num_tracks] is $num_tracks" );
 77
 78		is( $cd->play_tracks( 4, 0, 5, 0 ),
 79			0, "[SDL::CD->play_tracks] playing track 4"
 80		);
 81		SDL::delay(2000);
 82		is( $cd->pause(), 0, "[SDL::CD->pause] succeeded" );
 83		SDL::delay(2000);
 84		SKIP:
 85		{
 86			skip( "I have no idea why cur_track and cur_frame are 0.", 2 );
 87			is( $cd->cur_track(), 4, "[SDL::CD->cur_track] is 4" );
 88			my $frame = $cd->cur_frame();
 89			ok( $frame, "[SDL::CD->cur_frame] is $frame" );
 90		}
 91
 92		my $t_id = $track->id();
 93		ok( $t_id, "[SDL::CDTrack->id] is $t_id" );
 94		my $t_type = $track->type();
 95		ok( defined $types{$t_type},
 96			"[SDL::CDTrack->type] is " . ( defined $types{$t_type} ? $types{$t_type} : 'undefined' )
 97		);
 98		my $t_length = $track->length();
 99		ok( $t_length > 0, "[SDL::CDTrack->length] is $t_length" );
100		my $t_offset = $track->offset();
101		ok( $t_offset > 0, "[SDL::CDTrack->offset] is $t_offset" );
102
103		is( $cd->resume(), 0, "[SDL::CD->resume] succeeded" );
104		SDL::delay(2000);
105		is( $cd->stop(), 0, "[SDL::CD->stop] succeeded" );
106		SDL::delay(2000);
107		is( $cd->play( CD_FPS * 30, CD_FPS * 2 ),
108			0, "[SDL::CD->play] succeeded"
109		);
110		SDL::delay(2000);
111	}
112	SKIP:
113	{
114		skip( "CD should be in CD_STOPPED or CD_TRAYEMPTY state", 1 )
115			unless $status == CD_STOPPED || $status == CD_TRAYEMPTY;
116
117		is( $cd->eject(), 0, "[SDL::CD->eject] succeeded" )
118			unless SDL::delay(2000);
119	}
120}
121
122done_testing;
123
124sleep(1);