testautomation_audio.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073
  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 SDL_QuitSubSystem
  47. * \sa SDL_InitSubSystem
  48. */
  49. static int audio_quitInitAudioSubSystem(void *arg)
  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 SDL_InitAudio
  62. * \sa SDL_QuitAudio
  63. */
  64. static int audio_initQuitAudio(void *arg)
  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 SDL_InitAudio
  108. * \sa SDL_OpenAudioDevice
  109. * \sa SDL_CloseAudioDevice
  110. * \sa SDL_QuitAudio
  111. */
  112. static int audio_initOpenCloseQuitAudio(void *arg)
  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 SDL_PauseAudioDevice
  187. * \sa SDL_PlayAudioDevice
  188. */
  189. static int audio_pauseUnpauseAudio(void *arg)
  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 SDL_GetNumAudioDevices
  295. * \sa SDL_GetAudioDeviceName
  296. */
  297. static int audio_enumerateAndNameAudioDevices(void *arg)
  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 SDL_GetNumAudioDevices
  347. * \sa SDL_GetAudioDeviceName
  348. */
  349. static int audio_enumerateAndNameAudioDevicesNegativeTests(void *arg)
  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 SDL_GetNumAudioDrivers
  387. * \sa SDL_GetAudioDriver
  388. */
  389. static int audio_printAudioDrivers(void *arg)
  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 SDL_GetCurrentAudioDriver
  414. */
  415. static int audio_printCurrentAudioDriver(void *arg)
  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. static 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. static 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. static const int g_numAudioChannels = 4;
  435. static Uint8 g_audioChannels[] = { 1, 2, 4, 6 };
  436. static const int g_numAudioFrequencies = 4;
  437. static int g_audioFrequencies[] = { 11025, 22050, 44100, 48000 };
  438. /**
  439. * \brief Builds various audio conversion structures
  440. *
  441. * \sa SDL_CreateAudioStream
  442. */
  443. static int audio_buildAudioStream(void *arg)
  444. {
  445. SDL_AudioStream *stream;
  446. SDL_AudioSpec spec1;
  447. SDL_AudioSpec spec2;
  448. int i, ii, j, jj, k, kk;
  449. /* No conversion needed */
  450. spec1.format = AUDIO_S16LSB;
  451. spec1.channels = 2;
  452. spec1.freq = 22050;
  453. stream = SDL_CreateAudioStream(spec1.format, spec1.channels, spec1.freq,
  454. spec1.format, spec1.channels, spec1.freq);
  455. SDLTest_AssertPass("Call to SDL_CreateAudioStream(spec1 ==> spec1)");
  456. SDLTest_AssertCheck(stream != NULL, "Verify stream value; expected: != NULL, got: %p", (void *)stream);
  457. SDL_DestroyAudioStream(stream);
  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. stream = SDL_CreateAudioStream(spec1.format, spec1.channels, spec1.freq,
  466. spec2.format, spec2.channels, spec2.freq);
  467. SDLTest_AssertPass("Call to SDL_CreateAudioStream(spec1 ==> spec2)");
  468. SDLTest_AssertCheck(stream != NULL, "Verify stream value; expected: != NULL, got: %p", (void *)stream);
  469. SDL_DestroyAudioStream(stream);
  470. /* All source conversions with random conversion targets, allow 'null' conversions */
  471. for (i = 0; i < g_numAudioFormats; i++) {
  472. for (j = 0; j < g_numAudioChannels; j++) {
  473. for (k = 0; k < g_numAudioFrequencies; k++) {
  474. spec1.format = g_audioFormats[i];
  475. spec1.channels = g_audioChannels[j];
  476. spec1.freq = g_audioFrequencies[k];
  477. ii = SDLTest_RandomIntegerInRange(0, g_numAudioFormats - 1);
  478. jj = SDLTest_RandomIntegerInRange(0, g_numAudioChannels - 1);
  479. kk = SDLTest_RandomIntegerInRange(0, g_numAudioFrequencies - 1);
  480. spec2.format = g_audioFormats[ii];
  481. spec2.channels = g_audioChannels[jj];
  482. spec2.freq = g_audioFrequencies[kk];
  483. stream = SDL_CreateAudioStream(spec1.format, spec1.channels, spec1.freq,
  484. spec2.format, spec2.channels, spec2.freq);
  485. SDLTest_AssertPass("Call to SDL_CreateAudioStream(format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i ==> format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i)",
  486. i, g_audioFormatsVerbose[i], spec1.format, j, spec1.channels, k, spec1.freq, ii, g_audioFormatsVerbose[ii], spec2.format, jj, spec2.channels, kk, spec2.freq);
  487. SDLTest_AssertCheck(stream != NULL, "Verify stream value; expected: != NULL, got: %p", (void *)stream);
  488. if (stream == NULL) {
  489. SDLTest_LogError("%s", SDL_GetError());
  490. }
  491. SDL_DestroyAudioStream(stream);
  492. }
  493. }
  494. }
  495. return TEST_COMPLETED;
  496. }
  497. /**
  498. * \brief Checks calls with invalid input to SDL_CreateAudioStream
  499. *
  500. * \sa SDL_CreateAudioStream
  501. */
  502. static int audio_buildAudioStreamNegative(void *arg)
  503. {
  504. const char *error;
  505. SDL_AudioStream *stream;
  506. SDL_AudioSpec spec1;
  507. SDL_AudioSpec spec2;
  508. int i;
  509. char message[256];
  510. /* Valid format */
  511. spec1.format = AUDIO_S8;
  512. spec1.channels = 1;
  513. spec1.freq = 22050;
  514. spec2.format = AUDIO_S16LSB;
  515. spec2.channels = 2;
  516. spec2.freq = 44100;
  517. SDL_ClearError();
  518. SDLTest_AssertPass("Call to SDL_ClearError()");
  519. /* Invalid conversions */
  520. for (i = 1; i < 64; i++) {
  521. /* Valid format to start with */
  522. spec1.format = AUDIO_S8;
  523. spec1.channels = 1;
  524. spec1.freq = 22050;
  525. spec2.format = AUDIO_S16LSB;
  526. spec2.channels = 2;
  527. spec2.freq = 44100;
  528. SDL_ClearError();
  529. SDLTest_AssertPass("Call to SDL_ClearError()");
  530. /* Set various invalid format inputs */
  531. SDL_strlcpy(message, "Invalid: ", 256);
  532. if (i & 1) {
  533. SDL_strlcat(message, " spec1.format", 256);
  534. spec1.format = 0;
  535. }
  536. if (i & 2) {
  537. SDL_strlcat(message, " spec1.channels", 256);
  538. spec1.channels = 0;
  539. }
  540. if (i & 4) {
  541. SDL_strlcat(message, " spec1.freq", 256);
  542. spec1.freq = 0;
  543. }
  544. if (i & 8) {
  545. SDL_strlcat(message, " spec2.format", 256);
  546. spec2.format = 0;
  547. }
  548. if (i & 16) {
  549. SDL_strlcat(message, " spec2.channels", 256);
  550. spec2.channels = 0;
  551. }
  552. if (i & 32) {
  553. SDL_strlcat(message, " spec2.freq", 256);
  554. spec2.freq = 0;
  555. }
  556. SDLTest_Log("%s", message);
  557. stream = SDL_CreateAudioStream(spec1.format, spec1.channels, spec1.freq,
  558. spec2.format, spec2.channels, spec2.freq);
  559. SDLTest_AssertPass("Call to SDL_CreateAudioStream(spec1 ==> spec2)");
  560. SDLTest_AssertCheck(stream == NULL, "Verify stream value; expected: NULL, got: %p", (void *)stream);
  561. error = SDL_GetError();
  562. SDLTest_AssertPass("Call to SDL_GetError()");
  563. SDLTest_AssertCheck(error != NULL && error[0] != '\0', "Validate that error message was not NULL or empty");
  564. SDL_DestroyAudioStream(stream);
  565. }
  566. SDL_ClearError();
  567. SDLTest_AssertPass("Call to SDL_ClearError()");
  568. return TEST_COMPLETED;
  569. }
  570. /**
  571. * \brief Checks current audio status.
  572. *
  573. * \sa SDL_GetAudioDeviceStatus
  574. */
  575. static int audio_getAudioStatus(void *arg)
  576. {
  577. SDL_AudioStatus result;
  578. /* Check current audio status */
  579. result = SDL_GetAudioDeviceStatus(g_audio_id);
  580. SDLTest_AssertPass("Call to SDL_GetAudioDeviceStatus(g_audio_id)");
  581. SDLTest_AssertCheck(result == SDL_AUDIO_STOPPED || result == SDL_AUDIO_PLAYING || result == SDL_AUDIO_PAUSED,
  582. "Verify returned value; expected: STOPPED (%i) | PLAYING (%i) | PAUSED (%i), got: %i",
  583. SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED, result);
  584. return TEST_COMPLETED;
  585. }
  586. /**
  587. * \brief Opens, checks current audio status, and closes a device.
  588. *
  589. * \sa SDL_GetAudioStatus
  590. */
  591. static int audio_openCloseAndGetAudioStatus(void *arg)
  592. {
  593. SDL_AudioStatus result;
  594. int i;
  595. int count;
  596. const char *device;
  597. SDL_AudioDeviceID id;
  598. SDL_AudioSpec desired, obtained;
  599. /* Get number of devices. */
  600. count = SDL_GetNumAudioDevices(0);
  601. SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
  602. if (count > 0) {
  603. for (i = 0; i < count; i++) {
  604. /* Get device name */
  605. device = SDL_GetAudioDeviceName(i, 0);
  606. SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
  607. SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
  608. if (device == NULL) {
  609. return TEST_ABORTED;
  610. }
  611. /* Set standard desired spec */
  612. desired.freq = 22050;
  613. desired.format = AUDIO_S16SYS;
  614. desired.channels = 2;
  615. desired.samples = 4096;
  616. desired.callback = audio_testCallback;
  617. desired.userdata = NULL;
  618. /* Open device */
  619. id = SDL_OpenAudioDevice(device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
  620. SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
  621. SDLTest_AssertCheck(id > 0, "Validate device ID; expected: > 0, got: %" SDL_PRIu32, id);
  622. if (id > 0) {
  623. /* Check device audio status */
  624. result = SDL_GetAudioDeviceStatus(id);
  625. SDLTest_AssertPass("Call to SDL_GetAudioDeviceStatus()");
  626. SDLTest_AssertCheck(result == SDL_AUDIO_STOPPED || result == SDL_AUDIO_PLAYING || result == SDL_AUDIO_PAUSED,
  627. "Verify returned value; expected: STOPPED (%i) | PLAYING (%i) | PAUSED (%i), got: %i",
  628. SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED, result);
  629. /* Close device again */
  630. SDL_CloseAudioDevice(id);
  631. SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
  632. }
  633. }
  634. } else {
  635. SDLTest_Log("No devices to test with");
  636. }
  637. return TEST_COMPLETED;
  638. }
  639. /**
  640. * \brief Locks and unlocks open audio device.
  641. *
  642. * \sa SDL_LockAudioDevice
  643. * \sa SDL_UnlockAudioDevice
  644. */
  645. static int audio_lockUnlockOpenAudioDevice(void *arg)
  646. {
  647. int i;
  648. int count;
  649. const char *device;
  650. SDL_AudioDeviceID id;
  651. SDL_AudioSpec desired, obtained;
  652. /* Get number of devices. */
  653. count = SDL_GetNumAudioDevices(0);
  654. SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
  655. if (count > 0) {
  656. for (i = 0; i < count; i++) {
  657. /* Get device name */
  658. device = SDL_GetAudioDeviceName(i, 0);
  659. SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
  660. SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
  661. if (device == NULL) {
  662. return TEST_ABORTED;
  663. }
  664. /* Set standard desired spec */
  665. desired.freq = 22050;
  666. desired.format = AUDIO_S16SYS;
  667. desired.channels = 2;
  668. desired.samples = 4096;
  669. desired.callback = audio_testCallback;
  670. desired.userdata = NULL;
  671. /* Open device */
  672. id = SDL_OpenAudioDevice(device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
  673. SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
  674. SDLTest_AssertCheck(id > 1, "Validate device ID; expected: > 0, got: %" SDL_PRIu32, id);
  675. if (id > 0) {
  676. /* Lock to protect callback */
  677. SDL_LockAudioDevice(id);
  678. SDLTest_AssertPass("SDL_LockAudioDevice(%" SDL_PRIu32 ")", id);
  679. /* Simulate callback processing */
  680. SDL_Delay(10);
  681. SDLTest_Log("Simulate callback processing - delay");
  682. /* Unlock again */
  683. SDL_UnlockAudioDevice(id);
  684. SDLTest_AssertPass("SDL_UnlockAudioDevice(%" SDL_PRIu32 ")", id);
  685. /* Close device again */
  686. SDL_CloseAudioDevice(id);
  687. SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
  688. }
  689. }
  690. } else {
  691. SDLTest_Log("No devices to test with");
  692. }
  693. return TEST_COMPLETED;
  694. }
  695. /**
  696. * \brief Convert audio using various conversion structures
  697. *
  698. * \sa SDL_CreateAudioStream
  699. */
  700. static int audio_convertAudio(void *arg)
  701. {
  702. SDL_AudioStream *stream;
  703. SDL_AudioSpec spec1;
  704. SDL_AudioSpec spec2;
  705. int c;
  706. char message[128];
  707. int i, ii, j, jj, k, kk;
  708. /* Iterate over bitmask that determines which parameters are modified in the conversion */
  709. for (c = 1; c < 8; c++) {
  710. SDL_strlcpy(message, "Changing:", 128);
  711. if (c & 1) {
  712. SDL_strlcat(message, " Format", 128);
  713. }
  714. if (c & 2) {
  715. SDL_strlcat(message, " Channels", 128);
  716. }
  717. if (c & 4) {
  718. SDL_strlcat(message, " Frequencies", 128);
  719. }
  720. SDLTest_Log("%s", message);
  721. /* All source conversions with random conversion targets */
  722. for (i = 0; i < g_numAudioFormats; i++) {
  723. for (j = 0; j < g_numAudioChannels; j++) {
  724. for (k = 0; k < g_numAudioFrequencies; k++) {
  725. spec1.format = g_audioFormats[i];
  726. spec1.channels = g_audioChannels[j];
  727. spec1.freq = g_audioFrequencies[k];
  728. /* Ensure we have a different target format */
  729. do {
  730. if (c & 1) {
  731. ii = SDLTest_RandomIntegerInRange(0, g_numAudioFormats - 1);
  732. } else {
  733. ii = 1;
  734. }
  735. if (c & 2) {
  736. jj = SDLTest_RandomIntegerInRange(0, g_numAudioChannels - 1);
  737. } else {
  738. jj = j;
  739. }
  740. if (c & 4) {
  741. kk = SDLTest_RandomIntegerInRange(0, g_numAudioFrequencies - 1);
  742. } else {
  743. kk = k;
  744. }
  745. } while ((i == ii) && (j == jj) && (k == kk));
  746. spec2.format = g_audioFormats[ii];
  747. spec2.channels = g_audioChannels[jj];
  748. spec2.freq = g_audioFrequencies[kk];
  749. stream = SDL_CreateAudioStream(spec1.format, spec1.channels, spec1.freq,
  750. spec2.format, spec2.channels, spec2.freq);
  751. SDLTest_AssertPass("Call to SDL_CreateAudioStream(format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i ==> format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i)",
  752. i, g_audioFormatsVerbose[i], spec1.format, j, spec1.channels, k, spec1.freq, ii, g_audioFormatsVerbose[ii], spec2.format, jj, spec2.channels, kk, spec2.freq);
  753. SDLTest_AssertCheck(stream != NULL, "Verify stream value; expected: != NULL, got: %p", (void *)stream);
  754. if (stream == NULL) {
  755. SDLTest_LogError("%s", SDL_GetError());
  756. } else {
  757. Uint8 *dst_buf = NULL, *src_buf = NULL;
  758. int dst_len = 0, src_len = 0, real_dst_len = 0;
  759. int l = 64;
  760. int src_samplesize, dst_samplesize;
  761. src_samplesize = (SDL_AUDIO_BITSIZE(spec1.format) / 8) * spec1.channels;
  762. dst_samplesize = (SDL_AUDIO_BITSIZE(spec2.format) / 8) * spec2.channels;
  763. /* Create some random data to convert */
  764. src_len = l * src_samplesize;
  765. SDLTest_Log("Creating dummy sample buffer of %i length (%i bytes)", l, src_len);
  766. src_buf = (Uint8 *)SDL_malloc(src_len);
  767. SDLTest_AssertCheck(dst_buf != NULL, "Check src data buffer to convert is not NULL");
  768. if (src_buf == NULL) {
  769. return TEST_ABORTED;
  770. }
  771. src_len = src_len & ~(src_samplesize - 1);
  772. dst_len = dst_samplesize * (src_len / src_samplesize);
  773. if (spec1.freq < spec2.freq) {
  774. const double mult = ((double)spec2.freq) / ((double)spec1.freq);
  775. dst_len *= (int) SDL_ceil(mult);
  776. }
  777. dst_len = dst_len & ~(dst_samplesize - 1);
  778. dst_buf = (Uint8 *)SDL_calloc(1, dst_len);
  779. SDLTest_AssertCheck(dst_buf != NULL, "Check dst data buffer to convert is not NULL");
  780. if (dst_buf == NULL) {
  781. return TEST_ABORTED;
  782. }
  783. /* Run the audio converter */
  784. if (SDL_PutAudioStreamData(stream, src_buf, src_len) < 0 ||
  785. SDL_FlushAudioStream(stream) < 0) {
  786. return TEST_ABORTED;
  787. }
  788. real_dst_len = SDL_GetAudioStreamData(stream, dst_buf, dst_len);
  789. SDLTest_AssertCheck(real_dst_len > 0, "Verify result value; expected: > 0; got: %i", real_dst_len);
  790. if (real_dst_len < 0) {
  791. return TEST_ABORTED;
  792. }
  793. SDL_DestroyAudioStream(stream);
  794. /* Free converted buffer */
  795. SDL_free(src_buf);
  796. SDL_free(dst_buf);
  797. }
  798. }
  799. }
  800. }
  801. }
  802. return TEST_COMPLETED;
  803. }
  804. /**
  805. * \brief Opens, checks current connected status, and closes a device.
  806. *
  807. * \sa SDL_AudioDeviceConnected
  808. */
  809. static int audio_openCloseAudioDeviceConnected(void *arg)
  810. {
  811. int result = -1;
  812. int i;
  813. int count;
  814. const char *device;
  815. SDL_AudioDeviceID id;
  816. SDL_AudioSpec desired, obtained;
  817. /* Get number of devices. */
  818. count = SDL_GetNumAudioDevices(0);
  819. SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
  820. if (count > 0) {
  821. for (i = 0; i < count; i++) {
  822. /* Get device name */
  823. device = SDL_GetAudioDeviceName(i, 0);
  824. SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
  825. SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
  826. if (device == NULL) {
  827. return TEST_ABORTED;
  828. }
  829. /* Set standard desired spec */
  830. desired.freq = 22050;
  831. desired.format = AUDIO_S16SYS;
  832. desired.channels = 2;
  833. desired.samples = 4096;
  834. desired.callback = audio_testCallback;
  835. desired.userdata = NULL;
  836. /* Open device */
  837. id = SDL_OpenAudioDevice(device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
  838. SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
  839. SDLTest_AssertCheck(id > 0, "Validate device ID; expected: > 0, got: %" SDL_PRIu32, id);
  840. if (id > 0) {
  841. /* TODO: enable test code when function is available in SDL3 */
  842. #ifdef AUDIODEVICECONNECTED_DEFINED
  843. /* Get connected status */
  844. result = SDL_AudioDeviceConnected(id);
  845. SDLTest_AssertPass("Call to SDL_AudioDeviceConnected()");
  846. #endif
  847. SDLTest_AssertCheck(result == 1, "Verify returned value; expected: 1; got: %i", result);
  848. /* Close device again */
  849. SDL_CloseAudioDevice(id);
  850. SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
  851. }
  852. }
  853. } else {
  854. SDLTest_Log("No devices to test with");
  855. }
  856. return TEST_COMPLETED;
  857. }
  858. /* ================= Test Case References ================== */
  859. /* Audio test cases */
  860. static const SDLTest_TestCaseReference audioTest1 = {
  861. audio_enumerateAndNameAudioDevices, "audio_enumerateAndNameAudioDevices", "Enumerate and name available audio devices (output and capture)", TEST_ENABLED
  862. };
  863. static const SDLTest_TestCaseReference audioTest2 = {
  864. audio_enumerateAndNameAudioDevicesNegativeTests, "audio_enumerateAndNameAudioDevicesNegativeTests", "Negative tests around enumeration and naming of audio devices.", TEST_ENABLED
  865. };
  866. static const SDLTest_TestCaseReference audioTest3 = {
  867. audio_printAudioDrivers, "audio_printAudioDrivers", "Checks available audio driver names.", TEST_ENABLED
  868. };
  869. static const SDLTest_TestCaseReference audioTest4 = {
  870. audio_printCurrentAudioDriver, "audio_printCurrentAudioDriver", "Checks current audio driver name with initialized audio.", TEST_ENABLED
  871. };
  872. static const SDLTest_TestCaseReference audioTest5 = {
  873. audio_buildAudioStream, "audio_buildAudioStream", "Builds various audio conversion structures.", TEST_ENABLED
  874. };
  875. static const SDLTest_TestCaseReference audioTest6 = {
  876. audio_buildAudioStreamNegative, "audio_buildAudioStreamNegative", "Checks calls with invalid input to SDL_CreateAudioStream", TEST_ENABLED
  877. };
  878. static const SDLTest_TestCaseReference audioTest7 = {
  879. audio_getAudioStatus, "audio_getAudioStatus", "Checks current audio status.", TEST_ENABLED
  880. };
  881. static const SDLTest_TestCaseReference audioTest8 = {
  882. audio_openCloseAndGetAudioStatus, "audio_openCloseAndGetAudioStatus", "Opens and closes audio device and get audio status.", TEST_ENABLED
  883. };
  884. static const SDLTest_TestCaseReference audioTest9 = {
  885. audio_lockUnlockOpenAudioDevice, "audio_lockUnlockOpenAudioDevice", "Locks and unlocks an open audio device.", TEST_ENABLED
  886. };
  887. /* TODO: enable test when SDL_ConvertAudio segfaults on cygwin have been fixed.
  888. * TODO: re-check, since this was changer to AudioStream */
  889. /* For debugging, test case can be run manually using --filter audio_convertAudio */
  890. static const SDLTest_TestCaseReference audioTest10 = {
  891. audio_convertAudio, "audio_convertAudio", "Convert audio using available formats.", TEST_DISABLED
  892. };
  893. /* TODO: enable test when SDL_AudioDeviceConnected has been implemented. */
  894. static const SDLTest_TestCaseReference audioTest11 = {
  895. audio_openCloseAudioDeviceConnected, "audio_openCloseAudioDeviceConnected", "Opens and closes audio device and get connected status.", TEST_DISABLED
  896. };
  897. static const SDLTest_TestCaseReference audioTest12 = {
  898. audio_quitInitAudioSubSystem, "audio_quitInitAudioSubSystem", "Quit and re-init audio subsystem.", TEST_ENABLED
  899. };
  900. static const SDLTest_TestCaseReference audioTest13 = {
  901. audio_initQuitAudio, "audio_initQuitAudio", "Init and quit audio drivers directly.", TEST_ENABLED
  902. };
  903. static const SDLTest_TestCaseReference audioTest14 = {
  904. audio_initOpenCloseQuitAudio, "audio_initOpenCloseQuitAudio", "Cycle through init, open, close and quit with various audio specs.", TEST_ENABLED
  905. };
  906. static const SDLTest_TestCaseReference audioTest15 = {
  907. audio_pauseUnpauseAudio, "audio_pauseUnpauseAudio", "Pause and Unpause audio for various audio specs while testing callback.", TEST_ENABLED
  908. };
  909. /* Sequence of Audio test cases */
  910. static const SDLTest_TestCaseReference *audioTests[] = {
  911. &audioTest1, &audioTest2, &audioTest3, &audioTest4, &audioTest5, &audioTest6,
  912. &audioTest7, &audioTest8, &audioTest9, &audioTest10, &audioTest11,
  913. &audioTest12, &audioTest13, &audioTest14, &audioTest15, NULL
  914. };
  915. /* Audio test suite (global) */
  916. SDLTest_TestSuiteReference audioTestSuite = {
  917. "Audio",
  918. audioSetUp,
  919. audioTests,
  920. audioTearDown
  921. };