1.1 --- a/test/test-automation/tests/testaudio/testaudio.c Sun Oct 02 00:59:11 2011 -0400
1.2 +++ b/test/test-automation/tests/testaudio/testaudio.c Wed Oct 05 08:08:06 2011 -0700
1.3 @@ -1,5 +1,6 @@
1.4 /**
1.5 - * Original code: automated SDL rect test written by Edgar Simo "bobbens"
1.6 + * Original code: automated SDL audio test written by Edgar Simo "bobbens"
1.7 + * New/updated tests: aschiffler at ferzkopp dot net
1.8 */
1.9
1.10 #include <stdio.h>
1.11 @@ -10,10 +11,10 @@
1.12
1.13 /* Test cases */
1.14 static const TestCaseReference test1 =
1.15 - (TestCaseReference){ "audio_printOutputDevices", "Checks available output (non-capture) device names.", TEST_ENABLED, TEST_REQUIRES_AUDIO, 0};
1.16 + (TestCaseReference){ "audio_enumerateAndNameAudioDevices", "Enumerate and name available audio devices (output and capture)", TEST_ENABLED, TEST_REQUIRES_AUDIO, 0};
1.17
1.18 static const TestCaseReference test2 =
1.19 - (TestCaseReference){ "audio_printInputDevices", "Checks available input (capture) device names.", TEST_ENABLED, TEST_REQUIRES_AUDIO, 0};
1.20 + (TestCaseReference){ "audio_enumerateAndNameAudioDevicesNegativeTests", "Netative tests around enumeration and naming of audio devices.", TEST_ENABLED, TEST_REQUIRES_AUDIO, 0};
1.21
1.22 static const TestCaseReference test3 =
1.23 (TestCaseReference){ "audio_printAudioDrivers", "Checks available audio driver names.", TEST_ENABLED, TEST_REQUIRES_AUDIO, 0};
1.24 @@ -31,7 +32,7 @@
1.25 return (TestCaseReference **)testSuite;
1.26 }
1.27
1.28 -// Fixture
1.29 +/* Fixture */
1.30
1.31 void
1.32 SetUp(void *arg)
1.33 @@ -51,49 +52,94 @@
1.34 /* Test case functions */
1.35
1.36 /**
1.37 - * @brief Checks available output (non-capture) device names.
1.38 + * \brief Enumerate and name available audio devices (output and capture).
1.39 + *
1.40 + * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetNumAudioDevices
1.41 + * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetAudioDeviceName
1.42 */
1.43 -int audio_printOutputDevices()
1.44 +int audio_enumerateAndNameAudioDevices()
1.45 {
1.46 int ret;
1.47 - int i, n;
1.48 - const char *name;
1.49 + int t, tt;
1.50 + int i, n, nn;
1.51 + const char *name, *nameAgain;
1.52
1.53 - /* Get number of devices. */
1.54 - n = SDL_GetNumAudioDevices(0);
1.55 - AssertTrue(n>=0, "Number of output devices < 0, reported as %i", n);
1.56 + /* Iterate over types: t=0 output device, t=1 input/capture device */
1.57 + for (t=0; t<2; t++) {
1.58
1.59 - /* List devices. */
1.60 - if (n>0)
1.61 - {
1.62 - for (i=0; i<n; i++) {
1.63 - name = SDL_GetAudioDeviceName(i, 0);
1.64 - AssertTrue(name != NULL, "name != NULL");
1.65 - AssertTrue(strlen(name)>0, "name blank");
1.66 + /* Get number of devices. */
1.67 + n = SDL_GetNumAudioDevices(t);
1.68 + AssertTrue(n>=0,
1.69 + "Number of %s devices < 0, reported as %i: %s",
1.70 + (t) ? "output" : "capture",
1.71 + n,
1.72 + SDL_GetError());
1.73 +
1.74 + /* Variation of non-zero type */
1.75 + if (t==1) {
1.76 + tt = t + RandomIntegerInRange(1,10);
1.77 + nn = SDL_GetNumAudioDevices(tt);
1.78 + AssertTrue(n==nn, "SDL_GetNumAudioDevices(%i) : expected same number of audio devices %i, got %i", tt, n, nn);
1.79 + nn = SDL_GetNumAudioDevices(-tt);
1.80 + AssertTrue(n==nn, "SDL_GetNumAudioDevices(%i) : expected same number of audio devices %i, got %i", -tt, n, nn);
1.81 + }
1.82 +
1.83 + /* List devices. */
1.84 + if (n>0) {
1.85 + for (i=0; i<n; i++) {
1.86 + name = SDL_GetAudioDeviceName(i, t);
1.87 + AssertTrue(name != NULL, "SDL_GetAudioDeviceName(%i, %i): returned NULL name", i, t);
1.88 + AssertTrue(strlen(name)>0, "SDL_GetAudioDeviceName(%i, %i): returned empty name string", i, t);
1.89 + if (t==1) {
1.90 + /* Also try non-zero type */
1.91 + nameAgain = SDL_GetAudioDeviceName(i, tt);
1.92 + AssertTrue(nameAgain != NULL, "SDL_GetAudioDeviceName(%i, %i): returned NULL name", i, tt);
1.93 + AssertTrue(strlen(nameAgain)>0, "SDL_GetAudioDeviceName(%i, %i): returned empty name string", i, tt);
1.94 + AssertTrue(strcmp(name, nameAgain)==0,
1.95 + "SDL_GetAudioDeviceName(%i, %i): returned unexpected name string %s, expected %s",
1.96 + i, tt, nameAgain, name);
1.97 + }
1.98 + }
1.99 }
1.100 }
1.101 }
1.102
1.103 /**
1.104 - * @brief Checks available input (capture) device names.
1.105 + * \brief Negative tests around enumeration and naming of audio devices.
1.106 + *
1.107 + * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetNumAudioDevices
1.108 + * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetAudioDeviceName
1.109 */
1.110 -int audio_printInputDevices()
1.111 +int audio_enumerateAndNameAudioDevicesNegativeTests()
1.112 {
1.113 int ret;
1.114 - int i, n;
1.115 + int t;
1.116 + int i, j, no, nc;
1.117 const char *name;
1.118 -
1.119 +
1.120 /* Get number of devices. */
1.121 - n = SDL_GetNumAudioDevices(1);
1.122 - AssertTrue(n>=0, "Number of input devices < 0, reported as %i", n);
1.123 + no = SDL_GetNumAudioDevices(0);
1.124 + nc = SDL_GetNumAudioDevices(1);
1.125
1.126 - /* List devices. */
1.127 - if (n>0)
1.128 - {
1.129 - for (i=0; i<n; i++) {
1.130 - name = SDL_GetAudioDeviceName(i, 1);
1.131 - AssertTrue(name != NULL, "name != NULL");
1.132 - AssertTrue(strlen(name)>0, "name empty");
1.133 + /* Invalid device index when getting name */
1.134 + for (t=0; t<2; t++) {
1.135 + /* Negative device index */
1.136 + i = -1;
1.137 + name = SDL_GetAudioDeviceName(i, t);
1.138 + AssertTrue(name == NULL, "SDL_GetAudioDeviceName(%i, %i): returned a name, should return NULL", i, t);
1.139 +
1.140 + /* Device index past range */
1.141 + for (j=0; j<3; j++) {
1.142 + i = (t) ? nc+j : no+j;
1.143 + name = SDL_GetAudioDeviceName(i, t);
1.144 + AssertTrue(name == NULL, "SDL_GetAudioDeviceName(%i, %i): returned a name, should return NULL", i, t);
1.145 + }
1.146 +
1.147 + /* Capture index past capture range but within output range */
1.148 + if ((no>0) && (no>nc) && (t==1)) {
1.149 + i = no-1;
1.150 + name = SDL_GetAudioDeviceName(i, t);
1.151 + AssertTrue(name == NULL, "SDL_GetAudioDeviceName(%i, %i): returned a name, should return NULL", i, t);
1.152 }
1.153 }
1.154 }