testautomation_audio.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  1. /**
  2. * Original code: automated SDL audio test written by Edgar Simo "bobbens"
  3. * New/updated tests: aschiffler at ferzkopp dot net
  4. */
  5. /* quiet windows compiler warnings */
  6. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
  7. #define _CRT_SECURE_NO_WARNINGS
  8. #endif
  9. #include <stdio.h>
  10. #include <SDL3/SDL.h>
  11. #include <SDL3/SDL_test.h>
  12. /* ================= Test Case Implementation ================== */
  13. /* Fixture */
  14. static void audioSetUp(void *arg)
  15. {
  16. /* Start SDL audio subsystem */
  17. int ret = SDL_InitSubSystem(SDL_INIT_AUDIO);
  18. SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_AUDIO)");
  19. SDLTest_AssertCheck(ret == 0, "Check result from SDL_InitSubSystem(SDL_INIT_AUDIO)");
  20. if (ret != 0) {
  21. SDLTest_LogError("%s", SDL_GetError());
  22. }
  23. }
  24. static void audioTearDown(void *arg)
  25. {
  26. /* Remove a possibly created file from SDL disk writer audio driver; ignore errors */
  27. (void)remove("sdlaudio.raw");
  28. SDLTest_AssertPass("Cleanup of test files completed");
  29. }
  30. /* Global counter for callback invocation */
  31. static int g_audio_testCallbackCounter;
  32. /* Global accumulator for total callback length */
  33. static int g_audio_testCallbackLength;
  34. /* Test callback function */
  35. static void SDLCALL audio_testCallback(void *userdata, Uint8 *stream, int len)
  36. {
  37. /* track that callback was called */
  38. g_audio_testCallbackCounter++;
  39. g_audio_testCallbackLength += len;
  40. }
  41. static SDL_AudioDeviceID g_audio_id = -1;
  42. /* Test case functions */
  43. /**
  44. * \brief Stop and restart audio subsystem
  45. *
  46. * \sa https://wiki.libsdl.org/SDL_QuitSubSystem
  47. * \sa https://wiki.libsdl.org/SDL_InitSubSystem
  48. */
  49. int audio_quitInitAudioSubSystem()
  50. {
  51. /* Stop SDL audio subsystem */
  52. SDL_QuitSubSystem(SDL_INIT_AUDIO);
  53. SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
  54. /* Restart audio again */
  55. audioSetUp(NULL);
  56. return TEST_COMPLETED;
  57. }
  58. /**
  59. * \brief Start and stop audio directly
  60. *
  61. * \sa https://wiki.libsdl.org/SDL_InitAudio
  62. * \sa https://wiki.libsdl.org/SDL_QuitAudio
  63. */
  64. int audio_initQuitAudio()
  65. {
  66. int result;
  67. int i, iMax;
  68. const char *audioDriver;
  69. /* Stop SDL audio subsystem */
  70. SDL_QuitSubSystem(SDL_INIT_AUDIO);
  71. SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
  72. /* Loop over all available audio drivers */
  73. iMax = SDL_GetNumAudioDrivers();
  74. SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
  75. SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
  76. for (i = 0; i < iMax; i++) {
  77. audioDriver = SDL_GetAudioDriver(i);
  78. SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
  79. SDLTest_Assert(audioDriver != NULL, "Audio driver name is not NULL");
  80. SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver); /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
  81. /* Call Init */
  82. SDL_SetHint("SDL_AUDIO_DRIVER", audioDriver);
  83. result = SDL_InitSubSystem(SDL_INIT_AUDIO);
  84. SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_AUDIO) with driver='%s'", audioDriver);
  85. SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
  86. /* Call Quit */
  87. SDL_QuitSubSystem(SDL_INIT_AUDIO);
  88. SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
  89. }
  90. /* NULL driver specification */
  91. audioDriver = NULL;
  92. /* Call Init */
  93. SDL_SetHint("SDL_AUDIO_DRIVER", audioDriver);
  94. result = SDL_InitSubSystem(SDL_INIT_AUDIO);
  95. SDLTest_AssertPass("Call to SDL_AudioInit(NULL)");
  96. SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
  97. /* Call Quit */
  98. SDL_QuitSubSystem(SDL_INIT_AUDIO);
  99. SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
  100. /* Restart audio again */
  101. audioSetUp(NULL);
  102. return TEST_COMPLETED;
  103. }
  104. /**
  105. * \brief Start, open, close and stop audio
  106. *
  107. * \sa https://wiki.libsdl.org/SDL_InitAudio
  108. * \sa https://wiki.libsdl.org/SDL_OpenAudioDevice
  109. * \sa https://wiki.libsdl.org/SDL_CloseAudioDevice
  110. * \sa https://wiki.libsdl.org/SDL_QuitAudio
  111. */
  112. int audio_initOpenCloseQuitAudio()
  113. {
  114. int result;
  115. int i, iMax, j, k;
  116. const char *audioDriver;
  117. SDL_AudioSpec desired;
  118. /* Stop SDL audio subsystem */
  119. SDL_QuitSubSystem(SDL_INIT_AUDIO);
  120. SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
  121. /* Loop over all available audio drivers */
  122. iMax = SDL_GetNumAudioDrivers();
  123. SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
  124. SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
  125. for (i = 0; i < iMax; i++) {
  126. audioDriver = SDL_GetAudioDriver(i);
  127. SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
  128. SDLTest_Assert(audioDriver != NULL, "Audio driver name is not NULL");
  129. SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver); /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
  130. /* Change specs */
  131. for (j = 0; j < 2; j++) {
  132. /* Call Init */
  133. SDL_SetHint("SDL_AUDIO_DRIVER", audioDriver);
  134. result = SDL_InitSubSystem(SDL_INIT_AUDIO);
  135. SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_AUDIO) with driver='%s'", audioDriver);
  136. SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
  137. /* Set spec */
  138. SDL_memset(&desired, 0, sizeof(desired));
  139. switch (j) {
  140. case 0:
  141. /* Set standard desired spec */
  142. desired.freq = 22050;
  143. desired.format = AUDIO_S16SYS;
  144. desired.channels = 2;
  145. desired.samples = 4096;
  146. desired.callback = audio_testCallback;
  147. desired.userdata = NULL;
  148. case 1:
  149. /* Set custom desired spec */
  150. desired.freq = 48000;
  151. desired.format = AUDIO_F32SYS;
  152. desired.channels = 2;
  153. desired.samples = 2048;
  154. desired.callback = audio_testCallback;
  155. desired.userdata = NULL;
  156. break;
  157. }
  158. /* Call Open (maybe multiple times) */
  159. for (k = 0; k <= j; k++) {
  160. result = SDL_OpenAudioDevice(NULL, 0, &desired, NULL, 0);
  161. if (k == 0) {
  162. g_audio_id = result;
  163. }
  164. SDLTest_AssertPass("Call to SDL_OpenAudioDevice(NULL, 0, desired_spec_%d, NULL, 0), call %d", j, k + 1);
  165. SDLTest_AssertCheck(result > 0, "Verify return value; expected: > 0, got: %d", result);
  166. }
  167. /* Call Close (maybe multiple times) */
  168. for (k = 0; k <= j; k++) {
  169. SDL_CloseAudioDevice(g_audio_id);
  170. SDLTest_AssertPass("Call to SDL_CloseAudioDevice(), call %d", k + 1);
  171. }
  172. /* Call Quit (maybe multiple times) */
  173. for (k = 0; k <= j; k++) {
  174. SDL_QuitSubSystem(SDL_INIT_AUDIO);
  175. SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO), call %d", k + 1);
  176. }
  177. } /* spec loop */
  178. } /* driver loop */
  179. /* Restart audio again */
  180. audioSetUp(NULL);
  181. return TEST_COMPLETED;
  182. }
  183. /**
  184. * \brief Pause and unpause audio
  185. *
  186. * \sa https://wiki.libsdl.org/SDL_PauseAudioDevice
  187. * \sa https://wiki.libsdl.org/SDL_PlayAudioDevice
  188. */
  189. int audio_pauseUnpauseAudio()
  190. {
  191. int result;
  192. int i, iMax, j, k, l;
  193. int totalDelay;
  194. int pause_on;
  195. int originalCounter;
  196. const char *audioDriver;
  197. SDL_AudioSpec desired;
  198. /* Stop SDL audio subsystem */
  199. SDL_QuitSubSystem(SDL_INIT_AUDIO);
  200. SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
  201. /* Loop over all available audio drivers */
  202. iMax = SDL_GetNumAudioDrivers();
  203. SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
  204. SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
  205. for (i = 0; i < iMax; i++) {
  206. audioDriver = SDL_GetAudioDriver(i);
  207. SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
  208. SDLTest_Assert(audioDriver != NULL, "Audio driver name is not NULL");
  209. SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver); /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
  210. /* Change specs */
  211. for (j = 0; j < 2; j++) {
  212. /* Call Init */
  213. SDL_SetHint("SDL_AUDIO_DRIVER", audioDriver);
  214. result = SDL_InitSubSystem(SDL_INIT_AUDIO);
  215. SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_AUDIO) with driver='%s'", audioDriver);
  216. SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
  217. /* Set spec */
  218. SDL_memset(&desired, 0, sizeof(desired));
  219. switch (j) {
  220. case 0:
  221. /* Set standard desired spec */
  222. desired.freq = 22050;
  223. desired.format = AUDIO_S16SYS;
  224. desired.channels = 2;
  225. desired.samples = 4096;
  226. desired.callback = audio_testCallback;
  227. desired.userdata = NULL;
  228. case 1:
  229. /* Set custom desired spec */
  230. desired.freq = 48000;
  231. desired.format = AUDIO_F32SYS;
  232. desired.channels = 2;
  233. desired.samples = 2048;
  234. desired.callback = audio_testCallback;
  235. desired.userdata = NULL;
  236. break;
  237. }
  238. /* Call Open */
  239. g_audio_id = SDL_OpenAudioDevice(NULL, 0, &desired, NULL, 0);
  240. result = g_audio_id;
  241. SDLTest_AssertPass("Call to SDL_OpenAudioDevice(NULL, 0, desired_spec_%d, NULL, 0)", j);
  242. SDLTest_AssertCheck(result > 0, "Verify return value; expected > 0 got: %d", result);
  243. /* Start and stop audio multiple times */
  244. for (l = 0; l < 3; l++) {
  245. SDLTest_Log("Pause/Unpause iteration: %d", l + 1);
  246. /* Reset callback counters */
  247. g_audio_testCallbackCounter = 0;
  248. g_audio_testCallbackLength = 0;
  249. /* Un-pause audio to start playing (maybe multiple times) */
  250. pause_on = 0;
  251. for (k = 0; k <= j; k++) {
  252. SDL_PlayAudioDevice(g_audio_id);
  253. SDLTest_AssertPass("Call to SDL_PlayAudioDevice(g_audio_id), call %d", k + 1);
  254. }
  255. /* Wait for callback */
  256. totalDelay = 0;
  257. do {
  258. SDL_Delay(10);
  259. totalDelay += 10;
  260. } while (g_audio_testCallbackCounter == 0 && totalDelay < 1000);
  261. SDLTest_AssertCheck(g_audio_testCallbackCounter > 0, "Verify callback counter; expected: >0 got: %d", g_audio_testCallbackCounter);
  262. SDLTest_AssertCheck(g_audio_testCallbackLength > 0, "Verify callback length; expected: >0 got: %d", g_audio_testCallbackLength);
  263. /* Pause audio to stop playing (maybe multiple times) */
  264. for (k = 0; k <= j; k++) {
  265. pause_on = (k == 0) ? 1 : SDLTest_RandomIntegerInRange(99, 9999);
  266. if (pause_on) {
  267. SDL_PauseAudioDevice(g_audio_id);
  268. SDLTest_AssertPass("Call to SDL_PauseAudioDevice(g_audio_id), call %d", k + 1);
  269. } else {
  270. SDL_PlayAudioDevice(g_audio_id);
  271. SDLTest_AssertPass("Call to SDL_PlayAudioDevice(g_audio_id), call %d", k + 1);
  272. }
  273. }
  274. /* Ensure callback is not called again */
  275. originalCounter = g_audio_testCallbackCounter;
  276. SDL_Delay(totalDelay + 10);
  277. SDLTest_AssertCheck(originalCounter == g_audio_testCallbackCounter, "Verify callback counter; expected: %d, got: %d", originalCounter, g_audio_testCallbackCounter);
  278. }
  279. /* Call Close */
  280. SDL_CloseAudioDevice(g_audio_id);
  281. SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
  282. /* Call Quit */
  283. SDL_QuitSubSystem(SDL_INIT_AUDIO);
  284. SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
  285. } /* spec loop */
  286. } /* driver loop */
  287. /* Restart audio again */
  288. audioSetUp(NULL);
  289. return TEST_COMPLETED;
  290. }
  291. /**
  292. * \brief Enumerate and name available audio devices (output and capture).
  293. *
  294. * \sa https://wiki.libsdl.org/SDL_GetNumAudioDevices
  295. * \sa https://wiki.libsdl.org/SDL_GetAudioDeviceName
  296. */
  297. int audio_enumerateAndNameAudioDevices()
  298. {
  299. int t, tt;
  300. int i, n, nn;
  301. const char *name, *nameAgain;
  302. /* Iterate over types: t=0 output device, t=1 input/capture device */
  303. for (t = 0; t < 2; t++) {
  304. /* Get number of devices. */
  305. n = SDL_GetNumAudioDevices(t);
  306. SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(%i)", t);
  307. SDLTest_Log("Number of %s devices < 0, reported as %i", (t) ? "capture" : "output", n);
  308. SDLTest_AssertCheck(n >= 0, "Validate result is >= 0, got: %i", n);
  309. /* Variation of non-zero type */
  310. if (t == 1) {
  311. tt = t + SDLTest_RandomIntegerInRange(1, 10);
  312. nn = SDL_GetNumAudioDevices(tt);
  313. SDLTest_AssertCheck(n == nn, "Verify result from SDL_GetNumAudioDevices(%i), expected same number of audio devices %i, got %i", tt, n, nn);
  314. nn = SDL_GetNumAudioDevices(-tt);
  315. SDLTest_AssertCheck(n == nn, "Verify result from SDL_GetNumAudioDevices(%i), expected same number of audio devices %i, got %i", -tt, n, nn);
  316. }
  317. /* List devices. */
  318. if (n > 0) {
  319. for (i = 0; i < n; i++) {
  320. name = SDL_GetAudioDeviceName(i, t);
  321. SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
  322. SDLTest_AssertCheck(name != NULL, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not NULL", i, t);
  323. if (name != NULL) {
  324. SDLTest_AssertCheck(name[0] != '\0', "verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, t, name);
  325. if (t == 1) {
  326. /* Also try non-zero type */
  327. tt = t + SDLTest_RandomIntegerInRange(1, 10);
  328. nameAgain = SDL_GetAudioDeviceName(i, tt);
  329. SDLTest_AssertCheck(nameAgain != NULL, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not NULL", i, tt);
  330. if (nameAgain != NULL) {
  331. SDLTest_AssertCheck(nameAgain[0] != '\0', "Verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, tt, nameAgain);
  332. SDLTest_AssertCheck(SDL_strcmp(name, nameAgain) == 0,
  333. "Verify SDL_GetAudioDeviceName(%i, %i) and SDL_GetAudioDeviceName(%i %i) return the same string",
  334. i, t, i, tt);
  335. }
  336. }
  337. }
  338. }
  339. }
  340. }
  341. return TEST_COMPLETED;
  342. }
  343. /**
  344. * \brief Negative tests around enumeration and naming of audio devices.
  345. *
  346. * \sa https://wiki.libsdl.org/SDL_GetNumAudioDevices
  347. * \sa https://wiki.libsdl.org/SDL_GetAudioDeviceName
  348. */
  349. int audio_enumerateAndNameAudioDevicesNegativeTests()
  350. {
  351. int t;
  352. int i, j, no, nc;
  353. const char *name;
  354. /* Get number of devices. */
  355. no = SDL_GetNumAudioDevices(0);
  356. SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
  357. nc = SDL_GetNumAudioDevices(1);
  358. SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(1)");
  359. /* Invalid device index when getting name */
  360. for (t = 0; t < 2; t++) {
  361. /* Negative device index */
  362. i = SDLTest_RandomIntegerInRange(-10, -1);
  363. name = SDL_GetAudioDeviceName(i, t);
  364. SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
  365. SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result NULL, expected NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
  366. /* Device index past range */
  367. for (j = 0; j < 3; j++) {
  368. i = (t) ? nc + j : no + j;
  369. name = SDL_GetAudioDeviceName(i, t);
  370. SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
  371. SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result, expected: NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
  372. }
  373. /* Capture index past capture range but within output range */
  374. if ((no > 0) && (no > nc) && (t == 1)) {
  375. i = no - 1;
  376. name = SDL_GetAudioDeviceName(i, t);
  377. SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
  378. SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result, expected: NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
  379. }
  380. }
  381. return TEST_COMPLETED;
  382. }
  383. /**
  384. * \brief Checks available audio driver names.
  385. *
  386. * \sa https://wiki.libsdl.org/SDL_GetNumAudioDrivers
  387. * \sa https://wiki.libsdl.org/SDL_GetAudioDriver
  388. */
  389. int audio_printAudioDrivers()
  390. {
  391. int i, n;
  392. const char *name;
  393. /* Get number of drivers */
  394. n = SDL_GetNumAudioDrivers();
  395. SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
  396. SDLTest_AssertCheck(n >= 0, "Verify number of audio drivers >= 0, got: %i", n);
  397. /* List drivers. */
  398. if (n > 0) {
  399. for (i = 0; i < n; i++) {
  400. name = SDL_GetAudioDriver(i);
  401. SDLTest_AssertPass("Call to SDL_GetAudioDriver(%i)", i);
  402. SDLTest_AssertCheck(name != NULL, "Verify returned name is not NULL");
  403. if (name != NULL) {
  404. SDLTest_AssertCheck(name[0] != '\0', "Verify returned name is not empty, got: '%s'", name);
  405. }
  406. }
  407. }
  408. return TEST_COMPLETED;
  409. }
  410. /**
  411. * \brief Checks current audio driver name with initialized audio.
  412. *
  413. * \sa https://wiki.libsdl.org/SDL_GetCurrentAudioDriver
  414. */
  415. int audio_printCurrentAudioDriver()
  416. {
  417. /* Check current audio driver */
  418. const char *name = SDL_GetCurrentAudioDriver();
  419. SDLTest_AssertPass("Call to SDL_GetCurrentAudioDriver()");
  420. SDLTest_AssertCheck(name != NULL, "Verify returned name is not NULL");
  421. if (name != NULL) {
  422. SDLTest_AssertCheck(name[0] != '\0', "Verify returned name is not empty, got: '%s'", name);
  423. }
  424. return TEST_COMPLETED;
  425. }
  426. /* Definition of all formats, channels, and frequencies used to test audio conversions */
  427. const int g_numAudioFormats = 18;
  428. static SDL_AudioFormat g_audioFormats[] = { AUDIO_S8, AUDIO_U8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_S16SYS, AUDIO_S16, AUDIO_U16LSB,
  429. AUDIO_U16MSB, AUDIO_U16SYS, AUDIO_U16, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_S32SYS, AUDIO_S32,
  430. AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_F32SYS, AUDIO_F32 };
  431. const char *g_audioFormatsVerbose[] = { "AUDIO_S8", "AUDIO_U8", "AUDIO_S16LSB", "AUDIO_S16MSB", "AUDIO_S16SYS", "AUDIO_S16", "AUDIO_U16LSB",
  432. "AUDIO_U16MSB", "AUDIO_U16SYS", "AUDIO_U16", "AUDIO_S32LSB", "AUDIO_S32MSB", "AUDIO_S32SYS", "AUDIO_S32",
  433. "AUDIO_F32LSB", "AUDIO_F32MSB", "AUDIO_F32SYS", "AUDIO_F32" };
  434. const int g_numAudioChannels = 4;
  435. Uint8 g_audioChannels[] = { 1, 2, 4, 6 };
  436. const int g_numAudioFrequencies = 4;
  437. int g_audioFrequencies[] = { 11025, 22050, 44100, 48000 };
  438. /**
  439. * \brief Builds various audio conversion structures
  440. *
  441. * \sa https://wiki.libsdl.org/SDL_BuildAudioCVT
  442. */
  443. int audio_buildAudioCVT()
  444. {
  445. int result;
  446. SDL_AudioCVT cvt;
  447. SDL_AudioSpec spec1;
  448. SDL_AudioSpec spec2;
  449. int i, ii, j, jj, k, kk;
  450. /* No conversion needed */
  451. spec1.format = AUDIO_S16LSB;
  452. spec1.channels = 2;
  453. spec1.freq = 22050;
  454. result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
  455. spec1.format, spec1.channels, spec1.freq);
  456. SDLTest_AssertPass("Call to SDL_BuildAudioCVT(spec1 ==> spec1)");
  457. SDLTest_AssertCheck(result == 0, "Verify result value; expected: 0, got: %i", result);
  458. /* Typical conversion */
  459. spec1.format = AUDIO_S8;
  460. spec1.channels = 1;
  461. spec1.freq = 22050;
  462. spec2.format = AUDIO_S16LSB;
  463. spec2.channels = 2;
  464. spec2.freq = 44100;
  465. result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
  466. spec2.format, spec2.channels, spec2.freq);
  467. SDLTest_AssertPass("Call to SDL_BuildAudioCVT(spec1 ==> spec2)");
  468. SDLTest_AssertCheck(result == 1, "Verify result value; expected: 1, got: %i", result);
  469. /* All source conversions with random conversion targets, allow 'null' conversions */
  470. for (i = 0; i < g_numAudioFormats; i++) {
  471. for (j = 0; j < g_numAudioChannels; j++) {
  472. for (k = 0; k < g_numAudioFrequencies; k++) {
  473. spec1.format = g_audioFormats[i];
  474. spec1.channels = g_audioChannels[j];
  475. spec1.freq = g_audioFrequencies[k];
  476. ii = SDLTest_RandomIntegerInRange(0, g_numAudioFormats - 1);
  477. jj = SDLTest_RandomIntegerInRange(0, g_numAudioChannels - 1);
  478. kk = SDLTest_RandomIntegerInRange(0, g_numAudioFrequencies - 1);
  479. spec2.format = g_audioFormats[ii];
  480. spec2.channels = g_audioChannels[jj];
  481. spec2.freq = g_audioFrequencies[kk];
  482. result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
  483. spec2.format, spec2.channels, spec2.freq);
  484. SDLTest_AssertPass("Call to SDL_BuildAudioCVT(format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i ==> format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i)",
  485. i, g_audioFormatsVerbose[i], spec1.format, j, spec1.channels, k, spec1.freq, ii, g_audioFormatsVerbose[ii], spec2.format, jj, spec2.channels, kk, spec2.freq);
  486. SDLTest_AssertCheck(result == 0 || result == 1, "Verify result value; expected: 0 or 1, got: %i", result);
  487. if (result < 0) {
  488. SDLTest_LogError("%s", SDL_GetError());
  489. } else {
  490. SDLTest_AssertCheck(cvt.len_mult > 0, "Verify that cvt.len_mult value; expected: >0, got: %i", cvt.len_mult);
  491. }
  492. }
  493. }
  494. }
  495. return TEST_COMPLETED;
  496. }
  497. /**
  498. * \brief Checkes calls with invalid input to SDL_BuildAudioCVT
  499. *
  500. * \sa https://wiki.libsdl.org/SDL_BuildAudioCVT
  501. */
  502. int audio_buildAudioCVTNegative()
  503. {
  504. const char *expectedError = "Parameter 'cvt' is invalid";
  505. const char *error;
  506. int result;
  507. SDL_AudioCVT cvt;
  508. SDL_AudioSpec spec1;
  509. SDL_AudioSpec spec2;
  510. int i;
  511. char message[256];
  512. /* Valid format */
  513. spec1.format = AUDIO_S8;
  514. spec1.channels = 1;
  515. spec1.freq = 22050;
  516. spec2.format = AUDIO_S16LSB;
  517. spec2.channels = 2;
  518. spec2.freq = 44100;
  519. SDL_ClearError();
  520. SDLTest_AssertPass("Call to SDL_ClearError()");
  521. /* NULL input for CVT buffer */
  522. result = SDL_BuildAudioCVT((SDL_AudioCVT *)NULL, spec1.format, spec1.channels, spec1.freq,
  523. spec2.format, spec2.channels, spec2.freq);
  524. SDLTest_AssertPass("Call to SDL_BuildAudioCVT(NULL,...)");
  525. SDLTest_AssertCheck(result == -1, "Verify result value; expected: -1, got: %i", result);
  526. error = SDL_GetError();
  527. SDLTest_AssertPass("Call to SDL_GetError()");
  528. SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
  529. if (error != NULL) {
  530. SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
  531. "Validate error message, expected: '%s', got: '%s'", expectedError, error);
  532. }
  533. /* Invalid conversions */
  534. for (i = 1; i < 64; i++) {
  535. /* Valid format to start with */
  536. spec1.format = AUDIO_S8;
  537. spec1.channels = 1;
  538. spec1.freq = 22050;
  539. spec2.format = AUDIO_S16LSB;
  540. spec2.channels = 2;
  541. spec2.freq = 44100;
  542. SDL_ClearError();
  543. SDLTest_AssertPass("Call to SDL_ClearError()");
  544. /* Set various invalid format inputs */
  545. SDL_strlcpy(message, "Invalid: ", 256);
  546. if (i & 1) {
  547. SDL_strlcat(message, " spec1.format", 256);
  548. spec1.format = 0;
  549. }
  550. if (i & 2) {
  551. SDL_strlcat(message, " spec1.channels", 256);
  552. spec1.channels = 0;
  553. }
  554. if (i & 4) {
  555. SDL_strlcat(message, " spec1.freq", 256);
  556. spec1.freq = 0;
  557. }
  558. if (i & 8) {
  559. SDL_strlcat(message, " spec2.format", 256);
  560. spec2.format = 0;
  561. }
  562. if (i & 16) {
  563. SDL_strlcat(message, " spec2.channels", 256);
  564. spec2.channels = 0;
  565. }
  566. if (i & 32) {
  567. SDL_strlcat(message, " spec2.freq", 256);
  568. spec2.freq = 0;
  569. }
  570. SDLTest_Log("%s", message);
  571. result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
  572. spec2.format, spec2.channels, spec2.freq);
  573. SDLTest_AssertPass("Call to SDL_BuildAudioCVT(spec1 ==> spec2)");
  574. SDLTest_AssertCheck(result == -1, "Verify result value; expected: -1, got: %i", result);
  575. error = SDL_GetError();
  576. SDLTest_AssertPass("Call to SDL_GetError()");
  577. SDLTest_AssertCheck(error != NULL && error[0] != '\0', "Validate that error message was not NULL or empty");
  578. }
  579. SDL_ClearError();
  580. SDLTest_AssertPass("Call to SDL_ClearError()");
  581. return TEST_COMPLETED;
  582. }
  583. /**
  584. * \brief Checks current audio status.
  585. *
  586. * \sa https://wiki.libsdl.org/SDL_GetAudioDeviceStatus
  587. */
  588. int audio_getAudioStatus()
  589. {
  590. SDL_AudioStatus result;
  591. /* Check current audio status */
  592. result = SDL_GetAudioDeviceStatus(g_audio_id);
  593. SDLTest_AssertPass("Call to SDL_GetAudioDeviceStatus(g_audio_id)");
  594. SDLTest_AssertCheck(result == SDL_AUDIO_STOPPED || result == SDL_AUDIO_PLAYING || result == SDL_AUDIO_PAUSED,
  595. "Verify returned value; expected: STOPPED (%i) | PLAYING (%i) | PAUSED (%i), got: %i",
  596. SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED, result);
  597. return TEST_COMPLETED;
  598. }
  599. /**
  600. * \brief Opens, checks current audio status, and closes a device.
  601. *
  602. * \sa https://wiki.libsdl.org/SDL_GetAudioStatus
  603. */
  604. int audio_openCloseAndGetAudioStatus()
  605. {
  606. SDL_AudioStatus result;
  607. int i;
  608. int count;
  609. const char *device;
  610. SDL_AudioDeviceID id;
  611. SDL_AudioSpec desired, obtained;
  612. /* Get number of devices. */
  613. count = SDL_GetNumAudioDevices(0);
  614. SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
  615. if (count > 0) {
  616. for (i = 0; i < count; i++) {
  617. /* Get device name */
  618. device = SDL_GetAudioDeviceName(i, 0);
  619. SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
  620. SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
  621. if (device == NULL) {
  622. return TEST_ABORTED;
  623. }
  624. /* Set standard desired spec */
  625. desired.freq = 22050;
  626. desired.format = AUDIO_S16SYS;
  627. desired.channels = 2;
  628. desired.samples = 4096;
  629. desired.callback = audio_testCallback;
  630. desired.userdata = NULL;
  631. /* Open device */
  632. id = SDL_OpenAudioDevice(device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
  633. SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
  634. SDLTest_AssertCheck(id > 0, "Validate device ID; expected: > 0, got: %" SDL_PRIu32, id);
  635. if (id > 0) {
  636. /* Check device audio status */
  637. result = SDL_GetAudioDeviceStatus(id);
  638. SDLTest_AssertPass("Call to SDL_GetAudioDeviceStatus()");
  639. SDLTest_AssertCheck(result == SDL_AUDIO_STOPPED || result == SDL_AUDIO_PLAYING || result == SDL_AUDIO_PAUSED,
  640. "Verify returned value; expected: STOPPED (%i) | PLAYING (%i) | PAUSED (%i), got: %i",
  641. SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED, result);
  642. /* Close device again */
  643. SDL_CloseAudioDevice(id);
  644. SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
  645. }
  646. }
  647. } else {
  648. SDLTest_Log("No devices to test with");
  649. }
  650. return TEST_COMPLETED;
  651. }
  652. /**
  653. * \brief Locks and unlocks open audio device.
  654. *
  655. * \sa https://wiki.libsdl.org/SDL_LockAudioDevice
  656. * \sa https://wiki.libsdl.org/SDL_UnlockAudioDevice
  657. */
  658. int audio_lockUnlockOpenAudioDevice()
  659. {
  660. int i;
  661. int count;
  662. const char *device;
  663. SDL_AudioDeviceID id;
  664. SDL_AudioSpec desired, obtained;
  665. /* Get number of devices. */
  666. count = SDL_GetNumAudioDevices(0);
  667. SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
  668. if (count > 0) {
  669. for (i = 0; i < count; i++) {
  670. /* Get device name */
  671. device = SDL_GetAudioDeviceName(i, 0);
  672. SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
  673. SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
  674. if (device == NULL) {
  675. return TEST_ABORTED;
  676. }
  677. /* Set standard desired spec */
  678. desired.freq = 22050;
  679. desired.format = AUDIO_S16SYS;
  680. desired.channels = 2;
  681. desired.samples = 4096;
  682. desired.callback = audio_testCallback;
  683. desired.userdata = NULL;
  684. /* Open device */
  685. id = SDL_OpenAudioDevice(device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
  686. SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
  687. SDLTest_AssertCheck(id > 1, "Validate device ID; expected: > 0, got: %" SDL_PRIu32, id);
  688. if (id > 0) {
  689. /* Lock to protect callback */
  690. SDL_LockAudioDevice(id);
  691. SDLTest_AssertPass("SDL_LockAudioDevice(%" SDL_PRIu32 ")", id);
  692. /* Simulate callback processing */
  693. SDL_Delay(10);
  694. SDLTest_Log("Simulate callback processing - delay");
  695. /* Unlock again */
  696. SDL_UnlockAudioDevice(id);
  697. SDLTest_AssertPass("SDL_UnlockAudioDevice(%" SDL_PRIu32 ")", id);
  698. /* Close device again */
  699. SDL_CloseAudioDevice(id);
  700. SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
  701. }
  702. }
  703. } else {
  704. SDLTest_Log("No devices to test with");
  705. }
  706. return TEST_COMPLETED;
  707. }
  708. /**
  709. * \brief Convert audio using various conversion structures
  710. *
  711. * \sa https://wiki.libsdl.org/SDL_BuildAudioCVT
  712. * \sa https://wiki.libsdl.org/SDL_ConvertAudio
  713. */
  714. int audio_convertAudio()
  715. {
  716. int result;
  717. SDL_AudioCVT cvt;
  718. SDL_AudioSpec spec1;
  719. SDL_AudioSpec spec2;
  720. int c;
  721. char message[128];
  722. int i, ii, j, jj, k, kk, l, ll;
  723. /* Iterate over bitmask that determines which parameters are modified in the conversion */
  724. for (c = 1; c < 8; c++) {
  725. SDL_strlcpy(message, "Changing:", 128);
  726. if (c & 1) {
  727. SDL_strlcat(message, " Format", 128);
  728. }
  729. if (c & 2) {
  730. SDL_strlcat(message, " Channels", 128);
  731. }
  732. if (c & 4) {
  733. SDL_strlcat(message, " Frequencies", 128);
  734. }
  735. SDLTest_Log("%s", message);
  736. /* All source conversions with random conversion targets */
  737. for (i = 0; i < g_numAudioFormats; i++) {
  738. for (j = 0; j < g_numAudioChannels; j++) {
  739. for (k = 0; k < g_numAudioFrequencies; k++) {
  740. spec1.format = g_audioFormats[i];
  741. spec1.channels = g_audioChannels[j];
  742. spec1.freq = g_audioFrequencies[k];
  743. /* Ensure we have a different target format */
  744. do {
  745. if (c & 1) {
  746. ii = SDLTest_RandomIntegerInRange(0, g_numAudioFormats - 1);
  747. } else {
  748. ii = 1;
  749. }
  750. if (c & 2) {
  751. jj = SDLTest_RandomIntegerInRange(0, g_numAudioChannels - 1);
  752. } else {
  753. jj = j;
  754. }
  755. if (c & 4) {
  756. kk = SDLTest_RandomIntegerInRange(0, g_numAudioFrequencies - 1);
  757. } else {
  758. kk = k;
  759. }
  760. } while ((i == ii) && (j == jj) && (k == kk));
  761. spec2.format = g_audioFormats[ii];
  762. spec2.channels = g_audioChannels[jj];
  763. spec2.freq = g_audioFrequencies[kk];
  764. result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
  765. spec2.format, spec2.channels, spec2.freq);
  766. SDLTest_AssertPass("Call to SDL_BuildAudioCVT(format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i ==> format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i)",
  767. i, g_audioFormatsVerbose[i], spec1.format, j, spec1.channels, k, spec1.freq, ii, g_audioFormatsVerbose[ii], spec2.format, jj, spec2.channels, kk, spec2.freq);
  768. SDLTest_AssertCheck(result == 1, "Verify result value; expected: 1, got: %i", result);
  769. if (result != 1) {
  770. SDLTest_LogError("%s", SDL_GetError());
  771. } else {
  772. SDLTest_AssertCheck(cvt.len_mult > 0, "Verify that cvt.len_mult value; expected: >0, got: %i", cvt.len_mult);
  773. if (cvt.len_mult < 1) {
  774. return TEST_ABORTED;
  775. }
  776. /* Create some random data to convert */
  777. l = 64;
  778. ll = l * cvt.len_mult;
  779. SDLTest_Log("Creating dummy sample buffer of %i length (%i bytes)", l, ll);
  780. cvt.len = l;
  781. cvt.buf = (Uint8 *)SDL_malloc(ll);
  782. SDLTest_AssertCheck(cvt.buf != NULL, "Check data buffer to convert is not NULL");
  783. if (cvt.buf == NULL) {
  784. return TEST_ABORTED;
  785. }
  786. /* Convert the data */
  787. result = SDL_ConvertAudio(&cvt);
  788. SDLTest_AssertPass("Call to SDL_ConvertAudio()");
  789. SDLTest_AssertCheck(result == 0, "Verify result value; expected: 0; got: %i", result);
  790. SDLTest_AssertCheck(cvt.buf != NULL, "Verify conversion buffer is not NULL");
  791. SDLTest_AssertCheck(cvt.len_ratio > 0.0, "Verify conversion length ratio; expected: >0; got: %f", cvt.len_ratio);
  792. /* Free converted buffer */
  793. SDL_free(cvt.buf);
  794. cvt.buf = NULL;
  795. }
  796. }
  797. }
  798. }
  799. }
  800. return TEST_COMPLETED;
  801. }
  802. /**
  803. * \brief Opens, checks current connected status, and closes a device.
  804. *
  805. * \sa https://wiki.libsdl.org/SDL_AudioDeviceConnected
  806. */
  807. int audio_openCloseAudioDeviceConnected()
  808. {
  809. int result = -1;
  810. int i;
  811. int count;
  812. const char *device;
  813. SDL_AudioDeviceID id;
  814. SDL_AudioSpec desired, obtained;
  815. /* Get number of devices. */
  816. count = SDL_GetNumAudioDevices(0);
  817. SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
  818. if (count > 0) {
  819. for (i = 0; i < count; i++) {
  820. /* Get device name */
  821. device = SDL_GetAudioDeviceName(i, 0);
  822. SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
  823. SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
  824. if (device == NULL) {
  825. return TEST_ABORTED;
  826. }
  827. /* Set standard desired spec */
  828. desired.freq = 22050;
  829. desired.format = AUDIO_S16SYS;
  830. desired.channels = 2;
  831. desired.samples = 4096;
  832. desired.callback = audio_testCallback;
  833. desired.userdata = NULL;
  834. /* Open device */
  835. id = SDL_OpenAudioDevice(device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
  836. SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
  837. SDLTest_AssertCheck(id > 0, "Validate device ID; expected: > 0, got: %" SDL_PRIu32, id);
  838. if (id > 0) {
  839. /* TODO: enable test code when function is available in SDL3 */
  840. #ifdef AUDIODEVICECONNECTED_DEFINED
  841. /* Get connected status */
  842. result = SDL_AudioDeviceConnected(id);
  843. SDLTest_AssertPass("Call to SDL_AudioDeviceConnected()");
  844. #endif
  845. SDLTest_AssertCheck(result == 1, "Verify returned value; expected: 1; got: %i", result);
  846. /* Close device again */
  847. SDL_CloseAudioDevice(id);
  848. SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
  849. }
  850. }
  851. } else {
  852. SDLTest_Log("No devices to test with");
  853. }
  854. return TEST_COMPLETED;
  855. }
  856. /* ================= Test Case References ================== */
  857. /* Audio test cases */
  858. static const SDLTest_TestCaseReference audioTest1 = {
  859. (SDLTest_TestCaseFp)audio_enumerateAndNameAudioDevices, "audio_enumerateAndNameAudioDevices", "Enumerate and name available audio devices (output and capture)", TEST_ENABLED
  860. };
  861. static const SDLTest_TestCaseReference audioTest2 = {
  862. (SDLTest_TestCaseFp)audio_enumerateAndNameAudioDevicesNegativeTests, "audio_enumerateAndNameAudioDevicesNegativeTests", "Negative tests around enumeration and naming of audio devices.", TEST_ENABLED
  863. };
  864. static const SDLTest_TestCaseReference audioTest3 = {
  865. (SDLTest_TestCaseFp)audio_printAudioDrivers, "audio_printAudioDrivers", "Checks available audio driver names.", TEST_ENABLED
  866. };
  867. static const SDLTest_TestCaseReference audioTest4 = {
  868. (SDLTest_TestCaseFp)audio_printCurrentAudioDriver, "audio_printCurrentAudioDriver", "Checks current audio driver name with initialized audio.", TEST_ENABLED
  869. };
  870. static const SDLTest_TestCaseReference audioTest5 = {
  871. (SDLTest_TestCaseFp)audio_buildAudioCVT, "audio_buildAudioCVT", "Builds various audio conversion structures.", TEST_ENABLED
  872. };
  873. static const SDLTest_TestCaseReference audioTest6 = {
  874. (SDLTest_TestCaseFp)audio_buildAudioCVTNegative, "audio_buildAudioCVTNegative", "Checks calls with invalid input to SDL_BuildAudioCVT", TEST_ENABLED
  875. };
  876. static const SDLTest_TestCaseReference audioTest7 = {
  877. (SDLTest_TestCaseFp)audio_getAudioStatus, "audio_getAudioStatus", "Checks current audio status.", TEST_ENABLED
  878. };
  879. static const SDLTest_TestCaseReference audioTest8 = {
  880. (SDLTest_TestCaseFp)audio_openCloseAndGetAudioStatus, "audio_openCloseAndGetAudioStatus", "Opens and closes audio device and get audio status.", TEST_ENABLED
  881. };
  882. static const SDLTest_TestCaseReference audioTest9 = {
  883. (SDLTest_TestCaseFp)audio_lockUnlockOpenAudioDevice, "audio_lockUnlockOpenAudioDevice", "Locks and unlocks an open audio device.", TEST_ENABLED
  884. };
  885. /* TODO: enable test when SDL_ConvertAudio segfaults on cygwin have been fixed. */
  886. /* For debugging, test case can be run manually using --filter audio_convertAudio */
  887. static const SDLTest_TestCaseReference audioTest10 = {
  888. (SDLTest_TestCaseFp)audio_convertAudio, "audio_convertAudio", "Convert audio using available formats.", TEST_DISABLED
  889. };
  890. /* TODO: enable test when SDL_AudioDeviceConnected has been implemented. */
  891. static const SDLTest_TestCaseReference audioTest11 = {
  892. (SDLTest_TestCaseFp)audio_openCloseAudioDeviceConnected, "audio_openCloseAudioDeviceConnected", "Opens and closes audio device and get connected status.", TEST_DISABLED
  893. };
  894. static const SDLTest_TestCaseReference audioTest12 = {
  895. (SDLTest_TestCaseFp)audio_quitInitAudioSubSystem, "audio_quitInitAudioSubSystem", "Quit and re-init audio subsystem.", TEST_ENABLED
  896. };
  897. static const SDLTest_TestCaseReference audioTest13 = {
  898. (SDLTest_TestCaseFp)audio_initQuitAudio, "audio_initQuitAudio", "Init and quit audio drivers directly.", TEST_ENABLED
  899. };
  900. static const SDLTest_TestCaseReference audioTest14 = {
  901. (SDLTest_TestCaseFp)audio_initOpenCloseQuitAudio, "audio_initOpenCloseQuitAudio", "Cycle through init, open, close and quit with various audio specs.", TEST_ENABLED
  902. };
  903. static const SDLTest_TestCaseReference audioTest15 = {
  904. (SDLTest_TestCaseFp)audio_pauseUnpauseAudio, "audio_pauseUnpauseAudio", "Pause and Unpause audio for various audio specs while testing callback.", TEST_ENABLED
  905. };
  906. /* Sequence of Audio test cases */
  907. static const SDLTest_TestCaseReference *audioTests[] = {
  908. &audioTest1, &audioTest2, &audioTest3, &audioTest4, &audioTest5, &audioTest6,
  909. &audioTest7, &audioTest8, &audioTest9, &audioTest10, &audioTest11,
  910. &audioTest12, &audioTest13, &audioTest14, &audioTest15, NULL
  911. };
  912. /* Audio test suite (global) */
  913. SDLTest_TestSuiteReference audioTestSuite = {
  914. "Audio",
  915. audioSetUp,
  916. audioTests,
  917. audioTearDown
  918. };