2011-07-10 18:42:52 +03:00
/**
2011-10-05 08:08:06 -07:00
* Original code : automated SDL audio test written by Edgar Simo " bobbens "
* New / updated tests : aschiffler at ferzkopp dot net
2011-07-10 18:42:52 +03:00
*/
2011-07-05 22:11:12 +03:00
# include <stdio.h>
# include <SDL/SDL.h>
2011-08-06 17:35:58 +03:00
# include "../../include/SDL_test.h"
2011-07-05 22:11:12 +03:00
2011-07-18 22:26:26 +03:00
/* Test cases */
2011-07-05 22:11:12 +03:00
static const TestCaseReference test1 =
2011-10-05 08:08:06 -07:00
( TestCaseReference ) { " audio_enumerateAndNameAudioDevices " , " Enumerate and name available audio devices (output and capture) " , TEST_ENABLED , TEST_REQUIRES_AUDIO , 0 } ;
2011-07-05 22:11:12 +03:00
static const TestCaseReference test2 =
2011-10-05 08:08:06 -07:00
( TestCaseReference ) { " audio_enumerateAndNameAudioDevicesNegativeTests " , " Netative tests around enumeration and naming of audio devices. " , TEST_ENABLED , TEST_REQUIRES_AUDIO , 0 } ;
2011-07-05 22:11:12 +03:00
static const TestCaseReference test3 =
2011-07-18 22:26:26 +03:00
( TestCaseReference ) { " audio_printAudioDrivers " , " Checks available audio driver names. " , TEST_ENABLED , TEST_REQUIRES_AUDIO , 0 } ;
2011-07-05 22:11:12 +03:00
static const TestCaseReference test4 =
2011-07-18 22:26:26 +03:00
( TestCaseReference ) { " audio_printCurrentAudioDriver " , " Checks current audio driver name with initialized audio. " , TEST_ENABLED , TEST_REQUIRES_AUDIO , 0 } ;
2011-07-05 22:11:12 +03:00
/* Test suite */
extern const TestCaseReference * testSuite [ ] = {
& test1 , & test2 , & test3 , & test4 , NULL
} ;
TestCaseReference * * QueryTestSuite ( ) {
return ( TestCaseReference * * ) testSuite ;
}
2011-10-05 08:08:06 -07:00
/* Fixture */
2011-08-06 19:49:37 +03:00
void
SetUp ( void * arg )
{
/* Start SDL. */
int ret = SDL_Init ( SDL_INIT_AUDIO ) ;
AssertTrue ( ret = = 0 , " SDL_Init(SDL_INIT_AUDIO): %s " , SDL_GetError ( ) ) ;
}
void
TearDown ( void * arg )
{
/* Quit SDL. */
SDL_Quit ( ) ;
}
2011-07-05 22:11:12 +03:00
/* Test case functions */
/**
2011-10-05 08:08:06 -07:00
* \ brief Enumerate and name available audio devices ( output and capture ) .
*
* \ sa http : //wiki.libsdl.org/moin.cgi/SDL_GetNumAudioDevices
* \ sa http : //wiki.libsdl.org/moin.cgi/SDL_GetAudioDeviceName
2011-07-05 22:11:12 +03:00
*/
2011-10-05 08:08:06 -07:00
int audio_enumerateAndNameAudioDevices ( )
2011-07-05 22:11:12 +03:00
{
int ret ;
2011-10-05 08:08:06 -07:00
int t , tt ;
int i , n , nn ;
const char * name , * nameAgain ;
2011-07-05 22:11:12 +03:00
2011-10-05 08:08:06 -07:00
/* Iterate over types: t=0 output device, t=1 input/capture device */
for ( t = 0 ; t < 2 ; t + + ) {
2011-07-05 22:11:12 +03:00
2011-10-05 08:08:06 -07:00
/* Get number of devices. */
n = SDL_GetNumAudioDevices ( t ) ;
AssertTrue ( n > = 0 ,
" Number of %s devices < 0, reported as %i: %s " ,
( t ) ? " output " : " capture " ,
n ,
SDL_GetError ( ) ) ;
/* Variation of non-zero type */
if ( t = = 1 ) {
tt = t + RandomIntegerInRange ( 1 , 10 ) ;
nn = SDL_GetNumAudioDevices ( tt ) ;
AssertTrue ( n = = nn , " SDL_GetNumAudioDevices(%i) : expected same number of audio devices %i, got %i " , tt , n , nn ) ;
nn = SDL_GetNumAudioDevices ( - tt ) ;
AssertTrue ( n = = nn , " SDL_GetNumAudioDevices(%i) : expected same number of audio devices %i, got %i " , - tt , n , nn ) ;
}
/* List devices. */
if ( n > 0 ) {
for ( i = 0 ; i < n ; i + + ) {
name = SDL_GetAudioDeviceName ( i , t ) ;
AssertTrue ( name ! = NULL , " SDL_GetAudioDeviceName(%i, %i): returned NULL name " , i , t ) ;
AssertTrue ( strlen ( name ) > 0 , " SDL_GetAudioDeviceName(%i, %i): returned empty name string " , i , t ) ;
if ( t = = 1 ) {
/* Also try non-zero type */
nameAgain = SDL_GetAudioDeviceName ( i , tt ) ;
AssertTrue ( nameAgain ! = NULL , " SDL_GetAudioDeviceName(%i, %i): returned NULL name " , i , tt ) ;
AssertTrue ( strlen ( nameAgain ) > 0 , " SDL_GetAudioDeviceName(%i, %i): returned empty name string " , i , tt ) ;
AssertTrue ( strcmp ( name , nameAgain ) = = 0 ,
" SDL_GetAudioDeviceName(%i, %i): returned unexpected name string %s, expected %s " ,
i , tt , nameAgain , name ) ;
}
}
2011-07-05 22:11:12 +03:00
}
}
}
/**
2011-10-05 08:08:06 -07:00
* \ brief Negative tests around enumeration and naming of audio devices .
*
* \ sa http : //wiki.libsdl.org/moin.cgi/SDL_GetNumAudioDevices
* \ sa http : //wiki.libsdl.org/moin.cgi/SDL_GetAudioDeviceName
2011-07-05 22:11:12 +03:00
*/
2011-10-05 08:08:06 -07:00
int audio_enumerateAndNameAudioDevicesNegativeTests ( )
2011-07-05 22:11:12 +03:00
{
int ret ;
2011-10-05 08:08:06 -07:00
int t ;
int i , j , no , nc ;
2011-08-06 19:49:37 +03:00
const char * name ;
2011-10-05 08:08:06 -07:00
2011-07-05 22:11:12 +03:00
/* Get number of devices. */
2011-10-05 08:08:06 -07:00
no = SDL_GetNumAudioDevices ( 0 ) ;
nc = SDL_GetNumAudioDevices ( 1 ) ;
2011-07-05 22:11:12 +03:00
2011-10-05 08:08:06 -07:00
/* Invalid device index when getting name */
for ( t = 0 ; t < 2 ; t + + ) {
/* Negative device index */
i = - 1 ;
name = SDL_GetAudioDeviceName ( i , t ) ;
AssertTrue ( name = = NULL , " SDL_GetAudioDeviceName(%i, %i): returned a name, should return NULL " , i , t ) ;
/* Device index past range */
for ( j = 0 ; j < 3 ; j + + ) {
i = ( t ) ? nc + j : no + j ;
name = SDL_GetAudioDeviceName ( i , t ) ;
AssertTrue ( name = = NULL , " SDL_GetAudioDeviceName(%i, %i): returned a name, should return NULL " , i , t ) ;
}
/* Capture index past capture range but within output range */
if ( ( no > 0 ) & & ( no > nc ) & & ( t = = 1 ) ) {
i = no - 1 ;
name = SDL_GetAudioDeviceName ( i , t ) ;
AssertTrue ( name = = NULL , " SDL_GetAudioDeviceName(%i, %i): returned a name, should return NULL " , i , t ) ;
2011-07-05 22:11:12 +03:00
}
}
}
/**
* @ brief Checks available audio driver names .
*/
int audio_printAudioDrivers ( )
{
int i , n ;
2011-08-06 19:49:37 +03:00
const char * name ;
2011-07-05 22:11:12 +03:00
/* Get number of drivers */
n = SDL_GetNumAudioDrivers ( ) ;
AssertTrue ( n > = 0 , " Number of audio drivers >= 0 " ) ;
/* List drivers. */
if ( n > 0 )
{
for ( i = 0 ; i < n ; i + + ) {
name = SDL_GetAudioDriver ( i ) ;
AssertTrue ( name ! = NULL , " name != NULL " ) ;
AssertTrue ( strlen ( name ) > 0 , " name empty " ) ;
}
}
}
/**
* @ brief Checks current audio driver name with initialized audio .
*/
int audio_printCurrentAudioDriver ( )
{
int ret ;
2011-08-06 19:49:37 +03:00
const char * name ;
2011-07-05 22:11:12 +03:00
/* Check current audio driver */
name = SDL_GetCurrentAudioDriver ( ) ;
AssertTrue ( name ! = NULL , " name != NULL " ) ;
AssertTrue ( strlen ( name ) > 0 , " name empty " ) ;
}