Added simple audio test. gsoc2009_unit_tests
authorEdgar Simo <bobbens@gmail.com>
Mon, 17 Aug 2009 17:52:42 +0000
branchgsoc2009_unit_tests
changeset 3756427f059bc814
parent 3755 e04d9c69a6fd
child 4408 c5616d36b2ac
Added simple audio test.
test/automated/Makefile
test/automated/audio/audio.c
test/automated/audio/audio.h
test/automated/testsdl.c
     1.1 --- a/test/automated/Makefile	Thu Aug 06 17:00:07 2009 +0000
     1.2 +++ b/test/automated/Makefile	Mon Aug 17 17:52:42 2009 +0000
     1.3 @@ -11,11 +11,17 @@
     1.4  						rwops/rwops.c \
     1.5  						platform/platform.c \
     1.6  						surface/surface.c \
     1.7 -						render/render.c
     1.8 +						render/render.c \
     1.9 +						audio/audio.c
    1.10  COMMON_SRC     := SDL_at.c common/common.c
    1.11  COMMON_INCLUDE := SDL_at.h
    1.12  
    1.13 -TESTS_ALL := testsdl rwops/rwops platform/platform surface/surface render/render
    1.14 +TESTS_ALL := testsdl \
    1.15 +	rwops/rwops \
    1.16 +	platform/platform \
    1.17 +	surface/surface \
    1.18 +	render/render \
    1.19 +	audio/audio
    1.20  
    1.21  
    1.22  .PHONY: all clean test
    1.23 @@ -41,5 +47,8 @@
    1.24  render/render: render/render.c $(COMMON_INCLUDE) $(COMMON_SRC)
    1.25  	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ render/render.c $(COMMON_SRC) -DTEST_STANDALONE
    1.26  
    1.27 +audio/audio: audio/audio.c $(COMMON_INCLUDE) $(COMMON_SRC)
    1.28 +	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ audio/audio.c $(COMMON_SRC) -DTEST_STANDALONE
    1.29 +
    1.30  clean:
    1.31  	$(RM) $(TESTS_ALL)
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/automated/audio/audio.c	Mon Aug 17 17:52:42 2009 +0000
     2.3 @@ -0,0 +1,89 @@
     2.4 +/**
     2.5 + * Automated SDL_RWops test.
     2.6 + *
     2.7 + * Written by Edgar Simo "bobbens"
     2.8 + *
     2.9 + * Released under Public Domain.
    2.10 + */
    2.11 +
    2.12 +
    2.13 +#include "SDL.h"
    2.14 +#include "SDL_at.h"
    2.15 +
    2.16 +
    2.17 +/**
    2.18 + * @brief Prints available devices.
    2.19 + */
    2.20 +static int audio_printDevices( int iscapture )
    2.21 +{
    2.22 +   int i, n;
    2.23 +
    2.24 +   /* Get number of devices. */
    2.25 +   n = SDL_GetNumAudioDevices(iscapture);
    2.26 +   SDL_ATprintVerbose( 1, "%d %s Audio Devices\n",
    2.27 +         n, iscapture ? "Capture" : "Output" );
    2.28 +
    2.29 +   /* List devices. */
    2.30 +   for (i=0; i<n; i++) {
    2.31 +      SDL_ATprintVerbose( 1, "   %d) %s\n", i+1, SDL_GetAudioDeviceName( i, iscapture ) );
    2.32 +   }
    2.33 +
    2.34 +   return 0;
    2.35 +}
    2.36 +
    2.37 +
    2.38 +/**
    2.39 + * @brief Makes sure parameters work properly.
    2.40 + */
    2.41 +static void audio_testOpen (void)
    2.42 +{
    2.43 +   int i, n;
    2.44 +   int ret;
    2.45 +
    2.46 +   /* Begin testcase. */
    2.47 +   SDL_ATbegin( "Audio Open" );
    2.48 +
    2.49 +   /* List drivers. */
    2.50 +   n = SDL_GetNumAudioDrivers();
    2.51 +   SDL_ATprintVerbose( 1, "%d Audio Drivers\n", n );
    2.52 +   for (i=0; i<n; i++) {
    2.53 +      SDL_ATprintVerbose( 1, "   %s\n", SDL_GetAudioDriver(i) );
    2.54 +   }
    2.55 +
    2.56 +   /* Start SDL. */
    2.57 +   ret = SDL_Init( SDL_INIT_AUDIO );
    2.58 +   if (SDL_ATvassert( ret==0, "SDL_Init( SDL_INIT_AUDIO ): %s", SDL_GetError()))
    2.59 +      return;
    2.60 +
    2.61 +   /* Print devices. */
    2.62 +   SDL_ATprintVerbose( 1, "Using Audio Driver '%s'\n", SDL_GetCurrentAudioDriver() );
    2.63 +   audio_printDevices(0);
    2.64 +   audio_printDevices(1);
    2.65 +
    2.66 +   /* Quit SDL. */
    2.67 +   SDL_Quit();
    2.68 +
    2.69 +   /* End testcase. */
    2.70 +   SDL_ATend();
    2.71 +}
    2.72 +
    2.73 +
    2.74 +/**
    2.75 + * @brief Entry point.
    2.76 + */
    2.77 +#ifdef TEST_STANDALONE
    2.78 +int main( int argc, const char *argv[] )
    2.79 +{
    2.80 +   (void) argc;
    2.81 +   (void) argv;
    2.82 +#else /* TEST_STANDALONE */
    2.83 +int test_audio (void)
    2.84 +{
    2.85 +#endif /* TEST_STANDALONE */
    2.86 +
    2.87 +   SDL_ATinit( "SDL_Audio" );
    2.88 +
    2.89 +   audio_testOpen();
    2.90 +
    2.91 +   return SDL_ATfinish();
    2.92 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/automated/audio/audio.h	Mon Aug 17 17:52:42 2009 +0000
     3.3 @@ -0,0 +1,18 @@
     3.4 +/**
     3.5 + * Part of SDL test suite.
     3.6 + *
     3.7 + * Written by Edgar Simo "bobbens"
     3.8 + *
     3.9 + * Released under Public Domain.
    3.10 + */
    3.11 +
    3.12 +
    3.13 +#ifndef _TEST_AUDIO
    3.14 +#  define _TEST_AUDIO
    3.15 +
    3.16 +
    3.17 +int test_audio (void);
    3.18 +
    3.19 +
    3.20 +#endif /* _TEST_AUDIO */
    3.21 +
     4.1 --- a/test/automated/testsdl.c	Thu Aug 06 17:00:07 2009 +0000
     4.2 +++ b/test/automated/testsdl.c	Mon Aug 17 17:52:42 2009 +0000
     4.3 @@ -14,6 +14,7 @@
     4.4  #include "rwops/rwops.h"
     4.5  #include "surface/surface.h"
     4.6  #include "render/render.h"
     4.7 +#include "audio/audio.h"
     4.8  
     4.9  #include <stdio.h> /* printf */
    4.10  #include <stdlib.h> /* exit */
    4.11 @@ -32,6 +33,7 @@
    4.12  static int run_rwops       = 1; /**< Run RWops tests. */
    4.13  static int run_surface     = 1; /**< Run surface tests. */
    4.14  static int run_render      = 1; /**< Run render tests. */
    4.15 +static int run_audio       = 1; /**< Run audio tests. */
    4.16  
    4.17  /*
    4.18   * Prototypes.
    4.19 @@ -52,6 +54,7 @@
    4.20     printf("   --norwops       do not run the rwops tests\n");
    4.21     printf("   --nosurface     do not run the surface tests\n");
    4.22     printf("   --norender      do not run the render tests\n");
    4.23 +   printf("   --noaudio       do not run the audio tests\n");
    4.24     printf("   -v, --verbose   increases verbosity level by 1 for each -v\n");
    4.25     printf("   -q, --quiet     only displays errors\n");
    4.26     printf("   -h, --help      display this message and exit\n");
    4.27 @@ -69,6 +72,7 @@
    4.28        { "norwops", no_argument, 0, 0 },
    4.29        { "nosurface", no_argument, 0, 0 },
    4.30        { "norender", no_argument, 0, 0 },
    4.31 +      { "noaudio", no_argument, 0, 0 },
    4.32        { "verbose", no_argument, 0, 'v' },
    4.33        { "quiet", no_argument, 0, 'q' },
    4.34        { "help", no_argument, 0, 'h' },
    4.35 @@ -96,6 +100,8 @@
    4.36                 run_surface = 0;
    4.37              else if (strcmp(str,"norender")==0)
    4.38                 run_render = 0;
    4.39 +            else if (strcmp(str,"noaudio")==0)
    4.40 +               run_audio = 0;
    4.41              break;
    4.42  
    4.43           /* Manual. */
    4.44 @@ -154,6 +160,8 @@
    4.45        failed += test_surface();
    4.46     if (run_render)
    4.47        failed += test_render();
    4.48 +   if (run_audio)
    4.49 +      failed += test_audio();
    4.50  
    4.51     /* Manual tests. */
    4.52     if (run_manual) {