Prechádzať zdrojové kódy

test: Update testautomation_audio for SDL3 audio API.

Ryan C. Gordon 1 rok pred
rodič
commit
11dfc4d737
1 zmenil súbory, kde vykonal 36 pridanie a 260 odobranie
  1. 36 260
      test/testautomation_audio.c

+ 36 - 260
test/testautomation_audio.c

@@ -176,28 +176,22 @@ static int audio_initOpenCloseQuitAudio(void *arg)
                 desired.freq = 22050;
                 desired.format = SDL_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 = SDL_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_OpenAudioDevice(NULL, 0, &desired, NULL, 0);
+                result = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &desired);
                 if (k == 0) {
                     g_audio_id = result;
                 }
-                SDLTest_AssertPass("Call to SDL_OpenAudioDevice(NULL, 0, desired_spec_%d, NULL, 0), call %d", j, k + 1);
+                SDLTest_AssertPass("Call to SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, desired_spec_%d), call %d", j, k + 1);
                 SDLTest_AssertCheck(result > 0, "Verify return value; expected: > 0, got: %d", result);
             }
 
@@ -269,9 +263,6 @@ static int audio_pauseUnpauseAudio(void *arg)
                 desired.freq = 22050;
                 desired.format = SDL_AUDIO_S16SYS;
                 desired.channels = 2;
-                desired.samples = 4096;
-                desired.callback = audio_testCallback;
-                desired.userdata = NULL;
                 break;
 
             case 1:
@@ -279,18 +270,16 @@ static int audio_pauseUnpauseAudio(void *arg)
                 desired.freq = 48000;
                 desired.format = SDL_AUDIO_F32SYS;
                 desired.channels = 2;
-                desired.samples = 2048;
-                desired.callback = audio_testCallback;
-                desired.userdata = NULL;
                 break;
             }
 
             /* Call Open */
-            g_audio_id = SDL_OpenAudioDevice(NULL, 0, &desired, NULL, 0);
+            g_audio_id = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &desired);
             result = g_audio_id;
-            SDLTest_AssertPass("Call to SDL_OpenAudioDevice(NULL, 0, desired_spec_%d, NULL, 0)", j);
+            SDLTest_AssertPass("Call to SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, desired_spec_%d)", j);
             SDLTest_AssertCheck(result > 0, "Verify return value; expected > 0 got: %d", result);
 
+#if 0  /* !!! FIXME: maybe update this? */
             /* Start and stop audio multiple times */
             for (l = 0; l < 3; l++) {
                 SDLTest_Log("Pause/Unpause iteration: %d", l + 1);
@@ -332,6 +321,7 @@ static int audio_pauseUnpauseAudio(void *arg)
                 SDL_Delay(totalDelay + 10);
                 SDLTest_AssertCheck(originalCounter == g_audio_testCallbackCounter, "Verify callback counter; expected: %d, got: %d", originalCounter, g_audio_testCallbackCounter);
             }
+#endif
 
             /* Call Close */
             SDL_CloseAudioDevice(g_audio_id);
