summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndreas Schiffler <aschiffler@ferzkopp.net>2011-10-05 08:08:06 -0700
committerAndreas Schiffler <aschiffler@ferzkopp.net>2011-10-05 08:08:06 -0700
commit7ef3d640240a75745f2c387361e04a109fb207c9 (patch)
tree13664557b1ffcdc2f44484a95d991dc22e4870ad /test
parent903080ece8d1e5cfda9890105fa4dc7163b33ad5 (diff)
Refactored audio device enumeration/naming tests ana added negative cases
Diffstat (limited to 'test')
-rw-r--r--test/test-automation/tests/testaudio/testaudio.c108
1 files changed, 77 insertions, 31 deletions
diff --git a/test/test-automation/tests/testaudio/testaudio.c b/test/test-automation/tests/testaudio/testaudio.c
index fb025fc0..511a78fe 100644
--- a/test/test-automation/tests/testaudio/testaudio.c
+++ b/test/test-automation/tests/testaudio/testaudio.c
@@ -1,5 +1,6 @@
/**
- * Original code: automated SDL rect test written by Edgar Simo "bobbens"
+ * Original code: automated SDL audio test written by Edgar Simo "bobbens"
+ * New/updated tests: aschiffler at ferzkopp dot net
*/
#include <stdio.h>
@@ -10,10 +11,10 @@
/* Test cases */
static const TestCaseReference test1 =
- (TestCaseReference){ "audio_printOutputDevices", "Checks available output (non-capture) device names.", TEST_ENABLED, TEST_REQUIRES_AUDIO, 0};
+ (TestCaseReference){ "audio_enumerateAndNameAudioDevices", "Enumerate and name available audio devices (output and capture)", TEST_ENABLED, TEST_REQUIRES_AUDIO, 0};
static const TestCaseReference test2 =
- (TestCaseReference){ "audio_printInputDevices", "Checks available input (capture) device names.", TEST_ENABLED, TEST_REQUIRES_AUDIO, 0};
+ (TestCaseReference){ "audio_enumerateAndNameAudioDevicesNegativeTests", "Netative tests around enumeration and naming of audio devices.", TEST_ENABLED, TEST_REQUIRES_AUDIO, 0};
static const TestCaseReference test3 =
(TestCaseReference){ "audio_printAudioDrivers", "Checks available audio driver names.", TEST_ENABLED, TEST_REQUIRES_AUDIO, 0};
@@ -31,7 +32,7 @@ TestCaseReference **QueryTestSuite() {
return (TestCaseReference **)testSuite;
}
-// Fixture
+/* Fixture */
void
SetUp(void *arg)
@@ -51,49 +52,94 @@ TearDown(void *arg)
/* Test case functions */
/**
- * @brief Checks available output (non-capture) device names.
+ * \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
*/
-int audio_printOutputDevices()
+int audio_enumerateAndNameAudioDevices()
{
int ret;
- int i, n;
- const char *name;
+ int t, tt;
+ int i, n, nn;
+ const char *name, *nameAgain;
- /* Get number of devices. */
- n = SDL_GetNumAudioDevices(0);
- AssertTrue(n>=0, "Number of output devices < 0, reported as %i", n);
+ /* Iterate over types: t=0 output device, t=1 input/capture device */
+ for (t=0; t<2; t++) {
- /* List devices. */
- if (n>0)
- {
- for (i=0; i<n; i++) {
- name = SDL_GetAudioDeviceName(i, 0);
- AssertTrue(name != NULL, "name != NULL");
- AssertTrue(strlen(name)>0, "name blank");
+ /* 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);
+ }
+ }
}
}
}
/**
- * @brief Checks available input (capture) device names.
+ * \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
*/
-int audio_printInputDevices()
+int audio_enumerateAndNameAudioDevicesNegativeTests()
{
int ret;
- int i, n;
+ int t;
+ int i, j, no, nc;
const char *name;
-
+
/* Get number of devices. */
- n = SDL_GetNumAudioDevices(1);
- AssertTrue(n>=0, "Number of input devices < 0, reported as %i", n);
+ no = SDL_GetNumAudioDevices(0);
+ nc = SDL_GetNumAudioDevices(1);
- /* List devices. */
- if (n>0)
- {
- for (i=0; i<n; i++) {
- name = SDL_GetAudioDeviceName(i, 1);
- AssertTrue(name != NULL, "name != NULL");
- AssertTrue(strlen(name)>0, "name empty");
+ /* 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);
}
}
}