Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
diff --git a/test/testautomation_audio.c b/test/testautomation_audio.c
index 4a5e9ee..0607156 100644
--- a/test/testautomation_audio.c
+++ b/test/testautomation_audio.c
@@ -3,6 +3,9 @@
* New/updated tests: aschiffler at ferzkopp dot net
*/
+/* quiet windows compiler warnings */
+#define _CRT_SECURE_NO_WARNINGS
+
#include <stdio.h>
#include <string.h>
@@ -25,11 +28,29 @@ _audioSetUp(void *arg)
}
}
+void
+_audioTearDown(void *arg)
+{
+ /* Remove a possibly created file from SDL disk writer audio driver; ignore errors */
+ remove("sdlaudio.raw");
+
+ SDLTest_AssertPass("Cleanup of test files completed");
+}
+
+
+/* Global counter for callback invocation */
+int _audio_testCallbackCounter;
+
+/* Global accumulator for total callback length */
+int _audio_testCallbackLength;
+
/* Test callback function */
void _audio_testCallback(void *userdata, Uint8 *stream, int len)
{
- /* TODO: add tracking if callback was called */
+ /* track that callback was called */
+ _audio_testCallbackCounter++;
+ _audio_testCallbackLength += len;
}
@@ -38,8 +59,8 @@ void _audio_testCallback(void *userdata, Uint8 *stream, int len)
/**
* \brief Stop and restart audio subsystem
*
- * \sa http://wiki.libsdl.org/moin.cgi/SDL_QuitSubSystem
- * \sa http://wiki.libsdl.org/moin.cgi/SDL_InitSubSystem
+ * \sa https://wiki.libsdl.org/SDL_QuitSubSystem
+ * \sa https://wiki.libsdl.org/SDL_InitSubSystem
*/
int audio_quitInitAudioSubSystem()
{
@@ -56,8 +77,8 @@ int audio_quitInitAudioSubSystem()
/**
* \brief Start and stop audio directly
*
- * \sa http://wiki.libsdl.org/moin.cgi/SDL_InitAudio
- * \sa http://wiki.libsdl.org/moin.cgi/SDL_QuitAudio
+ * \sa https://wiki.libsdl.org/SDL_InitAudio
+ * \sa https://wiki.libsdl.org/SDL_QuitAudio
*/
int audio_initQuitAudio()
{
@@ -110,15 +131,104 @@ int audio_initQuitAudio()
/**
* \brief Start, open, close and stop audio
*
- * \sa http://wiki.libsdl.org/moin.cgi/SDL_InitAudio
- * \sa http://wiki.libsdl.org/moin.cgi/SDL_OpenAudio
- * \sa http://wiki.libsdl.org/moin.cgi/SDL_CloseAudio
- * \sa http://wiki.libsdl.org/moin.cgi/SDL_QuitAudio
+ * \sa https://wiki.libsdl.org/SDL_InitAudio
+ * \sa https://wiki.libsdl.org/SDL_OpenAudio
+ * \sa https://wiki.libsdl.org/SDL_CloseAudio
+ * \sa https://wiki.libsdl.org/SDL_QuitAudio
*/
int audio_initOpenCloseQuitAudio()
{
+ int result, expectedResult;
+ int i, iMax, j, k;
+ const char* audioDriver;
+ SDL_AudioSpec desired;
+
+ /* Stop SDL audio subsystem */
+ SDL_QuitSubSystem( SDL_INIT_AUDIO );
+ SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
+
+ /* Loop over all available audio drivers */
+ iMax = SDL_GetNumAudioDrivers();
+ SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers");
+ SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
+ for (i = 0; i < iMax; i++) {
+ audioDriver = SDL_GetAudioDriver(i);
+ SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
+ SDLTest_AssertCheck(audioDriver != NULL, "Audio driver name is not NULL");
+ SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver);
+
+ /* Change specs */
+ for (j = 0; j < 2; j++) {
+
+ /* Call Init */
+ result = SDL_AudioInit(audioDriver);
+ SDLTest_AssertPass("Call to SDL_AudioInit('%s')", audioDriver);
+ SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
+
+ /* Set spec */
+ SDL_memset(&desired, 0, sizeof(desired));
+ switch (j) {
+ case 0:
+ /* Set standard desired spec */
+ desired.freq = 22050;
+ desired.format = AUDIO_S16SYS;
+ desired.channels = 2;
+ desired.samples = 4096;
+ desired.callback = _audio_testCallback;
+ desired.userdata = NULL;
+
+ case 1:
+ /* Set custom desired spec */
+ desired.freq = 48000;
+ desired.format = AUDIO_F32SYS;
+ desired.channels = 2;
+ desired.samples = 2048;
+ desired.callback = _audio_testCallback;
+ desired.userdata = NULL;
+ break;
+ }
+
+ /* Call Open (maybe multiple times) */
+ for (k=0; k <= j; k++) {
+ result = SDL_OpenAudio(&desired, NULL);
+ SDLTest_AssertPass("Call to SDL_OpenAudio(desired_spec_%d, NULL), call %d", j, k+1);
+ expectedResult = (k==0) ? 0 : -1;
+ SDLTest_AssertCheck(result == expectedResult, "Verify return value; expected: %d, got: %d", expectedResult, result);
+ }
+
+ /* Call Close (maybe multiple times) */
+ for (k=0; k <= j; k++) {
+ SDL_CloseAudio();
+ SDLTest_AssertPass("Call to SDL_CloseAudio(), call %d", k+1);
+ }
+
+ /* Call Quit (maybe multiple times) */
+ for (k=0; k <= j; k++) {
+ SDL_AudioQuit();
+ SDLTest_AssertPass("Call to SDL_AudioQuit(), call %d", k+1);
+ }
+
+ } /* spec loop */
+ } /* driver loop */
+
+ /* Restart audio again */
+ _audioSetUp(NULL);
+
+ return TEST_COMPLETED;
+}
+
+/**
+ * \brief Pause and unpause audio
+ *
+ * \sa https://wiki.libsdl.org/SDL_PauseAudio
+ */
+int audio_pauseUnpauseAudio()
+{
int result;
- int i, iMax, j;
+ int i, iMax, j, k, l;
+ int totalDelay;
+ int pause_on;
+ int originalCounter;
const char* audioDriver;
SDL_AudioSpec desired;
@@ -172,9 +282,47 @@ int audio_initOpenCloseQuitAudio()
SDLTest_AssertPass("Call to SDL_OpenAudio(desired_spec_%d, NULL)", j);
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0 got: %d", result);
+ /* Start and stop audio multiple times */
+ for (l=0; l<3; l++) {
+ SDLTest_Log("Pause/Unpause iteration: %d", l+1);
+
+ /* Reset callback counters */
+ _audio_testCallbackCounter = 0;
+ _audio_testCallbackLength = 0;
+
+ /* Un-pause audio to start playing (maybe multiple times) */
+ pause_on = 0;
+ for (k=0; k <= j; k++) {
+ SDL_PauseAudio(pause_on);
+ SDLTest_AssertPass("Call to SDL_PauseAudio(%d), call %d", pause_on, k+1);
+ }
+
+ /* Wait for callback */
+ totalDelay = 0;
+ do {
+ SDL_Delay(10);
+ totalDelay += 10;
+ }
+ while (_audio_testCallbackCounter == 0 && totalDelay < 1000);
+ SDLTest_AssertCheck(_audio_testCallbackCounter > 0, "Verify callback counter; expected: >0 got: %d", _audio_testCallbackCounter);
+ SDLTest_AssertCheck(_audio_testCallbackLength > 0, "Verify callback length; expected: >0 got: %d", _audio_testCallbackLength);
+
+ /* Pause audio to stop playing (maybe multiple times) */
+ for (k=0; k <= j; k++) {
+ pause_on = (k==0) ? 1 : SDLTest_RandomIntegerInRange(99, 9999);
+ SDL_PauseAudio(pause_on);
+ SDLTest_AssertPass("Call to SDL_PauseAudio(%d), call %d", pause_on, k+1);
+ }
+
+ /* Ensure callback is not called again */
+ originalCounter = _audio_testCallbackCounter;
+ SDL_Delay(totalDelay + 10);
+ SDLTest_AssertCheck(originalCounter == _audio_testCallbackCounter, "Verify callback counter; expected: %d, got: %d", originalCounter, _audio_testCallbackCounter);
+ }
+
/* Call Close */
- SDL_CloseAudio();
- SDLTest_AssertPass("Call to SDL_CloseAudio()");
+ SDL_CloseAudio();
+ SDLTest_AssertPass("Call to SDL_CloseAudio()");
/* Call Quit */
SDL_AudioQuit();
@@ -183,8 +331,8 @@ int audio_initOpenCloseQuitAudio()
} /* spec loop */
} /* driver loop */
- /* Restart audio again */
- _audioSetUp(NULL);
+ /* Restart audio again */
+ _audioSetUp(NULL);
return TEST_COMPLETED;
}
@@ -192,8 +340,8 @@ int audio_initOpenCloseQuitAudio()
/**
* \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
+ * \sa https://wiki.libsdl.org/SDL_GetNumAudioDevices
+ * \sa https://wiki.libsdl.org/SDL_GetAudioDeviceName
*/
int audio_enumerateAndNameAudioDevices()
{
@@ -250,8 +398,8 @@ int audio_enumerateAndNameAudioDevices()
/**
* \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
+ * \sa https://wiki.libsdl.org/SDL_GetNumAudioDevices
+ * \sa https://wiki.libsdl.org/SDL_GetAudioDeviceName
*/
int audio_enumerateAndNameAudioDevicesNegativeTests()
{
@@ -297,8 +445,8 @@ int audio_enumerateAndNameAudioDevicesNegativeTests()
/**
* \brief Checks available audio driver names.
*
- * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetNumAudioDrivers
- * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetAudioDriver
+ * \sa https://wiki.libsdl.org/SDL_GetNumAudioDrivers
+ * \sa https://wiki.libsdl.org/SDL_GetAudioDriver
*/
int audio_printAudioDrivers()
{
@@ -330,7 +478,7 @@ int audio_printAudioDrivers()
/**
* \brief Checks current audio driver name with initialized audio.
*
- * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetCurrentAudioDriver
+ * \sa https://wiki.libsdl.org/SDL_GetCurrentAudioDriver
*/
int audio_printCurrentAudioDriver()
{
@@ -362,7 +510,7 @@ int _audioFrequencies[] = { 11025, 22050, 44100, 48000 };
/**
* \brief Builds various audio conversion structures
*
- * \sa http://wiki.libsdl.org/moin.cgi/SDL_BuildAudioCVT
+ * \sa https://wiki.libsdl.org/SDL_BuildAudioCVT
*/
int audio_buildAudioCVT()
{
@@ -426,7 +574,7 @@ int audio_buildAudioCVT()
/**
* \brief Checkes calls with invalid input to SDL_BuildAudioCVT
*
- * \sa http://wiki.libsdl.org/moin.cgi/SDL_BuildAudioCVT
+ * \sa https://wiki.libsdl.org/SDL_BuildAudioCVT
*/
int audio_buildAudioCVTNegative()
{
@@ -521,7 +669,7 @@ int audio_buildAudioCVTNegative()
/**
* \brief Checks current audio status.
*
- * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetAudioStatus
+ * \sa https://wiki.libsdl.org/SDL_GetAudioStatus
*/
int audio_getAudioStatus()
{
@@ -542,7 +690,7 @@ int audio_getAudioStatus()
/**
* \brief Opens, checks current audio status, and closes a device.
*
- * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetAudioStatus
+ * \sa https://wiki.libsdl.org/SDL_GetAudioStatus
*/
int audio_openCloseAndGetAudioStatus()
{
@@ -600,8 +748,8 @@ int audio_openCloseAndGetAudioStatus()
/**
* \brief Locks and unlocks open audio device.
*
- * \sa http://wiki.libsdl.org/moin.cgi/SDL_LockAudioDevice
- * \sa http://wiki.libsdl.org/moin.cgi/SDL_UnlockAudioDevice
+ * \sa https://wiki.libsdl.org/SDL_LockAudioDevice
+ * \sa https://wiki.libsdl.org/SDL_UnlockAudioDevice
*/
int audio_lockUnlockOpenAudioDevice()
{
@@ -663,8 +811,8 @@ int audio_lockUnlockOpenAudioDevice()
/**
* \brief Convert audio using various conversion structures
*
- * \sa http://wiki.libsdl.org/moin.cgi/SDL_BuildAudioCVT
- * \sa http://wiki.libsdl.org/moin.cgi/SDL_ConvertAudio
+ * \sa https://wiki.libsdl.org/SDL_BuildAudioCVT
+ * \sa https://wiki.libsdl.org/SDL_ConvertAudio
*/
int audio_convertAudio()
{
@@ -762,7 +910,7 @@ int audio_convertAudio()
/**
* \brief Opens, checks current connected status, and closes a device.
*
- * \sa http://wiki.libsdl.org/moin.cgi/SDL_AudioDeviceConnected
+ * \sa https://wiki.libsdl.org/SDL_AudioDeviceConnected
*/
int audio_openCloseAudioDeviceConnected()
{
@@ -871,11 +1019,14 @@ static const SDLTest_TestCaseReference audioTest13 =
static const SDLTest_TestCaseReference audioTest14 =
{ (SDLTest_TestCaseFp)audio_initOpenCloseQuitAudio, "audio_initOpenCloseQuitAudio", "Cycle through init, open, close and quit with various audio specs.", TEST_ENABLED };
+static const SDLTest_TestCaseReference audioTest15 =
+ { (SDLTest_TestCaseFp)audio_pauseUnpauseAudio, "audio_pauseUnpauseAudio", "Pause and Unpause audio for various audio specs while testing callback.", TEST_ENABLED };
+
/* Sequence of Audio test cases */
static const SDLTest_TestCaseReference *audioTests[] = {
&audioTest1, &audioTest2, &audioTest3, &audioTest4, &audioTest5, &audioTest6,
&audioTest7, &audioTest8, &audioTest9, &audioTest10, &audioTest11,
- &audioTest12, &audioTest13, &audioTest14, NULL
+ &audioTest12, &audioTest13, &audioTest14, &audioTest15, NULL
};
/* Audio test suite (global) */
@@ -883,5 +1034,5 @@ SDLTest_TestSuiteReference audioTestSuite = {
"Audio",
_audioSetUp,
audioTests,
- NULL
+ _audioTearDown
};