@@ -360,49 +350,32 @@ static int audio_enumerateAndNameAudioDevices(void *arg)
 {
     int t, tt;
     int i, n, nn;
-    const char *name, *nameAgain;
+    char *name, *nameAgain;
+    SDL_AudioDeviceID *devices = NULL;
 
     /* Iterate over types: t=0 output device, t=1 input/capture device */
     for (t = 0; t < 2; t++) {
-
         /* Get number of devices. */
-        n = SDL_GetNumAudioDevices(t);
-        SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(%i)", t);
+        devices = (t) ? SDL_GetAudioCaptureDevices(&n) : SDL_GetAudioOutputDevices(&n);
+        SDLTest_AssertPass("Call to SDL_GetAudio%sDevices(%i)", (t) ? "Capture" : "Output", t);
         SDLTest_Log("Number of %s devices < 0, reported as %i", (t) ? "capture" : "output", n);
         SDLTest_AssertCheck(n >= 0, "Validate result is >= 0, got: %i", n);
 
-        /* Variation of non-zero type */
-        if (t == 1) {
-            tt = t + SDLTest_RandomIntegerInRange(1, 10);
-            nn = SDL_GetNumAudioDevices(tt);
-            SDLTest_AssertCheck(n == nn, "Verify result from SDL_GetNumAudioDevices(%i), expected same number of audio devices %i, got %i", tt, n, nn);
-            nn = SDL_GetNumAudioDevices(-tt);
-            SDLTest_AssertCheck(n == nn, "Verify result from SDL_GetNumAudioDevices(%i), expected same number of audio devices %i, got %i", -tt, n, nn);
-        }
-
         /* List devices. */
         if (n > 0) {
+            SDLTest_AssertCheck(devices != NULL, "Validate devices is not NULL if n > 0");
             for (i = 0; i < n; i++) {
-                name = SDL_GetAudioDeviceName(i, t);
-                SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
-                SDLTest_AssertCheck(name != NULL, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not NULL", i, t);
+                name = SDL_GetAudioDeviceName(devices[i]);
+                SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i)", i);
+                SDLTest_AssertCheck(name != NULL, "Verify result from SDL_GetAudioDeviceName(%i) is not NULL", i);
                 if (name != NULL) {
-                    SDLTest_AssertCheck(name[0] != '\0', "verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, t, name);
-                    if (t == 1) {
-                        /* Also try non-zero type */
-                        tt = t + SDLTest_RandomIntegerInRange(1, 10);
-                        nameAgain = SDL_GetAudioDeviceName(i, tt);
-                        SDLTest_AssertCheck(nameAgain != NULL, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not NULL", i, tt);
-                        if (nameAgain != NULL) {
-                            SDLTest_AssertCheck(nameAgain[0] != '\0', "Verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, tt, nameAgain);
-                            SDLTest_AssertCheck(SDL_strcmp(name, nameAgain) == 0,
-                                                "Verify SDL_GetAudioDeviceName(%i, %i) and SDL_GetAudioDeviceName(%i %i) return the same string",
-                                                i, t, i, tt);
-                        }
-                    }
+                    SDLTest_AssertCheck(name[0] != '\0', "verify result from SDL_GetAudioDeviceName(%i) is not empty, got: '%s'", i, name);
+                    SDL_free(name);
                 }
             }
         }
+
+        SDL_free(devices);
     }
 
     return TEST_COMPLETED;
@@ -416,42 +389,7 @@ static int audio_enumerateAndNameAudioDevices(void *arg)
  */
 static int audio_enumerateAndNameAudioDevicesNegativeTests(void *arg)
 {
-    int t;
-    int i, j, no, nc;
-    const char *name;
-
-    /* Get number of devices. */
-    no = SDL_GetNumAudioDevices(0);
-    SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
-    nc = SDL_GetNumAudioDevices(1);
-    SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(1)");
-
-    /* Invalid device index when getting name */
-    for (t = 0; t < 2; t++) {
-        /* Negative device index */
-        i = SDLTest_RandomIntegerInRange(-10, -1);
-        name = SDL_GetAudioDeviceName(i, t);
-        SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
-        SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result NULL, expected NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
-
-        /* Device index past range */
-        for (j = 0; j < 3; j++) {
-            i = (t) ? nc + j : no + j;
-            name = SDL_GetAudioDeviceName(i, t);
-            SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
-            SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result, expected: NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
-        }
-
-        /* Capture index past capture range but within output range */
-        if ((no > 0) && (no > nc) && (t == 1)) {
-            i = no - 1;
-            name = SDL_GetAudioDeviceName(i, t);
-            SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
-            SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result, expected: NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
-        }
-    }
-
-    return TEST_COMPLETED;
+    return TEST_COMPLETED;  /* nothing in here atm since these interfaces changed in SDL3. */
 }
 
 /**
@@ -532,8 +470,7 @@ static int audio_buildAudioStream(void *arg)
     spec1.format = SDL_AUDIO_S16LSB;
     spec1.channels = 2;
     spec1.freq = 22050;
-    stream = SDL_CreateAudioStream(spec1.format, spec1.channels, spec1.freq,
-                                   spec1.format, spec1.channels, spec1.freq);
+    stream = SDL_CreateAudioStream(&spec1, &spec1);
     SDLTest_AssertPass("Call to SDL_CreateAudioStream(spec1 ==> spec1)");
     SDLTest_AssertCheck(stream != NULL, "Verify stream value; expected: != NULL, got: %p", (void *)stream);
     SDL_DestroyAudioStream(stream);
@@ -545,8 +482,7 @@ static int audio_buildAudioStream(void *arg)
     spec2.format = SDL_AUDIO_S16LSB;
     spec2.channels = 2;
     spec2.freq = 44100;
-    stream = SDL_CreateAudioStream(spec1.format, spec1.channels, spec1.freq,
-                                   spec2.format, spec2.channels, spec2.freq);
+    stream = SDL_CreateAudioStream(&spec1, &spec2);
     SDLTest_AssertPass("Call to SDL_CreateAudioStream(spec1 ==> spec2)");
     SDLTest_AssertCheck(stream != NULL, "Verify stream value; expected: != NULL, got: %p", (void *)stream);
     SDL_DestroyAudioStream(stream);
@@ -564,8 +500,7 @@ static int audio_buildAudioStream(void *arg)
                 spec2.format = g_audioFormats[ii];
                 spec2.channels = g_audioChannels[jj];
                 spec2.freq = g_audioFrequencies[kk];
-                stream = SDL_CreateAudioStream(spec1.format, spec1.channels, spec1.freq,
-                                               spec2.format, spec2.channels, spec2.freq);
+                stream = SDL_CreateAudioStream(&spec1, &spec2);
 
                 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)",
                                    i, g_audioFormatsVerbose[i], spec1.format, j, spec1.channels, k, spec1.freq, ii, g_audioFormatsVerbose[ii], spec2.format, jj, spec2.channels, kk, spec2.freq);
@@ -646,8 +581,7 @@ static int audio_buildAudioStreamNegative(void *arg)
             spec2.freq = 0;
         }
         SDLTest_Log("%s", message);
-        stream = SDL_CreateAudioStream(spec1.format, spec1.channels, spec1.freq,
-                                       spec2.format, spec2.channels, spec2.freq);
+        stream = SDL_CreateAudioStream(&spec1, &spec2);
         SDLTest_AssertPass("Call to SDL_CreateAudioStream(spec1 ==> spec2)");
         SDLTest_AssertCheck(stream == NULL, "Verify stream value; expected: NULL, got: %p", (void *)stream);
         error = SDL_GetError();
@@ -669,16 +603,7 @@ static int audio_buildAudioStreamNegative(void *arg)
  */
 static int audio_getAudioStatus(void *arg)
 {
-    SDL_AudioStatus result;
-
-    /* Check current audio status */
-    result = SDL_GetAudioDeviceStatus(g_audio_id);
-    SDLTest_AssertPass("Call to SDL_GetAudioDeviceStatus(g_audio_id)");
-    SDLTest_AssertCheck(result == SDL_AUDIO_STOPPED || result == SDL_AUDIO_PLAYING || result == SDL_AUDIO_PAUSED,
-                        "Verify returned value; expected: STOPPED (%i) | PLAYING (%i) | PAUSED (%i), got: %i",
-                        SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED, result);
-
-    return TEST_COMPLETED;
+    return TEST_COMPLETED;  /* no longer a thing in SDL3. */
 }
 
 /**
@@ -688,57 +613,7 @@ static int audio_getAudioStatus(void *arg)
  */
 static int audio_openCloseAndGetAudioStatus(void *arg)
 {
-    SDL_AudioStatus result;
-    int i;
-    int count;
-    const char *device;
-    SDL_AudioDeviceID id;
-    SDL_AudioSpec desired, obtained;
-
-    /* Get number of devices. */
-    count = SDL_GetNumAudioDevices(0);
-    SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
-    if (count > 0) {
-        for (i = 0; i < count; i++) {
-            /* Get device name */
-            device = SDL_GetAudioDeviceName(i, 0);
-            SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
-            SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
-            if (device == NULL) {
-                return TEST_ABORTED;
-            }
-
-            /* Set standard desired spec */
-            desired.freq = 22050;
-            desired.format = SDL_AUDIO_S16SYS;
-            desired.channels = 2;
-            desired.samples = 4096;
-            desired.callback = audio_testCallback;
-            desired.userdata = NULL;
-
-            /* Open device */
-            id = SDL_OpenAudioDevice(device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
-            SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
-            SDLTest_AssertCheck(id > 0, "Validate device ID; expected: > 0, got: %" SDL_PRIu32, id);
-            if (id > 0) {
-
-                /* Check device audio status */
-                result = SDL_GetAudioDeviceStatus(id);
-                SDLTest_AssertPass("Call to SDL_GetAudioDeviceStatus()");
-                SDLTest_AssertCheck(result == SDL_AUDIO_STOPPED || result == SDL_AUDIO_PLAYING || result == SDL_AUDIO_PAUSED,
-                                    "Verify returned value; expected: STOPPED (%i) | PLAYING (%i) | PAUSED (%i), got: %i",
-                                    SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED, result);
-
-                /* Close device again */
-                SDL_CloseAudioDevice(id);
-                SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
-            }
-        }
-    } else {
-        SDLTest_Log("No devices to test with");
-    }
-
-    return TEST_COMPLETED;
+    return TEST_COMPLETED;  /* not a thing in SDL3. */
 }
 
 /**
@@ -749,60 +624,7 @@ static int audio_openCloseAndGetAudioStatus(void *arg)
  */
 static int audio_lockUnlockOpenAudioDevice(void *arg)
 {
-    int i;
-    int count;
-    const char *device;
-    SDL_AudioDeviceID id;
-    SDL_AudioSpec desired, obtained;
-
-    /* Get number of devices. */
-    count = SDL_GetNumAudioDevices(0);
-    SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
-    if (count > 0) {
-        for (i = 0; i < count; i++) {
-            /* Get device name */
-            device = SDL_GetAudioDeviceName(i, 0);
-            SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
-            SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
-            if (device == NULL) {
-                return TEST_ABORTED;
-            }
-
-            /* Set standard desired spec */
-            desired.freq = 22050;
-            desired.format = SDL_AUDIO_S16SYS;
-            desired.channels = 2;
-            desired.samples = 4096;
-            desired.callback = audio_testCallback;
-            desired.userdata = NULL;
-
-            /* Open device */
-            id = SDL_OpenAudioDevice(device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
-            SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
-            SDLTest_AssertCheck(id > 1, "Validate device ID; expected: > 0, got: %" SDL_PRIu32, id);
-            if (id > 0) {
-                /* Lock to protect callback */
-                SDL_LockAudioDevice(id);
-                SDLTest_AssertPass("SDL_LockAudioDevice(%" SDL_PRIu32 ")", id);
-
-                /* Simulate callback processing */
-                SDL_Delay(10);
-                SDLTest_Log("Simulate callback processing - delay");
-
-                /* Unlock again */
-                SDL_UnlockAudioDevice(id);
-                SDLTest_AssertPass("SDL_UnlockAudioDevice(%" SDL_PRIu32 ")", id);
-
-                /* Close device again */
-                SDL_CloseAudioDevice(id);
-                SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
-            }
-        }
-    } else {
-        SDLTest_Log("No devices to test with");
-    }
-
-    return TEST_COMPLETED;
+    return TEST_COMPLETED;  /* not a thing in SDL3 */
 }
 
 /**
@@ -862,8 +684,7 @@ static int audio_convertAudio(void *arg)
                     spec2.channels = g_audioChannels[jj];
                     spec2.freq = g_audioFrequencies[kk];
 
-                    stream = SDL_CreateAudioStream(spec1.format, spec1.channels, spec1.freq,
-                                                   spec2.format, spec2.channels, spec2.freq);
+                    stream = SDL_CreateAudioStream(&spec1, &spec2);
                     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)",
                                        i, g_audioFormatsVerbose[i], spec1.format, j, spec1.channels, k, spec1.freq, ii, g_audioFormatsVerbose[ii], spec2.format, jj, spec2.channels, kk, spec2.freq);
                     SDLTest_AssertCheck(stream != NULL, "Verify stream value; expected: != NULL, got: %p", (void *)stream);
@@ -936,59 +757,7 @@ static int audio_convertAudio(void *arg)
  */
 static int audio_openCloseAudioDeviceConnected(void *arg)
 {
-    int result = -1;
-    int i;
-    int count;
-    const char *device;
-    SDL_AudioDeviceID id;
-    SDL_AudioSpec desired, obtained;
-
-    /* Get number of devices. */
-    count = SDL_GetNumAudioDevices(0);
-    SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
-    if (count > 0) {
-        for (i = 0; i < count; i++) {
-            /* Get device name */
-            device = SDL_GetAudioDeviceName(i, 0);
-            SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
-            SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
-            if (device == NULL) {
-                return TEST_ABORTED;
-            }
-
-            /* Set standard desired spec */
-            desired.freq = 22050;
-            desired.format = SDL_AUDIO_S16SYS;
-            desired.channels = 2;
-            desired.samples = 4096;
-            desired.callback = audio_testCallback;
-            desired.userdata = NULL;
-
-            /* Open device */
-            id = SDL_OpenAudioDevice(device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
-            SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
-            SDLTest_AssertCheck(id > 0, "Validate device ID; expected: > 0, got: %" SDL_PRIu32, id);
-            if (id > 0) {
-
-                /* TODO: enable test code when function is available in SDL3 */
-
-#ifdef AUDIODEVICECONNECTED_DEFINED
-                /* Get connected status */
-                result = SDL_AudioDeviceConnected(id);
-                SDLTest_AssertPass("Call to SDL_AudioDeviceConnected()");
-#endif
-                SDLTest_AssertCheck(result == 1, "Verify returned value; expected: 1; got: %i", result);
-
-                /* Close device again */
-                SDL_CloseAudioDevice(id);
-                SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
-            }
-        }
-    } else {
-        SDLTest_Log("No devices to test with");
-    }
-
-    return TEST_COMPLETED;
+    return TEST_COMPLETED;  /* not a thing in SDL3. */
 }
 
 static double sine_wave_sample(const Sint64 idx, const Sint64 rate, const Sint64 freq, const double phase)
@@ -1040,6 +809,7 @@ static int audio_resampleLoss(void *arg)
     const int len_in = frames_in * (int)sizeof(float);
     const int len_target = frames_target * (int)sizeof(float);
 
+    SDL_AudioSpec tmpspec1, tmpspec2;
     Uint64 tick_beg = 0;
     Uint64 tick_end = 0;
     int i = 0;
@@ -1056,7 +826,13 @@ static int audio_resampleLoss(void *arg)
     SDLTest_AssertPass("Test resampling of %i s %i Hz %f phase sine wave from sampling rate of %i Hz to %i Hz",
                        spec->time, spec->freq, spec->phase, spec->rate_in, spec->rate_out);
 
-    stream = SDL_CreateAudioStream(SDL_AUDIO_F32, 1, spec->rate_in, SDL_AUDIO_F32, 1, spec->rate_out);
+    tmpspec1.format = SDL_AUDIO_F32;
+    tmpspec1.channels = 1;
+    tmpspec1.freq = spec->rate_in;
+    tmpspec2.format = SDL_AUDIO_F32;
+    tmpspec2.channels = 1;
+    tmpspec2.freq = spec->rate_out;
+    stream = SDL_CreateAudioStream(&tmpspec1, &tmpspec2);
     SDLTest_AssertPass("Call to SDL_CreateAudioStream(SDL_AUDIO_F32, 1, %i, SDL_AUDIO_F32, 1, %i)", spec->rate_in, spec->rate_out);
     SDLTest_AssertCheck(stream != NULL, "Expected SDL_CreateAudioStream to succeed.");
     if (stream == NULL) {